*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* A child leaning on the screen should never select text, trigger the
   browser's double-tap zoom, or rubber-band the page out of the way. */
body {
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  /* Keeps content clear of the iPad's rounded corners and home indicator. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  min-height: 100%;
  /* dvh tracks Safari's collapsing toolbars; 100% is the fallback. */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

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

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Vertical rhythm scales with the viewport. On an iPad in portrait the
     fixed 2rem gaps pushed the ✓ key below the fold, which is fatal: he
     taps his answer and then cannot find the button to submit it. */
  gap: clamp(0.6rem, 2.2vh, 2rem);
  padding: clamp(0.6rem, 1.8vh, 1.5rem);
  animation: screen-in 220ms ease-out;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.screen__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.25rem, 7vw, 4rem);
  line-height: 1.05;
  letter-spacing: -0.015em;
  text-align: center;
}

.screen__sub {
  margin: 0;
  font-size: 1.15rem;
  color: var(--ink-soft);
  text-align: center;
}

/* A full-bleed electric blue field, the way the reference site opens. Used
   for the moments either side of the work — arriving and finishing — while
   the questions themselves stay on white, where manipulatives have the
   contrast they need. */
.screen--hero {
  background: var(--blue);
  color: var(--ink-invert);
}

.screen--hero .screen__sub { color: rgba(255, 255, 255, 0.82); }

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

/* Pills throughout, following the reference site. Flat surfaces with soft
   ambient shadow rather than the stacked "3D" edge — but the press still
   moves, because a button that visibly responds is worth a lot to a child
   who is not yet sure the tap registered. */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: 0 1.75rem;
  cursor: pointer;
  transition: transform 90ms ease, box-shadow 90ms ease, background 120ms ease;
}

.btn:hover  { box-shadow: var(--shadow-lift); transform: translateY(-2px); }
.btn:active { transform: translateY(1px); box-shadow: var(--shadow); }

.btn:focus-visible {
  outline: 3px solid var(--blue-bright);
  outline-offset: 3px;
}

.btn--primary {
  background: var(--primary);
  color: var(--ink-invert);
  box-shadow: 0 6px 18px rgba(0, 67, 239, 0.32);
}
.btn--primary:hover { background: var(--blue-bright); box-shadow: 0 10px 26px rgba(0, 67, 239, 0.38); }

.btn--go {
  font-size: clamp(1.4rem, 3.6vw, 2rem);
  font-weight: 700;
  padding: 1.15rem 3.5rem;
  min-height: 92px;
}

.btn--ghost {
  background: transparent;
  box-shadow: none;
  color: var(--ink-soft);
  font-weight: 600;
}
.btn--ghost:hover { background: var(--surface-sunk); box-shadow: none; transform: none; }

/* On the blue field, the secondary action is an outlined pill — the
   reference site's pattern exactly. */
.screen--hero .btn--primary {
  background: var(--surface);
  color: var(--blue);
  box-shadow: 0 6px 20px rgba(3, 19, 61, 0.22);
}
.screen--hero .btn--primary:hover { background: #fff; }

.screen--hero .btn--ghost {
  color: var(--ink-invert);
  border: 1px solid rgba(255, 255, 255, 0.7);
}
.screen--hero .btn--ghost:hover { background: rgba(255, 255, 255, 0.14); }

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

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar__spacer { flex: 1; }

.topbar__skill {
  font-weight: 700;
  font-size: 1.05rem;
}

.topbar__stage {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.iconbtn {
  width: var(--tap-min);
  height: var(--tap-min);
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-sunk);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 120ms ease, border-color 120ms ease;
}
.iconbtn:hover { background: var(--primary-soft); border-color: var(--blue); }
.iconbtn:focus-visible { outline: 3px solid var(--blue-bright); outline-offset: 2px; }
.iconbtn[aria-pressed="false"] { opacity: 0.45; }

/* --------------------------------------------------------- session progress */

.pips {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pip {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface-sunk);
  border: 2px solid var(--border);
  transition: background 200ms ease, transform 200ms ease;
}
.pip--done    { background: var(--correct); border-color: var(--correct-dark); }
.pip--current { transform: scale(1.35); border-color: var(--primary); background: var(--primary-soft); }

/* The phone stand-in for the pip row; hidden everywhere else. */
.progress-count {
  display: none;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* -------------------------------------------------------------- problem area */

.problem {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.6rem, 2.2vh, 2.5rem);
  padding: clamp(0.4rem, 1.2vh, 1.5rem);
  width: 100%;
}

/* NOTE: this base rule must stay ABOVE the media queries below. Same
   specificity means source order decides, and when it sat underneath them its
   `max-width` silently cancelled the landscape override — the prompt kept
   sharing a row instead of taking one, pushing the number pad off screen. */
.problem__prompt {
  margin: 0;
  font-size: var(--prompt-size);
  font-weight: 600;
  text-align: center;
  /* Story problems are a whole sentence; at 24ch they wrapped to four lines
     and ate the height the answer pad needed. */
  max-width: 32ch;
  line-height: 1.25;
}

/* Landscape on a tablet is wide and short. Stacking everything vertically
   wastes the width and runs out of height, so the question and the answer
   pad sit side by side instead. */
@media (orientation: landscape) and (max-height: 1100px) {
  .problem {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: clamp(0.75rem, 2vw, 1.75rem);
  }
  .problem__prompt { flex-basis: 100%; max-width: none; }

  /* The Make Ten hint sits under two ten-frames that are already wide; left
     unbounded it forces the number pad onto its own row. */
  .movehint { max-width: 28ch; font-size: 0.9rem; }

  .numpad { gap: 8px; }
}

/* Short landscape — a regular iPad turned sideways. Here the display and the
   answer pad genuinely compete for width, so the widest thing on screen (a
   row of ten objects) gives some back. */
@media (orientation: landscape) and (max-height: 880px) {
  :root { --counter-size: 36px; }
  .countergroup__grid--wide { gap: 7px; }
  .problem__prompt { font-size: clamp(1.2rem, 2.6vw, 1.8rem); }
}

.problem__stage-hint {
  font-size: 1rem;
  color: var(--ink-soft);
}

/* the big equation, e.g.  4 + 3 = ? */
.equation {
  display: flex;
  align-items: center;
  gap: clamp(0.5rem, 2vw, 1.25rem);
  font-size: var(--numeral-size);
  font-weight: 700;
  /* Tabular so a digit does not shift as answers swap in and out, lining so
     every numeral sits on the baseline at a uniform height. */
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--navy);
}

.equation__op { color: var(--blue); }

/* In a sequence, adjacent numerals must never read as one number — "1 2 ? 4"
   scanned as "12" defeats the whole exercise. Each value gets its own card. */
.equation[data-kind="sequence"] { gap: clamp(0.6rem, 2.5vw, 1.5rem); }

.equation[data-kind="sequence"] .equation__num,
.equation[data-kind="sequence"] .equation__slot {
  min-width: 1.5em;
  min-height: 1.3em;
  padding: 0.1em 0.2em;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
}

.equation[data-kind="sequence"] .equation__num {
  background: var(--surface);
  border: 3px solid var(--border);
}

.equation__slot {
  min-width: 1.4em;
  min-height: 1.2em;
  padding: 0 0.15em;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--surface-sunk);
  border: 3px dashed #b9c4dd;
  color: var(--ink-soft);
}

.equation__slot--filled {
  background: var(--primary-soft);
  border-style: solid;
  border-color: var(--primary);
  color: var(--blue);
}

.equation__slot--correct {
  background: var(--correct-soft);
  border-color: var(--correct);
  color: var(--correct-dark);
}

.equation__slot--retry {
  background: var(--retry-soft);
  border-color: var(--retry);
  color: var(--retry-dark);
  animation: nudge 320ms ease;
}

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-8px); }
  75%      { transform: translateX(8px); }
}

/* ------------------------------------------------- counters (Concrete stage) */

.counters {
  display: flex;
  align-items: center;
  gap: clamp(0.75rem, 3vw, 2rem);
  flex-wrap: wrap;
  justify-content: center;
}

.counters__sep {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  color: var(--ink-soft);
}

.countergroup {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem;
}

.counters--stack {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.countergroup__grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), auto);
  gap: 10px;
}

/* Ten to a row for large counts, with a break after the fifth so the
   five-structure survives — 8 is still "five and three", not a blur. */
.countergroup__grid--wide > *:nth-child(10n + 6) { margin-left: 14px; }

.countergroup__grid--tray {
  background: var(--surface);
  border: 4px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
}

/* Display counters may shrink to fit a screen; tappable ones may not, so the
   two sizes are deliberately separate. --tap-min is a floor, not a target. */
.counter {
  width: var(--counter-size);
  height: var(--counter-size);
  border-radius: 50%;
  display: block;
  position: relative;
}

.counterslot {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: block;
  position: relative;
  border: 3px dashed var(--border);
  background: var(--surface-sunk);
  padding: 0;
  cursor: pointer;
  transition: transform 90ms ease, background 120ms ease;
}
.counterslot:hover:not(:disabled) { transform: scale(1.08); }
.counterslot:focus-visible { outline: 4px solid var(--primary); outline-offset: 3px; }
.counterslot--filled { border: 3px solid rgba(0, 0, 0, 0.12); }

/* Color classes come last so they win over the slot's own background. */
.counter--a { background: var(--counter-a); }
.counter--b { background: var(--counter-b); }
.counter--c { background: var(--counter-c); }

.counter { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16); }

.counter--crossed { opacity: 0.3; }
.counter--crossed::after {
  content: '';
  position: absolute;
  top: -6px;
  bottom: -6px;
  left: 50%;
  width: 5px;
  margin-left: -2.5px;
  background: var(--ink);
  border-radius: 3px;
  transform: rotate(45deg);
}

.filltray {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* Secondary to the target numeral above it — two identical bold numbers on
   one screen is the fastest way to make a child answer the wrong question. */
.filltray__count {
  font-size: 1.9rem;
  font-weight: 700;
  min-width: 2.4ch;
  padding: 0.15rem 0.6rem;
  text-align: center;
  color: var(--ink-soft);
  background: var(--surface-sunk);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.filltray__count--correct { color: var(--correct-dark); }
.filltray__count--retry   { color: var(--retry-dark); animation: nudge 320ms ease; }

.filltray__done {
  font-size: 1.4rem;
  padding: 0 2.25rem;
  min-height: 72px;
}

.taprow {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Ordinal position is meaningless without an obvious starting point — you
   cannot find "the 4th" unless you know which end to count from. */
.taprow__start {
  font-size: 2.2rem;
  line-height: 1;
  color: var(--primary);
  margin-right: 4px;
}

.taprow__item--marked {
  outline: 6px solid var(--counter-b);
  outline-offset: 5px;
  transform: scale(1.12);
}

.taprow__item--correct { outline: 5px solid var(--correct); outline-offset: 4px; }
.taprow__item--retry   { outline: 5px solid var(--retry);   outline-offset: 4px; }

/* ------------------------------------------------ ten-frames (Pictorial) */

.tenframes {
  display: flex;
  align-items: center;
  gap: clamp(0.75rem, 3vw, 1.75rem);
  flex-wrap: wrap;
  justify-content: center;
}

.tenframe {
  display: grid;
  grid-template-columns: repeat(5, var(--tf-cell));
  grid-template-rows: repeat(2, var(--tf-cell));
  background: var(--surface);
  border: 4px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
}

.tenframe__cell {
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
}

.tenframe__dot {
  width: calc(var(--tf-cell) - 18px);
  height: calc(var(--tf-cell) - 18px);
  border-radius: 50%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
}

/* Make Ten tints the counters that crossed over, so the split is visible. */
.tenframe__dot--highlight { background: var(--counter-b); }

/* ------------------------------------------- base-ten blocks (place value) */

/* Rods and ones share a bottom baseline: the ones stack upward like a rod
   being built, so "nine ones is nearly a ten" is visible at a glance. */
.baseten {
  display: flex;
  align-items: flex-end;
  gap: clamp(1rem, 4vw, 2.5rem);
  justify-content: center;
  min-height: 138px;
}

.baseten__tens {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.baseten__ones {
  display: flex;
  flex-direction: column-reverse;
  gap: 2px;
}

/* Ten visibly joined units — never a bar with "10" printed on it. The point
   is that a ten IS ten ones bundled. */
.rod {
  display: grid;
  grid-template-rows: repeat(10, 13px);
  width: 22px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  overflow: hidden;
}

.rod__seg { border-bottom: 1px solid rgba(255, 255, 255, 0.55); }
.rod__seg:last-child { border-bottom: none; }

/* A struck-through block, at both rod and cube proportions. The bar has to
   scale with the shape or it turns into an unreadable smudge on a cube. */
.rod--crossed,
.cube.counter--crossed {
  opacity: 0.32;
  position: relative;
}

.rod--crossed::after,
.cube.counter--crossed::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: 0;
  width: auto;
  transform: none;
  border-radius: 0;
  background: linear-gradient(
    to bottom right,
    transparent calc(50% - 2px),
    var(--ink) calc(50% - 2px),
    var(--ink) calc(50% + 2px),
    transparent calc(50% + 2px)
  );
}

/* One cube is exactly one rod segment tall, so "nine ones is nearly a rod"
   is visible rather than asserted. */
.cube {
  width: 22px;
  height: 13px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  position: relative;
}

.btbuilder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.btbuilder__row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  padding: 0.5rem;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: var(--radius-sm);
}

.btslot {
  border: 2px dashed var(--border);
  background: var(--surface-sunk);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.btslot--ten { width: 26px; height: 134px; }
.btslot--one { width: 26px; height: 17px; }
.btslot--filled { border-color: transparent; background: none; }
.btslot:disabled { cursor: default; }
.btslot:focus-visible { outline: 4px solid var(--primary); outline-offset: 2px; }

.pvchart {
  border-collapse: collapse;
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.pvchart th {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  padding: 0.3rem 1.4rem;
}

.pvchart td {
  border: 3px solid var(--border);
  padding: 0.35rem 1.4rem;
  text-align: center;
  background: var(--surface);
}

.pvchart__op {
  border: none !important;
  background: none !important;
  padding-right: 0.4rem !important;
  color: var(--ink-soft);
}

.pvchart__unknown { background: var(--primary-soft); color: var(--primary-dark); }

/* ------------------------------------------------- discrete strips (K–1) */

.strip {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: flex-start;
}

.strip__row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.strip__label {
  min-width: 4.5ch;
  text-align: right;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink-soft);
}

.strip__units { display: flex; }

/* One square, one object. Never scaled — he can always count them. */
.strip__unit {
  width: var(--strip-unit);
  height: calc(var(--strip-unit) + 4px);
  border: 2px solid rgba(0, 0, 0, 0.22);
  margin-right: -2px;
}
.strip__unit:first-child { border-radius: 6px 0 0 6px; }
.strip__unit:last-child  { border-radius: 0 6px 6px 0; margin-right: 0; }

/* The split between the two parts of a part-whole strip. */
.strip__unit--divide { border-right: 5px solid var(--ink); margin-right: 4px; }
.strip__unit--divide + .strip__unit { border-radius: 6px 0 0 6px; }

.strip--partwhole { align-items: stretch; }

/* The two parts sit side by side with a visible break between them. */
.strip__row--split { gap: 8px; align-items: flex-start; }

.strip__seg {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.strip__part {
  text-align: center;
  font-weight: 800;
  font-size: 1.25rem;
  min-width: 2.5ch;
  padding: 0.15rem 0.3rem;
  background: var(--surface-sunk);
  border-radius: var(--radius-sm);
}

.strip__part--unknown {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.strip__whole {
  text-align: center;
  font-weight: 800;
  font-size: 1.3rem;
  padding: 0.2rem 0;
  border-top: 3px solid var(--border);
  color: var(--ink-soft);
}

/* Story problems show the actual object rather than an abstract disc.
   Scales with the shared counter size — hard-coded, a group of eighteen
   apples pushed the answer pad off the bottom of an iPad. */
.counter--glyph {
  background: none;
  box-shadow: none;
  font-size: calc(var(--counter-size) - 12px);
  line-height: var(--counter-size);
  text-align: center;
}

/* ------------------------------------- Make Ten mover (interactive frames) */

.moveframes {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.tenframes--interactive .tenframe__cell {
  padding: 0;
  background: none;
  cursor: default;
}

.tenframes--interactive button.tenframe__cell {
  cursor: pointer;
  border: 2px solid var(--border);
  transition: transform 90ms ease;
}
.tenframes--interactive button.tenframe__cell:hover:not(:disabled) { transform: scale(1.1); }
.tenframes--interactive button.tenframe__cell:disabled { cursor: default; }
.tenframes--interactive button.tenframe__cell:focus-visible {
  outline: 4px solid var(--primary);
  outline-offset: -2px;
}

.movehint {
  font-size: 1rem;
  color: var(--ink-soft);
  text-align: center;
  max-width: 34ch;
}

/* ----------------------------------------------- number line (Pictorial) */

.numberline {
  width: min(640px, 92vw);
  height: auto;
}

.numberline__axis {
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linecap: round;
}

.numberline__tick { stroke: var(--border); stroke-width: 3; }
.numberline__tick--major { stroke: var(--ink); stroke-width: 4; }

.numberline__label {
  font-family: var(--font);
  font-size: 22px;
  font-weight: 700;
  fill: var(--ink-soft);
}

.numberline__hop {
  stroke: var(--primary);
  stroke-width: 5;
  stroke-linecap: round;
}

.numberline__hoplabel {
  font-family: var(--font);
  font-size: 24px;
  font-weight: 800;
  fill: var(--primary);
}

.numberline__dot { fill: var(--primary); }
.numberline__dot--end { fill: var(--counter-b); }

/* --------------------------------------------- number bond (Pictorial) */

.bond {
  width: min(340px, 82vw);
  height: auto;
  overflow: visible;
}

.bond__link {
  stroke: var(--ink-soft);
  stroke-width: 5;
  stroke-linecap: round;
}

.bond__circle {
  fill: var(--surface);
  stroke: var(--primary);
  stroke-width: 5;
  transition: fill 150ms ease, stroke 150ms ease;
}

.bond__circle--part { stroke: var(--counter-b); }

.bond__circle--slot {
  fill: var(--surface-sunk);
  stroke-dasharray: 11 9;
}

.bond__circle--filled {
  fill: var(--primary-soft);
  stroke-dasharray: none;
}

.bond__circle--correct {
  fill: var(--correct-soft);
  stroke: var(--correct);
  stroke-dasharray: none;
}

.bond__circle--retry {
  fill: var(--retry-soft);
  stroke: var(--retry);
  stroke-dasharray: none;
}

.bond__text {
  font-family: var(--font);
  font-size: 44px;
  font-weight: 800;
  fill: var(--ink);
}

/* ------------------------------------------------------------------ numpad */

.numpad {
  display: grid;
  grid-template-columns: repeat(3, var(--key));
  gap: 10px;
  justify-content: center;
}

.numpad__key {
  height: var(--key);
  font-size: 2.15rem;
  font-weight: 700;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-variant-numeric: tabular-nums lining-nums;
  transition: transform 80ms ease, box-shadow 80ms ease, background 120ms ease;
}
.numpad__key:hover  { background: var(--primary-soft); border-color: var(--blue); }
.numpad__key:active { transform: translateY(2px); box-shadow: none; }
.numpad__key:focus-visible { outline: 3px solid var(--blue-bright); outline-offset: 2px; }

.numpad__key--wide { grid-column: span 2; }

.numpad__key--enter {
  background: var(--correct);
  border-color: var(--correct-dark);
  color: var(--ink-invert);
  box-shadow: 0 6px 16px rgba(14, 158, 130, 0.30);
}
.numpad__key--enter:hover { background: var(--correct); border-color: var(--correct-dark); }
.numpad__key--enter:disabled {
  opacity: 0.3;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.numpad__key--back {
  background: var(--surface-sunk);
  font-size: 1.8rem;
  color: var(--ink-soft);
}

/* --------------------------------------------------------------- choice pad */

.choicepad {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.choicepad__key {
  min-width: 120px;
  min-height: 92px;
  padding: 0 1.75rem;
  font-size: 2.4rem;
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 80ms ease, background 120ms ease;
}
.choicepad__key:hover  { background: var(--primary-soft); border-color: var(--blue); }
.choicepad__key:active { transform: translateY(2px); box-shadow: none; }
.choicepad__key:focus-visible { outline: 3px solid var(--blue-bright); outline-offset: 2px; }

.choicepad__key--sm { font-size: 1.6rem; min-height: var(--tap-min); }

.choicepad__key--correct {
  background: var(--correct); color: var(--ink-invert);
  border-color: var(--correct-dark);
}
.choicepad__key--retry {
  background: var(--retry-soft); color: var(--retry-dark);
  animation: nudge 320ms ease;
}

/* ---------------------------------------------------------------- feedback */

.flash {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-size: clamp(5rem, 18vw, 12rem);
  z-index: 40;
}

.flash__mark { animation: pop 620ms cubic-bezier(0.2, 1.4, 0.4, 1) forwards; }

@keyframes pop {
  0%   { transform: scale(0.3) rotate(-12deg); opacity: 0; }
  35%  { transform: scale(1.15) rotate(3deg);  opacity: 1; }
  70%  { transform: scale(1) rotate(0);        opacity: 1; }
  100% { transform: scale(1);                  opacity: 0; }
}

.banner {
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius);
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 40ch;
  text-align: center;
}
.banner--correct { background: var(--correct-soft); color: var(--correct-dark); }
.banner--retry   { background: var(--retry-soft);   color: var(--retry-dark); }

/* ------------------------------------------------------------------ reward */

.stars { font-size: clamp(3rem, 12vw, 6rem); letter-spacing: 0.1em; }

.tally {
  display: flex;
  gap: 2.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.tally__item { text-align: center; }
.tally__num  {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums lining-nums;
}
.tally__label{ font-size: 0.9rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; }

.screen--hero .tally__label { color: rgba(255, 255, 255, 0.75); }

/* --------------------------------------------------- shapes and patterns */

.shaperow {
  display: flex;
  align-items: center;
  gap: clamp(0.5rem, 2vw, 1rem);
  flex-wrap: wrap;
  justify-content: center;
}

.shape { width: 64px; height: 64px; display: block; }

/* SVG needs `fill`; the shared counter colour classes only set `background`,
   which leaves the shapes rendering solid black. */
.shape__fill { stroke: rgba(0, 0, 0, 0.28); stroke-width: 3; }
.shape__fill.counter--a { fill: var(--counter-a); }
.shape__fill.counter--b { fill: var(--counter-b); }
.shape__fill.counter--c { fill: var(--counter-c); }

.shapebox {
  padding: 6px;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: var(--radius-sm);
}

.shapeslot {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--ink-soft);
  background: var(--surface-sunk);
  border: 4px dashed var(--border);
  border-radius: var(--radius-sm);
}

.shapebtn {
  padding: 8px;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 90ms ease, box-shadow 90ms ease;
}
.shapebtn:hover:not(:disabled) { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.shapebtn:active { transform: translateY(2px); }
.shapebtn:focus-visible { outline: 4px solid var(--primary); outline-offset: 3px; }
.shapebtn--correct { border-color: var(--correct); background: var(--correct-soft); }
.shapebtn--retry   { border-color: var(--retry);   background: var(--retry-soft); animation: nudge 320ms ease; }

/* -------------------------------------------- measuring in loose units */

.measure {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.measure__object {
  height: 34px;
  border-radius: 17px;
  border: 3px solid rgba(0, 0, 0, 0.25);
}

.measure__units { display: flex; }

.measure__unit {
  height: 26px;
  border: 2px solid rgba(0, 0, 0, 0.3);
  margin-right: -2px;
  padding: 0;
}
.measure__unit:first-child { border-radius: 5px 0 0 5px; }
.measure__unit:last-child  { border-radius: 0 5px 5px 0; margin-right: 0; }

.measure__units--fill .measure__unit { cursor: pointer; }
.measure__unit--empty { background: var(--surface-sunk); border-style: dashed; }
.measure__unit:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.measurefill {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  align-items: center;
}

/* The numbered scale: units are no longer objects, they are positions. */
.measure__scale {
  position: relative;
  height: 40px;
  border-top: 4px solid var(--ink);
}

.measure__tick {
  position: absolute;
  top: 0;
  width: 0;
  border-left: 3px solid var(--ink);
  height: 12px;
  margin-left: -1.5px;
}

.measure__ticklabel {
  position: absolute;
  top: 14px;
  left: 0;
  transform: translateX(-50%);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-soft);
}

/* ------------------------------------------------------ stickers and map */

.stickerboard {
  display: grid;
  grid-template-columns: repeat(8, 46px);
  gap: 8px;
  justify-content: center;
}

.sticker {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--surface-sunk);
  border: 2px dashed var(--border);
  display: grid;
  place-items: center;
  font-size: 26px;
}

.sticker--earned {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(3, 19, 61, 0.10);
}

.screen--hero .sticker {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
}
.screen--hero .sticker--earned {
  background: var(--surface);
  border-color: transparent;
}

.sticker--new { animation: pop-in 700ms cubic-bezier(0.2, 1.5, 0.4, 1); }

@keyframes pop-in {
  0%   { transform: scale(0) rotate(-25deg); }
  60%  { transform: scale(1.25) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}

.skillmap {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  width: min(760px, 100%);
}

.skillchip {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.6rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  box-shadow: 0 1px 2px rgba(3, 19, 61, 0.05);
}

/* In preview the chip is a button; it needs to look pressable and to reset
   the browser's default button typography. */
.skillchip--pickable {
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 90ms ease, box-shadow 90ms ease;
}
.skillchip--pickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.skillchip--pickable:active { transform: translateY(1px); }
.skillchip--pickable:focus-visible { outline: 3px solid var(--blue-bright); outline-offset: 3px; }

/* Room for the lock / star badge pinned to the top-right corner. */
.skillchip__title {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  padding-right: 1.4rem;
}

.skillchip__dots { display: flex; gap: 5px; }

.skilldot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--surface-sunk);
  border: 2px solid var(--border);
}
.skilldot--done { background: var(--correct); border-color: var(--correct-dark); }

.skillchip__lock {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.95rem;
}

.skillchip--locked { opacity: 0.55; }
.skillchip--mastered { border-color: var(--correct); background: var(--correct-soft); }
.skillchip--current {
  border-color: var(--blue);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(0, 67, 239, 0.22);
}

/* On the blue field the chips need their own contrast. They must also reset
   the inherited white text — an unlocked chip has a light background, so
   inheriting the hero's white makes its title vanish. */
.screen--hero .skillchip {
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: none;
}
.screen--hero .skillchip--locked {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.22);
  color: rgba(255, 255, 255, 0.85);
  opacity: 1;
}
.screen--hero .skillchip--locked .skilldot {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
}
.screen--hero .skillchip--current {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.75);
}

/* =========================================================================
   PHONES
   Everything above is sized for a tablet. A phone is about half the width,
   so the rule here is simple: anything that sat side by side now stacks.
   The manipulatives are genuinely cramped at this size — the iPad is the
   better device for this app — but a phone works as a backup.
   ========================================================================= */

@media (max-width: 560px) {
  /* Two ten-frames are ~560px side by side. Stacked, one is ~200px. */
  .tenframes,
  .tenframes--interactive {
    flex-direction: column;
    gap: 0.5rem;
  }

  /* Same for two groups of counters: "+" simply reads vertically instead. */
  .counters { flex-direction: column; }

  /* Ten-to-a-row survives on a phone only with tight gaps; keeping the row
     intact matters more than the gap, because the whole point of a
     comparison is that the two rows line up. */
  .countergroup__grid--wide { gap: 4px; }
  .countergroup__grid--wide > *:nth-child(10n + 6) { margin-left: 7px; }
  .countergroup { padding: 0.5rem; }

  .strip__label { min-width: 3ch; font-size: 0.8rem; }
  .strip__row { gap: 0.4rem; }

  /* Base-ten blocks shrink as a set so a rod stays exactly ten cubes tall. */
  .rod { grid-template-rows: repeat(10, 10px); width: 18px; }
  .cube { width: 18px; height: 10px; }
  .btslot--ten { width: 22px; height: 108px; }
  .btslot--one { width: 22px; height: 14px; }
  .btbuilder__row { gap: 4px; padding: 0.35rem; }

  /* Twenty pips do not fit; a plain count does. */
  .topbar { padding: 0.5rem 0.7rem; gap: 0.6rem; }
  .topbar__skill { font-size: 0.9rem; }
  .topbar__stage { font-size: 0.68rem; }
  .pips { display: none; }
  .progress-count { display: block; }

  .numpad { gap: 8px; }
  .numpad__key { font-size: 1.7rem; border-radius: 16px; }

  .choicepad__key { min-width: 88px; min-height: 68px; font-size: 1.8rem; padding: 0 1.1rem; }
  .choicepad__key--sm { font-size: 1.1rem; min-height: var(--tap-min); }

  .shape { width: 48px; height: 48px; }
  .shapeslot { width: 58px; height: 58px; font-size: 1.8rem; }

  .btn--go { padding: 0.9rem 2.5rem; min-height: 72px; }

  .skillmap { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 8px; }
  .skillchip__title { font-size: 0.82rem; padding-right: 1.2rem; }

  .stickerboard { grid-template-columns: repeat(8, 34px); gap: 5px; }
  .sticker { width: 34px; height: 34px; font-size: 18px; border-radius: 10px; }

  .tally { gap: 1.5rem; }
  .tally__num { font-size: 2.2rem; }

  .bond { width: min(260px, 76vw); }
  .numberline { width: 94vw; }
}

/* Small phones. The Make Ten hint goes: it is supplementary text, and the
   instruction it repeats is already spoken aloud with every question. */
@media (max-width: 560px) and (max-height: 700px) {
  .movehint { display: none; }
  .screen { gap: 0.5rem; padding: 0.5rem; }
  .problem { gap: 0.5rem; padding: 0.3rem; }
  .countergroup { padding: 0.4rem; }
  .countergroup__grid { gap: 6px; }
  .numpad { gap: 6px; }
  .topbar { padding: 0.4rem 0.6rem; }
}

/* ---------------------------------------------------- turn-upright prompt */

.rotate-hint { display: none; }

/* Only a phone on its side: narrow AND short. An iPad in landscape is
   768px tall, nowhere near this, so tablets never see it. */
@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  .rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    background: var(--blue);
    color: var(--ink-invert);
    padding: 1rem;
  }

  /* Nothing behind it should be reachable, including by keyboard. */
  .app { display: none; }
}

.rotate-hint__art { width: min(190px, 34vw); height: auto; }
.rotate-hint__phone-flat { fill: rgba(255, 255, 255, 0.22); }
.rotate-hint__phone-up { fill: #fff; }
.rotate-hint__dot { fill: var(--blue); }
.rotate-hint__arrow { stroke: #fff; stroke-width: 5; stroke-linecap: round; }
.rotate-hint__arrowhead { fill: #fff; }

.rotate-hint__text {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.1rem, 3.4vw, 1.6rem);
  text-align: center;
}

/* Phone held sideways — the display and pad share a row, so the vertical
   budget is tiny. */
@media (max-height: 470px) {
  .topbar { padding: 0.35rem 0.7rem; }
  .iconbtn { width: 48px; height: 48px; font-size: 1.2rem; }
  .problem { gap: clamp(0.4rem, 1.5vw, 1rem); }
  .movehint { display: none; }
  .bond { width: min(210px, 30vw); }
}

/* ------------------------------------------------------------------- debug */

.debug {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 50;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  font-size: 0.85rem;
  max-width: 300px;
  box-shadow: var(--shadow);
}
.debug h3 { margin: 0 0 0.5rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }
.debug select, .debug button { font: inherit; margin: 2px 0; width: 100%; }
.debug__row { display: flex; gap: 4px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
