:root {
  --sky: #0b1030;
  --panel: #1b2358;
  --panel-hi: #2b3680;
  --text: #f4f6ff;
  --muted: #aab3e6;
  --gold: #ffcc33;
  --go: #3ddc97;
  --hop: #5cc8ff;
  --warn: #ff9b73;
  --key: 72px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(2px 2px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 78% 12%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 64% 72%, #ffe9a8 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 30% 84%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 90% 52%, #cfe8ff 50%, transparent 51%),
    radial-gradient(ellipse at 80% 110%, #3a1d6e 0%, transparent 60%),
    var(--sky);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
}

button {
  font: inherit;
  font-weight: 700;
  min-width: 44px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 18px;
  color: var(--text);
  background: var(--panel-hi);
  touch-action: manipulation;
  cursor: pointer;
}

button[aria-pressed="true"] { background: var(--gold); color: var(--sky); }
button:disabled { opacity: 0.35; }
/* A locked choice must still read as the one he picked. */
button[aria-pressed="true"]:disabled { opacity: 1; }

#app {
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.home {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
}

.home h1 { margin: 0; font-size: 44px; color: var(--gold); }
.home > .home-button { align-self: flex-start; }
/* The dealt problem sits in the column, so it must not stretch the way it does in the play bar. */
.home > .problem { flex: none; }
.place, .ore { margin: 0; font-size: 26px; }
.notice { margin: 0; color: var(--warn); font-size: 20px; }
.mission-line { margin: 0; font-size: 22px; font-weight: 700; text-wrap: balance; }
.mission-line.speaker-line { display: flex; align-items: center; justify-content: center; gap: 12px; }
.choice h2 { margin: 4px 0 8px; font-size: 20px; color: var(--muted); font-weight: 600; }
.choice-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.choice-row button { min-width: 64px; min-height: 64px; font-size: 28px; }

.start { min-height: 64px; padding: 0 40px; font-size: 30px; background: var(--go); color: var(--sky); }

.ship, .base-panel, .base-info, .suit, .helper { display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(100%, 420px); padding: 16px 24px; border-radius: 18px; background: var(--panel); }
.ship h2, .base-panel h2, .suit h2, .helper h2 { margin: 0; font-size: 34px; color: var(--gold); }
.ship p, .base-panel p, .base-info p, .home > .base-built, .suit p, .helper p { margin: 0; font-size: 24px; }
.ship .ship-built, .base-panel .base-built, .home > .base-built, .suit .suit-worn, .helper .helper-owned { font-size: 30px; font-weight: 800; color: var(--go); }
.ship .ship-short, .ship .ship-needs, .base-panel .base-short, .suit .suit-short, .helper .helper-short { color: var(--hop); font-weight: 700; }
.suit .explorer-drawing { flex: none; width: auto; height: 120px; }
.helper .helper-drawing { flex: none; width: auto; height: 100px; }

/* The height cap keeps the panel below the drawing within a scroll on a phone on its side. The scene keeps the
   drawing's shape under that cap, so each of its three buttons stays over its own module's third. */
.base-scene { flex: none; position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: min(100%, 560px, 40dvh * 15 / 7); aspect-ratio: 600 / 280; }
.base-drawing { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.base-scene .base-slot { position: relative; padding: 0; background: transparent; }
.base-scene .base-slot:focus-visible { outline: 4px solid var(--hop); outline-offset: -4px; }
.base-mark { display: none; fill: var(--gold); stroke: var(--sky); stroke-width: 3; }
.base-mark.base-mark-on { display: inline; }
.base-info button { min-height: 52px; font-size: 22px; }
.base-crater { fill: rgba(11, 16, 48, 0.25); }
.base-module .base-shape, .base-module .base-detail { stroke-linejoin: round; stroke-linecap: round; }
.base-on .base-shape { stroke: var(--sky); stroke-width: 4; }
.base-on .base-detail { fill: none; stroke: var(--sky); stroke-width: 4; }
.base-on .base-window { fill: var(--hop); }
.base-on.base-pad .base-shape { fill: var(--warn); }
.base-on.base-dome .base-shape { fill: var(--text); }
.base-on.base-mine .base-shape { fill: var(--gold); }
/* Dashed as well as uncoloured, so built and not built differ in more than colour. */
.base-off .base-shape, .base-off .base-detail { fill: none; stroke: var(--muted); stroke-width: 4; stroke-dasharray: 10 8; }
.base-label { fill: var(--text); font-size: 28px; font-weight: 800; text-anchor: middle; paint-order: stroke; stroke: var(--sky); stroke-width: 6px; stroke-linejoin: round; }

/* With the explorer the Mission screen no longer fits a phone as one column, so the buttons go two or four to a row
   and the drawing takes only the height left over, giving way before any button is pushed off. */
.mission { display: grid; grid-template: "info" auto "goal" auto "drawing" minmax(0, 1fr) "buttons" auto / minmax(0, 1fr); justify-items: center; }
.mission-info { grid-area: info; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 20px; }
.mission-info h1, .mission-info .place, .mission-info .notice { flex-basis: 100%; }
/* The mission and the story so far share a column of speakers, so the two buttons line up, and the story is set lighter
   so the mission stays the heading. The block is as wide as its words, so it stays centred under the heading. */
.mission-lines { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; text-align: left; }
.mission-lines > .mission-line { grid-column: 1 / -1; }
.mission-lines > .mission-line.speaker-line { display: grid; grid-template-columns: subgrid; }
.mission-story { font-size: 18px; font-weight: 600; }
.mission .explorer-drawing { grid-area: drawing; max-height: 50dvh; }
.mission-buttons { grid-area: buttons; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: min(100%, 720px); }
.mission-buttons button { min-height: 52px; padding: 0 8px; font-size: 22px; }
.mission-buttons .secondary { font-size: 20px; }
.goal { grid-area: goal; display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(100%, 560px); padding: 12px 20px 16px; border-radius: 18px; background: var(--panel); }
.goal h2 { margin: 0; font-size: 20px; color: var(--muted); font-weight: 600; }
.goal .speaker-line { display: flex; align-items: center; justify-content: center; gap: 12px; }
.goal-text { margin: 0; font-size: 30px; font-weight: 800; line-height: 1.2; text-wrap: balance; }

@media (orientation: landscape) {
  .mission { grid-template: "drawing info" 1fr "drawing goal" 1fr "buttons buttons" auto / minmax(0, 300px) minmax(0, 420px); justify-content: center; }
  .mission-info { align-self: end; }
  .goal { align-self: start; }
}

@media (orientation: landscape), (min-width: 700px) {
  .mission-buttons { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* On a phone the goal is set tighter, so the explorer keeps some room upright. On its side the goal sits beside the
   words, with the explorer under them, so both rows of buttons stay in view. */
@media (max-width: 500px), (max-height: 500px) {
  .goal { gap: 4px; padding: 8px 16px 12px; }
  .goal-text { font-size: 26px; }
  .mission-buttons button { min-height: 48px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .mission { grid-template: "info goal" auto "drawing goal" minmax(0, 1fr) "buttons buttons" auto / minmax(0, 300px) minmax(0, 360px); }
  .mission-info, .mission .goal { align-self: start; }
  .mission-info h1 { font-size: 32px; }
}

/* As on the Mission screen, the scene takes only the height left over, so it shrinks before Play is pushed off. */
.start-screen { display: grid; grid-template: "info" auto "scene" minmax(0, 1fr) "play" auto "watch" auto "grown-ups" auto / minmax(0, 1fr); justify-items: center; }
.start-info { grid-area: info; display: flex; flex-direction: column; align-items: center; gap: 4px; }
/* The explorer stands in the lower three quarters, below the backdrop's planet, whatever shape the scene takes. */
.start-scene { grid-area: scene; position: relative; display: grid; place-items: end center; align-self: stretch; width: min(100%, 640px); min-height: 0; padding-bottom: 12px; border-radius: 18px; overflow: hidden; }
.start-scene .space-drawing { position: absolute; inset: 0; }
.start-scene .explorer-drawing { position: relative; height: 74%; }
.start-screen .start-play { grid-area: play; min-height: 96px; padding: 0 72px; font-size: 44px; }
.start-screen .start-watch { grid-area: watch; display: flex; justify-content: center; gap: 12px; }
.start-screen .start-grown-ups { grid-area: grown-ups; }
.start-screen button:focus-visible { outline: 4px solid var(--gold); outline-offset: 4px; }

@media (orientation: landscape) {
  .start-screen { grid-template: "scene ." minmax(0, 1fr) "scene info" auto "scene play" auto "scene watch" auto "scene grown-ups" auto "scene ." minmax(0, 1fr) / minmax(0, 420px) minmax(0, 420px); justify-content: center; }
}

/* On a phone the mission line is set small, so the drawing under it keeps some room. On its side the start screen also
   gives the line the width to stay on one line, taken from the scene, and a shorter Play, so its buttons stay in view. */
@media (max-width: 500px), (max-height: 500px) {
  .mission-line { font-size: 17px; }
  .mission-line.speaker-line { gap: 8px; }
  .mission-line .speaker { width: 36px; height: 36px; min-width: 0; min-height: 0; border-radius: 12px; }
  .mission-lines { column-gap: 8px; }
  .mission-story { font-size: 16px; line-height: 1.25; }
}

/* On a short phone, either way up, the drawing has no height left to give the story line, so with one shown the
   heading and the lines under it are set smaller and the rows closer, keeping every button in view. */
@media (max-width: 500px) and (max-height: 700px), (max-height: 500px) {
  .mission:has(.mission-story) { row-gap: 8px; }
  .mission:has(.mission-story) .mission-info h1 { font-size: 32px; }
  .mission:has(.mission-story) :is(.place, .ore) { font-size: 22px; }
  .mission-story { font-size: 14px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .start-screen { grid-template-columns: minmax(0, 1fr) minmax(0, 420px); }
  .start-screen .start-play { min-height: 64px; }
}

/* As on the start screen, the picture takes only the height left over, so it shrinks before the words or the buttons
   are pushed off. Its layers share one cell; the bottom row is the ground, and whoever stands sits on its top edge. */
.story-screen { display: grid; grid-template: "picture" minmax(0, 1fr) "words" auto "buttons" auto / minmax(0, 1fr); justify-items: center; }
.story-picture { grid-area: picture; display: grid; grid-template: minmax(0, 1fr) 16% / minmax(0, 1fr); align-self: stretch; width: min(100%, 640px); min-height: 0; border-radius: 18px; overflow: hidden; }
.story-picture > * { grid-row: 1 / -1; grid-column: 1; min-width: 0; min-height: 0; }
.story-picture .space-drawing { width: 100%; height: 100%; }
.story-night { fill: var(--panel); }
.story-ground { display: block; grid-row: 2; width: 100%; height: 100%; }
.story-crater { fill: rgba(11, 16, 48, 0.25); }
.story-picture .explorer-drawing { grid-row: 1; align-self: end; justify-self: center; width: auto; height: 80%; transform: translateY(3%); }
/* Beside the ore or the base he keeps to the left third, so neither drawing ever sits behind his boots. */
.story-panel-mine .explorer-drawing, .story-panel-base .explorer-drawing { justify-self: start; margin-left: 4%; width: 34%; height: auto; max-height: 66%; }
.story-ore { display: block; grid-row: 1; align-self: end; justify-self: end; width: 36%; height: auto; margin-right: 8%; }
.story-ore-rocks { fill: #a0603c; stroke: var(--sky); stroke-width: 2; stroke-linejoin: round; }
.story-ore-shine { fill: var(--gold); }
.story-signal { display: block; grid-row: 1; align-self: start; justify-self: end; width: 22%; height: auto; margin: 3% 8% 0 0; }
.story-signal-waves { fill: none; stroke: var(--gold); stroke-width: 3; stroke-linecap: round; }
.story-signal-point { fill: var(--gold); }
.story-base { display: block; grid-row: 1; align-self: end; justify-self: end; width: 58%; height: auto; margin-right: 2%; }
.story-base-parts { stroke: var(--sky); stroke-width: 3; stroke-linejoin: round; }
.story-base-pad { fill: var(--warn); }
.story-base-pad-ring { fill: none; }
.story-base-dome { fill: var(--text); }
.story-base-window { fill: var(--hop); }
.story-picture .place-drawing { display: block; align-self: start; justify-self: end; width: auto; height: 56%; aspect-ratio: 1; margin: 4% 4% 0 0; }
.story-picture .flight-ship { display: block; align-self: end; justify-self: start; height: auto; margin: 0; transform: rotate(-24deg); }
.story-panel-moon .flight-ship { width: 40%; margin: 0 0 14% 8%; }
.story-panel-ships .flight-ship:nth-child(2) { width: 18%; margin: 0 0 8% 6%; }
.story-panel-ships .flight-ship:nth-child(3) { align-self: center; justify-self: center; width: 28%; margin-top: 10%; }
.story-panel-ships .flight-ship:nth-child(4) { align-self: start; justify-self: end; width: 40%; margin: 26% 4% 0 0; }
/* The planet's body is a fifth of its drawing in from the top, so the signal's turned point, at the middle of its own
   drawing, is moved up to that edge. Sizes are of the smaller side of the picture, so both fit either way up. */
.story-here { position: relative; container-type: size; }
.story-picture .story-here > * { position: absolute; left: 50%; top: 50%; margin: 0; }
.story-picture .story-here .place-drawing { width: 64cqmin; height: 64cqmin; transform: translate(-50%, -40%); }
.story-picture .story-here .story-signal { width: 40cqmin; height: 40cqmin; transform: translate(-50%, calc(-50% - 12cqmin)) rotate(180deg); }
.story-panel-found .flight-ship { width: 26%; margin: 0 0 6% 4%; }
/* The helpers and the explorer stand side by side on the ground, sized by the picture's width so none overlaps. */
.story-picture .helper-drawing { grid-row: 1; align-self: end; width: 28%; height: auto; transform: translateY(4%); }
.story-panel-song .helper-drawing:nth-child(3), .story-panel-friends .helper-drawing:nth-child(3) { justify-self: start; margin-left: 3%; }
.story-panel-song .helper-drawing:nth-child(4) { justify-self: center; width: 32%; }
.story-panel-song .helper-drawing:nth-child(5), .story-panel-friends .helper-drawing:nth-child(5) { justify-self: end; margin-right: 3%; }
.story-notes { display: block; grid-row: 1; align-self: start; justify-self: end; width: 40%; height: auto; margin: 14% 8% 0 0; }
.story-notes-shapes { fill: var(--gold); }
.story-panel-friends .explorer-drawing { width: 34%; height: auto; max-height: 80%; }
.story-panel-more .flight-ship { align-self: start; justify-self: end; width: 36%; margin: 16% 8% 0 0; }
.story-panel-more .helper-drawing:nth-child(4) { justify-self: start; margin-left: 8%; }
.story-panel-more .helper-drawing:nth-child(5) { justify-self: center; margin-left: 12%; }
.story-line { grid-area: words; display: flex; align-items: center; justify-content: center; gap: 12px; width: min(100%, 640px); }
.story-text { margin: 0; font-size: 28px; font-weight: 800; line-height: 1.25; text-wrap: balance; }
.story-buttons { grid-area: buttons; display: flex; align-items: center; justify-content: center; gap: 16px; }
.story-buttons .secondary { min-height: 56px; }
.story-buttons .start { min-width: 200px; min-height: 72px; font-size: 34px; }
.story-screen button:focus-visible { outline: 4px solid var(--gold); outline-offset: 4px; }

@media (orientation: landscape) {
  .story-screen { grid-template: "picture ." minmax(0, 1fr) "picture words" auto "picture buttons" auto "picture ." minmax(0, 1fr) / minmax(0, 520px) minmax(0, 420px); justify-content: center; }
}

@media (max-width: 500px), (max-height: 500px) {
  .story-text { font-size: 24px; }
  .story-buttons .start { min-height: 60px; font-size: 30px; }
}

.space-drawing { display: block; width: 100%; height: 100%; }
.space-sky { fill: var(--panel); }
.space-star { fill: #fff; }
.space-planet { fill: var(--hop); }
.space-band { fill: none; stroke: #b48cff; stroke-width: 4; stroke-linecap: round; }
.space-ring { fill: none; stroke: var(--gold); stroke-width: 4; stroke-linecap: round; }

.explorer-drawing { display: block; width: 100%; height: 100%; min-height: 0; }
.explorer-figure { stroke: var(--sky); stroke-width: 4; stroke-linejoin: round; }
.explorer-shine { fill: #fff; stroke: none; opacity: 0.7; }

.helper-figure { stroke: var(--sky); stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; }
.helper-eye { fill: #fff; }
.helper-pupil { fill: var(--sky); stroke: none; }

/* Two columns, each stop two rows tall and one row below the last, so the stops zigzag down without overlapping. Every
   row is the same height, which puts each drawing one column over and one row down from the one before. */
.map { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 1fr; column-gap: 12px; width: min(100%, 560px); }
.map-stop { position: relative; align-self: start; justify-self: center; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; padding: 8px; border: 3px solid transparent; border-radius: 18px; }
.map-go { background: var(--panel); border-color: var(--hop); }
.map-go:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
.map-stop .place-drawing { flex: none; width: 88px; height: 88px; }
.map-name { font-size: 22px; font-weight: 800; color: var(--gold); overflow-wrap: anywhere; }
.map-here, .map-needs { font-size: 18px; font-weight: 700; }
.map-here { color: var(--go); }
.map-needs { color: var(--hop); }
.map-stop .imagined { font-size: 16px; }
/* Placed in its row across both columns, but out of the flow so it never sizes the rows: a row tall, from one column's
   middle to the other's, moved down to the middle of the drawings. The stops come after it, so they cover it. */
.map-trail { position: absolute; grid-column: 1 / span 2; top: calc(3px + 8px + 44px); left: calc((100% - 12px) / 4); width: calc((100% + 12px) / 2); height: 100%; overflow: visible; }
.map-trail path { fill: none; stroke: var(--muted); stroke-width: 3; stroke-dasharray: 2 10; stroke-linecap: round; }

.place-figure { stroke: var(--sky); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.place-haze { stroke: none; opacity: 0.7; }
.place-glow { stroke: none; opacity: 0.35; }
.place-siblings { fill: var(--muted); stroke: none; }
.place-flag path { fill: none; stroke: var(--text); stroke-width: 4; stroke-linecap: round; }
.place-flag .place-flag-cloth { fill: var(--go); stroke: var(--sky); stroke-width: 2; stroke-linejoin: round; }
/* Shaded, ringed with dashes and padlocked, so a place he can't reach yet differs in more than colour. */
.place-shade { fill: var(--sky); stroke: none; opacity: 0.6; }
/* The shade fades as one layer, so the haze or glow in it must not fade again on its own. */
.place-shade > * { opacity: 1; }
.place-ring { fill: none; stroke: var(--muted); stroke-width: 4; stroke-dasharray: 10 8; }
.place-lock { fill: var(--muted); stroke: var(--muted); stroke-width: 4; }
.place-lock rect { stroke: var(--sky); stroke-width: 2; }

/* The ship rides a track from the middle of one drawing to the middle of the other. Its mover is as wide as the track,
   so moving it by its own width takes the ship the whole way at any screen size. */
.flight { justify-content: center; }
/* Clipped, because the ship's mover, as wide as the track, is pushed past the scene's edge as it moves. */
.flight-scene { position: relative; display: flex; justify-content: space-between; width: min(100%, 560px); overflow: hidden; }
.flight-place { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 120px; }
.flight-place .place-drawing { width: 120px; height: 120px; }
.flight-track { position: absolute; top: 40px; left: 60px; right: 60px; height: 40px; }
.flight-mover { width: 100%; height: 100%; animation: flight-go ease-in-out forwards; }
.flight-ship { display: block; width: 80px; height: 40px; margin-left: -40px; }
.ship-figure { stroke: var(--sky); stroke-width: 2; stroke-linejoin: round; }
.ship-body { fill: var(--text); }
.ship-fin { fill: var(--warn); }
.ship-flame { fill: var(--gold); }
.ship-window { fill: var(--hop); }

@keyframes flight-go { to { transform: translateX(100%); } }

.facts { width: min(100%, 560px); margin: 0; padding: 16px 24px 16px 44px; border-radius: 18px; background: var(--panel); font-size: 24px; text-align: left; }
.facts li + li { margin-top: 12px; }
/* The speaker buttons stand in for the bullets, in one column, with each fact wrapping beside its own button. */
.facts:has(.speaker-line) { padding-left: 16px; }
.facts .speaker-line { display: flex; align-items: center; gap: 12px; list-style: none; }
.ore.speaker-line { display: flex; align-items: center; justify-content: center; gap: 12px; }
/* Outlined with no panel behind it, so the story line above the facts never looks like one more of them. */
.story-moment { display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(100%, 560px); padding: 12px 20px 16px; border: 3px solid var(--muted); border-radius: 18px; }
.story-moment h2 { margin: 0; font-size: 20px; color: var(--muted); font-weight: 600; }
.story-moment .speaker-line { display: flex; align-items: center; justify-content: center; gap: 12px; }
.story-moment-text { margin: 0; font-size: 24px; font-weight: 700; line-height: 1.3; text-wrap: balance; }

/* The word in an unfilled outline, so it says what it marks without relying on colour and never looks like a button. */
.imagined {
  display: inline-block;
  padding: 0 10px;
  border: 2px solid currentColor;
  border-radius: 999px;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.4;
  vertical-align: middle;
  white-space: nowrap;
}

.speaker {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 14px;
}

.secondary { font-size: 20px; }

/* Off screen but still read, for words only a screen reader needs. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.method { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; width: min(100%, 560px); padding: 16px 24px; border-radius: 18px; background: var(--panel); text-align: left; }
.method h2 { margin: 0; font-size: 30px; color: var(--gold); }
.method p { margin: 0; font-size: 20px; line-height: 1.35; }
.method-standard strong { color: var(--hop); }

/* A curriculum link looks like the small buttons around it, so it reads as something to tap without needing hover. */
.how {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 18px;
  background: var(--panel-hi);
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
  touch-action: manipulation;
}
.bar .how { flex: none; width: 44px; padding: 0; font-size: 20px; }
/* Beside the link, Show me how and the link each keep their label on one line where the width allows, and a label that
   still wraps has room above and below inside its 44px. */
.lesson:has(.how) :is(button, .how) { padding: 0 12px; line-height: 1.1; }

/* During a lesson the link sits in the bar, so the problem keeps its one line and the stats wrap instead. On a short
   screen the bar and the lesson row already share the top line and there is no room for it, so it waits until the lesson ends. */
@media (min-height: 501px) {
  .bar:has(.how) .problem { white-space: nowrap; }
  .bar:has(.how) .stats { min-width: 0; }
  .bar:has(.how) .stats span { white-space: nowrap; }
}

@media (max-height: 500px) {
  .bar .how { display: none; }
}

.play { height: 100%; display: flex; flex-direction: column; touch-action: none; }

.bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; }
.problem { flex: 1; margin: 0; text-align: center; font-size: 40px; font-weight: 800; }
.stats { margin: 0; font-size: 20px; color: var(--gold); text-align: right; }
.home-button { font-size: 20px; }

/* The lesson row sits above the tool, outside the solved banner. Two lines stay reserved so the tool never moves when a line wraps. */
.lesson { display: flex; align-items: center; justify-content: center; gap: 12px; width: min(100%, 720px); align-self: center; padding: 0 12px 8px; }
.lesson-line { flex: 1; margin: 0; font-size: 20px; font-weight: 700; line-height: 1.25; min-height: 2.5em; display: flex; align-items: center; color: var(--gold); text-wrap: balance; }
.lesson button { font-size: 18px; }

.tool {
  flex: 1;
  min-height: 0;
  position: relative;
}

.nl {
  height: 100%;
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto auto auto;
  grid-template-areas: "line" "msg" "hops" "pad";
}

.nl:has(.nl-modes) {
  grid-template-rows: minmax(0, 1fr) auto auto auto auto;
  grid-template-areas: "line" "modes" "msg" "hops" "pad";
}

@media (orientation: landscape) {
  .nl {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr) auto auto;
    grid-template-areas: "line pad" "msg pad" "hops pad";
  }

  .nl:has(.nl-modes) {
    grid-template-rows: minmax(0, 1fr) auto auto auto;
    grid-template-areas: "line pad" "modes pad" "msg pad" "hops pad";
  }
}

.nl-line { grid-area: line; min-height: 0; }
.nl-line svg { width: 100%; height: 100%; display: block; }
.nl-axis { stroke: var(--muted); stroke-width: 6; stroke-linecap: round; }
.nl-tick { stroke: var(--muted); stroke-width: 4; }
/* No text-anchor here: the view sets it per label, and a stylesheet rule would override the attribute. */
.nl-num { fill: var(--text); font-size: 34px; font-weight: 700; }
.nl-goal { fill: var(--go); font-size: 40px; }
.nl-ring { fill: none; stroke: var(--go); stroke-width: 6; }
.nl-now { fill: var(--gold); font-size: 40px; }
.nl-hop { fill: none; stroke: var(--hop); stroke-width: 6; stroke-linecap: round; }
.nl-hop-label { fill: var(--hop); font-size: 32px; font-weight: 800; text-anchor: middle; }
.nl-pending { fill: none; stroke: var(--gold); stroke-width: 5; stroke-dasharray: 12 10; }
.nl-pending-label { fill: var(--gold); font-size: 32px; font-weight: 800; text-anchor: middle; }
.nl-ship circle { fill: var(--gold); }
.nl-ship path { fill: var(--warn); }

.message { grid-area: msg; margin: 0; min-height: 2.6em; font-size: 22px; color: var(--warn); text-align: center; }
/* The line holding a message takes the message's place. With speech it keeps at least the button's height whether or not
   a message is showing, so the tool never moves; without speech it is only the message, as before. */
.message-line { grid-area: msg; }
.message-line.can-speak { display: flex; align-items: center; justify-content: center; gap: 12px; }
.message-line.can-speak .message { display: flex; align-items: center; }
:is(.nl, .ba, .nb, .dk) .message-line.can-speak { min-height: 48px; }

.nl-modes { grid-area: modes; display: flex; justify-content: center; gap: 10px; }
.nl-modes button { flex: 1; max-width: 300px; min-height: 56px; font-size: 22px; padding: 4px 10px; }

.nl-hops { grid-area: hops; display: flex; justify-content: center; gap: 10px; }
.nl-hops button { flex: 1; max-width: 140px; min-height: 64px; font-size: 28px; padding: 0 8px; }

.nl-pad { grid-area: pad; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.nl-prompt { margin: 0; font-size: 20px; text-align: center; max-width: calc(3 * var(--key) + 20px); }

.keypad { display: flex; flex-direction: column; gap: 8px; }
.keypad[inert] { opacity: 0.35; }
.keypad-display {
  display: block;
  height: 56px;
  border-radius: 14px;
  background: var(--panel);
  font-size: 40px;
  font-weight: 800;
  line-height: 56px;
  text-align: center;
  color: var(--gold);
}
.keypad-keys { display: grid; grid-template-columns: repeat(3, var(--key)); gap: 10px; }
.key { width: var(--key); height: var(--key); padding: 0; font-size: 32px; background: var(--panel); }
.key-submit { background: var(--go); color: var(--sky); }

.dk {
  height: 100%;
  display: grid;
  gap: 8px 16px;
  padding: 0 12px 12px;
  /* The table takes what is left, so the written problem never costs the disks any size. */
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 340px);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "table wf panel";
}

.dk-table { grid-area: table; min-height: 0; min-width: 0; }
.dk-table svg { width: 100%; height: 100%; display: block; }
.dk-table text { pointer-events: none; text-anchor: middle; font-weight: 800; }
.dk-col { fill: var(--panel); }
.dk-label { fill: var(--muted); font-size: 30px; }
.dk-split { stroke: var(--panel-hi); stroke-width: 3; stroke-dasharray: 8 8; }
.dk-split-on { stroke: var(--muted); }
.dk-tally { fill: var(--gold); font-size: 22px; }
.dk-tally-done { fill: var(--go); }

.dk-disk circle { stroke: var(--sky); stroke-width: 2; }
.dk-disk text { fill: var(--sky); font-size: 18px; }
.dk-v0 circle { fill: var(--go); }
.dk-v1 circle { fill: var(--hop); }
.dk-v2 circle { fill: var(--warn); }
.dk-locked { opacity: 0.4; }
.dk-second circle { stroke: var(--text); stroke-width: 4; }
.dk-picked circle { stroke: var(--gold); stroke-width: 6; }
.dk-dragging { opacity: 0.85; }
.dk-new { animation: dk-pop 0.5s ease-out; transform-box: fill-box; transform-origin: center; }
.dk-fade { pointer-events: none; animation: dk-fade 0.6s ease-out forwards; }
.dk-loop { fill: rgba(255, 204, 51, 0.15); stroke: var(--gold); stroke-width: 5; stroke-linejoin: round; stroke-linecap: round; }

@keyframes dk-pop { from { transform: scale(0.2); opacity: 0; } }
@keyframes dk-fade { to { opacity: 0; } }

/* Read like his paper: digits in place-value columns, new groups and renamed numbers small, the answer in gold. */
.wf { grid-area: wf; align-self: center; display: grid; justify-content: center; font-variant-numeric: tabular-nums; column-gap: 10px; justify-items: center; align-items: end; font-weight: 800; }
.wf > span { line-height: 1.15; min-height: 1.15em; }
.wf-head { font-size: 18px; color: var(--muted); }
.wf-num { font-size: 40px; }
.wf-small { font-size: 24px; color: var(--gold); }
.wf-answer { color: var(--gold); }
.wf s { text-decoration-thickness: 4px; text-decoration-color: var(--warn); color: var(--muted); opacity: 0.6; }
.wf .wf-bar { grid-column: 1 / -1; justify-self: stretch; min-height: 0; height: 0; border-top: 4px solid var(--text); margin: 2px 0 4px; }

.dk-panel { grid-area: panel; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.dk-info { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.dk-prompt { margin: 0; font-size: 24px; font-weight: 700; text-align: center; }
.dk-actions button { min-height: 64px; font-size: 28px; }
.keypad[hidden] { display: none; }

@media (orientation: portrait) and (min-width: 601px) {
  .dk {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "table wf" "table panel";
  }
}

@media (max-width: 600px), (max-height: 500px) {
  .wf { column-gap: 6px; }
  .wf-head { font-size: 13px; }
  .wf-num { font-size: 26px; }
  .wf-small { font-size: 16px; }
  .wf s { text-decoration-thickness: 3px; }
  .wf .wf-bar { border-top-width: 3px; }
}

@media (max-width: 600px) {
  /* Every line of the panel becomes its own grid cell, so the written problem can sit beside the message and button
     (the height they already took) and move above the prompt while the keypad is up. Either way the disks keep their size. */
  .dk {
    --key: 56px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto auto auto;
    grid-template-areas: "table table" "prompt prompt" "wf msg" "wf actions";
  }
  .dk:has(.keypad:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr) auto auto auto auto;
    grid-template-areas: "table table" "wf pad" "prompt pad" "msg pad" "actions pad";
  }
  .dk-panel, .dk-info { display: contents; }
  .dk-prompt { grid-area: prompt; }
  .dk-actions { grid-area: actions; justify-self: center; }
  .dk .keypad { grid-area: pad; align-self: end; }
  .wf > span { line-height: 1; min-height: 1em; }
  .wf-head { font-size: 12px; }
  .wf-num { font-size: 22px; }
  .wf-small { font-size: 14px; }
}

@media (max-width: 600px), (max-height: 500px) {
  .dk-panel { flex-direction: row; }
  .dk-info { flex: 1; min-width: 0; }
  .dk-prompt { font-size: 18px; }
  .dk-actions button { min-height: 48px; font-size: 22px; }
}

/* Number bonds (.nb) shares the break apart layout, bubbles and reward strip. */
.ba, .nb {
  height: 100%;
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto auto;
  grid-template-areas: "tree" "msg" "pad";
}

@media (orientation: landscape) {
  .ba, .nb {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "tree pad" "msg pad";
  }
}

@media (max-width: 600px) {
  .ba, .nb { --key: 56px; }
}

.ba-tree { grid-area: tree; min-height: 0; min-width: 0; }
.ba-tree svg { width: 100%; height: 100%; display: block; }
.ba-tree text { text-anchor: middle; dominant-baseline: central; font-weight: 800; }
.ba-whole { fill: var(--text); font-size: 56px; }
.ba-branch { stroke: var(--muted); stroke-width: 4; stroke-linecap: round; }
.ba-tree .ba-eq { fill: var(--text); font-size: 32px; text-anchor: end; }
.ba-bubble circle { fill: var(--sky); stroke: var(--muted); stroke-width: 4; }
.ba-bubble text { fill: var(--gold); font-size: 34px; }
.ba-filled circle { fill: var(--panel); stroke: var(--hop); }
.ba-empty circle { stroke-dasharray: 10 8; opacity: 0.6; }
.ba-now circle { fill: rgba(255, 204, 51, 0.2); stroke: var(--gold); stroke-width: 8; }

.ba-pad { grid-area: pad; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
/* Two lines are always reserved so the keypad stays put when a prompt wraps. */
.ba-prompt { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.3; min-height: 2.6em; display: flex; align-items: center; justify-content: center; text-align: center; width: calc(3 * var(--key) + 40px); }

@media (max-height: 500px) {
  .ba-prompt { font-size: 16px; }
}

.banner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(11, 16, 48, 0.88);
}
.earned { margin: 0; font-size: 56px; font-weight: 800; color: var(--gold); }
.from-mine { margin: 0; font-size: 24px; font-weight: 700; color: var(--gold); }

/* The finished tree or written problem is his worked answer, so the reward sits in a strip below it instead of covering it. */
.tool:has(.ba, .nb, .dk) { display: flex; flex-direction: column; }
.tool:has(.ba, .nb, .dk) :is(.ba, .nb, .dk) { flex: 1; height: auto; min-height: 0; }
.tool:has(.ba, .nb, .dk) .banner { position: static; flex-direction: row; padding: 12px; }
.tool:has(.ba, .nb, .dk) .earned { font-size: 40px; }
/* On a narrow screen the mine line moves under the amount rather than squeezing it onto two lines. */
.tool:has(.ba, .nb, .dk) .banner:has(.from-mine) { flex-wrap: wrap; }

@media (max-height: 500px) {
  .tool:has(.ba, .nb, .dk) .banner { padding: 6px; }
  .tool:has(.ba, .nb, .dk) .earned { font-size: 30px; }
  .tool:has(.ba, .nb, .dk) .from-mine { font-size: 18px; }
  .tool:has(.ba, .nb, .dk) .banner .start { min-height: 48px; font-size: 24px; }
}

@media (max-height: 500px) {
  :root { --key: 46px; }
  .bar { padding: 4px 12px; }
  .problem { font-size: 30px; }
  .message { font-size: 18px; min-height: 1.3em; }
  :is(.nl, .ba, .nb, .dk) .message-line.can-speak { min-height: 36px; }
  .message-line .speaker { width: 36px; height: 36px; min-width: 0; min-height: 0; border-radius: 12px; }
  .nl-hops button { min-height: 48px; font-size: 22px; }
  .nl-modes button { min-height: 44px; font-size: 18px; }
  .keypad-display { height: 40px; line-height: 40px; font-size: 30px; }
  .keypad-keys { gap: 6px; }
  .key { font-size: 24px; }
  .nl-prompt { font-size: 16px; }
  /* The keypad column already fills the height, so the lesson row moves up beside the bar instead of taking height from it. */
  .play:has(.lesson) { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
  .play:has(.lesson) > .bar { grid-area: 1 / 1; }
  .play:has(.lesson) > .lesson { grid-area: 1 / 2; padding: 4px 12px 4px 0; }
  .play:has(.lesson) > .notice { grid-area: 2 / 1 / 3 / -1; }
  .play:has(.lesson) > .tool { grid-area: 3 / 1 / 4 / -1; }
  .lesson-line { font-size: 16px; min-height: 0; }
  /* The speaker takes width from the line, so the stats break between their two parts to give it back, and the longest
     lines still take three. Set tight, three lines fit the speaker's 48px, so the top line stays the bar's height. */
  .play:has(.lesson .speaker) { grid-template-columns: min-content minmax(0, 1fr); }
  .play:has(.lesson .speaker) :is(.problem, .stats span) { white-space: nowrap; }
  .play:has(.lesson .speaker) .stats { line-height: 1.1; }
  .play:has(.lesson) > .lesson:has(.speaker) { padding-top: 2px; padding-bottom: 2px; }
  .lesson:has(.speaker) .lesson-line { line-height: 1; }
}

@media (max-width: 500px) {
  /* Smaller choice buttons pair the four tools and keep the five levels on one row, so Start stays on screen. */
  .choice-row button { min-width: 56px; min-height: 56px; padding: 0 12px; font-size: 22px; }
  .problem { font-size: 30px; }
  .stats { font-size: 16px; }
  .message { font-size: 18px; }
  .nl-hops, .nl-modes { gap: 6px; }
  .nl-modes button { font-size: 17px; }
  /* The longest lesson lines need three lines at 20px beside Skip, and a row that grows and shrinks moves the tool.
     Two 16px lines are shorter than Skip, so the line keeps Skip's height for when Skip goes at the end. */
  .lesson-line { font-size: 16px; min-height: 44px; }
  /* Beside the speaker the longest lines take three. Set tight, they fit its 48px, and the smaller gap below keeps the
     row as tall as it is without the speaker. */
  .lesson:has(.speaker) { padding-bottom: 4px; }
  .lesson:has(.speaker) .lesson-line { line-height: 1; min-height: 48px; }
}

/* On a short phone the drawing is the only row that can shrink, so the rows below it get smaller to keep a line to hop on
   and the keypad on screen. Two lines stay reserved for the prompt and message so the keypad never moves. */
@media (max-width: 500px) and (min-height: 501px) and (max-height: 760px) {
  .nl { --key: 56px; gap: 6px; padding-bottom: 8px; }
  .nl .message { font-size: 16px; line-height: 1.25; min-height: 2.5em; }
  .nl .message-line.can-speak { min-height: 40px; }
  .nl .message-line .speaker { width: 40px; height: 40px; min-width: 0; min-height: 0; border-radius: 12px; }
  .nl-modes button { min-height: 44px; font-size: 16px; line-height: 1.15; padding: 2px 8px; }
  .nl-hops button { min-height: 48px; font-size: 22px; }
  .nl-pad { gap: 4px; }
  .nl-prompt { font-size: 18px; line-height: 1.25; min-height: 2.5em; display: flex; align-items: center; justify-content: center; }
  .nl .keypad { gap: 6px; }
  .nl .keypad-display { height: 44px; line-height: 44px; font-size: 32px; }
  .nl .keypad-keys { gap: 6px; }
  .nl .key { font-size: 26px; }
}

/* On a short phone the lesson row takes its height from the tree, so the rows below the tree give it back and the tree's
   numbers stay as large as without the row. Two lines stay reserved for the prompt and message so the keypad never moves. */
@media (max-width: 500px) and (min-height: 501px) and (max-height: 760px) {
  .play:has(.lesson) :is(.ba, .nb) { --key: 52px; gap: 6px; }
  .play:has(.lesson) :is(.ba, .nb) .message { font-size: 16px; line-height: 1.25; min-height: 2.5em; }
  .play:has(.lesson) :is(.ba, .nb) .message-line.can-speak { min-height: 40px; }
  .play:has(.lesson) :is(.ba, .nb) .message-line .speaker { width: 40px; height: 40px; min-width: 0; min-height: 0; border-radius: 12px; }
  .play:has(.lesson) .ba-pad { gap: 4px; }
  .play:has(.lesson) .ba-prompt { font-size: 18px; line-height: 1.25; min-height: 2.5em; }
  .play:has(.lesson) :is(.ba, .nb) .keypad { gap: 6px; }
  .play:has(.lesson) :is(.ba, .nb) .keypad-display { height: 44px; line-height: 44px; font-size: 32px; }
  .play:has(.lesson) :is(.ba, .nb) .keypad-keys { gap: 6px; }
  .play:has(.lesson) :is(.ba, .nb) .key { font-size: 26px; }
}

/* Below 600px tall (an iPhone SE with the browser's bars showing) four rows of keys leave the tree a strip too thin to read.
   The keys go into two rows of six and the display moves up beside the prompt, so the tree gets that height back. */
@media (max-width: 500px) and (min-height: 501px) and (max-height: 600px) {
  .ba .ba-pad { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "prompt display" "keys keys"; }
  .ba .keypad:not([hidden]) { display: contents; }
  .ba .ba-prompt { grid-area: prompt; width: auto; }
  .ba .keypad-display { grid-area: display; width: calc(2 * var(--key)); }
  .ba .keypad-keys { grid-area: keys; grid-template-columns: repeat(6, var(--key)); justify-content: center; }
}

/* On its side below 360px tall (the same phone with the browser's bars showing) the prompt and four rows of keys are taller
   than the space beside the tree, so ✓ falls off the bottom. The display moves left of the keys and the gaps shrink, which
   keeps every key on screen without taking any height from the tree. */
@media (max-height: 360px) {
  .ba .ba-pad { gap: 4px; }
  .ba .ba-prompt { line-height: 1.2; min-height: 2.4em; width: 222px; }
  .ba .keypad { flex-direction: row; align-items: start; gap: 4px; }
  .ba .keypad-display { width: 72px; }
  .ba .keypad-keys { gap: 4px; }
  /* Number bonds shares the pad, which is taller than its space here and rises into the top line. Beside the speaker the
     lesson line takes three lines down to that line's bottom, so the pad packs the same way and stays below it. */
  .play:has(.lesson .speaker) .nb .ba-pad { gap: 4px; }
  .play:has(.lesson .speaker) .nb .ba-prompt { line-height: 1.2; min-height: 2.4em; width: 222px; }
  .play:has(.lesson .speaker) .nb .keypad { flex-direction: row; align-items: start; gap: 4px; }
  .play:has(.lesson .speaker) .nb .keypad-display { width: 72px; }
  .play:has(.lesson .speaker) .nb .keypad-keys { gap: 4px; }
}

/* Motion only when the device allows it. Later animated screens add their animations inside this block too. */
@media (prefers-reduced-motion: no-preference) {
  .space-twinkle-1 { animation: space-twinkle 4s ease-in-out infinite alternate; }
  .space-twinkle-2 { animation: space-twinkle 6s ease-in-out 2s infinite alternate; }
  .start-scene .explorer-drawing { animation: start-float 5s ease-in-out infinite alternate; }
  .story-picture { animation: story-fade 400ms ease-out; }
  .story-signal-waves path { animation: story-signal 1.5s ease-in-out infinite alternate; }
  .story-signal-waves path:nth-child(2) { animation-delay: 0.5s; }
  .story-signal-waves path:nth-child(3) { animation-delay: 1s; }

  @keyframes space-twinkle { to { opacity: 0.25; } }
  @keyframes start-float { from { transform: translateY(6px); } to { transform: translateY(-6px); } }
  @keyframes story-fade { from { opacity: 0; } }
  @keyframes story-signal { to { opacity: 0.25; } }
}
