:root{
  --sky:#EAF6FF;
  --ink:#22314F;
  --ink-soft:#5B6B8C;
  --bond:#FFB100;
  --bond-deep:#E89400;
  --grow:#17B978;
  --grow-deep:#0E9A61;
  --spark:#FF5D5D;
  --card:#FFFFFF;
  --lilac:#F1ECFF;
  --lilac-deep:#DCD2FF;
  /* Text-safe partners for the brand hues. The bright hues stay for fills,
     rings and decoration; anything that has to be READ uses these
     (all ≥4.5:1 on white, sky, lilac and their own tinted washes). */
  --bond-ink:#9A5B00;
  --grow-ink:#0B7A4B;
  --spark-ink:#B02E2E;
  --streak-ink:#B04000;
  /* Fills that carry white text (Check, total circle, right/wrong choice,
     danger button) — deep enough for white at ≥4.5:1. */
  --grow-strong:#0C8350;
  --spark-strong:#D63B3B;
  /* Text on the bright amber fill. */
  --bond-on:#3A2400;
  /* Pale feedback/pill backgrounds, each paired with its ink. */
  --bond-wash:#FFF3D6;
  --gold-wash:#FFE7B0;
  --grow-wash:#E4FBEF;
  --spark-wash:#FFEBEB;
  --spark-wash-deep:#FFE0E0;
  --cloud-wash:#EAF2FF;
  --cloud-line:#CFE0FF;
  --radius-lg:28px;
  --radius-md:18px;
  --radius-sm:12px;
  --shadow-soft:0 12px 30px -12px rgba(34,49,79,0.25);
  --shadow-pop:0 6px 14px -6px rgba(34,49,79,0.3);
  --font-display:'Baloo 2', 'Baloo 2 Fallback', system-ui, sans-serif;
  --font-body:'Nunito', 'Nunito Fallback', system-ui, sans-serif;
  /* The outline of a form field is the only thing that says "type here", so it
     needs 3:1 against white (the lilac borders on cards and chips are only 1.4:1). */
  --field-line:#7F8BAA;
  /* Light only, by design: stops Android and Chrome auto-dark from inverting the app. */
  color-scheme:only light;

  /* Game-screen sizing follows the viewport HEIGHT, not just its width: a
     laptop or Chromebook is wide but short, and the answer pad has to fit
     above the fold there too. --vh1 is dvh where supported (so a phone's
     collapsing address bar is counted) and plain vh otherwise. */
  --vh1:1vh;
  --circle-max:96px;
  --key-max:62px;
  --key-h:clamp(44px, calc(var(--vh1) * 7.4), var(--key-max));
  /* Capped by height AND by width: a bond diagram is about 3.2 circles plus
     two operators, so on a 360px phone it has to be 65px or it wraps. */
  --circle:clamp(52px, min(calc(var(--vh1) * 12), calc((100vw - 154px) / 3.2)), var(--circle-max));
  --mascot:clamp(44px, calc(var(--vh1) * 8), 64px);
  --timer:clamp(46px, calc(var(--vh1) * 7.5), 56px);
  --chrome-gap:clamp(8px, calc(var(--vh1) * 2.4), 18px);
}
@supports (height:1dvh){ :root{ --vh1:1dvh; } }

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  min-height:100vh;
  background:var(--sky);
  color:var(--ink);
  font-family:var(--font-body);
  overflow-x:hidden;
  -webkit-font-smoothing:antialiased;
}

.bg-bonds{
  position:fixed; inset:0; z-index:-1; overflow:hidden;
}
.bg-bonds svg{
  position:absolute; top:-30vmax; right:-30vmax; width:80vmax; height:80vmax;
  opacity:.5;
}
.bg-bonds circle{ fill:none; stroke:var(--lilac-deep); stroke-width:60; }
.bg-bonds::after{
  content:"";
  position:absolute; left:-25vmax; bottom:-35vmax; width:70vmax; height:70vmax;
  border-radius:50%;
  border:50px solid var(--gold-wash);
  opacity:.45;
}

/* touch-action stops double-tap zoom on fast numpad taps without
   disabling pinch-zoom for the whole app. */
button{ font-family:inherit; cursor:pointer; touch-action:manipulation; }
:focus-visible{ outline:3px solid var(--ink); outline-offset:2px; }
/* Each screen moves focus to its heading (tabindex="-1") so screen readers
   announce the new screen; that isn't a control, so it gets no ring. */
[tabindex="-1"]:focus{ outline:none; }
/* The parts the browser draws, themed from the palette. */
:root{ accent-color:var(--grow-strong); }
::selection{ background:var(--gold-wash); color:var(--ink); }
input, textarea{ caret-color:var(--bond-ink); }
.timer-num, .dash-stat b, .dash-bar-pct, .compare-table td, .leader-row .medals{ font-variant-numeric:tabular-nums; }

/* Settings: checkbox rows are full 44px targets; help text under a control. */
.check-row{ display:flex; gap:8px; align-items:center; font-weight:700; min-height:44px; cursor:pointer; }
.check-row input[type=checkbox]{ width:20px; height:20px; margin:0; flex:none; }
.setting-help{ font-size:.8rem; margin-top:4px; }

/* ---------- Topbar ---------- */
.topbar{
  display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:8px;
  padding:14px 20px; position:sticky; top:0; z-index:20;
  background:rgba(234,246,255,0.82); backdrop-filter:blur(8px);
}
.brand{
  display:flex; align-items:center; gap:10px; background:none; border:none;
  font-family:var(--font-display); font-weight:700; font-size:1.15rem; color:var(--ink);
  min-height:44px; padding:2px;
}
.brand-mark{ width:44px; height:28px; }
.bond-line{ stroke:var(--ink-soft); stroke-width:3; fill:none; }
.bond-dot{ stroke:var(--card); stroke-width:3; }
.dot-a{ fill:var(--bond); }
.dot-b{ fill:var(--grow); }
.dot-total{ fill:var(--ink); }

.topnav{ display:flex; align-items:center; gap:6px; flex-wrap:wrap; justify-content:flex-end; }
/* 44px tall everywhere: small fingers are the primary users. */
.nav-btn{
  border:none; background:var(--card); color:var(--ink);
  min-height:44px; padding:0 14px; border-radius:999px; font-weight:800; font-size:.85rem;
  box-shadow:var(--shadow-pop); white-space:nowrap;
}
.nav-btn:hover{ transform:translateY(-1px); }

/* ---------- Grown-ups menu ----------
   Below 900px the adult items (Reports, Sync, Premium, Settings, About)
   fold into one "Grown-ups" dropdown; above it they sit inline as before. */
.grownups{ position:relative; }
.grownups-toggle{ display:inline-flex; align-items:center; gap:5px; }
/* A small solid triangle, not a chevron: a rotated chevron reads as a ✓
   at this size, right next to "Premium ✓". */
.grownups-toggle::after{
  content:""; border-left:4.5px solid transparent; border-right:4.5px solid transparent;
  border-top:6px solid currentColor; transition:transform .15s ease;
}
.grownups.open .grownups-toggle::after{ transform:rotate(180deg); }
.grownups-menu{
  display:none; position:absolute; right:0; top:calc(100% + 8px); z-index:30;
  min-width:190px; padding:6px; flex-direction:column; gap:2px;
  background:var(--card); border-radius:var(--radius-md); box-shadow:var(--shadow-soft);
}
.grownups.open .grownups-menu{ display:flex; }
.grownups-menu .nav-btn{ box-shadow:none; border-radius:var(--radius-sm); text-align:left; width:100%; }
.grownups-menu .nav-btn:hover{ transform:none; background:var(--lilac); }
@media(min-width:900px){
  .grownups, .grownups-menu{ display:contents; }
  .grownups-toggle, .grownups-only{ display:none; }
  .grownups-menu .nav-btn{ box-shadow:var(--shadow-pop); border-radius:999px; width:auto; }
  .grownups-menu .nav-btn:hover{ transform:translateY(-1px); background:var(--card); }
}

/* Smaller phones: the sticky topbar can otherwise eat a third of the
   viewport and push the game screen's primary "Check" button below the
   fold on the very first question of a session. The logo mark stays (and
   keeps its "Go to welcome screen" label); the wordmark steps aside so
   Shop, Medals and Grown-ups fit on one row. */
@media(max-width:480px){
  .topbar{ padding:6px 10px; gap:4px; flex-wrap:nowrap; }
  .brand{ font-size:1rem; gap:7px; }
  .brand > span{ display:none; }
  .brand-mark{ width:40px; height:26px; }
  .topnav{ gap:4px; flex-wrap:nowrap; }
  .nav-btn{ padding:0 9px; font-size:.8rem; }
}
/* The very narrowest phones: wrap to two rows rather than scroll sideways. */
@media(max-width:350px){
  .topbar{ flex-wrap:wrap; }
  .topnav{ flex:1 1 100%; justify-content:flex-end; }
}

main{ max-width:720px; margin:0 auto; padding:20px 18px 60px; }

/* ---------- Generic building blocks ---------- */
.screen{ display:flex; flex-direction:column; gap:18px; animation:rise .35s ease; }
@keyframes rise{ from{opacity:0; transform:translateY(10px);} to{opacity:1; transform:none;} }

.card{
  background:var(--card); border-radius:var(--radius-lg); padding:26px 22px;
  box-shadow:var(--shadow-soft);
}
h1,h2,h3{ font-family:var(--font-display); margin:0 0 4px; color:var(--ink); }
h1{ font-size:1.9rem; font-weight:800; }
h2{ font-size:1.4rem; font-weight:700; }
p{ margin:0; line-height:1.5; color:var(--ink-soft); }
.eyebrow{
  font-family:var(--font-display); font-weight:700; letter-spacing:.02em;
  color:var(--bond-ink); font-size:.85rem; text-transform:uppercase;
}

.btn{
  border:none; border-radius:999px; padding:14px 22px; font-weight:800;
  font-size:1.02rem; font-family:var(--font-display); box-shadow:var(--shadow-pop);
  transition:transform .12s ease;
}
.btn:active{ transform:scale(.96); }
.btn-primary{ background:var(--bond); color:var(--bond-on); }
.btn-primary:hover{ background:var(--bond-deep); }
.btn-secondary{ background:var(--lilac); color:var(--ink); }
.btn-ghost{ background:transparent; box-shadow:none; color:var(--ink-soft); font-weight:700; }
.btn-danger{ background:var(--spark-strong); color:#fff; }
.btn-block{ width:100%; }
/* A disabled button must look disabled (flat, grey-lilac, no pointer) rather than
   keep its bright fill and ignore taps; the text still clears 4.5:1. */
.btn:disabled{ background:var(--lilac); color:var(--ink-soft); box-shadow:none; cursor:not-allowed; }
.btn:disabled:active, .btn:disabled:hover{ transform:none; }
.btn-row{ display:flex; gap:10px; flex-wrap:wrap; }

.field{ display:flex; flex-direction:column; gap:6px; margin-bottom:14px; }
.field label{ font-weight:800; font-size:.88rem; color:var(--ink); }
.field small{ color:var(--ink-soft); font-size:.78rem; }
input[type=text], input[type=number], input[type=password], input[type=email], input[type=tel], input[type=url], select{
  border:2px solid var(--field-line); border-radius:var(--radius-sm);
  padding:12px 14px; font-size:1rem; font-family:var(--font-body); font-weight:700;
  color:var(--ink); background:#fff;
}
select{ max-width:100%; }
input:focus, select:focus{ border-color:var(--bond); }
.segmented{ display:flex; gap:8px; flex-wrap:wrap; }
.seg-opt{
  border:2px solid var(--lilac-deep); background:#fff; color:var(--ink-soft);
  min-height:44px; padding:0 16px; border-radius:999px; font-weight:800; font-size:.9rem;
}
.seg-opt.active{ background:var(--ink); border-color:var(--ink); color:#fff; }

/* ---------- Welcome ---------- */
.welcome-hero{ text-align:center; padding-top:8px; }
.welcome-hero .brand-mark{ width:120px; height:76px; margin:0 auto 10px; display:block; }
.name-grid{ display:flex; flex-wrap:wrap; gap:10px; justify-content:center; margin-top:10px; }
.name-chip{
  background:var(--lilac); border:2px solid transparent; border-radius:999px;
  min-height:44px; padding:10px 18px; font-weight:800; color:var(--ink); display:flex; align-items:center; gap:8px;
}
/* Names are typed by children (up to 20 characters, no spaces needed), so every place
   one appears has to be able to wrap it rather than push the page wider. */
.name-chip{ max-width:100%; }
.chip-name, .person-name{ min-width:0; overflow-wrap:anywhere; text-align:left; }
.leader-row > div{ min-width:0; }
.leader-row .medals, .manage-student-row button{ flex:none; }
.round-result h1, .certificate-name, h1.eyebrow{ overflow-wrap:anywhere; }
/* The legal links in the app are stand-alone, so they get full-size touch targets. */
.legal-links a{ display:inline-flex; align-items:center; min-height:44px; padding:0 10px; }
.name-chip .medals{ color:var(--bond-ink); }
.name-chip .streak{ color:var(--streak-ink); }
.name-chip.active{ border-color:var(--bond); background:#fff; }
.mode-grid{ display:grid; grid-template-columns:1fr; gap:12px; }
@media(min-width:560px){ .mode-grid{ grid-template-columns:1fr 1fr 1fr; } }
.mode-card{
  background:#fff; border:2px solid var(--lilac-deep); border-radius:var(--radius-md);
  padding:18px 16px; text-align:left; display:flex; flex-direction:column; gap:6px; position:relative;
}
/* Subject groups on Welcome: a native <details>, so it opens with a tap, Enter or Space. */
.mode-cat > summary{ display:flex; align-items:center; gap:12px; min-height:44px; cursor:pointer; list-style:none; }
.mode-cat > summary::-webkit-details-marker{ display:none; }
.mode-cat > summary h2{ margin:0; }
.mode-cat .cat-count{ margin-left:auto; color:var(--ink-soft); font-size:.85rem; font-weight:700; }
.mode-cat > summary::after{
  content:""; flex:none; border-left:5px solid transparent; border-right:5px solid transparent;
  border-top:7px solid var(--ink-soft); transition:transform .15s ease;
}
.mode-cat[open] > summary::after{ transform:rotate(180deg); }
.level-badge{
  align-self:flex-start; margin-top:4px; background:var(--lilac); color:var(--ink);
  font-family:var(--font-display); font-weight:700; font-size:.72rem;
  padding:3px 10px; border-radius:999px;
}
.mode-card:hover{ border-color:var(--bond); }
.mode-card .m-icon{ font-size:1.6rem; }
.mode-card b{ font-family:var(--font-display); font-size:1.05rem; }
.mode-card span{ color:var(--ink-soft); font-size:.85rem; }

/* ---------- Game screen ---------- */
.progress-dots{ display:flex; gap:7px; justify-content:center; flex-wrap:wrap; }
.p-dot{
  width:18px; height:18px; border-radius:50%; background:var(--lilac-deep);
  transition:transform .2s ease, background .2s ease;
}
/* Right vs wrong differs in shape as well as colour (filled + tick vs.
   hollow ring), so it reads for colour-blind players too. */
.p-dot.done-correct{
  background:var(--grow-strong) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M5 9.5l2.6 2.6L13 6.6' fill='none' stroke='%23fff' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat;
  transform:scale(1.1);
}
.p-dot.done-wrong{ background:var(--card); box-shadow:inset 0 0 0 4px var(--spark-strong); transform:scale(1.1); }
.p-dot.current{ background:var(--bond); box-shadow:0 0 0 4px var(--gold-wash); }

.screen:has(.game-card){ gap:var(--chrome-gap); }
.game-card{ text-align:center; position:relative; padding-block:clamp(12px, calc(var(--vh1) * 3), 26px); }
/* The question side and the answer pad are wrapped so wide, short screens can
   set them side by side (see the landscape block below). Stacked, the
   wrappers add nothing. */
.game-main, .game-pad{ display:contents; }
.game-toprow{ display:flex; align-items:center; justify-content:center; gap:14px; flex-wrap:wrap; margin-bottom:4px; }
.game-toprow .mascot-stage.small .mascot{ width:var(--mascot); height:var(--mascot); }
.timer-wrap{ display:flex; justify-content:center; margin-bottom:clamp(0px, calc(var(--vh1) * 1.2), 10px); }
.timer-ring{ position:relative; width:var(--timer); height:var(--timer); }
.timer-ring svg{ transform:rotate(-90deg); width:var(--timer); height:var(--timer); }
.timer-ring circle{ fill:none; stroke-width:6; }
.timer-track{ stroke:var(--lilac-deep); }
.timer-bar{ stroke:var(--grow); stroke-linecap:round; transition:stroke-dashoffset 1s linear, stroke .3s; }
.timer-ring.low .timer-bar{ stroke:var(--spark); }
.timer-num{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  font-family:var(--font-display); font-weight:800; font-size:1.1rem;
}

.bond-diagram{ display:flex; align-items:center; justify-content:center; gap:6px; margin:clamp(6px, calc(var(--vh1) * 1.6), 14px) 0 clamp(4px, var(--vh1), 8px); flex-wrap:wrap; }
.bond-circle{
  width:var(--circle); height:var(--circle); border-radius:50%; display:flex; align-items:center; justify-content:center;
  font-family:var(--font-display); font-weight:800; font-size:calc(var(--circle) * .333); color:#fff;
  background:var(--ink); box-shadow:var(--shadow-pop);
}
.bond-circle.given{ background:var(--ink); }
.bond-circle.long-val{ font-size:calc(var(--circle) * .19); }
.bond-circle.blank{ background:var(--bond); color:var(--bond-on); }
.bond-circle input{
  width:100%; height:100%; border:none; background:transparent; text-align:center;
  font-family:var(--font-display); font-weight:800; font-size:calc(var(--circle) * .3); color:inherit;
}
.bond-circle input:focus{ outline:none; }
.bond-circle.blank:has(input:focus-visible){ outline:3px solid var(--ink); outline-offset:3px; }
.bond-op{ font-family:var(--font-display); font-weight:800; font-size:1.8rem; color:var(--ink-soft); text-align:center; }
.bond-op.long-op{ font-size:.95rem; max-width:140px; line-height:1.25; }
.bond-eq{ font-family:var(--font-display); font-weight:800; font-size:1.8rem; color:var(--ink-soft); }
.bond-total{ width:calc(var(--circle) * 1.167); height:calc(var(--circle) * 1.167); border-radius:50%; background:var(--grow-strong); color:#fff; }

.bond-circle.pulse-correct{ animation:pulseGreen .6s ease; }
.bond-circle.pulse-wrong{ animation:shakeRed .5s ease; }

/* ---------- Long Division (its own small widget, shares the numpad) ---------- */
.longdiv-problem{ display:flex; align-items:center; justify-content:center; gap:10px; margin:clamp(6px, calc(var(--vh1) * 1.6), 14px) 0 clamp(8px, calc(var(--vh1) * 2), 20px); flex-wrap:wrap; }
.longdiv-answers{ display:flex; align-items:center; justify-content:center; gap:clamp(8px, 1.4vw, 12px); flex-wrap:wrap; }
/* A fixed, narrow width: left to size itself the field took on its input's
   default width (about 370px), so Quotient and Remainder could never sit
   on one row and the Remainder box dropped under the Quotient. */
.longdiv-field{
  background:var(--lilac); border:3px solid transparent; border-radius:var(--radius-md);
  padding:6px 8px; flex:0 0 auto; width:clamp(104px, 30vw, 156px); text-align:center; cursor:pointer; transition:border-color .15s, background .15s;
}
.longdiv-field.active{ border-color:var(--bond); background:#fff; box-shadow:var(--shadow-pop); }
.longdiv-field.pulse-correct{ animation:pulseGreen .6s ease; }
.longdiv-field.pulse-wrong{ animation:shakeRed .5s ease; }
.longdiv-field-label{ font-size:.72rem; font-weight:800; color:var(--ink-soft); text-transform:uppercase; letter-spacing:.03em; }
.longdiv-field input{
  width:100%; min-width:0; padding:0; border:none; background:transparent; text-align:center;
  font-family:var(--font-display); font-weight:800; font-size:1.6rem; line-height:1.2; color:var(--ink);
}
.longdiv-r-label{ font-family:var(--font-display); font-weight:800; font-size:1.4rem; color:var(--ink-soft); }
.longdiv-stage.shake-retry{ animation:shakeRetry .4s ease; }
@keyframes pulseGreen{ 0%{box-shadow:0 0 0 0 rgba(23,185,120,.6);} 100%{box-shadow:0 0 0 22px rgba(23,185,120,0);} }
@keyframes shakeRed{ 0%,100%{transform:translateX(0);} 25%{transform:translateX(-8px);} 75%{transform:translateX(8px);} }

/* ---------- Fractions ---------- */
.frac{ display:inline-flex; flex-direction:column; align-items:center; line-height:1.15; font-weight:800; }
.frac-num{ border-bottom:2px solid currentColor; padding:0 4px 3px; }
.frac-den{ padding:3px 4px 0; }
.bond-circle.blank{ position:relative; }
.bond-circle.blank .frac-den-label{
  position:absolute; bottom:10px; font-size:.85rem; font-weight:700; color:inherit; opacity:.85;
}
.bond-circle.blank:has(.frac-den-label) input{ height:60%; margin-top:8px; }

/* ---------- Sequences ---------- */
.seq-term{ width:min(64px, var(--circle)); height:min(64px, var(--circle)); font-size:1.3rem; }
.seq-arrow{ font-size:1.4rem; color:var(--ink-soft); font-weight:800; align-self:center; }

/* ---------- Clock (Telling Time) ---------- */
.shape-display svg circle[stroke]{ }

/* Key height is set outright (not padding + the display font's tall line
   height, which made the pad 450px), and shrinks with the viewport's height
   down to the 44px touch-target floor. */
.numpad{ display:grid; grid-template-columns:repeat(3,1fr); gap:clamp(6px, calc(var(--vh1) * 1.2), 10px); max-width:320px; margin:clamp(8px, calc(var(--vh1) * 2), 18px) auto 0; }
.numpad button{
  border:none; background:var(--lilac); border-radius:var(--radius-md);
  font-family:var(--font-display); font-weight:800; font-size:1.4rem; color:var(--ink);
  height:var(--key-h); padding:0; line-height:1; box-shadow:var(--shadow-pop);
}
.numpad button:active{ transform:scale(.94); }
.numpad .np-clear{ background:var(--spark-wash-deep); color:var(--spark-ink); }
.numpad .np-neg{ background:var(--gold-wash); color:var(--bond-ink); }
/* Clear shares the last row with a double-width Check. Left in a row of its
   own, Clear stranded two empty cells and added a whole row of height. */
.numpad .np-submit{ background:var(--grow-strong); color:#fff; grid-column:span 2; font-size:1.15rem; height:calc(var(--key-h) + 4px); }
.numpad .np-clear{ height:calc(var(--key-h) + 4px); font-size:1.05rem; }

/* Smaller phones: smaller ceilings for the circles and the keys (they still
   shrink further with the viewport's height), and a tighter top margin. */
@media(max-width:480px){
  :root{ --circle-max:76px; --key-max:56px; }
  main{ padding-top:12px; }
  .numpad{ gap:7px; }
  /* Mascot, timer and Hint stay on one row; a long Hint label wraps inside
     its button instead of pushing the row onto a second line. */
  .game-toprow{ flex-wrap:nowrap; gap:8px; }
  .hint-btn{ white-space:normal; line-height:1.15; padding:4px 10px; font-size:.78rem; flex:1 1 0; min-width:0; max-width:170px; }
}

/* Small phones: take back width where it costs nothing, and keep diagrams with
   four or five items on ONE row (they wrapped onto a second row, about 65px of
   height) by drawing their circles smaller. These are the older children's
   subjects: order of operations, ratio, sequences. */
@media(max-width:480px){
  main{ padding-inline:10px; }
  .game-card{ padding-inline:14px; }
  :root{ --circle:clamp(52px, min(calc(var(--vh1) * 10.5), calc((100vw - 120px) / 3.2)), var(--circle-max)); }
  .bond-diagram.dense{ gap:3px; --circle:clamp(34px, calc((100vw - 140px) / 5.2), 56px); }
  .bond-diagram.dense .bond-circle{ font-size:calc(var(--circle) * .42); }
  .bond-diagram.dense .bond-circle input{ font-size:calc(var(--circle) * .4); }
  .bond-diagram.dense .bond-op, .bond-diagram.dense .bond-eq, .bond-diagram.dense .seq-arrow{ font-size:1.1rem; }
  /* Answer buttons: still 48px tall (a thumb target), and four short answers
     (Rectangle, Octagon, Pentagon, Square) share one row instead of wrapping to two. */
  .choice-grid .choice-btn{ min-height:48px; padding:12px 6px; font-size:1.1rem; overflow-wrap:anywhere; }
  .choice-grid.choice-grid{ gap:8px; }
  .choice-grid[data-short]{ grid-template-columns:repeat(auto-fit, minmax(64px, 1fr)); }
}
/* Short phones: the gaps above the question card are the last cheap height to give back. */
@media(max-width:480px) and (max-height:700px){
  .screen:has(.game-card){ gap:8px; }
  .game-card{ padding-block:12px; }
}
/* A picture question (shape, clock, chart, spinner) gives back height on short screens. */
.shape-display svg{ max-height:max(92px, calc(var(--vh1) * 17)); width:auto; }

/* Short viewports (laptops, Chromebooks, small phones): the sticky topbar and
   the page's own margins are the cheapest height to give back, then the
   lines the game card reserves for text that is usually empty. */
@media(max-height:700px){
  .topbar{ padding-block:6px; }
  main{ padding-top:12px; padding-bottom:32px; }
}
@media(max-height:740px){
  .game-toprow{ margin-bottom:0; }
  .tries-indicator{ margin-bottom:0; }
  .hint-text{ min-height:1.15em; margin:0; }
  .longdiv-problem{ margin-bottom:8px; }
  .longdiv-field input{ font-size:1.4rem; }
}
@media(max-width:480px){
  .shape-prompt{ font-size:1rem; line-height:1.25; }
}

/* Wide AND short (laptops and Chromebooks, tablets and phones on their side):
   the width is there and the height isn't, so the question and the answer pad
   sit side by side instead of stacking, and Check never needs a scroll. The
   pad keeps full-size keys; the question side is the one that flexes. */
@media(orientation:landscape) and (min-width:640px) and (max-height:1000px){
  :root{ --key-h:clamp(44px, calc(var(--vh1) * 10), var(--key-max)); --circle:clamp(58px, calc(var(--vh1) * 15), var(--circle-max)); }
  main:has(.game-card){ max-width:980px; }
  .game-card{ display:grid; grid-template-columns:minmax(0, 1fr) auto; align-items:start; column-gap:clamp(20px, 3vw, 40px); }
  .game-main, .game-pad{ display:block; min-width:0; }
  .game-pad .numpad{ width:min(320px, 38vw); margin:0; }
  .game-pad .choice-grid{ width:min(420px, 46vw); margin:0; }
}
/* Very little height left (a phone on its side, or a small phone with the
   browser's bars showing): the subject-and-player line above the dots is the
   first thing to give way. It stays in the page for screen readers. */
@media(max-height:600px), (max-width:480px) and (max-height:700px){
  .screen:has(.game-card) > .eyebrow{
    position:absolute; width:1px; height:1px; margin:-1px; padding:0; overflow:hidden;
    clip-path:inset(50%); white-space:nowrap; border:0;
  }
}

/* Stays in the layout (collapsed when empty) rather than display:none, so
   screen readers treat it as a live region and announce each result. */
.feedback-banner{
  font-family:var(--font-display); font-weight:800; font-size:1.1rem; padding:10px; border-radius:var(--radius-sm);
}
.feedback-banner:empty{ padding:0; }
.feedback-banner.correct{ background:var(--grow-wash); color:var(--grow-ink); }
.feedback-banner.wrong{ background:var(--spark-wash); color:var(--spark-ink); }
.feedback-banner.retry{ background:var(--bond-wash); color:var(--bond-ink); }

.bond-circle.shake-retry{ animation:shakeRetry .4s ease; }
@keyframes shakeRetry{ 0%,100%{transform:translateX(0);} 25%{transform:translateX(-6px);} 75%{transform:translateX(6px);} }

.tries-indicator{ font-weight:700; font-size:.8rem; color:var(--ink-soft); min-height:1.1em; margin-bottom:4px; }

.hint-btn{
  border:none; background:var(--lilac); color:var(--ink);
  min-height:44px; padding:0 14px; border-radius:999px; font-weight:800; font-family:var(--font-display);
  font-size:.85rem; box-shadow:var(--shadow-pop); white-space:nowrap;
}
.hint-btn:disabled{ color:var(--ink-soft); box-shadow:none; cursor:default; }
.hint-text{
  min-height:1.4em; font-weight:800; font-family:var(--font-display); color:var(--bond-ink);
  font-size:.95rem; margin:2px 0 4px;
}

.choice-btn.choice-wrong-try{ background:var(--spark-wash-deep); color:var(--spark-ink); }
.choice-btn.choice-eliminated{ background:var(--lilac); color:var(--ink-soft); opacity:.5; text-decoration:line-through; }

.review-note{ color:var(--ink-soft); font-weight:600; font-size:.85em; }

/* ---------- Cloud Sync screen ---------- */
.auth-divider{
  display:flex; align-items:center; gap:10px; color:var(--ink-soft); font-size:.8rem; font-weight:700;
  margin:14px 0;
}
.auth-divider::before, .auth-divider::after{ content:""; flex:1; height:1px; background:var(--lilac-deep); }
/* Text-style buttons keep their inline look, but the padding/negative-
   margin pair grows the tap area to ~44px without moving anything. */
.link-btn{
  background:none; border:none; color:var(--bond-ink); font-weight:800; text-decoration:underline;
  padding:14px 6px; margin:-14px -6px; font-size:inherit; box-shadow:none;
}

.sync-nudge{
  display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap;
  background:var(--cloud-wash); border:1px solid var(--cloud-line); color:var(--ink);
  padding:10px 16px; border-radius:var(--radius-sm); font-size:.85rem; font-weight:700;
}
.sync-nudge-actions{ display:flex; gap:14px; white-space:nowrap; }
.sync-status-error{ color:var(--spark-ink); font-weight:800; font-size:.85rem; }

.manage-students-list{ display:flex; flex-direction:column; gap:6px; }
.manage-student-row{
  display:flex; align-items:center; justify-content:space-between;
  background:var(--lilac); padding:8px 14px; border-radius:var(--radius-sm); font-weight:700;
}
.danger-link{ color:var(--spark-ink); }

/* ---------- Summary ---------- */
.leader-row{
  display:flex; align-items:center; justify-content:space-between;
  padding:12px 16px; border-radius:var(--radius-sm); background:var(--lilac);
  margin-bottom:8px; font-weight:700;
}
.leader-row .rank{ font-family:var(--font-display); font-weight:800; color:var(--bond-ink); width:28px; }
.leader-row .medals{ font-family:var(--font-display); font-weight:800; }

/* ---------- Settings ---------- */
/* min-width:0 everywhere here: a fieldset and a 1fr grid column both default to
   "as wide as my widest child", which let a long dropdown option stretch the
   whole Settings page past a phone's edge. */
fieldset{ border:none; padding:0; margin:0 0 18px; min-width:0; }
legend{ font-family:var(--font-display); font-weight:700; font-size:1rem; padding:0 0 8px; }
.setting-grid{ display:grid; grid-template-columns:minmax(0,1fr); gap:14px; }
.setting-grid > *, .field{ min-width:0; }
.field input, .field select{ width:100%; min-width:0; }
@media(min-width:560px){ .setting-grid.two{ grid-template-columns:minmax(0,1fr) minmax(0,1fr); } }
.lock-card{ text-align:center; max-width:320px; margin:0 auto; }

.settings-category{
  background:var(--lilac); border-radius:var(--radius-md); padding:4px 16px;
  margin-bottom:14px;
}
.settings-category summary{
  cursor:pointer; list-style:none; font-family:var(--font-display); font-weight:800;
  font-size:1.05rem; color:var(--ink); padding:14px 0; display:flex; align-items:center;
  justify-content:space-between;
}
.settings-category summary::-webkit-details-marker{ display:none; }
.settings-category summary::after{
  content:"▸"; color:var(--bond-ink); font-size:1.1rem; transition:transform .15s ease; margin-left:10px;
}
.settings-category[open] summary::after{ transform:rotate(90deg); }
.settings-category fieldset{
  background:#fff; border-radius:var(--radius-sm); padding:16px; margin:0 0 12px;
}
.settings-category fieldset:last-of-type{ margin-bottom:16px; }

.toast{
  position:fixed; left:50%; bottom:26px; transform:translate(-50%,120%);
  background:var(--ink); color:#fff; padding:12px 20px; border-radius:999px;
  font-weight:700; box-shadow:var(--shadow-soft); z-index:50;
  /* translate alone leaves a sliver of the pill over the Check button on
     phones; hide it fully once it has slid away. */
  visibility:hidden; transition:transform .3s ease, visibility 0s linear .3s;
}
.toast.show{ transform:translate(-50%,0); visibility:visible; transition:transform .3s ease, visibility 0s; }

.round-result{ text-align:center; }
.round-result .big-medal{ font-size:3.4rem; }
.streak-line{ margin-top:8px; font-weight:800; color:var(--streak-ink); }
.level-line{ margin-top:4px; font-weight:700; color:var(--ink-soft); font-size:.9rem; }

/* ---------- Mascot ---------- */
.mascot-stage{ display:flex; justify-content:center; margin-bottom:6px; }
.mascot{ width:88px; height:88px; }
.mascot-stage.small .mascot{ width:64px; height:64px; }
.mascot-idle{ animation:mascotFloat 2.6s ease-in-out infinite; }
.mascot-happy{ animation:mascotBounce .5s ease; }
.mascot-sad{ animation:mascotWobble .5s ease; }
.mascot-celebrate{ animation:mascotBounce .7s ease infinite; }
@keyframes mascotFloat{ 0%,100%{transform:translateY(0);} 50%{transform:translateY(-6px);} }
@keyframes mascotBounce{ 0%{transform:scale(1) translateY(0);} 30%{transform:scale(1.15,.85) translateY(6px);} 60%{transform:scale(.92,1.1) translateY(-14px);} 100%{transform:scale(1) translateY(0);} }
@keyframes mascotWobble{ 0%,100%{transform:rotate(0);} 25%{transform:rotate(-8deg);} 75%{transform:rotate(8deg);} }

/* ---------- Confetti ---------- */
.confetti-layer{ position:fixed; inset:0; pointer-events:none; z-index:60; overflow:hidden; }
.confetti-piece{
  position:absolute; top:-20px; width:9px; height:14px; opacity:.9;
  border-radius:2px; animation-name:confettiFall; animation-timing-function:ease-in; animation-fill-mode:forwards;
}
@keyframes confettiFall{
  0%{ transform:translate(0,0) rotate(0); opacity:1; }
  100%{ transform:translate(var(--drift), 100vh) rotate(var(--rot)); opacity:0; }
}

/* ---------- Round review list ---------- */
.review-list{ display:flex; flex-direction:column; gap:8px; }
.review-row{
  display:flex; align-items:center; gap:10px; flex-wrap:wrap;
  padding:10px 14px; border-radius:var(--radius-sm); font-weight:700; font-family:var(--font-body);
}
.review-row.ok{ background:var(--grow-wash); }
.review-row.bad{ background:var(--spark-wash); }
.review-icon{ font-size:1.05rem; }
.review-expr{ font-family:var(--font-display); font-weight:700; color:var(--ink); }
.review-expr u{ text-decoration-color:var(--bond-ink); text-decoration-thickness:2px; }
.review-given{ color:var(--spark-ink); font-size:.85rem; font-weight:700; margin-left:auto; }

/* ---------- Round-result callouts ---------- */
.coins-line{ margin-top:4px; font-weight:800; color:var(--bond-ink); }
/* A coin drawn in CSS: the coin emoji is missing on Android 10 and older. */
.coin{
  display:inline-block; width:1em; height:1em; margin-right:.15em; vertical-align:-.14em;
  border-radius:50%; box-sizing:border-box; border:.13em solid var(--bond-deep);
  background:radial-gradient(circle, var(--bond-deep) 0 20%, var(--bond) 22%);
}

/* ---------- Coin pill on welcome ---------- */
.coin-pill{
  display:inline-block; margin-top:14px; background:var(--bond-wash); color:var(--bond-ink);
  font-weight:800; padding:8px 16px; border-radius:999px; font-size:.88rem;
}

/* ---------- Shop ---------- */
.shop-grid{ display:grid; grid-template-columns:repeat(auto-fill,minmax(140px,1fr)); gap:14px; margin-top:16px; }
.shop-item{
  background:#fff; border:2px solid var(--lilac-deep); border-radius:var(--radius-md);
  padding:16px 12px; display:flex; flex-direction:column; align-items:center; gap:8px; text-align:center;
}
.shop-item.equipped{ border-color:var(--grow); }
/* Locked items dim the picture only. Dimming the whole tile dropped the name
   and the Premium button to 2.2-3.3:1. */
.shop-item.locked .shop-swatch{ opacity:.55; }
.shop-swatch{ width:52px; height:52px; border-radius:50%; box-shadow:var(--shadow-pop); overflow:hidden; }
.shop-swatch svg{ display:block; }
.shop-tag{
  font-family:var(--font-display); font-weight:700; font-size:.78rem; color:var(--grow-ink);
  background:var(--grow-wash); padding:4px 10px; border-radius:999px;
}
.shop-btn{ font-size:.82rem; min-height:44px; padding:0 14px; }

/* ---------- About screen ---------- */
.about-nav-grid{ display:grid; grid-template-columns:1fr; gap:10px; margin-top:12px; }
@media(min-width:560px){ .about-nav-grid{ grid-template-columns:1fr 1fr; } }
.about-nav-item{
  background:var(--lilac); border-radius:var(--radius-sm); padding:12px 14px;
  display:flex; flex-direction:column; gap:2px;
}
.about-nav-item b{ font-family:var(--font-display); }
.about-nav-item span{ font-size:.85rem; }
.about-author a{ color:var(--bond-ink); font-weight:800; }

/* ---------- Dashboard ---------- */
.dash-stat-grid{ display:grid; grid-template-columns:repeat(2,1fr); gap:12px; margin-top:12px; }
@media(min-width:560px){ .dash-stat-grid{ grid-template-columns:repeat(4,1fr); } }
.dash-stat{
  background:var(--lilac); border-radius:var(--radius-sm); padding:14px; text-align:center;
}
.dash-stat b{ display:block; font-family:var(--font-display); font-size:1.5rem; color:var(--ink); }
.dash-stat span{ font-size:.78rem; }
.dash-bars{ display:flex; flex-direction:column; gap:10px; margin-top:10px; }
.dash-bar-row{ display:flex; align-items:center; gap:10px; }
.dash-bar-label{ width:110px; font-weight:700; font-size:.85rem; flex-shrink:0; }
.dash-bar-track{ flex:1; height:12px; background:var(--lilac); border-radius:999px; overflow:hidden; }
.dash-bar-fill{ height:100%; background:var(--grow); border-radius:999px; }
.dash-bar-pct{ width:42px; text-align:right; font-weight:800; font-size:.85rem; }
.dash-note{ margin-top:12px; background:var(--bond-wash); color:var(--bond-ink); padding:10px 14px; border-radius:var(--radius-sm); font-weight:700; }

/* ---------- Multi-child comparison (Premium) ---------- */
.compare-table{ width:100%; border-collapse:collapse; margin-top:10px; min-width:520px; }
.compare-table th, .compare-table td{ padding:10px 12px; text-align:center; border-bottom:1px solid var(--lilac-deep); }
.compare-table th{ font-family:var(--font-display); color:var(--ink); }
.compare-table td:first-child, .compare-table th:first-child{ text-align:left; font-weight:700; }

/* ---------- Certificate (Premium) ---------- */
.certificate{ max-width:640px; margin:0 auto; }
.certificate-border{
  border:6px double var(--bond); border-radius:var(--radius-md); padding:36px 24px; text-align:center;
  background:linear-gradient(180deg,#fff, var(--lilac) 220%);
}
.certificate-eyebrow{ font-family:var(--font-display); font-weight:700; letter-spacing:.08em; text-transform:uppercase; color:var(--bond-ink); margin-top:14px; }
.certificate-name{ font-size:2.2rem; margin:6px 0; }
.certificate-body{ color:var(--ink-soft); }
.certificate-date{ margin-top:18px; font-weight:700; }
.certificate-signoff{ margin-top:4px; font-size:.85rem; color:var(--ink-soft); }

/* ---------- Choice-type questions (Comparing Numbers, Shapes) ---------- */
.choice-stage{ display:flex; flex-direction:column; align-items:center; margin:10px 0; }
.shape-display{ display:flex; justify-content:center; margin-bottom:10px; }
.shape-prompt{ font-family:var(--font-display); font-weight:700; font-size:1.1rem; color:var(--ink); text-align:center; }
.choice-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(84px,1fr)); gap:12px; max-width:420px; margin:clamp(8px, calc(var(--vh1) * 2), 16px) auto 0; }
.choice-btn{
  border:none; background:var(--lilac); border-radius:var(--radius-md);
  font-family:var(--font-display); font-weight:800; font-size:1.3rem; color:var(--ink);
  padding:18px 10px; box-shadow:var(--shadow-pop); transition:transform .12s ease;
}
.choice-btn:active{ transform:scale(.95); }
/* Only the buttons that are simply out of play fade. The right answer, the
   chosen wrong one and the retry state keep full contrast (opacity took the
   white-on-green answer down to 3.1:1). */
.choice-btn:disabled:not(.choice-correct):not(.choice-wrong):not(.choice-wrong-try):not(.choice-eliminated){ opacity:.75; }
.choice-btn.choice-correct{ background:var(--grow-strong); color:#fff; }
.choice-btn.choice-wrong{ background:var(--spark-strong); color:#fff; }

@page{ margin:12mm; }
@media print{
  .topbar, .no-print, .toast, .confetti-layer, .bg-bonds{ display:none !important; }
  body{ background:#fff; min-height:0; }
  main{ max-width:100%; padding:0; }
  .screen{ animation:none; gap:12px; }
  .card{ box-shadow:none; border:1px solid var(--lilac-deep); break-inside:avoid; }
  h1, h2{ break-after:avoid; }
  /* Browsers leave background colours out of a printout unless told to keep them,
     and the progress bars, stat tiles and certificate are made of background colour. */
  .dash-bar-track, .dash-bar-fill, .dash-stat, .certificate-border, .level-badge{
    -webkit-print-color-adjust:exact; print-color-adjust:exact;
  }
}

/* Reduced motion: keep the feedback, drop the movement. Screens and the
   toast still fade and every colour/state change still shows (the green
   "correct" ripple, dot ticks and rings, banners), but nothing slides,
   shakes, bounces or floats. Confetti is skipped in JS. */
@media(prefers-reduced-motion: reduce){
  @keyframes fadeIn{ from{opacity:0;} to{opacity:1;} }
  .screen{ animation-name:fadeIn; }
  .mascot-idle, .mascot-happy, .mascot-sad, .mascot-celebrate,
  .bond-circle.shake-retry, .longdiv-stage.shake-retry,
  .bond-circle.pulse-wrong, .longdiv-field.pulse-wrong{ animation:none; }
  .btn:active, .numpad button:active, .choice-btn:active,
  .nav-btn:hover, .p-dot.done-correct, .p-dot.done-wrong{ transform:none; }
  .toast{ transform:translate(-50%,0); opacity:0; transition:opacity .2s ease, visibility 0s linear .2s; }
  .toast.show{ opacity:1; transition:opacity .2s ease, visibility 0s; }
}

/* ---------- Race the clock (child's own timer choice) ---------- */
.clock-pick{
  margin-top:10px; padding:12px 14px; background:var(--lilac); border:2px solid var(--lilac-deep);
  border-radius:var(--radius-sm); color:var(--ink);
}
.clock-pick b{ display:block; font-family:var(--font-display); font-size:1rem; margin-bottom:8px; }
.clock-pick small{ display:block; margin-top:8px; font-size:.82rem; font-weight:700; color:var(--ink-soft); }
.clock-opts{ display:grid; grid-template-columns:repeat(auto-fit,minmax(64px,1fr)); gap:8px; }
.clock-opt{
  min-height:48px; border-radius:var(--radius-sm); border:2px solid var(--lilac-deep); background:#fff;
  color:var(--ink); font-family:var(--font-display); font-weight:800; font-size:1rem; cursor:pointer; box-shadow:none;
}
.clock-opt.on{ background:#0A7A4C; border-color:#0A7A4C; color:#fff; }
.clock-nudge{
  margin:16px auto 0; max-width:420px; padding:12px 14px; border-radius:var(--radius-sm);
  background:var(--bond-wash); color:var(--ink);
}
.clock-nudge p{ margin:0 0 6px; }

/* ---------- WhatsApp link ---------- */
.wa-link{
  display:inline-flex; align-items:center; min-height:44px; font-weight:800;
  color:#0B6B5D; text-decoration:underline;
}
.clock-own{ margin-top:10px; }
.clock-own label{ display:block; font-size:.85rem; font-weight:800; margin-bottom:6px; }
.clock-own-row{ display:flex; gap:8px; align-items:stretch; }
.clock-own-row input{ flex:1; min-width:0; min-height:48px; font-size:1.1rem; font-weight:800; text-align:center; }
.clock-own-row .btn{ padding:10px 22px; min-height:48px; }
