/* Whiskerblade's screens (src/ui/app.js, battle_screen.js). One bright look,
   the same whatever the device's theme, with big targets for small hands and
   only the device's own fonts, so the game asks nothing of any other site. */

:root {
  --sky: #dfeaff;
  --sky-low: #fff3df;
  --surface: #ffffff;
  --ink: #1b2333;
  --muted: #55607a;
  --line: #d3dbea;
  --orange: #e8620f;
  --orange-deep: #b94c08;
  --orange-soft: #fff1e6;
  --indigo: #3f3cbb;
  --indigo-soft: #f1f0ff;
  --right: #15803d;
  --right-soft: #dcfce7;
  --wrong: #b91c1c;
  --wrong-soft: #fee2e2;
  --radius: 14px;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --display: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { background: var(--sky); }
body {
  margin: 0;
  min-height: 100vh;
  font: 18px/1.5 var(--body);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky), var(--sky-low)) fixed;
}
.game {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  padding-block: 10px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.loading { color: var(--muted); }
[hidden] { display: none !important; }

h1 { font: 800 clamp(30px, 6vw, 46px)/1.1 var(--display); margin: 0; text-wrap: balance; }
[tabindex="-1"]:focus { outline: none; } /* headings take focus only to be announced */
:focus-visible { outline: 4px solid var(--indigo); outline-offset: 3px; }
.tagline { margin: 6px 0 0; color: var(--muted); font-size: 19px; }

button { font: inherit; color: inherit; cursor: pointer; }
.primary {
  justify-self: start;
  background: var(--orange);
  color: #fff;
  border: 0;
  border-bottom: 4px solid var(--orange-deep);
  border-radius: 12px;
  padding: 12px 22px;
  font-weight: 800;
}
.primary:active { transform: translateY(2px); border-bottom-width: 2px; }
.big { font-size: 24px; padding: 16px 34px; }
.quiet {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
}
.quiet:hover { border-color: var(--indigo); }
.danger { border-color: var(--wrong); color: var(--wrong); }
.link { background: none; border: 0; padding: 0; color: var(--indigo); font-weight: 700; text-decoration: underline; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 12px; }
.brand { font: 800 18px var(--display); color: var(--indigo); letter-spacing: 0.02em; }
.sound { font-size: 15px; }

.card {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 16px 18px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}
legend, .card-title { font: 800 21px var(--display); margin: 0; padding: 0; }
legend { float: left; width: 100%; } /* keeps the legend inside the card's padding */
select {
  font: inherit;
  font-size: 20px;
  max-width: 100%;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
}

.still {
  display: inline-block;
  height: 120px;
  aspect-ratio: var(--frame-aspect, 1);
  background-repeat: no-repeat;
  background-size: 300% 100%;
  background-position: 0 0;
  opacity: 0;
  transition: opacity 0.2s;
}
.still.is-ready { opacity: 1; }

/* The title */
.title-screen, .victory-screen, .treasures-screen { display: grid; gap: 18px; }
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.banner .still { height: 140px; }
.game[data-screen="title"] .brand { visibility: hidden; } /* the title says it already */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* The chosen hero faces a monster in front of one of the painted backdrops,
   standing on its floor line as on the battle stage (css/stage.css). The art
   covers the stage from the bottom up: when the stage is shorter than the
   art's 2.4:1 shape, the art's floor is that much further up. 100cqw is the
   title screen's width, which is the stage's. */
.title-screen { container-type: inline-size; }
.title-stage {
  --floor: 0.9;
  position: relative;
  isolation: isolate;
  height: min(100cqw / 2.4, 330px);
  overflow: hidden;
  border-radius: 18px;
  background: #24324c center bottom / cover no-repeat;
  box-shadow: 0 8px 24px rgb(27 35 51 / 0.18);
}
.title-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse 80% 90% at 50% 70%, rgb(0 0 0 / 0) 60%, rgb(16 22 40 / 0.3));
}
.title-words {
  position: absolute;
  top: 16px;
  left: 50%;
  translate: -50% 0;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 24px 12px;
  text-align: center;
  background: rgb(255 255 255 / 0.86);
  border-radius: 16px;
  box-shadow: 0 4px 14px rgb(27 35 51 / 0.15);
}
.title-words .tagline { margin-top: 4px; color: var(--ink); }
.title-fighter {
  position: absolute;
  bottom: calc((1 - var(--floor)) * max(100%, 100cqw / 2.4));
  height: 50%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  justify-items: center;
  gap: 4px;
}
.title-fighter--hero { left: 10%; }
.title-fighter--monster { right: 10%; }
.title-fighter .still { height: 100%; }
.title-fighter--monster .still { scale: -1 1; } /* facing the hero */
.title-fighter::after { /* a shadow at its feet */
  content: "";
  position: absolute;
  z-index: -1;
  bottom: -7px;
  left: 50%;
  translate: -50% 0;
  width: 70%;
  height: 16px;
  background: radial-gradient(closest-side, rgb(16 22 40 / 0.4), rgb(16 22 40 / 0));
}
.title-plate {
  padding: 2px 10px;
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
  background: rgb(255 255 255 / 0.9);
  border-radius: 9px;
}

.heroes { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 132px), 1fr)); }
.hero-choice {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 10px 8px;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  align-content: start;
}
.hero-choice .still { height: 84px; }
.hero-choice:has(input:checked) { border-color: var(--orange); background: var(--orange-soft); }
.hero-choice:has(input:focus-visible) { outline: 4px solid var(--indigo); outline-offset: 2px; }
.hero-name { font-weight: 800; text-align: center; }
.lead { margin: 0; color: var(--muted); }

/* Who's playing: a card for each player, and one to make a new player. */
.player-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.player-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 12px;
  width: 100%;
  min-height: 84px;
  padding: 8px 14px 8px 8px;
  text-align: left;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 14px;
}
.player-card:hover { border-color: var(--indigo); background: var(--indigo-soft); }
.player-hero { grid-row: span 2; }
.player-hero .still { height: 64px; }
.player-name { align-self: end; font: 800 20px/1.2 var(--display); overflow-wrap: anywhere; }
.player-note { align-self: start; font-size: 15px; color: var(--muted); }
.player-card--new { border-style: dashed; }
.player-plus { grid-row: span 2; display: grid; place-items: center; width: 64px; height: 64px; font: 800 40px var(--display); color: var(--indigo); }
.player-card--new .player-name { grid-row: span 2; align-self: center; }

.name-input {
  font: inherit;
  font-size: 22px;
  width: min(100%, 22ch);
  padding: 10px 14px;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
}
.name-input:focus-visible { border-color: var(--indigo); }
.field-hint { margin: 0; font-size: 15px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; }
.check input { width: 24px; height: 24px; margin: 0; accent-color: var(--orange); }
/* Read to me: at the top of the question, out of the way of the answers. */
.read-aloud { justify-self: start; font-size: 16px; white-space: nowrap; }
/* Read to me, or Stop while reading (readButton in src/speech.js): both laid out in one place, so
   the button is as wide as the wider, and the other hidden. */
.can-stop { display: inline-grid; justify-items: center; }
.can-stop > span { grid-area: 1 / 1; }
.can-stop:not([data-speaking]) > .read-stop, .can-stop[data-speaking] > .read-say { visibility: hidden; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.panel-head .read-aloud { flex: none; }
.code-box {
  width: 100%;
  padding: 10px 12px;
  font: 15px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace;
  word-break: break-all;
  color: var(--ink);
  background: #f7f9fc;
  border: 2px solid var(--line);
  border-radius: 10px;
  resize: vertical;
}
.code-in { display: grid; gap: 10px; }
.code-in .link { justify-self: start; }
.code-error { margin: 0; min-height: 1.2em; font-weight: 700; color: var(--wrong); }
.code-copied { font-weight: 700; color: var(--right); }
[data-ref="code-out"] .quiet { justify-self: start; }
.remove { border-color: #f3c7c7; }
.remove > .danger { justify-self: start; }
.remove p { margin: 0; }

/* Grades: a button for each year, then what that grade's adventure covers. */
.grade-years { display: grid; gap: 8px; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.grade-choice {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  padding: 8px 2px 7px;
  text-align: center;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.grade-choice input, .hero-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.grade-number { font: 800 30px/1.1 var(--display); color: var(--indigo); }
.grade-word { font-size: 13px; font-weight: 700; line-height: 1.2; color: var(--muted); }
.grade-choice:hover, .hero-choice:hover { border-color: var(--indigo); }
.grade-choice:has(input:checked) { border-color: var(--orange); background: var(--orange-soft); }
.grade-choice:has(input:checked) .grade-number { color: var(--orange-deep); }
.grade-choice:has(input:focus-visible) { outline: 4px solid var(--indigo); outline-offset: 2px; }
.practice { display: grid; gap: 8px; padding: 12px 14px; background: #f6f8fc; border-radius: 12px; }
.practice p { margin: 0; }
.practice-head { font-weight: 800; }
/* The chapters, numbered, as tags. */
.topics { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; counter-reset: topic; }
.topics li { padding: 3px 11px; font-size: 15px; font-weight: 700; color: var(--indigo); background: var(--indigo-soft); border-radius: 999px; counter-increment: topic; }
.topics li::before { content: counter(topic) ". "; color: var(--muted); }

/* The map: who is playing, one big way to play on, a tile for each other way
   to play, and the chapters, each one line but the one being played, which is
   open with its levels. Grown-ups' things are folded away at the bottom. A
   level is a big button: its number, or a crown for a boss, and its stars
   once it's done; only the one to play next stands out. */
.map-screen, .note-screen, .player-screen { display: grid; gap: 18px; }
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.map-head { display: flex; align-items: center; gap: 14px; }
.map-hero .still { height: 84px; }
.map-who { display: grid; gap: 6px; flex: 1; min-width: 0; }
.map-who h1 { overflow-wrap: break-word; }
.map-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0; }
.grade-chip { padding: 2px 12px; border-radius: 999px; background: var(--indigo); color: #fff; font-size: 15px; font-weight: 800; white-space: nowrap; }
.hero-level { color: var(--muted); font-size: 15px; font-weight: 700; }
.switch-player { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; }
.play-card { gap: 12px; }
.continue { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 18px; width: 100%; text-align: left; }
.continue-play { display: inline-flex; align-items: center; gap: 10px; font-size: 32px; }
.continue-topic { font-size: 18px; font-weight: 700; opacity: 0.95; }
.map-progress { display: flex; align-items: center; gap: 12px; }
.map-progress .progress-bar { flex: 1; }
.map-stars { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; color: #b45309; }
.map-stars .icon { color: #f59e0b; }
.map-count, .map-finished { margin: 0; }
.progress-bar { height: 14px; overflow: hidden; background: #eef1f7; border-radius: 7px; }
.progress-bar span { display: block; height: 100%; background: var(--indigo); border-radius: 7px; }
/* Other ways to play: tiles with an icon and a word or two, each its own colour. */
.map-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.tile { display: grid; justify-items: center; align-content: center; gap: 4px; padding: 14px 8px; border: 2px solid; border-radius: var(--radius); font-size: 17px; font-weight: 800; }
.tile-icon { width: 38px; height: 38px; }
.tile-count { font-size: 13px; font-weight: 700; opacity: 0.8; }
.tile:hover { filter: brightness(0.96); }
.tile--training { color: #075985; background: #e0f2fe; border-color: #bae6fd; }
.tile--quick { color: #991b1b; background: #fee2e2; border-color: #fecaca; }
.tile--challenge { color: #5b21b6; background: #ede9fe; border-color: #ddd6fe; }
.tile--treasures { color: #92400e; background: #fef3c7; border-color: #fde68a; }
.chapters { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.chapter { overflow: hidden; background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); }
.chapter.is-current { border: 3px solid var(--orange); }
.chapter-line { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; list-style: none; }
.chapter-line::-webkit-details-marker { display: none; }
/* A chevron: down when closed, up when open. */
.chapter-line::after { content: ""; width: 9px; height: 9px; margin: 0 4px 4px; border-right: 3px solid var(--muted); border-bottom: 3px solid var(--muted); rotate: 45deg; }
details[open] > .chapter-line::after { rotate: 225deg; margin-bottom: -4px; }
.chapter-badge { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--indigo-soft); color: var(--indigo); font: 800 17px var(--display); }
.chapter.is-current .chapter-badge { background: var(--orange); color: #fff; }
.chapter.is-finished .chapter-badge { background: var(--indigo); color: #fff; }
.chapter-title { flex: 1; min-width: 0; font: 800 20px/1.2 var(--display); }
.chapter.is-locked .chapter-title, .chapter.is-locked .chapter-state { color: var(--muted); }
.chapter-state { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; color: #b45309; }
.chapter-state .icon { width: 18px; height: 18px; }
.chapter-open { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); border-top: 2px solid var(--line); }
.chapter-art { position: relative; min-height: 120px; background: #24324c center bottom / cover no-repeat; }
.chapter.is-locked .chapter-art { filter: grayscale(0.7) brightness(0.9); }
/* The chapter's opening scene: a round play button on its picture. */
.chapter-watch { position: absolute; right: 10px; bottom: 10px; display: grid; place-items: center; width: 48px; height: 48px; padding: 0 0 0 3px; border: 0; border-radius: 50%; background: rgb(255 255 255 / 0.92); color: var(--indigo); box-shadow: 0 2px 8px rgb(0 0 0 / 0.25); }
.chapter-watch .icon { width: 26px; height: 26px; }
.chapter-body { display: grid; gap: 10px; align-content: center; padding: 14px 16px; }
.levels { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.level-button {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  width: 64px;
  height: 64px;
  padding: 4px;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 14px;
}
.level-number { font: 800 22px/1 var(--display); }
.level-stars { font-size: 13px; line-height: 1; color: #d97706; letter-spacing: -0.04em; }
.level-stars .icon { width: 16px; height: 16px; }
.level-button.is-open { border-color: #fdba74; }
/* The level to play next: the only one that glows. */
.level-button.is-next { border-color: var(--orange); background: var(--orange-soft); color: var(--orange-deep); animation: next-glow 1.8s ease-in-out infinite; }
.level-button.is-next .level-stars { color: var(--orange-deep); }
@keyframes next-glow { 0%, 100% { box-shadow: 0 0 0 3px rgb(232 98 15 / 0.25); } 50% { box-shadow: 0 0 0 7px rgb(232 98 15 / 0.1); } }
@media (prefers-reduced-motion: reduce) { .level-button.is-next { animation: none; box-shadow: 0 0 0 4px rgb(232 98 15 / 0.25); } }
/* For grown-ups, folded away at the bottom. */
.grown-ups { padding-top: 12px; border-top: 2px solid var(--line); }
.grown-ups summary { cursor: pointer; font-weight: 800; color: var(--muted); }
.grown-ups[open] { display: grid; gap: 10px; }
.grown-ups .map-count { color: var(--muted); }
.level-button.is-done { border-color: #c7c5f2; background: var(--indigo-soft); }
.level-button.is-locked { border-style: dashed; color: var(--muted); background: #f7f8fb; cursor: not-allowed; }
.level-button:hover:not(:disabled) { border-color: var(--indigo); }
.level-button--boss .level-number { font-size: 26px; }
.chapter-more p { margin: 0 0 8px; font-weight: 700; }

/* A chapter's note: its setting, its topic in a sentence or two, and a worked example. */
.note-art { aspect-ratio: 2.4; max-height: 220px; background: #24324c center bottom / cover no-repeat; border-radius: 16px; }
.note-kicker { margin: 0 0 -12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.note-text { margin: 0; font-size: 22px; line-height: 1.45; max-width: 46ch; }
.example { border-color: #c7c5f2; }
.example p { margin: 0; }
.example-prompt { font: 800 22px/1.3 var(--display); }
.example-answer { font-size: 20px; }
.example-answer strong { color: var(--right); }
.example-tip { color: var(--muted); }
/* In a battle, a question from an earlier chapter says it is review. */
.review-tag { justify-self: start; margin: 0; padding: 3px 10px; border-radius: 999px; background: var(--indigo-soft); color: var(--indigo); font-size: 14px; font-weight: 800; }
.review-tag[hidden] { display: none; }
.report-summary { margin: 0; font-size: 18px; }
/* The class view: a tag on students pasted in by code, and the topics the class needs. */
.class-from { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--indigo-soft); color: var(--indigo); font-size: 13px; font-weight: 700; }
.class-topics { display: grid; gap: 8px; margin: 0; padding-left: 20px; }
.class-said { margin: 0; font-weight: 700; }
.class-said:empty { display: none; }
@media print {
  /* The progress report on paper: the page itself, without buttons or backgrounds. */
  button, .brand, .lock-card, .class-codes { display: none !important; }
  body, .game { background: #fff !important; }
}

/* A teaching scene: the hero and the monster, the one speaking a little
   raised, the line between them in a bubble pointing at its speaker, and the
   picture below. */
.scene-screen { display: grid; gap: 16px; }
.scene-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.scene-top .note-kicker { margin: 0; }
.scene-skip { font-size: 16px; }
.scene-cast { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: end; gap: 14px; }
.scene-actor { opacity: 0.55; transition: transform 0.25s ease, opacity 0.25s ease; }
.scene-actor.is-speaking { opacity: 1; transform: translateY(-8px); }
.scene-actor .still { height: 130px; }
.scene-actor--monster .still { scale: -1 1; } /* facing the hero */
.scene-bubble { position: relative; align-self: center; min-height: 5.6em; padding: 12px 18px; background: var(--surface); border: 3px solid var(--indigo); border-radius: 18px; }
.scene-bubble[data-from="monster"] { border-color: var(--orange); }
.scene-bubble::after { /* the bubble's tail, toward whoever is speaking */
  content: "";
  position: absolute;
  bottom: 20px;
  width: 18px;
  height: 18px;
  background: var(--surface);
  border: 0 solid var(--indigo);
  border-width: 0 0 3px 3px;
}
.scene-bubble[data-from="hero"]::after { left: -11px; rotate: 45deg; }
.scene-bubble[data-from="monster"]::after { right: -11px; rotate: -135deg; border-color: var(--orange); }
.scene-speaker { margin: 0; font-size: 14px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.scene-line { margin: 4px 0 0; font: 700 24px/1.35 var(--display); }
.scene-line:focus { outline: none; } /* focused only so a check is read out */
.scene-picture[hidden], .scene-choices[hidden] { display: none; }
.scene-picture .tappable, .picture .tappable { cursor: pointer; }
/* A number line's ticks, tapped to answer in a battle: a box round the one pointed at. */
.picture .tappable:hover, .picture .tappable:focus-visible { outline: none; stroke: var(--indigo); stroke-width: 3; }
.picture .tappable:focus:not(:focus-visible) { outline: none; }
.picture .tappable.is-right { stroke: var(--right); stroke-width: 4; }
.picture .tappable.is-wrong { stroke: var(--wrong); stroke-width: 4; }
.scene-picture .focus { animation: ring-in 0.35s ease-out; }
@keyframes ring-in { from { opacity: 0; stroke-width: 12; } }
.scene-picture .tappable:hover, .scene-picture .tappable:focus-visible { outline: none; stroke: var(--indigo); stroke-width: 6; }
.scene-picture .tappable:focus:not(:focus-visible) { outline: none; }
/* Waiting on a check: plainly not ready yet. */
.scene-screen [data-ref="next"]:disabled { opacity: 0.4; cursor: default; box-shadow: none; }
.scene-picture .tappable.is-right { stroke: var(--right); stroke-width: 7; }
.scene-picture .tappable.is-wrong { stroke: var(--wrong); stroke-width: 7; }
.scene-steps { display: flex; justify-content: center; gap: 8px; margin: 0; padding: 0; list-style: none; }
.scene-steps li { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.scene-steps li.is-done { background: var(--indigo); }
.scene-more { justify-content: center; }
/* The same scene over a battle, after a miss. */
.scene-dialog { width: min(940px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 18px 22px; border: 0; border-radius: 18px; background: var(--surface); color: var(--ink); }
.scene-dialog::backdrop { background: rgba(20, 28, 48, 0.6); }
.after-reveal { justify-content: flex-start; }

/* Stars for a level: gold, with the ones not earned faint. */
.stars-big { margin: 0; font-size: 52px; line-height: 1; }
.stars { color: #f59e0b; letter-spacing: 0.06em; }
.stars-off { color: #e5e7eb; }
.chapter-note { border-color: var(--orange); background: var(--orange-soft); }
.chapter-note p { margin: 0; }
.topic-note { margin: 0; font-size: 20px; font-weight: 700; }
.training-offer { border-color: #c7c5f2; background: var(--indigo-soft); }
.training-offer p { margin: 0; }
.training-offer .quiet { justify-self: start; }
.backup-offer p, .rest-offer p, .talk-card p { margin: 0; }
/* After a level: something for a grown-up and the child to talk about. */
.talk-card { border-color: #c7c5f2; background: var(--indigo-soft); }
.backup-offer .quiet { justify-self: start; }
/* The grown-up lock's question, over whatever screen asked for it. */
.lock-dialog { width: min(420px, calc(100vw - 24px)); padding: 20px 22px; border: 0; border-radius: 18px; background: var(--surface); color: var(--ink); }
.lock-dialog::backdrop { background: rgba(20, 28, 48, 0.6); }
.lock-form { display: grid; gap: 12px; }
.lock-form label { font-size: 22px; font-weight: 800; }
.lock-form .code-error { margin: 0; }
.fact-note { display: block; font-size: 15px; color: var(--muted); }

/* The progress report: a table a grown-up can read at a glance, and a screen reader row by row. */
.report-screen { display: grid; gap: 18px; }
.report-table { overflow-x: auto; padding: 0; }
.report-table table { width: 100%; border-collapse: collapse; font-size: 17px; }
.report-table caption { padding: 14px 16px 6px; text-align: left; font: 800 19px var(--display); }
.report-table th, .report-table td { padding: 9px 16px; text-align: left; border-top: 1px solid var(--line); }
.report-table thead th { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.report-table tbody th { font-weight: 700; }
.strength { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 15px; font-weight: 700; white-space: nowrap; }
.strength--new { color: var(--muted); background: #f1f3f7; }
.strength--practise { color: var(--wrong); background: var(--wrong-soft); }
.strength--growing { color: #92400e; background: #fef3c7; }
.strength--strong { color: var(--right); background: var(--right-soft); }

/* Start stays in sight while the choices above it are scrolled through. */
.start-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-block: -12px;
  padding-block: 12px;
  background: linear-gradient(to top, rgb(255 243 223 / 0.96) 60%, rgb(255 243 223 / 0));
}
.start-bar .primary { box-shadow: 0 6px 18px rgb(185 76 8 / 0.28); }

.title-footer { padding-top: 14px; font-size: 15px; color: var(--muted); border-top: 2px solid var(--line); }
.title-footer p { margin: 0 0 6px; }
.title-footer a { color: var(--indigo); font-weight: 700; }

/* The battle */
.battle { display: grid; gap: 14px; }
.battle-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.journey-title { font-size: 22px; }
.journey { display: flex; gap: 7px; margin: 0; padding: 0; list-style: none; }
.journey li { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--indigo); background: var(--surface); }
.journey .beaten { background: var(--indigo); }
.journey .current { background: var(--orange); border-color: var(--orange-deep); scale: 1.25; }
/* The one-minute challenge: the clock, the score, and the time left as a bar that empties. */
.challenge { display: grid; gap: 14px; }
.challenge-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.challenge-bar [data-ref=stop] { margin-left: auto; }
.challenge-clock { margin: 0; min-width: 2.2ch; font: 800 34px var(--display); font-variant-numeric: tabular-nums; color: var(--indigo); }
.challenge-clock.is-low { color: #dc2626; }
.challenge-score { margin: 0; font-size: 22px; font-weight: 800; color: var(--orange-deep); }
.challenge-score.is-up { animation: score-up 300ms ease-out; }
@keyframes score-up { 40% { transform: scale(1.3); } }
.challenge-time { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; }
.challenge-time span { display: block; height: 100%; width: 100%; background: var(--indigo); }
.challenge:has(.is-low) .challenge-time span { background: #dc2626; }
.challenge-best { margin: 0; font-size: 18px; }
.challenge-final { margin: 0; font: 800 28px var(--display); }
.challenge-final strong { font-size: 64px; color: var(--indigo); }
.challenge-missed ul { display: grid; gap: 8px; margin: 0; padding-left: 20px; }
.challenge-missed strong { color: var(--indigo); }
.challenge-note { font-size: 15px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) {
  .challenge-score.is-up { animation: none; }
}
.streak { margin: 0; font-weight: 800; color: var(--orange-deep); }
.streak:empty { display: none; }
.leave { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.leave-ask { font-weight: 700; }

.panel {
  display: grid;
  gap: 14px;
  padding: 16px 18px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
}
.arrival { margin: 0; color: var(--muted); font-weight: 700; }
.ask { display: grid; gap: 12px; }
.prompt { margin: 0; font: 800 clamp(22px, 3.4vw, 28px)/1.3 var(--display); }
/* The box a question's picture goes in: div.picture, since a picture graph's
   pictures have the class too, and an <image> is :empty. */
div.picture { display: grid; place-items: center; padding: 8px; background: #f7f9fc; border-radius: 12px; }
div.picture:empty { display: none; }
.picture svg { width: 100%; max-width: 560px; max-height: 230px; height: auto; }
/* Graphs, grids, protractors and dials are read by their small print, so they get
   more room; squeezed to 230 pixels, a coordinate grid's numbers were 7 pixels high. */
.picture svg:is([data-visual="coordinates"], [data-visual="bar_graph"], [data-visual="picture_graph"], [data-visual="line_plot"], [data-visual="angle"], [data-visual="gauge"]) {
  max-height: min(380px, 50vh);
}

.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.choices.long { grid-template-columns: minmax(0, 1fr); }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 14px;
  text-align: left;
  font-size: 22px;
  font-weight: 800;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 12px;
}
.choice:hover:not(:disabled) { border-color: var(--indigo); background: var(--indigo-soft); }
.choice:disabled { cursor: default; }
.choice .key {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: #eef1f7;
  color: var(--muted);
  font-size: 15px;
}
.choice-text { min-width: 0; overflow-wrap: anywhere; }
/* Mixed numbers and fractions in the same bold type as the other answers, not a thin serif. */
.choice math { font-size: 1.35em; font-family: var(--display); font-weight: 800; }
.choice-picture { font-size: 38px; line-height: 1; }
:is(img, svg).choice-picture { width: 46px; height: 46px; object-fit: contain; vertical-align: middle; }
/* A typed answer: its field with delete and Strike beside it, and a row of digits under them,
   big enough for small fingers, that wraps to two rows on a phone. */
.numpad { display: grid; gap: 8px; justify-items: center; }
.numpad[hidden] { display: none; }
.numpad-top { display: flex; gap: 8px; align-items: stretch; }
.numpad-field {
  display: block; min-width: 6ch; padding: 4px 16px;
  border: 3px solid var(--line); border-radius: 12px; background: var(--surface);
  font: 800 32px/1.3 var(--display); text-align: center; font-variant-numeric: tabular-nums;
}
.numpad-field.right { border-color: var(--right); background: var(--right-soft); }
.numpad-field.wrong { border-color: var(--wrong); background: var(--wrong-soft); }
.numpad-keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 100%; }
.numpad-key { width: 52px; min-height: 52px; padding: 0; font-size: 24px; font-weight: 800; }
.numpad-enter { padding: 0 18px; font-size: 20px; }
.numpad-note, .numpad-tried { margin: 0; color: var(--muted); font-size: 15px; font-weight: 700; text-align: center; }
.numpad-tried:empty { display: none; }
.choice.right { border-color: var(--right); background: var(--right-soft); }
.choice.wrong { border-color: var(--wrong); background: var(--wrong-soft); color: #7f1d1d; }
.choice.wrong .choice-text { text-decoration: line-through; }
.choice.right::after, .choice.wrong::after { margin-left: auto; font-size: 26px; }
.choice.right::after { content: "✓"; color: var(--right); }
.choice.wrong::after { content: "✗"; color: var(--wrong); }
.feedback { margin: 0; min-height: 1.5em; font-weight: 800; }

/* Wide but short screens, like a school laptop's 1366 x 768 or a tablet on
   its side: stacked, the stage, picture and answers need about 900 pixels,
   so the answers fell below the fold. Side by side, the fight stays in view
   beside the question. On a short screen, from narrower too: a tablet on
   its side can be 850 x 530. */
@media (min-width: 960px) and (max-height: 1000px), (min-width: 800px) and (max-height: 640px) {
  .game:has(.battle) { max-width: 1320px; }
  .battle { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; }
  .battle-bar { grid-column: 1 / -1; }
  .battle > [data-ref="stage"] { position: sticky; top: 10px; }
  /* A taller stage in its narrower column, as on phones; the backdrop
     still covers it from the floor up. */
  .battle .stage { --aspect: 1.7; }
  .picture svg:is([data-visual="coordinates"], [data-visual="bar_graph"], [data-visual="picture_graph"], [data-visual="line_plot"], [data-visual="angle"], [data-visual="gauge"]) {
    max-height: max(230px, min(380px, 100vh - 390px));
  }
}
/* Shorter still, like a small tablet on its side (about 1000 x 560): the
   question's column ran past the bottom while the stage's had room under
   it. The level's bar goes over the stage, so the question starts at the
   top, and the question, its picture and the answers take a little less
   room, so the answers fit under the picture. */
@media (min-width: 800px) and (max-height: 640px) {
  .battle { grid-template-rows: auto 1fr; gap: 10px 14px; }
  .battle-bar { grid-column: 1; }
  .battle > [data-ref="stage"] { grid-column: 1; }
  .battle > .panel { grid-column: 2; grid-row: 1 / span 2; gap: 10px; padding: 12px 14px; }
  .battle .prompt { font-size: 22px; }
  .battle .choice { min-height: 50px; padding-block: 6px; font-size: 20px; }
  .battle .picture svg { max-height: max(140px, 100vh - 420px); }
  .battle .picture svg:is([data-visual="coordinates"], [data-visual="bar_graph"], [data-visual="picture_graph"], [data-visual="line_plot"], [data-visual="angle"], [data-visual="gauge"]) {
    max-height: max(180px, 100vh - 380px);
  }
  .battle .numpad-key { min-height: 44px; }
}

/* The victory and the treasures */
.facts { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.facts li { padding: 12px 14px; background: var(--surface); border: 2px solid var(--line); border-radius: 12px; }
.facts strong { display: block; font: 800 26px var(--display); color: var(--indigo); }
/* A treasure: its picture (or emoji, until it's drawn) and its name on a
   shelf; big, with what it was won for, when it's just been won or opened. */
.treasure-set { display: grid; gap: 10px; }
.treasure-shelf { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.treasure-shelf > li { display: grid; }
.treasure {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  width: 100%;
  padding: 10px 6px 12px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 14px;
  text-align: center;
}
button.treasure:hover { border-color: var(--indigo); }
.treasure-art { width: 88px; height: 88px; object-fit: contain; }
.treasure-art.is-emoji { display: grid; place-items: center; font-size: 54px; line-height: 1; }
.treasure-name { font-weight: 800; font-size: 15px; line-height: 1.25; }
.treasure.is-locked { background: transparent; border-style: dashed; color: var(--muted); }
.treasure.is-locked .treasure-name { font-weight: 600; }
.treasure-art.is-locked { display: grid; place-items: center; }
.treasure-art.is-locked .icon { width: 30px; height: 30px; opacity: 0.55; }
.treasure-reveal {
  display: flex;
  align-items: center;
  gap: 18px;
  background: linear-gradient(135deg, #fff6d6, var(--surface) 65%);
  border-color: #efcf72;
}
.treasure-art--big { flex: none; width: 136px; height: 136px; }
.treasure-art--big.is-emoji { font-size: 92px; }
.reveal-words { display: grid; gap: 2px; }
.reveal-kicker { margin: 0; font: 800 15px var(--display); letter-spacing: 0.05em; text-transform: uppercase; color: var(--orange-deep); }
.reveal-name { margin: 0; font: 800 26px/1.15 var(--display); }
.reveal-line { margin: 2px 0 0; }
.treasure-dialog { width: min(520px, calc(100vw - 24px)); padding: 20px; border: 0; border-radius: 18px; background: var(--surface); color: var(--ink); }
.treasure-dialog[open] { display: grid; gap: 16px; }
.treasure-dialog::backdrop { background: rgba(20, 28, 48, 0.6); }
.treasure-dialog .treasure-reveal { padding: 0; border: 0; background: none; }
@media (prefers-reduced-motion: no-preference) {
  .victory-screen .treasure-reveal .treasure-art--big { animation: treasure-pop 650ms cubic-bezier(0.2, 1.4, 0.4, 1) 250ms both; }
}
@keyframes treasure-pop {
  from { transform: scale(0.3) rotate(-14deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
/* The treasures and the monster book, a tab each. */
.tabs { display: flex; gap: 4px; justify-self: start; padding: 4px; background: var(--surface); border: 2px solid var(--line); border-radius: 14px; }
.tab { padding: 8px 16px; border: 0; border-radius: 10px; background: none; font-weight: 800; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--indigo); color: #fff; }
.tab-panel { display: grid; gap: 18px; }
.tab-panel[hidden] { display: none; }
.book-page { display: grid; gap: 10px; }
.monster-shelf { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.monster-card {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  padding: 10px 8px 12px;
  text-align: center;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 14px;
}
.monster-still { display: grid; place-items: center; height: 88px; }
.monster-still .still { height: 88px; }
.monster-name { font-weight: 800; font-size: 15px; line-height: 1.25; }
.monster-line { font-size: 14px; line-height: 1.35; color: var(--muted); }
.monster-card.is-unmet { background: transparent; border-style: dashed; color: var(--muted); }
.monster-unknown { display: grid; place-items: center; height: 88px; font: 800 40px var(--display); opacity: 0.4; }
@media (max-width: 480px) {
  .monster-shelf { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .monster-card { padding: 8px 4px 10px; }
  .monster-still, .monster-still .still, .monster-unknown { height: 64px; }
  .monster-name { font-size: 14px; }
  .monster-line { font-size: 13px; }
  .treasure-shelf { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .treasure-shelf .treasure-art { width: 72px; height: 72px; }
  .treasure-reveal { flex-direction: column; text-align: center; gap: 10px; }
}
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

/* On a phone the title stage is taller than the art, which is then cropped
   at the sides; the words sit above the fighters instead of over them. */
@media (max-width: 640px) {
  .title-stage { height: 330px; }
  .title-words { top: 12px; width: auto; left: 12px; right: 12px; translate: none; max-width: none; padding: 10px 14px; }
  .title-fighter { height: 42%; }
  .title-fighter--hero { left: 5%; }
  .title-fighter--monster { right: 5%; }
  .heroes { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .hero-choice { padding: 8px 4px; gap: 4px; }
  .hero-choice .still { height: 58px; }
  .hero-name { font-size: 14px; line-height: 1.2; }
  .grade-years { gap: 5px; }
  .grade-number { font-size: 26px; }
  .grade-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } /* the number is enough to see */
  /* An open chapter's picture goes across the top, above its levels. */
  .chapter-open { grid-template-columns: minmax(0, 1fr); }
  .chapter-art { min-height: 0; aspect-ratio: 3.2; }
  .map-hero .still { height: 64px; }
  .map-head { gap: 10px; }
  /* Switching player is the icon alone, so the name has the room. */
  .switch-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .switch-player { padding: 10px 12px; }
  .continue-play { font-size: 28px; }
  .map-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .levels { gap: 6px; }
  .level-button { width: 56px; height: 60px; }
  .note-text { font-size: 20px; }
  /* In battle the top bar steps aside, so the stage starts higher: the sound
     button, as an icon, sits at the top right beside the level's name. */
  .game[data-screen="battle"] .top { position: absolute; top: 10px; right: max(16px, env(safe-area-inset-right, 0px)); padding: 0; }
  .game[data-screen="battle"] .brand { display: none; }
  .game[data-screen="battle"] .sound-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .game[data-screen="battle"] .battle-bar { padding-right: 56px; }
  /* The report's rows become cards: the topic, then each cell after its label. */
  .report-table table, .report-table caption, .report-table tbody, .report-table tr, .report-table th, .report-table td { display: block; }
  .report-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .report-table tbody tr { padding: 10px 16px; border-top: 1px solid var(--line); }
  .report-table tbody th, .report-table td { padding: 2px 0; border: 0; }
  .report-table td { display: flex; justify-content: space-between; gap: 12px; font-size: 16px; }
  .report-table td::before { content: attr(data-label); color: var(--muted); }
}
/* A teaching scene's bubble between the two of them needs room: below this,
   the two side by side, and the bubble under them, its tail pointing up at
   the speaker. */
@media (max-width: 720px) {
  .scene-cast { grid-template-columns: 1fr 1fr; grid-template-areas: "hero monster" "bubble bubble"; gap: 4px 8px; }
  .scene-actor--hero { grid-area: hero; justify-self: start; }
  .scene-actor--monster { grid-area: monster; justify-self: end; }
  .scene-bubble { grid-area: bubble; }
  .scene-bubble::after { bottom: auto; top: -11px; }
  .scene-bubble[data-from="hero"]::after { left: 40px; rotate: 135deg; }
  .scene-bubble[data-from="monster"]::after { left: auto; right: 40px; rotate: 135deg; }
}
@media (max-width: 480px) {
  /* Every pixel of width goes to the picture, which is as wide as it can be. */
  .panel { padding: 14px 12px; }
  div.picture { padding: 4px; }
  .choices { grid-template-columns: minmax(0, 1fr); }
  .choice { min-height: 56px; font-size: 20px; }
  .banner .still { height: 110px; }
  .scene-actor .still { height: 88px; }
  .scene-bubble { min-height: 4.4em; padding: 10px 14px; }
  .scene-line { font-size: 20px; }
  .start-bar .primary { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .scene-actor.is-speaking { transform: none; } /* the bubble and the brighter speaker still say who it is */
  .scene-picture .focus { animation: none; }
}
