:root {
  --bg: #fff8ee;
  --ink: #2b2d42;
  --muted: #6b6f86;
  --card: #ffffff;
  --brand: #5b6cff;
  --ok: #22b07d;
  --warn: #ff9f1c;
  --bad: #ef476f;
  --kid: #5b6cff;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.08), 0 10px 24px rgba(43, 45, 66, 0.1);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
#app { min-height: 100%; padding: max(12px, env(safe-area-inset-top)) 16px 24px; max-width: 1100px; margin: 0 auto; }
h1, h2, h3 { margin: 0.3em 0; }
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); }
.center { display: flex; align-items: center; justify-content: center; min-height: 60vh; flex-direction: column; gap: 16px; text-align: center; }
.big { font-size: 4rem; }
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; font-weight: 700; font-size: 1.1rem; border: 0; cursor: pointer;
  border-radius: 16px; padding: 14px 20px; min-height: 52px; min-width: 52px;
  background: var(--brand); color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.06s; touch-action: manipulation; user-select: none;
}
button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18); }
button:disabled { opacity: 0.45; cursor: default; }
button.secondary { background: #fff; color: var(--ink); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12), inset 0 0 0 2px #e4e4ee; }
button.ghost { background: transparent; color: var(--ink); box-shadow: none; }
button.danger { background: var(--bad); }
button.ok { background: var(--ok); }
button.icon { font-size: 1.8rem; padding: 8px 14px; }
input, select, textarea {
  font: inherit; font-size: 1.05rem; padding: 12px 14px; border-radius: 12px; border: 2px solid #dedfea; background: #fff; min-height: 48px; color: var(--ink);
}
input:focus, select:focus { outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
label { font-weight: 600; display: flex; flex-direction: column; gap: 6px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.topbar .title { font-size: 1.4rem; font-weight: 800; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* kid picker */
.kids { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; margin-top: 12px; }
.kid-card { background: var(--c); color: #fff; border-radius: 28px; padding: 22px 16px; text-align: center; box-shadow: 0 8px 0 rgba(0, 0, 0, 0.15); min-height: 220px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; font-size: 1.6rem; }
.kid-card .avatar { font-size: 5rem; line-height: 1; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.15)); }
.kid-card .name { font-weight: 800; }
.kid-card .mini { font-size: 1rem; opacity: 0.95; font-weight: 600; }

/* progress ring */
.ring { position: relative; width: var(--size, 84px); height: var(--size, 84px); flex: none; }
.ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.ring .lbl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; font-weight: 800; font-size: calc(var(--size, 84px) * 0.2); line-height: 1.05; text-align: center; }
.ring .lbl small { font-size: 0.55em; font-weight: 600; color: var(--muted); }

/* kid home */
.hero { display: flex; gap: 16px; align-items: center; background: var(--kid); color: #fff; border-radius: 28px; padding: 16px 20px; box-shadow: var(--shadow); }
.hero .avatar { font-size: 3.4rem; }
.hero .name { font-size: 1.8rem; font-weight: 800; }
.hero .ring .lbl small { color: rgba(255, 255, 255, 0.85); }
.stat-pill { background: rgba(255, 255, 255, 0.25); border-radius: 999px; padding: 6px 12px; font-weight: 700; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 18px; margin-top: 18px; }
.tile { background: #fff; border-radius: 28px; box-shadow: var(--shadow); padding: 18px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--ink); min-height: 170px; justify-content: center; }
.tile .ico { font-size: 4.2rem; line-height: 1.1; }
.tile .lbl { font-size: 1.1rem; font-weight: 800; }
.tile:nth-child(6n + 1) { background: #ffe3ef; } .tile:nth-child(6n + 2) { background: #e2f2ff; } .tile:nth-child(6n + 3) { background: #fff1cc; }
.tile:nth-child(6n + 4) { background: #dcf8ec; } .tile:nth-child(6n + 5) { background: #ece4ff; } .tile:nth-child(6n) { background: #ffe6d6; }

/* games */
.game { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.prompt { display: flex; align-items: center; gap: 16px; justify-content: center; flex-wrap: wrap; }
.prompt .target { font-size: clamp(6rem, 22vw, 11rem); font-weight: 800; line-height: 1; color: var(--kid); font-family: "Comic Sans MS", "Segoe UI", Roboto, sans-serif; }
.prompt .pic { font-size: clamp(6rem, 22vw, 10rem); line-height: 1; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 16px; width: 100%; max-width: 760px; }
.choice { font-size: clamp(3rem, 10vw, 5rem); min-height: 130px; background: #fff; color: var(--ink); border-radius: 26px; font-family: "Comic Sans MS", "Segoe UI", Roboto, sans-serif; }
.choice.word { font-size: clamp(2rem, 7vw, 3rem); }
.choice.right { background: var(--ok); color: #fff; animation: pop 0.4s; }
.choice.wrong { animation: shake 0.4s; background: #ffe0e6; }
.stars { font-size: 2rem; letter-spacing: 4px; min-height: 2.4rem; }
.slots { display: flex; gap: 12px; justify-content: center; }
.slot { width: 90px; height: 110px; border-radius: 18px; border: 4px dashed #c9cbe0; display: flex; align-items: center; justify-content: center; font-size: 4rem; font-weight: 800; background: #fff; font-family: "Comic Sans MS", "Segoe UI", Roboto, sans-serif; }
.slot.filled { border-style: solid; border-color: var(--ok); color: var(--ok); }
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.celebrate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; background: rgba(255, 248, 238, 0.94); z-index: 50; font-size: 2rem; font-weight: 800; gap: 18px; text-align: center; padding: 20px; }
.celebrate .burst { font-size: 6rem; animation: pop 0.8s infinite; }
.confetti { position: fixed; top: -20px; font-size: 2rem; z-index: 60; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

/* books */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; margin-top: 12px; }
.book { background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 10px; color: var(--ink); text-align: left; display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.95rem; min-height: 0; }
.book .cover { aspect-ratio: 2/3; border-radius: 12px; background: linear-gradient(135deg, var(--kid), #ffb4d0); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.1rem; padding: 10px; text-align: center; overflow: hidden; font-weight: 800; }
.book .cover img { width: 100%; height: 100%; object-fit: cover; }
.bar { height: 8px; background: #eee; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.result { display: flex; gap: 12px; align-items: center; padding: 12px; border-bottom: 1px solid #eee; }
.result .t { flex: 1; min-width: 0; }
.result .t b { display: block; }

/* reader */
.reader { display: flex; flex-direction: column; gap: 14px; min-height: calc(100vh - 40px); }
.page { background: #fffdf8; border-radius: 24px; box-shadow: var(--shadow); padding: clamp(18px, 4vw, 40px); font-size: clamp(1.5rem, 3.4vw, 2.3rem); line-height: 1.75; font-family: Georgia, "Times New Roman", serif; flex: 1; white-space: pre-wrap; overflow-wrap: break-word; }
.page .ch { font-family: inherit; font-size: 0.7em; color: var(--muted); display: block; margin-bottom: 8px; white-space: normal; }
.w { border-radius: 8px; padding: 0 2px; transition: background 0.15s, color 0.15s; cursor: pointer; }
.w.cur { box-shadow: inset 0 -4px 0 var(--brand); }
.w.tent { background: #e5f7ee; }
.w.ok { background: #c8f2dc; color: #105c3e; }
.w.help { background: #ffe2a8; color: #7a4a00; }
.w.helping { background: var(--warn); color: #fff; animation: pop 0.5s; }
.helpbox { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); background: #fff; border-radius: 26px; box-shadow: var(--shadow); padding: 20px 34px; font-size: clamp(2.5rem, 8vw, 4.5rem); font-weight: 800; font-family: Georgia, serif; z-index: 40; color: #7a4a00; border: 5px solid var(--warn); }
.controls { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; position: sticky; bottom: 8px; }
.mic { font-size: 1.4rem; padding: 18px 28px; min-width: 180px; }
.mic.on { background: var(--bad); }
.meter { width: 80px; height: 14px; background: #eee; border-radius: 99px; overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: var(--ok); transition: width 0.08s; }
.engine-note { font-size: 0.9rem; color: var(--muted); text-align: center; }
.engine-note.cloud { color: var(--bad); font-weight: 700; }

/* parent */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 2px #e4e4ee; }
.tabs button.active { background: var(--brand); color: #fff; box-shadow: none; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid #eee; vertical-align: middle; }
th { font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.weekbars { display: flex; gap: 6px; align-items: flex-end; height: 80px; }
.weekbars div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 0.7rem; color: var(--muted); gap: 4px; }
.weekbars i { display: block; width: 100%; background: var(--kid); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.weekbars i.met { background: var(--ok); }
.pinpad { display: grid; grid-template-columns: repeat(3, 84px); gap: 14px; justify-content: center; }
.pinpad button { font-size: 2rem; min-height: 84px; background: #fff; color: var(--ink); }
.pindots { font-size: 2.4rem; letter-spacing: 12px; min-height: 3rem; }
.kidchips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 10px; min-height: 40px; font-size: 0.95rem; border-radius: 999px; background: #fff; color: var(--ink); box-shadow: inset 0 0 0 2px #e4e4ee; }
.chip.on { background: var(--c, var(--brand)); color: #fff; box-shadow: none; }
.warnbox { background: #fff3f5; border: 2px solid #ffc2cf; border-radius: 14px; padding: 12px; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(200%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 600; transition: transform 0.25s, opacity 0.25s; z-index: 100; max-width: 92vw; opacity: 0; pointer-events: none; }
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

@media (max-width: 560px) {
  .kids { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kid-card { min-height: 170px; font-size: 1.25rem; }
  .kid-card .avatar { font-size: 3.6rem; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .choices { grid-template-columns: 1fr 1fr; }
  .slot { width: 66px; height: 86px; font-size: 3rem; }
  .pinpad { grid-template-columns: repeat(3, 72px); }
}

/* ---- phonograms (Logic of English-style) */
.phon { font-family: "Comic Sans MS", "Segoe UI", Roboto, sans-serif; }
.phon.multi { text-decoration: underline; text-decoration-thickness: 0.08em; text-underline-offset: 0.22em; text-decoration-skip-ink: none; } /* multi-letter phonograms are underlined */
.bingo { display: grid; gap: 12px; width: 100%; max-width: 620px; }
.bingo .choice { min-height: 96px; font-size: clamp(2.2rem, 7vw, 3.4rem); }
.bingo .covered { background: var(--ok); color: #fff; }
.bingo .covered::after { content: ' ⭐'; font-size: 0.5em; }
.mem-card { background: #ece4ff; }
.mem-card.up { background: #fff; }
.board { width: 100%; max-width: 860px; aspect-ratio: 900 / 420; border-radius: 22px; box-shadow: var(--shadow); background: #fff; touch-action: none; }
.board.wrong { animation: shake 0.4s; }
.blend-tile { min-width: 110px; }
.blend-tile.silent { opacity: 0.45; }
.slot .phon { font-size: 0.8em; }
.slot { width: auto; min-width: 90px; padding: 0 8px; }

/* Read Aloud: missed word broken into phonograms */
.helpbox .seg { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.helpbox .seg span { font-size: 0.55em; padding: 2px 10px; border-radius: 10px; background: #fff4dc; border: 2px solid #ffd58a; }
.helpbox .seg span.silent { opacity: 0.45; border-style: dashed; }
.helpbox .seg span.multi { text-decoration: underline; text-underline-offset: 0.2em; text-decoration-skip-ink: none; }
.helpbox .rule { font-family: "Segoe UI", Roboto, sans-serif; font-size: 1.05rem; font-weight: 600; color: var(--ink); margin-top: 12px; max-width: 70vw; text-align: center; }
.helpbox .rule b { color: var(--brand); }

/* parent: phonogram mastery grid */
.phon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.ptile { background: #fff; border-radius: 14px; padding: 8px; box-shadow: inset 0 0 0 2px #e4e4ee; color: var(--ink); min-height: 92px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 0.8rem; font-weight: 600; }
.ptile .phon { font-size: 1.7rem; font-weight: 800; }
.ptile.st-learning { box-shadow: inset 0 0 0 3px #ffc94d; background: #fff9e8; }
.ptile.st-mastered { box-shadow: inset 0 0 0 3px var(--ok); background: #e9f9f1; }
.ptile.practicing { outline: 4px solid var(--brand); outline-offset: -4px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-right: 4px; }
.rule-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid #eee; flex-direction: row; font-weight: 500; }
.rule-row input { min-height: auto; margin-top: 4px; }
