/* ===================================================================
   Times Tables Trainer — design system (v2)
   Touch-first (iPad / Chromebook / phone), safe-area aware.

   Rules that hold everywhere:
     radius    4 / 8 / 12 only — every corner is a slight curve, never
               a pill and never a circle
     colour    one indigo brand + six game accents; a screen borrows
               its accent from the game it belongs to, nothing else
               invents a colour
     type      one rounded family, tabular numerals for every number
               a child has to read quickly
     targets   44px minimum; anything used mid-game is sized in vh so
               it grows to fill the screen it is on
     layout    headings, labels and tiles are centred — a third grader
               reads the middle of a tablet, not its left edge
   =================================================================== */

:root {
  /* brand */
  --brand: #3F3BD8;
  --brand-dark: #2E2AAE;
  --brand-deep: #211F7A;
  --brand-soft: #ECEBFB;

  /* game accents (mode tiles set --tint / --tint-soft from these) */
  --violet: #6B3FD4;
  --blue:   #1D6FD0;
  --teal:   #0E8C86;
  --amber:  #C9741A;
  --rose:   #CE4048;
  --green:  #2C8B4B;

  /* neutrals */
  --bg: #F1F3F8;
  --surface: #FFFFFF;
  --surface-sunk: #F7F8FC;
  --ink: #1B2130;
  --ink-soft: #5A6376;
  --ink-faint: #8A93A6;
  --border: #E1E5EF;
  --border-strong: #C8CEDD;
  --track: #EDF0F7;

  /* status */
  --good: #2C8B4B;
  --good-soft: #E6F3EA;
  --bad: #CE4048;
  --bad-soft: #FBEBEC;

  /* elevation */
  --shadow: 0 1px 2px rgba(27, 33, 48, .07);
  --shadow-raised: 0 6px 18px rgba(27, 33, 48, .12);

  /* geometry — slight curves only */
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* A screen (or any block) toggled via the `hidden` attribute must
   actually hide — rules below set `display` on those same elements and
   would otherwise beat the browser's default [hidden] rule. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
  /* Panning only: drops pinch-zoom and double-tap-zoom without adding
     any tap delay, so two fast taps on a keypad key still give two
     digits. See js/zoom.js for the gesture events CSS cannot cover. */
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", "Segoe UI Variable", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.015em; }

.center { text-align: center; }
.center-row { display: flex; justify-content: center; }
.num { font-variant-numeric: tabular-nums; }

.hint { color: var(--ink-soft); font-size: 13.5px; line-height: 1.5; margin: 0 0 12px; }

/* ---------- screens ---------- */

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* Play screens carry their game's accent as a faint wash, so switching
   games is visible before a single word is read. */
.screen[data-accent] { background: var(--tint-soft, var(--bg)); }

/* ---------- app bar ---------- */

.app-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  min-height: 60px;
  background: var(--tint, var(--brand));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-bar-title { flex: 1; font-size: 18px; text-align: center; }

/* Balances the back button so the title stays optically centred. */
.app-bar-slot {
  min-width: 44px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: inherit;
  flex: none;
  transition: background .12s ease;
}
.icon-btn:active { background: rgba(255, 255, 255, .18); }
.icon-btn svg { width: 24px; height: 24px; }

.stat-pill {
  font-size: 12.5px;
  font-weight: 800;
  color: #fff;
  background: rgba(255, 255, 255, .22);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- home header ---------- */

.home-header {
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-deep) 100%);
  color: #fff;
  padding: clamp(20px, 4vh, 34px) 16px clamp(22px, 4vh, 34px);
  text-align: center;
}

.home-header-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .18);
  border-radius: var(--radius);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}
.brand-text { font-size: clamp(22px, 4.5vw, 30px); font-weight: 800; letter-spacing: -0.02em; }
.home-tagline { margin: 10px 0 0; font-size: 15px; color: rgba(255, 255, 255, .85); font-weight: 600; }

.focus-tag {
  display: inline-block;
  margin-top: 14px;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  background: rgba(255, 255, 255, .2);
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- page bodies ---------- */

.home-body,
.sub-body {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px clamp(12px, 3vw, 28px) 36px;
}

.section { margin-bottom: 26px; }
.section:last-child { margin-bottom: 0; }

.section-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-faint);
  text-align: center;
  margin-bottom: 12px;
}

/* ---------- card: the single surface primitive ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card:last-child { margin-bottom: 0; }
.card-title { font-size: 17px; margin-bottom: 8px; text-align: center; }

/* ---------- mode grid ---------- */

/* Flex rather than grid so a row that isn't full — seven games never
   divide evenly — centres its tiles instead of leaving a hole. */
.mode-grid {
  --tile-gap: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--tile-gap);
}
.mode-card { flex: 0 1 calc(50% - var(--tile-gap) / 2); }
@media (min-width: 700px) {
  .mode-grid { --tile-gap: 14px; }
  .mode-card { flex-basis: calc(33.3333% - var(--tile-gap) * 2 / 3); }
}
@media (min-width: 1020px) {
  .mode-card { flex-basis: calc(25% - var(--tile-gap) * 3 / 4); }
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: clamp(14px, 2.4vw, 22px) 12px;
  min-height: clamp(140px, 21vh, 200px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 5px solid var(--tint);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .1s ease, box-shadow .12s ease, background .12s ease;
}
.mode-card:active { transform: translateY(1px); background: var(--tint-soft); box-shadow: var(--shadow); }
@media (hover: hover) {
  .mode-card:hover { box-shadow: var(--shadow-raised); }
}

.mode-icon {
  flex: none;
  width: clamp(52px, 8vw, 68px);
  height: clamp(52px, 8vw, 68px);
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--tint-soft);
  color: var(--tint);
}
.mode-icon svg { width: 60%; height: 60%; }

.mode-text { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.mode-name { font-size: clamp(16px, 2.2vw, 20px); font-weight: 800; letter-spacing: -0.01em; }
.mode-desc { font-size: clamp(12px, 1.4vw, 14px); font-weight: 600; color: var(--ink-soft); line-height: 1.35; }

/* On a narrow phone the one-line description turns two tiles into
   different heights for no benefit — the tile name already says it. */
@media (max-width: 420px) {
  .mode-desc { display: none; }
  .mode-card { min-height: 128px; }
}

/* ---------- setup panel ---------- */

.setup-card { padding: 4px clamp(12px, 2.5vw, 22px) 18px; }
.setup-row { padding: 14px 0; border-bottom: 1px solid var(--border); }
.setup-row:last-child { border-bottom: none; }

.setup-label {
  display: block;
  font-size: 12.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-faint);
  text-align: center;
  margin-bottom: 10px;
}

.preset-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.chip {
  padding: 11px 18px;
  min-height: 46px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 13.5px;
  color: var(--ink-soft);
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.chip:active { background: var(--track); }
.chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* number pad for choosing tables — 12 fit on one row from tablet up */
.table-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(6px, 1vw, 10px);
}
@media (min-width: 620px) { .table-picker { grid-template-columns: repeat(12, minmax(0, 1fr)); } }

.table-btn {
  height: clamp(52px, 7vw, 68px);
  font-size: clamp(18px, 2.4vw, 24px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.table-btn:active { background: var(--track); }
.table-btn.selected {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.range-row { display: flex; align-items: center; justify-content: center; gap: 12px; }
.range-row select {
  font-family: inherit;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
  padding: 12px 16px;
  min-height: 54px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
.range-sep { font-size: 13px; font-weight: 700; color: var(--ink-faint); }

/* ---------- buttons ---------- */

.primary-btn {
  padding: 16px 32px;
  min-height: clamp(56px, 8vh, 72px);
  font-size: clamp(17px, 2.4vh, 21px);
  font-weight: 800;
  color: #fff;
  background: var(--tint, var(--brand));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .1s ease, filter .12s ease;
}
.primary-btn:active { transform: translateY(1px); filter: brightness(.94); }
.primary-btn:disabled { opacity: .55; }

.secondary-btn {
  padding: 14px 24px;
  min-height: clamp(50px, 7vh, 64px);
  font-size: clamp(15px, 2.1vh, 18px);
  font-weight: 800;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: background .12s ease;
}
.secondary-btn:active { background: var(--track); }

.danger-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 13px;
  min-height: 48px;
  font-size: 14.5px;
  font-weight: 800;
  color: var(--bad);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.danger-btn:active { background: var(--bad-soft); }

/* ---------- progress (mastery) ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin-bottom: 16px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-soft);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.dot-new { background: var(--surface); border: 1px solid var(--border-strong); }
.dot-learning { background: #F2C14E; }
.dot-shaky { background: var(--bad); }
.dot-solid { background: #7FB2E0; }
.dot-due { background: transparent; border: 2px dashed var(--ink-faint); }
.dot-mastered { background: var(--good); }

.mastery-bars { display: flex; flex-direction: column; gap: 8px; }
.mastery-bar-row { display: flex; align-items: center; gap: 12px; }
.mastery-bar-label { width: 40px; font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }
.mastery-bar-track { flex: 1; height: 16px; background: var(--track); border-radius: var(--radius-sm); overflow: hidden; }
.mastery-bar-fill { height: 100%; background: var(--good); border-radius: var(--radius-sm); transition: width .3s ease; }
.mastery-bar-pct { width: 48px; text-align: right; font-size: 14px; font-weight: 800; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.mastery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(64px, 8vw, 88px), 1fr));
  gap: clamp(5px, 0.8vw, 9px);
}
.mastery-cell {
  padding: clamp(12px, 1.6vw, 18px) 2px;
  font-size: clamp(13px, 1.6vw, 16px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
}
.mastery-cell.m-learning { background: #FDF3D8; border-color: #F2C14E; color: #7A5A0B; }
.mastery-cell.m-shaky { background: var(--bad); border-color: var(--bad); color: #fff; }
/* Due for review: known once, not seen lately. */
.mastery-cell.is-due { border-style: dashed; border-width: 2px; }

/* Right, but worked out rather than recalled — nearly there, and
   distinct from both "learning" and "mastered". */
.mastery-cell.m-solid { background: #E7F1FB; border-color: #7FB2E0; color: #1B5A8C; }
.mastery-cell.m-mastered { background: var(--good); border-color: var(--good); color: #fff; }

/* ---------- leaderboard ---------- */

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #E3E8F3;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.segmented button {
  padding: 13px 8px;
  min-height: 52px;
  font-size: clamp(15px, 2vw, 18px);
  font-weight: 800;
  color: var(--ink-soft);
  border-radius: var(--radius-sm);
  transition: background .12s ease, color .12s ease;
}
.segmented button.active { background: var(--brand); color: #fff; box-shadow: var(--shadow); }

.lb-status {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-faint);
  text-align: center;
  margin: 0 0 12px;
  min-height: 18px;
}
.lb-status.warn { color: var(--amber); }

.leaderboard-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.leaderboard-row {
  display: grid;
  grid-template-columns: 42px 1fr 70px 64px;
  align-items: center;
  gap: 10px;
  padding: clamp(13px, 1.8vh, 20px) clamp(14px, 2vw, 22px);
  font-size: clamp(16px, 2vw, 19px);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.leaderboard-row:last-child { border-bottom: none; }
.leaderboard-row.leaderboard-head {
  background: var(--surface-sunk);
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 9px 14px;
}
.leaderboard-row.is-me { background: var(--brand-soft); color: var(--brand-deep); }
.lb-rank {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--track);
  color: var(--ink-soft);
  font-weight: 800;
  font-size: 15px;
}
.leaderboard-head .lb-rank { background: none; width: auto; height: auto; place-items: center start; }
.leaderboard-row.is-me .lb-rank { background: var(--brand); color: #fff; }
.lb-rank.top { background: var(--brand-dark); color: #fff; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score, .lb-accuracy { text-align: right; }
.leaderboard-list .hint { padding: 16px; margin: 0; text-align: center; }

.personal-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: clamp(8px, 1.4vw, 14px);
  margin-bottom: 16px;
}
.personal-stats .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 2.4vh, 26px) 10px;
  text-align: center;
}
.personal-stats .stat b { display: block; font-size: clamp(28px, 5vh, 44px); line-height: 1.15; font-variant-numeric: tabular-nums; }
.personal-stats .stat span { font-size: 11px; font-weight: 800; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .05em; }

.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 14px;
  align-items: center;
  padding: clamp(13px, 1.8vh, 18px) clamp(14px, 2vw, 20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.history-row .h-when { color: var(--ink-faint); font-size: 14px; font-weight: 700; }
.history-row .h-score b { font-size: 19px; }
.history-row.best { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-deep); }

/* ---------- play screens (shared) ---------- */

.play-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.8vh, 20px);
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(12px, 2vh, 22px) clamp(12px, 3vw, 24px) clamp(14px, 2.4vh, 26px);
}

.problem-card {
  width: 100%;
  padding: clamp(14px, 2.8vh, 36px) 16px;
  text-align: center;
  font-size: clamp(40px, min(13vw, 8.6vh), 88px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.answer-display {
  width: 100%;
  padding: clamp(12px, 2.4vh, 26px);
  text-align: center;
  font-size: clamp(34px, min(11vw, 7.5vh), 72px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--tint, var(--brand));
  background: var(--surface);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}
.answer-display.pop { animation: pop .35s ease; }
.answer-display.shake { animation: shake .4s ease; }

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.09); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

.feedback-msg {
  min-height: 28px;
  font-size: clamp(16px, 2.4vh, 22px);
  font-weight: 800;
  text-align: center;
}
.feedback-msg.good { color: var(--good); }
.feedback-msg.bad { color: var(--bad); }

/* ---------- keypad ---------- */

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(7px, 1.2vh, 12px);
  width: 100%;
}
.keypad button {
  min-height: clamp(54px, 8.4vh, 104px);
  font-size: clamp(24px, 3.8vh, 38px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  transition: background .1s ease, transform .08s ease;
}
.keypad button:active { background: var(--track); transform: translateY(1px); }
.keypad button svg { width: clamp(26px, 4vh, 38px); height: clamp(26px, 4vh, 38px); }
.keypad .key-clear { color: var(--ink-soft); }
.keypad .key-enter {
  color: #fff;
  background: var(--tint, var(--brand));
  border-color: transparent;
}
.keypad .key-enter:active { background: var(--tint, var(--brand)); filter: brightness(.92); }

/* ---------- flash cards ---------- */

.flash-row { display: flex; align-items: center; gap: clamp(8px, 2vw, 16px); width: 100%; }

.flash-card {
  flex: 1;
  min-width: 0;
  height: clamp(240px, 56vh, 520px);
  perspective: 1200px;
  position: relative;
  cursor: pointer;
}
.flash-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  font-size: clamp(52px, min(16vw, 14vh), 130px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-raised);
  backface-visibility: hidden;
  transition: transform .45s cubic-bezier(.4, .1, .2, 1);
}
.flash-front {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  transform: rotateY(0deg);
}
.flash-back {
  background: var(--tint, var(--brand));
  color: #fff;
  transform: rotateY(180deg);
}
.flash-card.flipped .flash-front { transform: rotateY(-180deg); }
.flash-card.flipped .flash-back { transform: rotateY(0deg); }

.nav-arrow {
  flex: none;
  width: clamp(54px, 8vw, 76px);
  height: clamp(72px, 14vh, 120px);
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.nav-arrow:active { background: var(--track); }
.nav-arrow:disabled { opacity: .4; }
.nav-arrow svg { width: clamp(26px, 4vw, 36px); height: clamp(26px, 4vw, 36px); }

/* ---------- quick tap ---------- */

/* Only three blocks on this screen, so the answer buttons take the
   slack instead of leaving empty bands above and below. */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: clamp(9px, 1.6vh, 16px);
  width: 100%;
  flex: 1 1 auto;
  max-height: 560px;
}
.choice-btn {
  padding: 24px 10px;
  min-height: clamp(92px, 17vh, 170px);
  font-size: clamp(30px, min(9vw, 6.5vh), 56px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: background .12s ease, border-color .12s ease, transform .1s ease;
}
.choice-btn:active { transform: translateY(1px); background: var(--track); }
.choice-btn.correct { border-color: var(--good); background: var(--good-soft); color: var(--good); }
.choice-btn.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }

/* ---------- speed round ---------- */

.timer-block { text-align: center; }
.timer-big {
  font-size: clamp(54px, min(16vw, 11vh), 110px);
  font-weight: 800;
  line-height: 1;
  color: var(--tint, var(--brand));
  font-variant-numeric: tabular-nums;
}
.timer-big.low { color: var(--bad); animation: pulse 1s ease-in-out infinite; }
.timer-label {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.results-headline { font-size: clamp(26px, 4.5vh, 38px); text-align: center; }

.results-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}
.results-stats .stat {
  flex: 1;
  min-width: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 10px;
  text-align: center;
}
.results-stats .stat b { display: block; font-size: clamp(28px, 5vh, 44px); line-height: 1.15; font-variant-numeric: tabular-nums; }
.results-stats .stat span { font-size: 11px; font-weight: 800; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .05em; }

.results-list { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.results-list .hint { width: 100%; text-align: center; margin: 0 0 2px; }
.results-list .rl-item {
  background: var(--bad-soft);
  color: var(--bad);
  font-weight: 800;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.save-score-row { display: flex; gap: 8px; width: 100%; }
.save-score-row input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  padding: 14px 16px;
  min-height: clamp(56px, 8vh, 72px);
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
}
.save-score-row input::placeholder { color: var(--ink-faint); font-weight: 600; }
.save-score-row input:focus { outline: 2px solid var(--tint, var(--brand)); outline-offset: -2px; }
.save-score-row input:disabled { opacity: .6; }

.results-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ---------- matching ---------- */

.matching-columns { display: flex; gap: clamp(10px, 2vw, 20px); width: 100%; max-width: 860px; margin: 0 auto 16px; }
.matching-col { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.matching-item {
  padding: 16px 8px;
  min-height: clamp(58px, 8.5vh, 92px);
  font-size: clamp(19px, min(5.5vw, 3.4vh), 30px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: background .12s ease, border-color .12s ease, opacity .2s ease;
}
.matching-item.selected { border-color: var(--tint, var(--brand)); background: var(--tint-soft, var(--brand-soft)); }
.matching-item.matched { opacity: .35; border-style: dashed; box-shadow: none; }
.matching-item.wrong-flash { border-color: var(--bad); background: var(--bad-soft); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translate(-50%, 12px);
  z-index: 100;
  max-width: min(90vw, 420px);
  padding: 12px 18px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }


/* ---------- answer feedback effects ---------- */

#fx-layer {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  overflow: hidden;
}
#fx-layer > * { position: absolute; will-change: transform, opacity; }

.fx-piece { width: 11px; height: 11px; border-radius: 2px; }
.fx-spark { width: 8px; height: 8px; border-radius: 2px; }
.fx-star { width: 30px; height: 30px; display: block; }
.fx-star svg { width: 100%; height: 100%; }

.fx-ring {
  width: 120px;
  height: 120px;
  border: 5px solid currentColor;
  border-radius: 50%;
}

.fx-word {
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(255, 255, 255, .85);
}

.fx-check svg { width: 100%; height: 100%; }

.fx-plus {
  font-size: clamp(20px, 4.5vw, 30px);
  font-weight: 800;
  color: var(--brand-dark);
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(255, 255, 255, .85);
}

/* Wrong answers get this and nothing else: a warm outline that fades. */
.fx-halo {
  border: 3px solid var(--bad);
  border-radius: var(--radius);
  background: rgba(206, 64, 72, .08);
}

/* ---------- home progress strip ---------- */

.home-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  width: min(100%, 340px);
}
.home-level { font-size: 14px; font-weight: 800; }
.home-xp-track {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, .25);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.home-xp-fill {
  display: block;
  height: 100%;
  width: 0;
  background: #fff;
  border-radius: var(--radius-sm);
  transition: width .4s ease;
}
.home-today { font-size: 12.5px; font-weight: 700; color: rgba(255, 255, 255, .82); }

/* ---------- rewards screen ---------- */

.sub-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-faint);
  text-align: center;
  margin: 4px 0 10px;
}

.level-card { text-align: center; }
.level-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 14px;
}
.level-badge {
  width: clamp(52px, 9vw, 66px);
  height: clamp(52px, 9vw, 66px);
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius);
  font-size: clamp(24px, 4vw, 30px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.level-text { display: flex; flex-direction: column; align-items: flex-start; }
.level-text b { font-size: clamp(19px, 3vw, 24px); }
.level-text span { font-size: 13.5px; font-weight: 700; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.xp-track, .goal-track {
  width: 100%;
  height: 14px;
  background: var(--track);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.xp-fill, .goal-fill {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: var(--radius-sm);
  transition: width .4s ease;
}
.goal-fill { background: var(--good); }

.today-stats, .week-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.week-facts { margin: 14px 0 0; }
.today-stats .stat, .week-facts .stat {
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
}
.today-stats .stat b, .week-facts .stat b {
  display: block;
  font-size: clamp(24px, 4vh, 34px);
  font-variant-numeric: tabular-nums;
}
.today-stats .stat span, .week-facts .stat span {
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* daily goals */

.quest-list { display: flex; flex-direction: column; gap: 8px; }
.quest-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
}
.quest-row.done { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.quest-check {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--good);
}
.quest-row.done .quest-check { border-color: var(--good); background: #fff; }
.quest-check svg { width: 17px; height: 17px; }
.quest-count { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 14px; }

/* week strip */

.week-strip { display: flex; justify-content: center; gap: clamp(8px, 2vw, 16px); }
.week-day {
  flex: 1;
  max-width: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.week-day b { font-size: 13px; font-weight: 800; color: var(--ink-faint); }
.week-day i {
  width: 100%;
  aspect-ratio: 1;
  max-height: 60px;
  display: grid;
  place-items: center;
  background: var(--surface-sunk);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: #fff;
}
.week-day i svg { width: 60%; height: 60%; }
.week-day.done i { background: var(--good); border-color: var(--good); }
.week-day.today b { color: var(--brand); }
.week-day.today i { border-color: var(--brand); }
.week-day.future i { opacity: .5; }

/* accuracy tiers */

.tier-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.tier-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunk);
  text-align: center;
  opacity: .55;
}
.tier-chip b { font-size: 15px; }
.tier-chip span { font-size: 11.5px; font-weight: 700; color: var(--ink-soft); }
.tier-chip.active { opacity: 1; box-shadow: var(--shadow); background: var(--surface); }
.tier-bronze.active { border-color: #B0722F; color: #8A5722; }
.tier-silver.active { border-color: #8C97A8; color: #5D6B79; }
.tier-gold.active { border-color: #D9A21B; color: #9C7212; }
.tier-diamond.active { border-color: #2FA8C6; color: #1B7E97; }

/* medals */

.medal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.medal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 14px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunk);
  text-align: center;
}
.medal-disc {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  border: 2px dashed var(--border-strong);
  color: var(--ink-faint);
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.medal-disc svg { width: 30px; height: 30px; }
.medal-name { font-size: 13.5px; font-weight: 800; }
.medal-sub { font-size: 11.5px; font-weight: 700; color: var(--ink-faint); }
.medal.earned { background: var(--surface); box-shadow: var(--shadow); }
.medal.earned .medal-disc { border-style: solid; color: #fff; }
.medal-bronze .medal-disc { background: #B0722F; border-color: #8A5722; }
.medal-silver .medal-disc { background: #8C97A8; border-color: #737F91; }
.medal-gold .medal-disc { background: #D9A21B; border-color: #B07F0F; }
.medal-diamond .medal-disc { background: #2FA8C6; border-color: #1B7E97; }
.medal.earned .medal-sub { color: var(--ink-soft); }

/* badges */

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.badge {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunk);
  text-align: center;
  opacity: .6;
}
.badge.earned {
  opacity: 1;
  background: var(--brand-soft);
  border-color: var(--brand);
  box-shadow: var(--shadow);
}
.badge-name { display: block; font-size: 14px; font-weight: 800; }
.badge.earned .badge-name { color: var(--brand-deep); }
.badge-hint { display: block; font-size: 11.5px; font-weight: 700; color: var(--ink-soft); margin-top: 2px; }

/* table trophies */

.trophy-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 12px;
}
@media (min-width: 620px) { .trophy-row { grid-template-columns: repeat(12, 1fr); } }
.trophy {
  height: clamp(46px, 7vw, 60px);
  display: grid;
  place-items: center;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--ink-faint);
  font-weight: 800;
  font-size: clamp(15px, 2vw, 19px);
  font-variant-numeric: tabular-nums;
}
.trophy.won {
  border-style: solid;
  background: #D9A21B;
  border-color: #B07F0F;
  color: #fff;
}


/* ---------- the chosen character ---------- */

.buddy-slot {
  flex: none;
  display: block;
  width: clamp(64px, 15vw, 128px);
  align-self: flex-end;
  transform-origin: 50% 90%;
}
.buddy-art {
  display: block;
  width: 100%;
  height: auto;
  max-height: clamp(90px, 22vh, 210px);
  object-fit: contain;
  object-position: bottom center;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* app-bar version: small enough to sit beside a stat pill */
.buddy-mini { width: 34px; align-self: center; }
.buddy-mini .buddy-art { max-height: 40px; }

/* results version: the character takes a bow */
.buddy-large { width: clamp(110px, 26vw, 190px); align-self: center; }
.buddy-large .buddy-art { max-height: clamp(130px, 26vh, 240px); }

/* Problem and buddy share a row so the character never overlaps
   anything — it simply takes its own column beside the sum. */
.problem-row {
  display: flex;
  align-items: flex-end;
  gap: clamp(8px, 2vw, 18px);
  width: 100%;
}
.problem-row .problem-card { flex: 1; min-width: 0; }

/* home header portrait */

.home-buddy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-top: 6px;
  padding: 6px 14px 8px;
  border-radius: var(--radius);
  color: inherit;
  transition: background .12s ease;
}
.home-buddy:active { background: rgba(255, 255, 255, .14); }
.home-buddy-art { display: block; width: clamp(96px, 26vw, 150px); }
.home-buddy-art .buddy-art { max-height: clamp(110px, 22vh, 170px); }
.home-buddy-name { font-size: clamp(17px, 3vw, 21px); font-weight: 800; }
.home-buddy-swap {
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: rgba(255, 255, 255, .72);
}

/* picker */

.pick-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(10px, 2vw, 16px);
}
@media (min-width: 560px) { .pick-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 940px) { .pick-grid { grid-template-columns: repeat(3, 1fr); } }

.pick-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 5px solid var(--tint);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform .1s ease, box-shadow .12s ease, background .12s ease;
}
.pick-card:active { transform: translateY(1px); background: var(--tint-soft); }
.pick-card.chosen { background: var(--tint-soft); border-color: var(--tint); box-shadow: var(--shadow-raised); }

.pick-art {
  display: block;
  width: 100%;
  height: clamp(150px, 26vh, 220px);
  margin-bottom: 6px;
}
/* The traced SVGs carry only a viewBox, so the browser gives them a
   default intrinsic size and a percentage max-height does not hold
   them. Sizing the image to the box and letting object-fit letterbox
   it is the version that actually constrains them. */
.pick-art img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
}
.pick-name { font-size: clamp(17px, 2.4vw, 20px); font-weight: 800; }
.pick-tagline { font-size: 13px; font-weight: 600; color: var(--ink-soft); line-height: 1.35; }
.pick-state {
  margin-top: 8px;
  padding: 8px 16px;
  min-height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-soft);
  background: var(--track);
}
.pick-card.chosen .pick-state { background: var(--tint); color: #fff; }


/* ---------- the character's strategy line ---------- */

.buddy-say {
  width: 100%;
  margin: 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--tint, var(--brand));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: clamp(14px, 2.1vh, 17px);
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
  text-align: center;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none;
}
.buddy-say:empty { display: none; }
.buddy-say.show { opacity: 1; transform: translateY(0); }
.buddy-say b { color: var(--tint, var(--brand)); }

/* strategy on the speed-round review list */
.review-tip {
  width: 100%;
  margin: 10px 0 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- flash card back: answer, array, strategy ---------- */

.flash-answer-num { font-size: 1em; line-height: 1; }
.flash-array {
  display: block;
  margin-top: 10px;
  color: rgba(255, 255, 255, .85);
  max-width: 70%;
}
.flash-array svg { width: 100%; height: auto; max-height: 22vh; }
.flash-tip {
  display: block;
  margin-top: 10px;
  max-width: 92%;
  font-size: clamp(12px, 1.7vh, 15px);
  font-weight: 700;
  line-height: 1.35;
  color: rgba(255, 255, 255, .92);
}
/* The back holds three stacked things, so it centres as a column
   rather than as one big number. */
.flash-back {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: clamp(38px, min(11vw, 9vh), 88px);
  padding: 18px 14px;
}

/* ---------- fact family ---------- */

.family-triangle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.fam-top, .fam-legs { display: flex; align-items: center; justify-content: center; gap: clamp(10px, 3vw, 26px); }
.fam-times { font-size: clamp(18px, 3vw, 24px); font-weight: 800; color: var(--ink-faint); }
.fam-cell {
  min-width: clamp(56px, 13vw, 84px);
  padding: clamp(8px, 1.4vh, 14px) 10px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.fam-cell.hidden-cell {
  background: var(--tint-soft, var(--brand-soft));
  border-color: var(--tint, var(--brand));
  border-style: dashed;
  color: var(--tint, var(--brand));
}
.family-sentence { font-size: clamp(30px, min(9vw, 6.5vh), 56px); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* Fact Family carries one more block than the other games — the
   triangle — so its stack runs tighter to stay on one screen. */
#screen-family .problem-card { padding: clamp(10px, 1.8vh, 22px) 12px; }
#screen-family .answer-display { padding: clamp(8px, 1.4vh, 18px); }
#screen-family .keypad button { min-height: clamp(48px, 7.2vh, 88px); }
#screen-family .fam-cell { padding: clamp(6px, 1vh, 12px) 10px; }
#screen-family .play-body { gap: clamp(8px, 1.2vh, 16px); }
