:root {
  --bg: #f6f3ff;
  --bg2: #fff7ec;
  --card: #ffffff;
  --ink: #1f1b3a;
  --ink2: #5d5878;
  --ink3: #9a95b3;
  --line: #e7e3f5;
  --accent: #5b47e0;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, white);
  --good: #12a46b;
  --good-soft: #dcf6ea;
  --bad: #e2445c;
  --bad-soft: #fde4e8;
  --gold: #f5b301;
  --r: 22px;
  --shadow: 0 1px 0 rgba(31, 27, 58, .04), 0 8px 24px -12px rgba(31, 27, 58, .18);
  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: var(--font); color: var(--ink); font-weight: 600;
  background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), linear-gradient(180deg, var(--bg), var(--bg2));
  background-attachment: fixed; min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; }
#app { max-width: 720px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom)); }
.boot { font-size: 64px; text-align: center; padding-top: 30vh; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; width: 100%; height: 100%; }

h1, h2, h3 { margin: 0; font-weight: 900; letter-spacing: -.01em; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
.muted { color: var(--ink2); }
.small { font-size: 14px; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 14px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 14px; white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px; border-radius: 16px; font-weight: 800; font-size: 18px;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 70%, black);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 70%, black); }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: 0 3px 0 var(--line), inset 0 0 0 2px var(--line); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.link { color: var(--ink2); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; padding: 8px; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; background: var(--card); box-shadow: var(--shadow); }

/* login */
.hero { text-align: center; padding: 28px 0 8px; }
.hero .logo { font-size: 56px; line-height: 1; }
.hero h1 { font-size: 34px; margin-top: 8px; }
.who { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 24px; }
.who button { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px 8px; text-align: center; border: 3px solid transparent; transition: transform .12s; }
.who button:hover { transform: translateY(-2px); }
.who button.on { border-color: var(--c); }
.who .av { font-size: 48px; display: block; }
.who .nm { font-weight: 900; font-size: 18px; margin-top: 6px; display: block; }
.who .gr { font-size: 13px; color: var(--ink2); }
.field { width: 100%; min-height: 56px; border-radius: 16px; border: 2px solid var(--line); padding: 0 16px; font-size: 20px; font-weight: 700; background: #fff; color: var(--ink); }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.err { color: var(--bad); font-weight: 800; min-height: 22px; }

/* home */
.top { display: flex; align-items: center; gap: 12px; }
.me-av { width: 64px; height: 64px; border-radius: 20px; background: var(--accent-soft); display: grid; place-items: center; font-size: 40px; flex: none; }
.me-name { font-size: 24px; font-weight: 900; }
.xpbar { height: 12px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 8px; }
.xpbar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #ffb400)); border-radius: 99px; transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: 18px; padding: 12px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 24px; font-weight: 900; }
.stat span { font-size: 13px; color: var(--ink2); }
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 4px; background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); display: grid; place-items: center; }
.ring > span { width: 48px; height: 48px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-weight: 900; font-size: 15px; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode { text-align: left; border-radius: var(--r); padding: 16px; min-height: 128px; color: #fff; position: relative; overflow: hidden; box-shadow: var(--shadow); transition: transform .12s; }
.mode:active { transform: scale(.98); }
.mode .e { font-size: 36px; display: block; }
.mode b { display: block; font-size: 20px; font-weight: 900; margin-top: 6px; }
.mode span { font-size: 14px; opacity: .92; }
.mode.big { grid-column: 1 / -1; min-height: 120px; }
.m1 { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #ff6fb5)); }
.m2 { background: linear-gradient(135deg, #0ea5a4, #22c55e); }
.m3 { background: linear-gradient(135deg, #f97316, #f43f5e); }
.m4 { background: linear-gradient(135deg, #1e293b, #4338ca); }
.mode .done { position: absolute; top: 12px; right: 12px; background: rgba(255,255,255,.25); border-radius: 99px; padding: 4px 10px; font-size: 13px; font-weight: 800; }

.board .r { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.board .r:first-of-type { border-top: 0; }
.board .pos { width: 26px; font-weight: 900; color: var(--ink3); text-align: center; }
.board .av { font-size: 30px; }
.board .nm { font-weight: 900; }
.board .bar { flex: 1; height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.board .bar i { display: block; height: 100%; border-radius: 99px; }
.board .pw { font-weight: 900; min-width: 44px; text-align: right; }

.shelf { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.shelf::-webkit-scrollbar { display: none; }
.bdg { flex: none; width: 84px; text-align: center; }
.bdg .e { width: 64px; height: 64px; margin: 0 auto; border-radius: 20px; background: linear-gradient(145deg, #fff6d6, #ffe08a); display: grid; place-items: center; font-size: 32px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.08); }
.bdg.locked .e { background: var(--line); filter: grayscale(1); opacity: .45; }
.bdg .n { font-size: 12px; font-weight: 800; margin-top: 6px; line-height: 1.2; }
.bdg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 14px; }
.bdg-grid .bdg { width: auto; }
.bdg .d { font-size: 11px; color: var(--ink2); font-weight: 600; margin-top: 2px; }

.skills { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.skill { background: var(--card); border-radius: 20px; padding: 16px; text-align: left; box-shadow: var(--shadow); }
.skill .e { font-size: 32px; }
.skill b { display: block; font-size: 17px; font-weight: 900; margin-top: 4px; }
.stars { color: var(--gold); letter-spacing: 2px; font-size: 15px; }
.stars .off { color: var(--line); }

/* play */
.playtop { display: flex; align-items: center; gap: 12px; }
.dots { flex: 1; display: flex; gap: 6px; }
.dots i { flex: 1; height: 8px; border-radius: 99px; background: var(--line); }
.dots i.ok { background: var(--good); }
.dots i.no { background: var(--bad); }
.dots i.cur { background: var(--accent); }
.qcard { background: var(--card); border-radius: 26px; box-shadow: var(--shadow); padding: 22px 20px; }
.qmeta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.qtext { font-size: 21px; font-weight: 800; line-height: 1.35; }
.qtext.long { font-size: 18px; font-weight: 700; }
.visual { margin-top: 14px; padding: 16px; border-radius: 18px; background: var(--accent-soft); font-size: 22px; font-weight: 900; line-height: 1.5; white-space: pre-wrap; text-align: center; overflow-wrap: anywhere; }
.visual.clues { text-align: left; font-size: 17px; font-weight: 700; }
.visual.emoji { font-size: 40px; line-height: 1.35; letter-spacing: 2px; }
.opts { display: grid; gap: 10px; margin-top: 16px; }
.opt { display: flex; align-items: stretch; gap: 8px; }
.opt .pick { flex: 1; text-align: left; min-height: 58px; padding: 12px 16px; border-radius: 16px; background: #fff; box-shadow: inset 0 0 0 2px var(--line), 0 3px 0 var(--line); font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 12px; transition: transform .08s; }
.opt .pick:active { transform: translateY(2px); }
.opt .key { width: 30px; height: 30px; border-radius: 10px; background: var(--bg); display: grid; place-items: center; font-size: 14px; font-weight: 900; color: var(--ink2); flex: none; }
.opt .x { width: 52px; border-radius: 16px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); font-size: 20px; color: var(--ink3); }
.opt.sel .pick { box-shadow: inset 0 0 0 3px var(--accent), 0 3px 0 var(--accent); background: var(--accent-soft); }
.opt.elim .pick { opacity: .4; text-decoration: line-through; text-decoration-thickness: 3px; }
.opt.elim .x { background: var(--ink); color: #fff; box-shadow: none; }
.opt.right .pick { background: var(--good-soft); box-shadow: inset 0 0 0 3px var(--good); }
.opt.wrong .pick { background: var(--bad-soft); box-shadow: inset 0 0 0 3px var(--bad); }
.opts.done .x { visibility: hidden; }
.tip { font-size: 14px; color: var(--ink2); text-align: center; margin-top: 12px; }
.conf { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.conf button { background: #fff; border-radius: 16px; padding: 12px 6px; box-shadow: inset 0 0 0 2px var(--line), 0 3px 0 var(--line); font-weight: 800; font-size: 15px; }
.conf button .e { font-size: 28px; display: block; }
.conf button:active { transform: translateY(2px); }
.sheet { position: sticky; bottom: 0; padding-top: 12px; background: linear-gradient(transparent, var(--bg2) 30%); }
.result { border-radius: 22px; padding: 18px; }
.result.good { background: var(--good-soft); }
.result.bad { background: #fff1e6; }
.result h2 { font-size: 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: #fff; border-radius: 99px; padding: 5px 10px; font-size: 13px; font-weight: 800; }
.chip.plus { color: var(--good); }
.whybox h3 { font-size: 19px; }
.whyopt { display: block; width: 100%; text-align: left; margin-top: 8px; padding: 14px 16px; border-radius: 16px; background: #fff; box-shadow: inset 0 0 0 2px var(--line); font-weight: 700; font-size: 16px; }
.whyopt.right { background: var(--good-soft); box-shadow: inset 0 0 0 3px var(--good); }
.whyopt.wrong { background: var(--bad-soft); box-shadow: inset 0 0 0 3px var(--bad); }

/* preschool */
.pre .qtext { font-size: 26px; text-align: center; }
.pre .opts { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.pre .opt .pick { justify-content: center; font-size: 52px; min-height: 120px; padding: 8px; }
.pre .opt .key { display: none; }
.speak { display: block; margin: 12px auto 0; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pop { animation: pop .4s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

/* speed */
.timer { font-size: 44px; font-weight: 900; text-align: center; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); }
.score-big { font-size: 72px; font-weight: 900; text-align: center; line-height: 1; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(31, 27, 58, .45); display: grid; place-items: center; padding: 16px; z-index: 40; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal .card { max-width: 420px; width: 100%; text-align: center; }
.modal .big-e { font-size: 80px; line-height: 1.1; }
.avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; }
.avatars button { font-size: 36px; height: 64px; border-radius: 18px; background: var(--card); box-shadow: inset 0 0 0 2px var(--line); position: relative; }
.avatars button.on { box-shadow: inset 0 0 0 3px var(--accent); background: var(--accent-soft); }
.avatars button[disabled] { filter: grayscale(1); opacity: .35; }
.avatars button small { position: absolute; bottom: 2px; left: 0; right: 0; font-size: 9px; font-weight: 800; color: var(--ink2); }

/* parents */
.ptabs { display: flex; gap: 8px; overflow-x: auto; }
.ptabs button { padding: 10px 16px; border-radius: 99px; background: var(--card); box-shadow: inset 0 0 0 2px var(--line); font-weight: 800; white-space: nowrap; }
.ptabs button.on { background: var(--ink); color: #fff; box-shadow: none; }
.kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.kv div { background: var(--bg); border-radius: 14px; padding: 10px 12px; }
.kv b { display: block; font-size: 20px; font-weight: 900; }
.kv span { font-size: 12px; color: var(--ink2); }
.radar { display: block; width: 100%; max-width: 380px; margin: 0 auto; }
.radar text { font-family: var(--font); font-size: 11px; font-weight: 800; fill: var(--ink2); }
.sk-row { display: grid; grid-template-columns: 1fr 120px 44px; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.sk-row:first-child { border-top: 0; }
.sk-row .t { font-size: 12px; color: var(--ink2); font-weight: 600; }
.meter { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.note { padding: 10px 0 10px 14px; border-left: 4px solid var(--accent); margin-top: 10px; font-weight: 700; line-height: 1.45; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; }
.bars div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bars i { display: block; width: 100%; border-radius: 6px 6px 2px 2px; background: var(--accent); min-height: 2px; }
.bars small { font-size: 10px; color: var(--ink3); margin-top: 4px; }
.habit { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.habit:first-child { border-top: 0; }
.habit b { font-weight: 900; }
.habit p { grid-column: 1 / -1; margin: 0; font-size: 13px; color: var(--ink2); font-weight: 600; }
details summary { cursor: pointer; font-weight: 800; }
.gloss dt { font-weight: 900; margin-top: 10px; }
.gloss dd { margin: 2px 0 0; color: var(--ink2); font-weight: 600; font-size: 14px; }

@media (max-width: 480px) {
  h1 { font-size: 24px; }
  .who .av { font-size: 40px; }
  .modes { gap: 10px; }
  .mode { min-height: 116px; padding: 14px; }
  .mode b { font-size: 18px; }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .sk-row { grid-template-columns: 1fr 80px 40px; }
  .qtext { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- mascot, effects, age themes, 3D ---------- */
.qcard { position: relative; }
.mascot { position: relative; width: 56px; height: 56px; flex: none; }
.mascot svg { width: 100%; height: 100%; overflow: visible; }
.mascot.sm { position: absolute; top: -18px; right: 12px; }
.mascot.md { width: 84px; height: 84px; margin: -6px auto 4px; }
.mascot.lg { width: 140px; height: 140px; margin: 0 auto; }
.mascot .body { transform-origin: 50% 90%; animation: m-idle 3s ease-in-out infinite; }
.m-happy .body, .m-cheer .body { animation: m-hop .5s cubic-bezier(.3, 1.6, .5, 1) 2; }
.m-oops .body { animation: m-tilt .6s ease-in-out; }
.m-cheer .wl, .m-cheer .wr { animation: m-flap .3s ease-in-out infinite alternate; transform-origin: 50% 70%; }
@keyframes m-idle { 50% { transform: translateY(-2px) rotate(-1deg); } }
@keyframes m-hop { 40% { transform: translateY(-12px) scale(1.05, .95); } }
@keyframes m-tilt { 30% { transform: rotate(-10deg); } 70% { transform: rotate(6deg); } }
@keyframes m-flap { to { transform: rotate(-12deg); } }
.mascot .bubble { position: absolute; right: 100%; top: 10%; margin-right: 6px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 800; padding: 6px 10px; border-radius: 12px; white-space: nowrap; animation: pop .35s cubic-bezier(.2, 1.6, .4, 1); }
.mascot.md .bubble, .mascot.lg .bubble { right: auto; left: 100%; margin: 0 0 0 6px; }
.fx-star { position: fixed; z-index: 60; pointer-events: none; font-size: 20px; translate: -50% -50%; animation: fx-burst .8s ease-out forwards; }
@keyframes fx-burst { to { transform: translate(var(--dx), var(--dy)) scale(.4) rotate(180deg); opacity: 0; } }
.fx-pts { position: fixed; z-index: 60; pointer-events: none; translate: -50% 0; font-weight: 900; font-size: 22px; color: var(--accent); animation: fx-up 1.1s ease-out forwards; }
@keyframes fx-up { to { transform: translateY(-50px); opacity: 0; } }
.hq3d { display: block; width: 100%; height: min(70vh, 460px); border-radius: var(--r); background: linear-gradient(180deg, var(--accent-soft), #fff); box-shadow: var(--shadow); touch-action: none; }
.reveal3d { display: block; width: 180px; height: 180px; margin: 0 auto; }

/* Preschool: bigger, bouncier, softer */
.theme-pre { --r: 28px; }
.theme-pre body, body.theme-pre { background: radial-gradient(circle at 15% 20%, #fff3b0 0 60px, transparent 61px), radial-gradient(circle at 85% 12%, #c9f2e3 0 80px, transparent 81px), radial-gradient(circle at 90% 85%, #ffd6e7 0 90px, transparent 91px), linear-gradient(180deg, #f2fff9, #fff8ec); background-attachment: fixed; }
body.theme-pre .mode, body.theme-pre .btn { border-radius: 26px; }
body.theme-pre .opt .pick { border-radius: 26px; }
body.theme-pre .pick:active { transform: scale(.94); }
/* Year 4: playful default */
/* Year 6: sleeker, calmer */
body.theme-y6 { background: linear-gradient(180deg, #f4f3fb, #eef0f7); }
body.theme-y6 .mode { background-blend-mode: normal; }
body.theme-y6 .m1 { background: linear-gradient(135deg, #2e1f73, var(--accent)); }
body.theme-y6 .m2 { background: linear-gradient(135deg, #0f3d3e, #0ea5a4); }
body.theme-y6 .m3 { background: linear-gradient(135deg, #3b0d1a, #e2445c); }
body.theme-y6 .mascot.sm { width: 44px; height: 44px; top: -14px; }
body.theme-y6 .qtext { letter-spacing: -.005em; }
