/* Maths practice, laid out for an iPad Air (834 x 1112 points) held either
   way: big numbers, 56px+ touch targets, no hover states, no scrolling while
   answering. Same colours and book print as the reader, kept in its own file. */

@font-face { font-family: 'Andika'; src: url('../fonts/andika.woff2') format('woff2'); font-display: block; }

:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --ink: #1d2433;
  --muted: #5b6577;
  --line: #e4dfd4;
  --accent: #2f5fb3;
  --accent-soft: #e9effa;
  --right: #1f9d55;
  --right-soft: #e6f6ec;
  --wrong: #d64545;
  --second: #f2a516;
  --gold: #f2b01e;
  --shadow: 0 1px 2px rgb(29 36 51 / 0.08), 0 8px 24px rgb(29 36 51 / 0.1);
  --ui: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --book: 'Andika', var(--ui);
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body.maths {
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.4 var(--ui);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.message { grid-row: 1 / -1; display: grid; place-content: center; justify-items: center; gap: 16px; padding: 24px; text-align: center; font-size: 22px; }

/* ---- Bars and buttons ---- */

.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.bar-title { flex: 1; min-width: 0; margin: 0; font: 400 32px/1.2 var(--book); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.round {
  flex: none;
  width: 56px;
  height: 56px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #fff;
  font-size: 26px;
  line-height: 1;
  text-decoration: none;
}
.round.spacer { visibility: hidden; }

.big {
  min-height: 64px;
  padding: 0 28px;
  border: 2px solid var(--line);
  border-radius: 32px;
  background: #fff;
  font-size: 22px;
  font-weight: 700;
  white-space: nowrap;
}
.big.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.round:active, .big:active, .topic-card:active, .choice:active:not(:disabled), .key:active, .level-tab:active, .thing:active,
.today-card:active, .pad-key:active {
  transform: scale(0.96);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 88px;
  padding: 12px 20px;
  background: #fff;
  border-top: 1px solid var(--line);
}
.controls.empty { min-height: 0; padding: 0; border: 0; }

.dots { display: flex; flex-wrap: wrap; gap: 10px; }
.dot { width: 18px; height: 18px; border-radius: 50%; background: var(--line); }
.dot.now { background: #fff; box-shadow: inset 0 0 0 3px var(--accent); }
.dot.first { background: var(--right); }
.dot.second { background: var(--second); }
.dot.shown { background: var(--wrong); }

.stars { display: inline-flex; gap: 2px; font-family: var(--ui); }
.star { color: #d8d2c4; }
.star.on { color: var(--gold); }

/* ---- Home: year levels and topics ---- */

.home { overflow-y: auto; padding: 18px 24px 32px; }

.levels {
  display: flex;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 20px;
  padding: 6px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
}
.level-tab {
  min-width: 120px;
  min-height: 56px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font: 700 22px/1 var(--ui);
  white-space: nowrap;
}
.level-tab[aria-selected="true"] { background: var(--accent); color: #fff; }

.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.topic-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: 'icon name' 'icon note' 'icon stars' 'icon codes';
  align-items: center;
  column-gap: 14px;
  min-height: 120px;
  padding: 14px 16px;
  border: 0;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: left;
}
.topic-icon { grid-area: icon; font: 52px/1 var(--emoji); }
.topic-name { grid-area: name; font: 400 26px/1.15 var(--book); }
.topic-note { grid-area: note; color: var(--muted); font-size: 16px; line-height: 1.25; }
.topic-score { grid-area: stars; display: flex; align-items: center; gap: 8px; min-width: 0; margin-top: 4px; }
.topic-card .stars { font-size: 24px; }

/* ---- A question: prompt, picture and answers; picture beside the answers when landscape ---- */

.ask {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: 'prompt' 'work' 'answers';
  gap: 14px;
  min-height: 0;
  padding: 14px 24px 18px;
}
.ask.no-work { grid-template-rows: auto minmax(0, 1fr); grid-template-areas: 'prompt' 'answers'; }

@media (orientation: landscape) {
  .ask { grid-template-columns: minmax(0, 1.35fr) minmax(320px, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: 'prompt prompt' 'work answers'; }
  .ask.no-work { grid-template-columns: 1fr; grid-template-areas: 'prompt' 'answers'; }
  .ask.input-choice:not(.no-work) .answers { align-self: center; }
}

.prompt { grid-area: prompt; display: flex; align-items: center; gap: 14px; margin: 0; font: 400 30px/1.2 var(--book); word-spacing: 0.12em; }
.say { flex: none; width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%; background: var(--accent-soft); font-size: 26px; }

.work {
  grid-area: work;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
  padding: 12px;
  border-radius: 24px;
  background: #fff;
  box-shadow: var(--shadow);
}
.caption { margin: 0; color: var(--muted); font: 400 30px/1.2 var(--book); }
.hint:empty, .reveal:empty { display: none; }
.hint { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; min-height: 0; padding-top: 10px; border-top: 2px dashed var(--line); }
.hint-label { margin: 0; color: var(--muted); font-size: 16px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.hint .pic.svg { max-height: 170px; }
.hint .row { --most: 44px; }
.reveal { margin: 0; padding: 6px 18px; border-radius: 14px; background: var(--right-soft); color: var(--right); font: 400 30px/1.25 var(--book); text-align: center; }

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

.answers { grid-area: answers; min-height: 0; }
.choices { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 14px; align-content: center; }
.choices.n2 { --cols: 2; }
.choices.n4 { --cols: 4; }
.choices.opt-words { --cols: 1; }
.choices.opt-pictures { height: 100%; }

.choice {
  min-height: 96px;
  padding: 8px 12px;
  border: 3px solid var(--line);
  border-radius: 24px;
  background: #fff;
  font: 400 56px/1.1 var(--book);
}
.choice.big-emoji { font: 60px/1 var(--emoji); }
.choices.opt-words .choice { min-height: 80px; font-size: 36px; }
.choices.opt-pictures .choice { display: grid; place-items: center; min-height: 160px; padding: 14px; }
.choices.opt-pictures .choice .pic.svg { width: 100%; max-height: 220px; }
.choices.opt-pictures .choice .coin { max-width: 100%; }
.choice.right { border-color: var(--right); background: var(--right-soft); }
.choice.right.shown { animation: pulse 0.9s ease-in-out 2; }
.choice.wrong { border-color: var(--wrong); opacity: 0.4; animation: shake 0.35s; }

@media (orientation: landscape) {
  .ask:not(.no-work) .choices.opt-numbers { --cols: 1; }
  .ask:not(.no-work) .choices.opt-numbers .choice { min-height: 84px; }
  .ask:not(.no-work) .choices.opt-numbers.n4 { --cols: 2; }
  /* Groups to choose beside a picture (Find the group): one above the other. */
  .ask:not(.no-work) .choices.opt-pictures { --cols: 1; height: auto; }
  .ask:not(.no-work) .choices.opt-pictures .choice { min-height: 0; }
  /* The picture gets about 600px across: sequences and patterns stay on one line. */
  .row { --most: 64px; }
  .row.seq { --most: 52px; }
  .pattern .cell { width: 62px; height: 62px; font-size: 40px; }
}

.frac { display: inline-grid; justify-items: center; line-height: 1; }
.frac-top { padding: 0 0.15em 0.06em; border-bottom: 0.06em solid currentColor; }
.frac-bottom { padding-top: 0.06em; }
.choice .frac { font-size: 0.85em; }

/* The number pad, and the box it types into when the picture has none */
.keypad-area { display: grid; align-content: center; justify-items: center; gap: 12px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: min(100%, 420px); }
.key {
  min-height: 76px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: #fff;
  font: 400 40px/1 var(--book);
}
.key.rub { font: 30px/1 var(--ui); color: var(--muted); }
.key.ok { border-color: var(--right); background: var(--right); color: #fff; font: 800 36px/1 var(--ui); }

.answer-box {
  display: flex;
  align-items: baseline;
  justify-content: center;
  min-width: 200px;
  padding: 4px 24px;
  border: 3px dashed var(--accent);
  border-radius: 20px;
  background: var(--accent-soft);
  font: 400 64px/1.15 var(--book);
}
.unit { color: var(--muted); }
.answer-box[data-state="right"], .cell.blank[data-state="right"],
.answer-box[data-state="shown"], .cell.blank[data-state="shown"] { border-style: solid; border-color: var(--right); background: var(--right-soft); color: var(--right); }
.answer-box[data-state="wrong"], .cell.blank[data-state="wrong"] { border-color: var(--wrong); color: var(--wrong); animation: shake 0.35s; }

@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes pulse { 50% { transform: scale(1.05); } }

/* ---- Pictures ---- */

.pic.svg { display: block; flex: 1 1 auto; width: 100%; min-height: 0; max-height: 100%; }
.work > .pic.svg { max-width: 640px; }
.work > .pic.svg[aria-label="a clock"] { max-width: 380px; }

.emoji { font-family: var(--emoji); line-height: 1; }

/* Things to count, in rows of five */
.things { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; --thing: 76px; }
.things.size-m { --thing: 54px; }
.things.size-s { --thing: 42px; }
.five { display: flex; gap: 6px; }
.thing {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: calc(var(--thing) * 1.25);
  height: calc(var(--thing) * 1.25);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: transparent;
  font-size: var(--thing);
}
button.thing { background: var(--accent-soft); }
.thing[data-n] { background: #fff4cf; }
.tally {
  position: absolute;
  right: -4px;
  bottom: -4px;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 15px;
  background: var(--accent);
  color: #fff;
  font: 700 18px/30px var(--ui);
}
.thing.gone .emoji { opacity: 0.3; }
.thing.gone::after { content: '✕'; position: absolute; color: var(--wrong); font: 800 calc(var(--thing) * 0.9)/1 var(--ui); }
.choice .things { align-items: center; --thing: 44px; }
.choice .thing { width: calc(var(--thing) * 1.15); height: calc(var(--thing) * 1.15); }

.join { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; justify-content: center; }
.join .things { --thing: 54px; }
.sign { font: 400 64px/1 var(--book); color: var(--muted); }

/* Ten-frames */
.frames { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; }
.frame { display: grid; grid-template-columns: repeat(5, 76px); grid-auto-rows: 76px; border: 4px solid var(--ink); border-radius: 8px; background: #fff; }
.frame .cell { display: grid; place-items: center; border: 2px solid var(--ink); }
.counter { width: 56px; height: 56px; border-radius: 50%; background: var(--wrong); box-shadow: inset 0 -4px rgb(0 0 0 / 0.2); }
.hint .frame { grid-template-columns: repeat(5, 40px); grid-auto-rows: 40px; }
.hint .counter { width: 28px; height: 28px; }

/* Quick look: covered after a moment */
.flash { position: relative; display: grid; place-items: center; width: 100%; height: 100%; min-height: 0; }
.flash > .pic.svg { max-width: 280px; }
.look-again { position: absolute; inset: auto; display: none; }
.flash.covered > :first-child { visibility: hidden; }
.flash.covered .look-again { display: block; }

/* Number sentences and sequences */
.work { container-type: inline-size; }
.row { --most: 72px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.18em; font: 400 min(var(--most), calc(88cqw / var(--em, 6))) / 1.2 var(--book); }
.row .cell.sign { color: var(--muted); padding: 0 0.05em; }
.row.seq { --most: 60px; gap: 0.25em; }
.row.seq .cell.num { min-width: 1.6em; padding: 0.02em 0.25em; border: 3px solid var(--line); border-radius: 16px; background: #fff; text-align: center; }
.cell.blank { min-width: 1.6em; padding: 0.02em 0.25em; border: 3px dashed var(--accent); border-radius: 16px; background: var(--accent-soft); text-align: center; color: var(--accent); }

.numbers { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; min-height: 0; }
.big-number { font: 400 120px/1 var(--book); letter-spacing: 0.04em; }
.big-number .red { color: var(--wrong); text-decoration: underline; text-decoration-thickness: 0.06em; text-underline-offset: 0.12em; }
.numbers .pic.svg { max-height: 110px; max-width: 560px; }

.pattern { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.pattern .cell { display: grid; place-items: center; width: 76px; height: 76px; border-radius: 16px; background: var(--accent-soft); font: 50px/1 var(--emoji); }
.pattern .cell.blank { border: 3px dashed var(--accent); background: #fff; color: var(--accent); font: 400 48px/1 var(--book); }

/* Money */
.coins { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 14px; }
.coins .pic.svg { flex: none; width: 140px; height: auto; }
.coins .coin { flex: none; }
.coin-text { font-family: var(--ui); font-weight: 800; }
.clock-num { font: 400 22px var(--book); fill: var(--ink); }
.line-num { font: 400 24px var(--book); fill: var(--ink); }
.line-num.major { font-weight: 700; }
.line-num.mark { font-size: 30px; font-weight: 700; fill: var(--wrong); }

/* Charts, calendars, graphs and the shop */
.svg-small { font: 400 20px var(--book); fill: var(--muted); }
.svg-num { font: 400 40px var(--book); fill: var(--ink); }
.svg-num.blank { fill: var(--accent); font-weight: 700; }
.svg-title { font: 700 28px var(--book); fill: var(--ink); }
.svg-date { font: 400 24px var(--book); }
.svg-price { font: 700 46px var(--book); fill: var(--ink); }
.work > .pic.svg[aria-label^="part of a hundred"] { max-width: 300px; }
.work > .pic.svg[aria-label^="a calendar"] { max-width: 440px; }
.work > .pic.svg[aria-label^="an arrow turning"], .work > .pic.svg[aria-label^="a spinner"] { max-width: 320px; }
.work > .pic.svg[aria-label="an angle"] { max-width: 400px; }
.work > .pic.svg[aria-label^="a balance"] { max-width: 460px; }
.work > .pic.svg[aria-label="a tally"], .work > .pic.svg[aria-label="a picture graph"] { max-width: 560px; }
.choices.opt-pictures .choice .pic.svg[aria-label^="a pencil"] { max-height: 90px; }
.shop { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 28px; }
.shop-part { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.shop-label { color: var(--muted); font: 400 26px/1.2 var(--book); }
.shop .pic.svg { flex: none; width: 220px; height: auto; }
.shop .coin { flex: none; }
.shop .pic.svg[aria-label$="note"] { width: 180px; }
/* Three groups to choose from (Find the group): smaller things, so a group of 10 fits */
.choices.opt-pictures.n3 .choice .things, .choices.opt-pictures.n3 .choice .things.size-m, .choices.opt-pictures.n3 .choice .things.size-s { --thing: 30px; }
@media (max-width: 600px) {
  .choices.opt-pictures.n3 .choice .things, .choices.opt-pictures.n3 .choice .things.size-m, .choices.opt-pictures.n3 .choice .things.size-s { --thing: 15px; }
  .choices.n4 .choice.big-emoji { font-size: 40px; }
  .shop { flex-wrap: nowrap; gap: 14px; }
  .shop .pic.svg { width: 140px; }
  .shop .pic.svg[aria-label$="note"] { width: 120px; }
  .shop .coin { max-width: 80px; }
  .shop-label { font-size: 18px; }
}
/* An iPhone SE is too narrow for three groups side by side (a row of five ran out of its
   card): one group under another, with bigger things. */
@media (max-width: 380px) {
  .choices.opt-pictures.n3 { --cols: 1; }
  .choices.opt-pictures.n3 .choice { min-height: 0; }
  .choices.opt-pictures.n3 .choice .things, .choices.opt-pictures.n3 .choice .things.size-m, .choices.opt-pictures.n3 .choice .things.size-s { --thing: 22px; }
}

/* Groups, arrays and sharing */
.groups { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.group { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 4px; width: 160px; min-height: 120px; padding: 14px; border: 3px solid var(--line); border-radius: 50%; font-size: 38px; }
.hint .group { width: 110px; min-height: 80px; font-size: 24px; }
.share { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.pile { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 520px; padding: 12px 18px; border-radius: 18px; background: var(--accent-soft); font-size: 44px; }
.plates { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.plate { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 2px; width: 124px; height: 124px; padding: 16px; border: 4px solid #cfd6e2; border-radius: 50%; background: #fff; font-size: 28px; }

/* Column working */
.column { display: grid; grid-template-columns: 1.2em repeat(var(--cols), 1.1em); justify-items: center; font: 400 54px/1.15 var(--book); }
.col-head { color: var(--muted); font: 700 18px/2.2 var(--ui); }
.col-op { color: var(--muted); }
.col-rule { grid-column: 1 / -1; justify-self: stretch; height: 4px; margin: 4px 0 14px; background: var(--ink); border-radius: 2px; }

/* Listen for a number */
.listen {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 24px 40px;
  border: 0;
  border-radius: 28px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 700 24px/1.2 var(--ui);
}
.listen-icon { font: 96px/1 var(--emoji); }

/* ---- Round finished ---- */

/* Centred while it fits; from the top once it scrolls (plain centring pushed the top out
   of reach on a phone). Browsers without `safe` keep `start`. */
.done { display: grid; align-content: start; align-content: safe center; justify-items: center; gap: 14px; padding: 24px; text-align: center; }
.done-stars { font-size: 120px; line-height: 1; animation: pop 0.6s ease-out; }
.done h2 { margin: 0; font: 400 56px/1.1 var(--book); }
.done-note { margin: 0; color: var(--muted); font-size: 24px; }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .done-stars, .choice.wrong, .choice.right.shown, [data-state="wrong"] { animation: none; }
}

/* Small screens (phones) still work: smaller type and keys. */
@media (max-width: 600px) {
  .bar-title { font-size: 24px; }
  .level-tab { min-width: 0; padding: 0 12px; font-size: 18px; }
  .prompt { font-size: 22px; }
  .row { --most: 44px; }
  .row.seq { --most: 36px; }
  .frame { grid-template-columns: repeat(5, 52px); grid-auto-rows: 52px; }
  .counter { width: 38px; height: 38px; }
  .key { min-height: 58px; }
  .choice { min-height: 76px; font-size: 40px; }
  /* Four answers side by side leave a phone about 65px each: "1000" does not fit. */
  .choices.n4 { --cols: 2; }
  .big-number { font-size: 84px; }
  .things { --thing: 52px; }
  .things.size-m { --thing: 40px; }
  .things.size-s { --thing: 32px; }
  .choice .things, .choice .things.size-m { --thing: 22px; }
  .choice .things.size-s { --thing: 18px; }
  .choice .five { gap: 3px; }
  .choices.opt-pictures .choice { min-height: 120px; padding: 8px; }
  /* Neither the picture nor the answers are squeezed (a ruler or groups shrank to a thin
     strip on a small phone, or the keypad slid over the picture): the question scrolls. */
  .ask { gap: 10px; padding: 10px 14px 14px; overflow-y: auto; grid-template-rows: auto minmax(max-content, 1fr) max-content; }
  .ask.no-work { grid-template-rows: auto minmax(max-content, 1fr); }
  .home { padding: 14px 14px 24px; }
  .topic-card { min-height: 100px; padding: 10px 14px; }
  .topic-icon { font-size: 42px; }
  .topic-name { font-size: 22px; }
}

/* ---- Phones: bars and buttons shrink whichever way they're held ---- */

@media (max-width: 600px), (max-height: 500px) {
  .bar { gap: 8px; padding: 8px 10px; }
  .round { width: 46px; height: 46px; font-size: 22px; }
  .big { min-height: 52px; padding: 0 18px; font-size: 18px; }
  .controls { flex-wrap: wrap; justify-content: center; gap: 10px; min-height: 0; padding: 8px 12px; }
  .dots { gap: 6px; }
  .dot { width: 13px; height: 13px; }
  .say { width: 44px; height: 44px; font-size: 20px; }
  .done-stars { font-size: 84px; }
  .done h2 { font-size: 38px; }
  .done-note { font-size: 18px; }
}

/* Phone on its side: little height, so the keys, answers and pictures get shorter. */
@media (max-height: 500px) {
  .bar { padding: 4px 10px; }
  .bar-title { font-size: 24px; }
  .controls { padding: 4px 12px; }
  .ask { grid-template-columns: minmax(0, 1.2fr) minmax(260px, 1fr); grid-template-rows: auto minmax(max-content, 1fr); gap: 8px 14px; padding: 6px 16px 8px; overflow-y: auto; }
  .prompt { font-size: 22px; }
  .work { padding: 8px; border-radius: 18px; }
  .keypad { gap: 6px; width: min(100%, 300px); }
  .key { min-height: 44px; border-radius: 14px; font-size: 28px; }
  .key.rub { font-size: 22px; }
  .key.ok { font-size: 26px; }
  .keypad-area { gap: 6px; }
  .answer-box { min-width: 140px; padding: 2px 16px; font-size: 40px; }
  .choices { gap: 8px; }
  .choice { min-height: 52px; border-radius: 18px; font-size: 32px; }
  .ask:not(.no-work) .choices.opt-numbers .choice { min-height: 52px; }
  .choices.opt-words .choice { min-height: 52px; font-size: 24px; }
  .choices.opt-pictures .choice { min-height: 90px; padding: 6px; }
  .choice .frac { font-size: 0.7em; }
  .row { --most: 44px; }
  .row.seq { --most: 36px; }
  .things { --thing: 38px; }
  .things.size-m { --thing: 30px; }
  .things.size-s { --thing: 24px; }
  .choice .things, .choice .things.size-m, .choice .things.size-s { --thing: 22px; }
  .frame { grid-template-columns: repeat(5, 40px); grid-auto-rows: 40px; }
  .counter { width: 30px; height: 30px; }
  .pattern .cell { width: 46px; height: 46px; font-size: 30px; }
  .pattern .cell.blank { font-size: 30px; }
  .big-number { font-size: 64px; }
  .column { font-size: 36px; }
  .group { width: 110px; min-height: 80px; padding: 8px; font-size: 24px; }
  .pile { font-size: 28px; padding: 8px 12px; }
  .plate { width: 84px; height: 84px; padding: 10px; font-size: 20px; }
  .coins .pic.svg { width: 90px; }
  .listen { padding: 12px 24px; font-size: 18px; }
  .listen-icon { font-size: 56px; }
  .caption, .reveal { font-size: 22px; }
  .level-tab { min-height: 46px; }
  .topic-card { min-height: 96px; }
  .done-stars { font-size: 60px; }
}

/* ---- Home: today's mix, mistakes to fix and quick facts; mastery and curriculum codes ---- */

.today { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 0 0 20px; }
.today-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: 'icon name' 'icon note' 'icon chip';
  align-items: center;
  justify-items: start;
  column-gap: 12px;
  min-height: 96px;
  padding: 12px 16px;
  border: 3px solid var(--line);
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: left;
}
.today-card.mix { border-color: #f2c94c; background: #fff6d8; }
.today-card.mix.is-done { border-color: #9fd8b4; background: var(--right-soft); }
.today-card.fix { border-color: #f0a8a8; background: #fdecec; }
.today-card.facts { border-color: #c9b5f0; background: #f2ecfc; }
.today-icon { grid-area: icon; font: 44px/1 var(--emoji); }
.today-name { grid-area: name; font: 400 26px/1.15 var(--book); }
.today-note { grid-area: note; color: var(--muted); font-size: 16px; line-height: 1.25; }
.done-today { grid-area: chip; margin-top: 4px; padding: 2px 12px; border-radius: 999px; background: var(--right); color: #fff; font: 700 15px/1.6 var(--ui); white-space: nowrap; }
.done .done-today { padding: 4px 18px; font-size: 20px; }

/* Mastery 0-100: a bar with a mark at 80 (good); green from 80, gold at 100 */
.mastery { display: inline-flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.mastery-bar { position: relative; flex: 1; min-width: 40px; max-width: 110px; height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.mastery-bar::after { content: ''; position: absolute; top: 0; bottom: 0; left: 80%; width: 2px; background: #fff; }
.mastery-fill { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.mastery.good .mastery-fill { background: var(--right); }
.mastery.mastered .mastery-fill { background: var(--gold); }
.mastery.mastered .mastery-num { color: #a87708; }
.mastery-num { color: var(--muted); font: 700 14px/1 var(--ui); white-space: nowrap; }
.done .mastery { flex: none; width: min(320px, 80vw); }
.done .mastery-bar { max-width: none; height: 14px; border-radius: 7px; }
.done .mastery-num { font-size: 18px; }

/* Victorian Curriculum codes: small print for grown-ups */
.codes { grid-area: codes; margin-top: 4px; color: var(--muted); font: 600 11px/1.3 var(--ui); letter-spacing: 0.03em; }

/* ---- Quick facts ---- */

.facts-intro { margin: 0 0 16px; color: var(--muted); font-size: 18px; text-align: center; }
.best-note { grid-area: stars; margin-top: 4px; color: var(--accent); font-size: 16px; font-weight: 700; }

.timer-switch {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: fit-content;
  max-width: 100%;
  min-height: 64px;
  margin: 28px auto 0;
  padding: 8px 18px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: #fff;
  text-align: left;
}
/* Fills while held, so a grown-up can see the hold working. */
.timer-switch::before { content: ''; position: absolute; inset: 0 100% 0 0; background: var(--accent-soft); }
.timer-switch.holding::before { right: 0; transition: right 0.9s linear; }
.timer-switch > * { position: relative; }
.timer-icon { font: 30px/1 var(--emoji); }
.timer-text { display: grid; }
.timer-text strong { font-size: 18px; }
.timer-text span { color: var(--muted); font-size: 14px; }
.timer-knob { flex: none; width: 52px; height: 30px; border-radius: 15px; background: var(--line); }
.timer-knob::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.2s; }
.timer-switch.on .timer-knob { background: var(--right); }
.timer-switch.on .timer-knob::after { transform: translateX(22px); }

.fact-work .row { --most: 96px; }
.fact-pad { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; align-content: center; }
.pad-key { min-height: 88px; padding: 0; border: 3px solid var(--line); border-radius: 22px; background: #fff; font: 400 48px/1 var(--book); }
.pad-key.right { border-color: var(--right); background: var(--right-soft); }
.pad-key.wrong { border-color: var(--wrong); opacity: 0.5; animation: shake 0.35s; }
@media (orientation: landscape) { .fact-pad { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* The gentle timer: a bar that empties over the minute, no numbers counting down */
.time-bar { flex: 1; max-width: 520px; height: 16px; border-radius: 8px; background: var(--line); overflow: hidden; }
.time-left { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--accent); transition-property: width; transition-timing-function: linear; }
.time-left.going { width: 0; }
.fact-count { color: var(--right); font: 700 26px/1 var(--ui); white-space: nowrap; }
.fact-score { color: var(--ink); font: 400 34px/1.2 var(--book); }

@media (prefers-reduced-motion: reduce) {
  .pad-key.wrong { animation: none; }
}

@media (max-width: 600px) {
  .today { gap: 10px; margin-bottom: 14px; }
  .today-card { min-height: 76px; padding: 8px 12px; }
  .today-icon { font-size: 34px; }
  .today-name { font-size: 22px; }
  .fact-work .row { --most: 64px; }
  .fact-pad { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .pad-key { min-height: 64px; border-radius: 18px; font-size: 36px; }
  .fact-score { font-size: 28px; }
}

/* A finished screen scrolls rather than run under the bars... */
.done { min-height: 0; overflow-y: auto; }

@media (max-height: 500px) {
  /* ...and on a phone on its side Kobi cheers beside the words, so they fit. */
  .done { grid-template-columns: auto minmax(0, auto); justify-content: center; column-gap: 28px; row-gap: 6px; padding: 8px 16px; }
  .done::before { grid-row: 1 / span 6; }
  .done .mastery { width: min(240px, 40vw); }
  .today-card { min-height: 68px; padding: 6px 12px; }
  .today-icon { font-size: 30px; }
  .today-name { font-size: 20px; }
  .fact-work .row { --most: 56px; }
  .fact-pad { gap: 6px; }
  .pad-key { min-height: 44px; border-radius: 14px; font-size: 28px; }
  .timer-switch { min-height: 52px; margin-top: 16px; }
  .fact-count { font-size: 20px; }
  .fact-score { font-size: 24px; }
}

/* ---- KidStudy: Kobi is the way home, waits while things load and cheers at the end ---- */

.bar a.round[href="./"] { font-size: 0; border-color: var(--ks-blue); background: var(--ks-blue) url('../icons/icon-192.png') center / cover; }
.message::before { content: ''; width: 150px; aspect-ratio: 582 / 640; background: url('../brand/kobi-main.webp') center / contain no-repeat; }
.done::before { content: ''; width: min(170px, 30vh); aspect-ratio: 586 / 640; background: url('../brand/kobi-cheer.webp') center / contain no-repeat; animation: pop 0.6s ease-out; }
@media (prefers-reduced-motion: reduce) { .done::before { animation: none; } }

/* A phone held upright: a shorter picture and keys, so the picture and the keypad both fit
   on the screen together (the question still scrolls if they can't). */
@media (max-width: 600px) and (orientation: portrait) {
  .work > .pic.svg { max-height: 26vh; }
  .work { padding: 8px; }
  .key { min-height: 44px; }
  .keypad { gap: 6px; }
  .answer-box { padding: 0 16px; font-size: 40px; }
  .caption { font-size: 20px; }
}
/* An iPhone SE: five things in a row (Taking away) ran off both sides. Last in the file,
   after the phone sizes above. */
@media (max-width: 380px) {
  .things { --thing: 40px; }
  .things.size-m { --thing: 32px; }
  .things.size-s { --thing: 26px; }
}
