:root {
  --bg: #f4f1ff;
  --bg2: #e8f6ff;
  --card: #ffffff;
  --ink: #2a2350;
  --muted: #6b6690;
  --primary: #5b4bdb;
  --primary-dark: #4535c4;
  --good: #2eaa5c;
  --good-bg: #e3f8eb;
  --bad: #e5533d;
  --bad-bg: #fdebe8;
  --gold: #f2b705;
  --line: #e2ddf5;
  --shadow: 0 6px 0 rgba(42, 35, 80, .08), 0 10px 30px rgba(42, 35, 80, .08);
  --radius: 22px;
  --font: 'Andika', 'Comic Sans MS', system-ui, sans-serif;
  --display: 'Baloo 2', 'Andika', system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(circle at 10% 0%, var(--bg2), transparent 40%), var(--bg);
  min-height: 100vh;
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 1000px; margin: 0 auto;
}
.logo { display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 4px; }
.logo-owl { font-size: 34px; }
.logo-text { font-family: var(--display); font-weight: 800; font-size: 28px; color: var(--primary); }
.logo-text span { color: var(--gold); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.player-chip { border: 0; font-size: 18px; }
.player-chip, .star-count {
  background: var(--card); border-radius: 999px; padding: 6px 14px; font-weight: 700; box-shadow: var(--shadow);
}
.icon-btn {
  border: 0; background: var(--card); border-radius: 50%; width: 44px; height: 44px;
  font-size: 22px; box-shadow: var(--shadow); flex: none;
}
.icon-btn:active { transform: translateY(2px); }

main { max-width: 1000px; margin: 0 auto; padding: 8px 16px 48px; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 16px; padding: 14px 22px; font-size: 20px; font-weight: 700;
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:active { transform: translateY(3px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 5px 0 var(--primary-dark); }
.btn-primary:active { box-shadow: 0 2px 0 var(--primary-dark); }
.btn-ghost { background: var(--card); box-shadow: 0 4px 0 var(--line); }
.btn-small { padding: 8px 14px; font-size: 16px; }
.btn-danger { background: var(--bad-bg); color: var(--bad); box-shadow: 0 4px 0 #f5c7bf; font-size: 16px; }
:focus-visible { outline: 4px solid #ffb703; outline-offset: 3px; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; margin-bottom: 18px;
}
.card h3 { margin: 0 0 6px; font-family: var(--display); font-size: 24px; }

/* ---------- welcome ---------- */
.hero { text-align: center; padding: 20px 0 10px; }
.hero-owl { font-size: 88px; animation: bob 2.4s ease-in-out infinite; }
.hero h1 { font-family: var(--display); font-size: clamp(32px, 6vw, 48px); margin: 6px 0; }
.brand { color: var(--primary); }
.lead { font-size: 22px; color: var(--muted); margin: 0; }
.player-list { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.player-list:empty { display: none; }
.player-btn {
  border: 0; border-radius: 16px; padding: 12px 18px; font-size: 20px; font-weight: 700;
  background: #f0edff; box-shadow: 0 4px 0 var(--line);
}
.name-row { display: flex; gap: 10px; flex-wrap: wrap; }
.name-row input {
  flex: 1 1 200px; font: inherit; font-size: 22px; padding: 12px 16px; border-radius: 14px;
  border: 3px solid var(--line); min-width: 0;
}
.name-row input:focus { border-color: var(--primary); outline: none; }

/* ---------- home ---------- */
.home-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin: 8px 0 16px; }
.home-head h2 { font-family: var(--display); font-size: 32px; margin: 0; }
.home-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.mixed-card {
  width: 100%; display: flex; align-items: center; gap: 16px; text-align: left; border: 0;
  background: linear-gradient(120deg, #5b4bdb, #a24bdb); color: #fff; border-radius: var(--radius);
  padding: 18px 22px; margin-bottom: 18px; box-shadow: 0 6px 0 #3f2fb0; font-size: 22px;
}
.mixed-card small { display: block; font-size: 17px; opacity: .9; }
.mixed-card:active { transform: translateY(3px); box-shadow: 0 3px 0 #3f2fb0; }
.mixed-emoji { font-size: 44px; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.topic-card {
  border: 0; text-align: left; background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: 0 6px 0 var(--tc, var(--line)); border-top: 8px solid var(--tc, var(--primary));
  display: flex; flex-direction: column; gap: 4px; min-height: 150px;
}
.topic-card:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--tc); }
.topic-emoji { font-size: 40px; }
.topic-name { font-family: var(--display); font-size: 22px; font-weight: 800; }
.topic-blurb { color: var(--muted); font-size: 16px; }
.topic-meta { margin-top: auto; display: flex; justify-content: space-between; font-size: 15px; font-weight: 700; }
.level-pips { letter-spacing: 2px; }

/* ---------- quiz ---------- */
.quiz-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 10px; }
.quiz-topic { font-family: var(--display); font-weight: 800; font-size: 22px; text-align: center; flex: 1; }
.level-badge { background: var(--card); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 15px; box-shadow: var(--shadow); white-space: nowrap; }
.progress-dots { display: flex; gap: 6px; justify-content: center; margin: 6px 0 14px; flex-wrap: wrap; }
.dot { width: 22px; height: 22px; border-radius: 50%; background: var(--line); display: grid; place-items: center; font-size: 12px; }
.dot.current { background: var(--primary); box-shadow: 0 0 0 4px #d6d0ff; }
.dot.right { background: var(--good); }
.dot.retry { background: var(--gold); }
.dot.wrong { background: var(--bad); }

.question-card { text-align: center; padding: 22px 18px 26px; }
.question-card.pop { animation: pop .35s ease; }
.prompt-row { display: flex; align-items: flex-start; justify-content: center; gap: 10px; }
.prompt { font-size: clamp(22px, 4vw, 30px); font-weight: 700; margin: 4px 0 14px; line-height: 1.3; }
.visual { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 12px; margin-bottom: 16px; }
.visual:empty { display: none; }

.equation { font-family: var(--display); font-size: clamp(40px, 9vw, 64px); font-weight: 800; letter-spacing: 1px; }
.equation .hl { color: var(--bad); text-decoration: underline; text-decoration-thickness: 5px; }
.blank {
  display: inline-block; min-width: 1.3em; padding: 0 .15em; border: 4px dashed var(--primary); border-radius: 14px;
  color: var(--primary); line-height: 1.1;
}

/* base ten blocks */
.blocks { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; justify-content: center; padding: 6px; }
.blocks-group { display: flex; gap: 4px; align-items: flex-end; flex-wrap: wrap; max-width: 340px; }
.blocks-group.ones { max-width: 90px; }
.b-hundred, .b-ten, .b-one { background-color: #ffcf5c; border: 2px solid #c98f00; border-radius: 3px; }
.b-hundred {
  width: 72px; height: 72px;
  background-image: linear-gradient(#c98f0066 1px, transparent 1px), linear-gradient(90deg, #c98f0066 1px, transparent 1px);
  background-size: 7px 7px;
}
.b-ten {
  width: 10px; height: 72px; background-color: #7ed3ff; border-color: #1a8cc7;
  background-image: linear-gradient(#1a8cc766 1px, transparent 1px); background-size: 7px 7px;
}
.b-one { width: 12px; height: 12px; background-color: #ff9eb5; border-color: #d4466a; }
.plus { font-size: 40px; font-weight: 800; }

/* sequences */
.sequence { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.seq-item {
  min-width: 64px; padding: 10px 12px; border-radius: 16px; background: #f0edff;
  font-family: var(--display); font-weight: 800; font-size: clamp(24px, 5vw, 34px);
}
.seq-item.blank { border: 4px dashed var(--primary); background: #fff; }
.emoji-seq .seq-item { min-width: 54px; padding: 6px 8px; font-size: clamp(26px, 6vw, 40px); }

/* clock */
.clock { width: min(240px, 70vw); height: auto; }
.clock-face { fill: #fff; stroke: var(--primary); stroke-width: 7; }
.tick { stroke: #b9b3d9; stroke-width: 2; }
.tick-big { stroke: var(--ink); stroke-width: 4; }
.clock-num { font-family: var(--display); font-weight: 800; font-size: 22px; text-anchor: middle; fill: var(--ink); }
.hand-hour { stroke: var(--bad); stroke-width: 9; stroke-linecap: round; }
.hand-minute { stroke: var(--primary); stroke-width: 6; stroke-linecap: round; }
.clock-pin { fill: var(--ink); }

/* coins */
.coins { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.coin-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.coin-label { font-size: 15px; font-weight: 700; color: var(--muted); }
.coin {
  border-radius: 50%; border: 4px solid #8c8c96; display: grid; place-items: center; font-size: 28px;
  background: radial-gradient(circle at 35% 30%, #ffffff, #c9cbd3 55%, #9fa2ad);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .5), 0 3px 0 rgba(0, 0, 0, .15);
}
.coin-nickel { width: 64px; height: 64px; }
.coin-dime { width: 54px; height: 54px; font-size: 22px; }
.coin-quarter { width: 74px; height: 74px; font-size: 34px; }
.coin-loonie { width: 80px; height: 80px; border-color: #b8860b; background: radial-gradient(circle at 35% 30%, #fff3b0, #e5b62e 55%, #b8860b); }

/* shapes & fractions */
.shape, .fraction { width: min(220px, 60vw); height: auto; }
.shape g { stroke: var(--ink); stroke-width: 4; stroke-linejoin: round; }
.part { fill: #fff; stroke: var(--ink); stroke-width: 4; stroke-linejoin: round; }
.part.on { fill: #ff8a5b; }

/* answers */
.answer-area { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; width: 100%; max-width: 520px; }
.choices.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice {
  border: 0; border-radius: 18px; padding: 16px 10px; min-height: 70px; font-size: 24px; font-weight: 700;
  background: #f0edff; box-shadow: 0 5px 0 var(--line); transition: transform .08s ease;
}
.choice:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.choice.big { font-family: var(--display); font-size: 38px; font-weight: 800; }
.choice.emoji { font-size: 44px; }
.choice.right { background: var(--good); color: #fff; box-shadow: 0 5px 0 #1f7d42; }
.choice.wrong { background: var(--bad-bg); color: var(--bad); box-shadow: 0 5px 0 #f5c7bf; animation: shake .4s ease; }
.choice:disabled { cursor: default; }
.frac { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; font-family: var(--display); font-size: 32px; font-weight: 800; }
.frac .num { border-bottom: 4px solid currentColor; padding: 0 8px 2px; }
.frac .den { padding-top: 2px; }

.answer-display {
  min-width: 180px; min-height: 76px; border-radius: 18px; border: 4px solid var(--primary);
  font-family: var(--display); font-size: 48px; font-weight: 800; display: flex; align-items: center; justify-content: center;
  padding: 0 18px; background: #fff;
}
.answer-display.empty::before { content: '?'; color: #c9c3ec; }
.answer-display.wrong { border-color: var(--bad); animation: shake .4s ease; }
.answer-display.right { border-color: var(--good); background: var(--good-bg); }
.unit { font-size: 32px; margin-left: 4px; color: var(--muted); }
.numpad { display: grid; grid-template-columns: repeat(3, 76px); gap: 10px; }
.key {
  height: 64px; border: 0; border-radius: 16px; background: #f0edff; box-shadow: 0 5px 0 var(--line);
  font-family: var(--display); font-size: 30px; font-weight: 800;
}
.key:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }
.key.del { background: #fff4d6; box-shadow: 0 5px 0 #f3dd9b; }
.key.ok { background: var(--good); color: #fff; box-shadow: 0 5px 0 #1f7d42; }
.key:disabled { opacity: .4; }

.feedback { margin-top: 18px; border-radius: 18px; padding: 14px 16px; font-size: 21px; font-weight: 700; }
.feedback.good { background: var(--good-bg); color: #1d6b3b; }
.feedback.try { background: #fff6dc; color: #7a5a00; }
.feedback.bad { background: var(--bad-bg); color: #9b2b1b; }
.feedback .hint-visual { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin-top: 10px; }
.feedback .btn { margin-top: 12px; }

/* ---------- results ---------- */
.results-card { text-align: center; max-width: 560px; margin: 20px auto; }
.results-emoji { font-size: 84px; animation: bob 2s ease-in-out infinite; }
.results-card h2 { font-family: var(--display); font-size: 38px; margin: 6px 0; }
.results-score { font-size: 22px; }
.results-stars { font-size: 34px; letter-spacing: 2px; min-height: 40px; }
.results-stars span { display: inline-block; animation: pop .4s ease both; }
.sticker-unlock { margin: 14px auto; padding: 12px; border-radius: 18px; background: #fff6dc; font-size: 20px; font-weight: 700; }
.sticker-unlock .big { font-size: 60px; display: block; }
.results-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 18px; }

/* ---------- progress ---------- */
.sticker-book { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; margin-top: 10px; }
.sticker { aspect-ratio: 1; border-radius: 16px; background: #fff6dc; display: grid; place-items: center; font-size: 36px; }
.sticker.locked { background: #f0eef7; filter: grayscale(1); opacity: .5; font-size: 24px; }
.table-wrap { overflow-x: auto; }
.progress-table { width: 100%; border-collapse: collapse; font-size: 17px; }
.progress-table th, .progress-table td { padding: 10px 8px; border-bottom: 2px solid var(--line); text-align: left; white-space: nowrap; }
.progress-table th { color: var(--muted); font-size: 15px; }
.bar { height: 12px; border-radius: 6px; background: var(--line); min-width: 80px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--good); border-radius: 6px; }
.danger-zone { text-align: center; margin-top: 10px; }

/* ---------- forms: sign in, register, account ---------- */
.form-card { max-width: 600px; margin: 20px auto; }
.form-card.wide { max-width: none; margin: 0 0 18px; }
.form-title { font-family: var(--display); font-size: 32px; margin: 0; }
.form-sub { margin: 4px 0 18px; }
.form-title.small { font-size: 24px; margin-bottom: 10px; }
.mode-note { margin: 14px 0 0; text-align: center; font-size: 15px; color: var(--muted); }
.message-card { text-align: center; }
.message-card p { font-size: 19px; }
.btn:disabled { opacity: .6; cursor: default; }
.field { border: 0; padding: 0; margin: 0 0 18px; min-width: 0; }
.field > label, .field > legend { display: block; font-weight: 700; font-size: 20px; margin-bottom: 8px; padding: 0; }
.field > input {
  width: 100%; font: inherit; font-size: 22px; padding: 12px 16px; border-radius: 14px; border: 3px solid var(--line);
}
.field input:focus { border-color: var(--primary); outline: none; }
.field input[aria-invalid] { border-color: var(--bad); }
.field-hint { margin: 6px 0 0; font-size: 15px; color: var(--muted); }
.error { margin: 6px 0 0; color: var(--bad); font-weight: 700; font-size: 16px; }
.error:empty { display: none; }
.btn-block { width: 100%; }
.btn-secondary { background: #fff6dc; color: #7a5a00; box-shadow: 0 4px 0 #f3dd9b; }
.link-btn { border: 0; background: none; color: var(--primary); font-weight: 700; font-size: inherit; text-decoration: underline; padding: 0; }
.switch-link { text-align: center; margin: 16px 0 0; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 18px 0 14px; font-size: 16px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 2px; background: var(--line); }
.device-accounts:empty { display: none; }
.device-accounts { margin-bottom: 8px; }
.device-accounts .player-list { margin: 8px 0 16px; }
.player-btn small { display: block; font-size: 14px; color: var(--muted); font-weight: 400; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { position: relative; cursor: pointer; }
.pill input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: inherit; }
.pill span {
  display: block; padding: 10px 16px; border-radius: 999px; background: #f0edff; font-weight: 700;
  box-shadow: 0 3px 0 var(--line); border: 3px solid transparent;
}
.pill input:checked + span { background: var(--primary); color: #fff; box-shadow: 0 3px 0 var(--primary-dark); }
.pill input:focus-visible + span { outline: 4px solid #ffb703; outline-offset: 2px; }
.pill small, .subject-card small { display: block; text-align: center; font-size: 12px; color: var(--muted); margin-top: 2px; }
.pill.soon, .subject-card.soon { cursor: not-allowed; opacity: .55; }

.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.subject-grid > p { margin: 0; }
.subject-card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px;
  border-radius: 18px; background: #f0edff; border: 3px solid transparent; cursor: pointer; text-align: center;
}
.subject-card input { position: absolute; top: 10px; right: 10px; width: 20px; height: 20px; accent-color: var(--primary); }
.subject-card:has(input:checked) { border-color: var(--primary); background: #fff; }
.subject-emoji { font-size: 34px; }
.subject-name { font-weight: 700; }
.plan-note { background: var(--good-bg); color: #1d6b3b; border-radius: 14px; padding: 12px 14px; margin-bottom: 18px; }

.account-info { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; margin: 0; }
.account-info dt { color: var(--muted); font-weight: 700; }
.account-info dd { margin: 0; word-break: break-word; }
.plan-badge { background: var(--good-bg); color: #1d6b3b; border-radius: 999px; padding: 3px 12px; font-weight: 700; }
.saved-note { margin-left: 12px; font-weight: 700; color: var(--good); }
.empty-state { grid-column: 1 / -1; text-align: center; }

.subject-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.subject-tabs:has(> :only-child) { display: none; }
.subject-tab {
  border: 0; border-radius: 999px; padding: 10px 18px; font-size: 18px; font-weight: 700;
  background: var(--card); box-shadow: 0 3px 0 var(--line);
}
.subject-tab small { color: var(--muted); font-weight: 400; }
.subject-tab.on { background: var(--primary); color: #fff; box-shadow: 0 3px 0 var(--primary-dark); }
.subject-tab.on small { color: #e3defc; }
.topic-card.locked { opacity: .6; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px; font-weight: 700; box-shadow: var(--shadow);
}

.modal-backdrop {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: rgba(42, 35, 80, .45);
}
.modal { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; max-width: 440px; width: 100%; }
.modal p { margin: 0 0 18px; font-size: 20px; font-weight: 700; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.btn-danger-solid { background: var(--bad); color: #fff; box-shadow: 0 4px 0 #b23a27; }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }

@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes pop { 0% { transform: scale(.85); opacity: .3; } 70% { transform: scale(1.04); } 100% { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 520px) {
  body { font-size: 17px; }
  .logo-text { font-size: 24px; }
  .player-chip { display: none; }
  .numpad { grid-template-columns: repeat(3, 68px); }
  .choice.big { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.progress-table .bar { display: inline-block; vertical-align: middle; width: 90px; margin-right: 8px; }
