/* Light only on purpose: the cream paper and brass plate are the identity (see DESIGN.md). */
:root {
  --paper: #f1e9d6;
  --plate: #e8dcc0;
  --face: #f8f2e4;
  --ink: #2b2118;
  --ink-2: #5a4630;
  --brass: #8a6420; /* borders and graphics only: 4.43:1 on paper is too low for text */
  --signal: #a3361f; /* the one accent: the main action button */
  --rule: #cdb98d;
  --display: 'IM Fell English', Georgia, serif;
  /* In-game glass: one smoked tint, one brass hairline (it ties every panel to the brass speedometer),
     two corner sizes and two curves, so every HUD piece, pop-up and button over the scene matches. */
  --glass: rgba(28, 22, 36, 0.62);
  --glass-strong: rgba(28, 22, 36, 0.8);
  --glass-edge: rgba(232, 200, 120, 0.5);
  --glass-blur: blur(8px);
  --r-panel: 14px;
  --r-control: 10px;
  --spring: cubic-bezier(0.3, 1.4, 0.5, 1); /* a small overshoot, like an iOS spring */
  --settle: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.55 'Source Serif 4', Georgia, serif;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 16px 56px; }

h1, h2 { font-family: var(--display); font-weight: 400; }

header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 4px double var(--brass);
}

h1 { margin: 0; font-style: italic; font-size: clamp(2.4rem, 6vw, 3.4rem); line-height: 1; }
.tagline { margin: 6px 0 0; color: var(--ink-2); }

.plates { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.plates button {
  min-width: 48px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--brass);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font: 1.15rem var(--display);
  cursor: pointer;
}
.plates button:hover { background: var(--face); }
.plates button[aria-current='step'] { background: var(--ink); border-color: var(--ink); color: var(--face); }
.plates .done { margin-left: 4px; font-family: 'Source Serif 4', Georgia, serif; font-size: 0.95rem; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 40px;
  margin-top: 28px;
}

.plate-no { margin: 0; color: var(--ink-2); font-family: var(--display); font-size: 1.15rem; }
.plate-title { margin: 0; font-size: clamp(1.9rem, 4vw, 2.4rem); line-height: 1.1; }
.order { margin: 10px 0 18px; font-size: 1.12rem; max-width: 60ch; }
.order-label { font-weight: 600; }

.board { padding: 8px; background: var(--plate); border: 1px solid var(--brass); border-radius: 4px; }
#board { display: block; width: 100%; height: auto; font-family: 'Source Serif 4', Georgia, serif; }

/* Board pieces */
.label { font-size: 18px; fill: var(--ink); text-anchor: middle; }
.state { font-size: 16px; fill: var(--ink-2); text-anchor: middle; font-style: italic; }
.face { fill: var(--face); stroke: var(--brass); stroke-width: 3; }
.ring { fill: none; stroke: none; stroke-width: 3; }
#board [tabindex]:focus { outline: none; } /* replaced by the .ring outline below */
#board [tabindex]:focus-visible .ring { stroke: var(--ink); }
.boiler, .slot { cursor: pointer; }
.boiler:hover .face, .slot:hover .body { stroke: var(--ink); }

/* Track: sleepers under two rails. The gap between the rails fills in when the line is clear. */
.sleepers { fill: none; stroke: var(--rule); stroke-width: 20; stroke-dasharray: 3 7; }
.tube { fill: none; stroke: var(--brass); stroke-width: 11; stroke-linejoin: round; }
.bore { fill: none; stroke: var(--plate); stroke-width: 6; stroke-linejoin: round; }
.flow { fill: none; stroke: var(--face); stroke-width: 3; stroke-dasharray: 6 10; opacity: 0; }
.pipe.hot .bore { stroke: var(--brass); }
.pipe.hot .flow { opacity: 1; animation: flow 0.8s linear infinite; } /* moving dashes show which way the signal travels */
@keyframes flow { to { stroke-dashoffset: -16; } }

.window { fill: var(--plate); stroke: var(--brass); stroke-width: 1.5; }
/* Engine: cream body with brass trim, ink for the iron parts (smokebox, chimney, roof, cowcatcher). */
.loco { fill: var(--face); stroke: var(--brass); stroke-width: 2; stroke-linejoin: round; }
.iron { fill: var(--ink); }
.band { stroke: var(--brass); stroke-width: 1.5; }
.wheel { fill: var(--face); stroke: var(--ink); stroke-width: 2.5; }
.spoke { stroke: var(--ink); stroke-width: 1; }
.rod-bar { stroke: var(--brass); stroke-width: 3; stroke-linecap: round; }
.boiler:hover .loco { stroke: var(--ink); }
.frame { fill: var(--brass); }
/* Smoke only shows on a ready engine; its rise repeats only while the engine stays ready. */
.puff { fill: var(--face); stroke: var(--brass); stroke-width: 2; opacity: 0; transform-box: fill-box; transform-origin: center; }
.boiler.hot .puff, .piston.fired .puff { opacity: 1; animation: puff 1.6s ease-out infinite; }
.boiler.hot .puff + .puff, .piston.fired .puff + .puff { animation-delay: 0.4s; }
@keyframes puff { from { transform: translateY(5px) scale(0.7); } to { transform: translateY(-3px) scale(1); } }

.slot .body { fill: var(--plate); stroke: var(--brass); stroke-width: 2.5; stroke-dasharray: 6 5; }
.slot.filled .body { fill: var(--face); stroke-width: 3; stroke-dasharray: none; }
.slot .name { font-size: 18px; font-weight: 600; fill: var(--ink); text-anchor: middle; }
.slot:not(.filled) .name { font-weight: 400; font-style: italic; fill: var(--ink-2); font-size: 15px; }
.slot.target .body { stroke: var(--ink); stroke-dasharray: none; }
.roof { fill: none; stroke: var(--brass); stroke-width: 2.5; stroke-dasharray: 6 5; stroke-linejoin: round; }
.slot.filled .roof { fill: var(--brass); stroke-dasharray: none; }
.slot.target .roof { stroke: var(--ink); stroke-dasharray: none; }

.rod { transition: transform 0.6s cubic-bezier(0.5, 0, 0.2, 1); }
.piston.fired .rod { transform: translateX(40px); }

/* Drawer and buttons */
.drawer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.drawer-label { font-weight: 600; }
.parts { display: flex; flex-wrap: wrap; gap: 8px; }

button { font: inherit; color: inherit; }
.part, .quiet {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--brass);
  border-radius: 2px;
  background: var(--face);
  cursor: pointer;
}
.part { font-weight: 600; cursor: grab; }
.quiet { background: transparent; }
.part:hover, .quiet:hover { border-color: var(--ink); }
.part[aria-pressed='true'] { background: var(--ink); border-color: var(--ink); color: var(--face); }

.run {
  margin-left: auto;
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 2px;
  background: var(--signal);
  color: var(--face);
  font-weight: 600;
  cursor: pointer;
}
.run:hover { background: #8c2d19; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.status { min-height: 1.55em; margin: 12px 0 0; color: var(--ink); }

.howto { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--rule); }
.howto summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.howto ol { margin: 4px 0 0; padding-left: 1.3em; max-width: 62ch; }
.howto li + li { margin-top: 4px; }

/* Ledger and lesson */
aside h2 { margin: 0 0 4px; font-size: 1.6rem; }
.hint { margin: 0 0 10px; color: var(--ink-2); font-size: 0.95rem; }

#ledger { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin-top: 4px; }
#ledger th, #ledger td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--rule); }
#ledger th { font-weight: 600; border-bottom: 2px solid var(--brass); }
#ledger tr.testing td { background: var(--plate); }
#ledger tr.wrong td { font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
#ledger-note { margin-top: 10px; }

#verdict:empty { display: none; }
#verdict { margin-top: 16px; padding: 16px; background: var(--face); border: 1px solid var(--brass); border-radius: 4px; }
#verdict p { margin: 0 0 12px; }
#verdict p:last-child { margin-bottom: 0; }
#verdict strong { font-family: var(--display); font-weight: 400; font-size: 1.4rem; display: block; }

.lesson { margin-top: 32px; padding-top: 16px; border-top: 4px double var(--brass); }
.lesson p { margin: 0; }

@media (max-width: 880px) {
  main { grid-template-columns: minmax(0, 1fr); gap: 32px; }
}
@media (max-width: 520px) {
  .run { margin-left: 0; width: 100%; }
  .drawer-label { width: 100%; }
}
/* The board scales down on phones; bigger SVG text keeps labels near 14px on screen. */
@media (max-width: 560px) {
  .label, .slot .name { font-size: 25px; }
  .state, .slot:not(.filled) .name { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .rod { transition: none; }
  .pipe.hot .flow, .puff { animation: none !important; }
}

/* ---- Screens -------------------------------------------------------------- */
[hidden] { display: none !important; }
h3 { font-family: var(--display); font-weight: 400; font-size: 1.4rem; margin: 0 0 4px; }
.menu-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.menu-actions .run { margin-left: 0; }
.back { margin-bottom: 12px; }

/* Main menu */
.menu-head { display: block; }
.menu-head .tagline { max-width: 46ch; font-size: 1.1rem; }
.menu-main h2 { margin: 0 0 8px; font-size: 1.8rem; }
.difficulty { border: 0; margin: 0; padding: 0; }
.difficulty legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.mode {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 12px;
  align-items: baseline;
  margin-bottom: 10px;
  padding: 12px 14px;
  border: 1px solid var(--brass);
  border-radius: 4px;
  background: var(--face);
  cursor: pointer;
}
.mode:hover { border-color: var(--ink); }
.mode:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.mode input { grid-row: span 3; width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }
.mode-name { font-family: var(--display); font-size: 1.45rem; line-height: 1.2; }
.mode-text, .mode-best { grid-column: 2; }
.mode-best { color: var(--ink-2); font-size: 0.95rem; }
.chain { margin-top: 0; }
.board-list { margin: 8px 0 0; padding-left: 1.4em; font-variant-numeric: tabular-nums; }
.board-list li + li { margin-top: 4px; }
a { color: var(--ink); text-underline-offset: 3px; }

/* ---- The run ------------------------------------------------------------- */
.drive { position: fixed; inset: 0; overflow: hidden; background: var(--paper); }
#view { display: block; width: 100%; height: 100%; touch-action: none; }
#view:focus { outline: none; } /* the canvas only takes focus so key presses land on the game */
.hud {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}
.hud-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.gauge-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--ink-2); }
.hud-button { pointer-events: auto; }
.callout {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 6px 18px;
  text-align: center;
  font-family: var(--display);
  font-size: clamp(1.4rem, 4vw, 2.3rem);
  pointer-events: none;
}
.callout:empty { display: none; }
.steer {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.steer button {
  width: 76px;
  height: 76px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent; /* no grey flash on phones */
  font-size: 1.8rem;
  cursor: pointer;
}
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
.panel { max-width: 420px; padding: 24px; }
.panel h2 { margin: 0; font-size: 2rem; }

/* ---- Dialogs ------------------------------------------------------------- */
dialog {
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--brass);
  border-radius: 4px;
  padding: 18px 20px;
}
dialog::backdrop { background: rgba(43, 33, 24, 0.6); }
.repair { width: min(1120px, calc(100% - 16px)); max-height: calc(100% - 16px); }
.repair #workshop { margin-top: 8px; }
.repair-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 8px 24px; }
.repair-head h2 { margin: 0; font-size: 2rem; }
.repair-head p { margin: 0; max-width: 56ch; }
.timer { font-family: var(--display); font-size: 2rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.timebar { display: block; height: 10px; margin: 10px 0 4px; overflow: hidden; background: rgba(248, 242, 228, 0.18); border: 1px solid var(--glass-edge); border-radius: var(--r-control); }
.timebar span { display: block; height: 100%; background: var(--face); border-radius: inherit; }
.over { width: min(420px, calc(100% - 32px)); }
.over h2 { margin: 0 0 8px; font-size: 2rem; }

/* ---- Question categories, briefing, coding faults ------------------------- */
.category { margin-top: 18px; }
.brief h1 { margin: 0; font-style: italic; font-size: clamp(2.2rem, 6vw, 3.2rem); line-height: 1.1; }
.brief .tagline { margin: 8px 0 20px; font-size: 1.1rem; }
.brief h2 { margin: 0 0 10px; font-size: 1.6rem; }
.brief-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 32px; padding: 18px 0; border-top: 4px double var(--brass); }
.keys { margin: 0; }
.keys div { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.keys dt { font-weight: 600; }
.keys dd { margin: 0; }
kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 1px 6px;
  text-align: center;
  font: 600 0.95rem 'Source Serif 4', Georgia, serif;
  background: var(--face);
  border: 1px solid var(--brass);
  border-bottom-width: 3px;
  border-radius: 3px;
}
.rules { margin: 0; padding-left: 1.2em; }
.rules li + li { margin-top: 8px; }
@media (max-width: 760px) {
  .brief-grid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .keys div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}

.quiz { margin-top: 14px; }
.quiz h3 { margin-bottom: 8px; }
.quiz pre {
  margin: 0 0 14px;
  padding: 14px 16px;
  overflow-x: auto;
  background: var(--ink);
  color: var(--face);
  border-radius: 4px;
  font: 1rem/1.5 ui-monospace, Consolas, 'Courier New', monospace; /* code reads best in a fixed-width face */
}
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.choice {
  min-height: 52px;
  padding: 8px 14px;
  text-align: left;
  font: 1rem ui-monospace, Consolas, 'Courier New', monospace;
  background: var(--face);
  border: 1px solid var(--brass);
  border-radius: 3px;
  cursor: pointer;
}
.choice:hover { border-color: var(--ink); }
.choice.wrong { text-decoration: line-through; color: var(--ink-2); background: var(--plate); cursor: default; }
.choice.wrong::after { content: '  ✗'; }
.choice.right { background: var(--ink); color: var(--face); border-color: var(--ink); }
.choice.right::after { content: '  ✓'; }
.quiz-note { min-height: 1.55em; margin: 12px 0 0; }
@media (max-width: 520px) {
  .choices { grid-template-columns: minmax(0, 1fr); }
  .quiz pre { padding: 12px; font-size: 0.85rem; }
}

/* ---- Run notices ------------------------------------------------------------ */
/* The countdown sits in a brass-ringed glass dial, like the speedometer. */
.callout.count { display: grid; place-items: center; width: 1.6em; height: 1.6em; padding: 0; font-size: clamp(3.5rem, 12vw, 6.5rem); line-height: 1; border: 3px solid #c9a04a; border-radius: 50%; }
.notice { font-weight: 600; align-self: center; }
.turn-sign {
  position: absolute;
  top: 46%;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 14px 8px;
  font-weight: 600;
  pointer-events: none;
}
.turn-sign svg { width: 52px; height: 52px; fill: none; stroke: var(--face); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.turn-sign[data-dir='right'] svg { transform: scaleX(-1); }
.over { text-align: center; }
.over h2 { font-size: 2.6rem; }
.over-distance { margin: 0 0 4px; font-family: var(--display); font-size: 2.4rem; font-variant-numeric: tabular-nums; }
.over-distance .gauge-label { font-family: 'Source Serif 4', Georgia, serif; font-size: 0.9rem; }
.over .menu-actions { justify-content: center; }
/* On narrow screens the centre message can wrap into the sign's spot, so the sign sits above the right steering button. */
@media (max-width: 600px) {
  .turn-sign { top: auto; bottom: 106px; right: 12px; padding: 6px 10px 5px; font-size: 0.9rem; }
  .turn-sign svg { width: 40px; height: 40px; }
}

/* Dashboard at the top left: the brass speedometer, speed in glass below it, distance in glass beside it.
   The glass is a dark smoked tint, so light text reads over both the dark sky and the bright clouds. */
.dash { align-items: flex-start; gap: 10px; }
.speedo { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.speedo svg { width: 144px; height: 144px; display: block; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35)); }
.dash-side { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.glass {
  margin: 0;
  padding: 5px 12px;
  border-radius: var(--r-control);
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  text-align: center;
  min-width: 7.5em;
}
.glass .gauge-label { color: var(--face); }
@media (max-width: 600px) {
  .speedo svg { width: 108px; height: 108px; }
  .glass { min-width: 6.5em; padding: 4px 10px; }
}

/* Everything over the moving scene is the same glass: dashboard panels, messages, the bend sign, the
   countdown dial, the Pause and steering buttons, the pause menu, the repair pop-up and the loss screen.
   Light text passes 4.5:1 on this tint over every part of the scene, by day and by night. */
.glass, .callout, .turn-sign, .over, .panel, .repair, .hud-button, .steer button {
  color: var(--face);
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}
.callout, .turn-sign, .over, .panel, .repair { border-radius: var(--r-panel); }
.hud-button, .steer button { border-radius: var(--r-control); }
.over::backdrop, .repair::backdrop { background: rgba(20, 16, 28, 0.3); }
.overlay { background: rgba(20, 16, 28, 0.3); }
.over .gauge-label { color: var(--face); }
.over .quiet, .panel .quiet { color: var(--face); background: transparent; border-color: rgba(248, 242, 228, 0.55); }
.over .quiet:hover, .panel .quiet:hover, .hud-button:hover { border-color: var(--face); background: var(--glass-strong); }
/* The ink focus ring would vanish on dark glass, so these use a light one. */
.over :focus-visible, .panel :focus-visible, .hud-button:focus-visible { outline-color: var(--face); }
/* The repair pop-up: its header is glass like the rest; the puzzle itself sits on a paper card, because
   the circuit board and code snippets are drawn for ink on paper. */
.repair #repair-slot { margin-top: 12px; padding: 14px 16px; color: var(--ink); background: var(--paper); border-radius: var(--r-control); }
.repair #repair-slot:empty { display: none; }
/* On phones the pause menu and loss screen rise from the bottom as sheets, where thumbs reach the buttons. */
@media (max-width: 600px) {
  .overlay { align-items: flex-end; padding: 0; }
  .panel { max-width: none; width: 100%; border-radius: var(--r-panel) var(--r-panel) 0 0; border-bottom: 0; }
  .over { width: 100%; max-width: none; margin: auto 0 0; border-radius: var(--r-panel) var(--r-panel) 0 0; border-bottom: 0; }
}
/* The pause menu reads like the loss screen: everything centred. */
.panel { text-align: center; }
.panel .menu-actions { justify-content: center; }

/* ---- Leaderboards ----------------------------------------------------------- */
.menu-side { display: flex; flex-direction: column; gap: 28px; }
.menu-side .chain { padding-top: 16px; border-top: 4px double var(--brass); }
.topfive .board-list li { display: flex; justify-content: space-between; gap: 16px; max-width: 340px; padding: 6px 0; border-bottom: 1px solid var(--rule); }
.topfive .who { font-weight: 600; overflow-wrap: anywhere; }
.topfive .far { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Name entry on the glass loss screen */
.score-form { margin: 14px 0 4px; }
.score-form label { display: block; margin-bottom: 8px; font-weight: 600; }
.score-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.score-row input {
  min-height: 44px;
  width: 12em;
  max-width: 100%;
  padding: 0 12px;
  font: inherit;
  color: var(--face);
  background: rgba(10, 8, 16, 0.35); /* darker than the glass, so the typed text and placeholder stay above 4.5:1 */
  border: 1px solid rgba(248, 242, 228, 0.55);
  border-radius: 3px;
}
.score-row input::placeholder { color: rgba(248, 242, 228, 0.8); }
.score-row input[aria-invalid='true'] { border-color: #ffe08a; }
.score-error { min-height: 1.4em; margin: 6px 0 0; color: #ffe08a; font-size: 0.95rem; } /* pale amber: 4.6:1 even with the sun behind the glass */
.score-note { min-height: 0; margin: 8px 0 0; }
.score-note:empty { display: none; }

/* Obstacle legend in the briefing */
.legend { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.legend li { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 10px; align-items: center; margin: 0; }
.legend svg { width: 40px; height: 40px; }

/* ---- Live scene behind the screens ------------------------------------------ */
.scene { position: fixed; inset: 0; z-index: 0; }
.screen { position: relative; z-index: 1; }
/* The run's HUD layer must stay full-screen; the generic .screen rule above would collapse it to zero height. */
.screen.drive { position: fixed; inset: 0; background: transparent; }
/* Menu and briefing are the same smoked glass as the in-game panels, over the demo run. The tint is a
   little denser (they hold long text) so light text passes 4.5:1 even over the sun: 6.8:1 for body text,
   5.1:1 for the softer hints. Inside, the ink tokens flip to light so every rule that uses them follows. */
#menu, #briefing { min-height: 100vh; padding: 28px 16px; }
#menu > .wrap, #briefing > .wrap {
  --ink: #f8f2e4;
  --ink-2: #ddd3bf;
  --brass: rgba(232, 200, 120, 0.6);
  --rule: rgba(232, 200, 120, 0.3);
  padding: 28px 32px;
  color: var(--face);
  background: rgba(28, 22, 36, 0.74);
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 24px 60px rgba(14, 10, 24, 0.5); /* lifts the panel off the moving scene */
}
#menu .mode { background: rgba(0, 0, 0, 0.18); border-radius: var(--r-control); }
#menu .mode:has(input:checked) { background: rgba(0, 0, 0, 0.32); }
#menu .quiet, #briefing .quiet { border-radius: var(--r-control); }
#menu .quiet:hover, #briefing .quiet:hover { background: rgba(0, 0, 0, 0.25); }
#menu .run, #briefing .run { border-radius: var(--r-control); }
#briefing kbd { color: var(--face); background: rgba(0, 0, 0, 0.3); }
.mute { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; margin-top: 12px; font-weight: 600; cursor: pointer; }
.mute input { width: 20px; height: 20px; margin: 0; accent-color: var(--signal); }
#practice { min-height: 100vh; background: var(--paper); } /* practice needs a calm, plain page */
.practice-mode { display: flex; gap: 6px; margin-top: 14px; }
.practice-level { margin: 0 0 8px; }
.practice-mode [aria-pressed='true'] { background: var(--ink); border-color: var(--ink); color: var(--face); }
.coding-practice { padding-top: 18px; max-width: 760px; }
.coding-practice .run { margin: 12px 0 0; }
@media (max-width: 600px) {
  #menu, #briefing { padding: 12px 10px; }
  #menu > .wrap, #briefing > .wrap { padding: 20px 16px; }
}

/* ---- Feedback on every button ----------------------------------------------- */
button { transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease; }
.run:hover { box-shadow: 0 3px 0 rgba(43, 33, 24, 0.35); transform: translateY(-1px); }
button:active { transform: translateY(1px) scale(0.98); box-shadow: none; }
.mode { transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease; }
.mode:hover { transform: translateY(-1px); }

/* Repair clock: amber, then red as time runs out. */
.timebar span { transition: width 0.1s linear, background-color 0.3s ease; }
.timebar.low span { background: #c98a1b; }
.timebar.critical span { background: var(--signal); }

/* ---- Motion with a job; all of it is off for people who ask for reduced motion -- */
@media (prefers-reduced-motion: no-preference) {
  /* Where you landed: panels rise in, pop-ups scale in. */
  #menu:not([hidden]) > .wrap, #briefing:not([hidden]) > .wrap { animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
  .topfive li, .board-list li { animation: rise 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
  .topfive li:nth-child(2) { animation-delay: 0.05s; }
  .topfive li:nth-child(3) { animation-delay: 0.1s; }
  .topfive li:nth-child(4) { animation-delay: 0.15s; }
  .topfive li:nth-child(5) { animation-delay: 0.2s; }
  dialog[open], .overlay:not([hidden]) .panel { animation: pop 0.35s var(--spring) both; }

  /* The HUD settles in piece by piece each time a run starts: dial, readouts, then the controls. */
  #drive:not([hidden]) .speedo { animation: drop 0.5s var(--spring) both; }
  #drive:not([hidden]) .dash-side > .glass { animation: drop 0.5s var(--spring) 0.08s both; }
  #drive:not([hidden]) .hud-button { animation: drop 0.5s var(--spring) 0.16s both; }
  #drive:not([hidden]) .steer button { animation: rise 0.5s var(--spring) 0.24s both; }
  dialog[open]::backdrop, .overlay:not([hidden]) { animation: fade 0.3s ease both; }

  /* What to react to: messages and countdown numbers pop, the bend sign slides in. */
  .callout.pop { animation: callout 0.4s var(--spring) both; }
  .callout.count.pop { animation-duration: 0.5s; }
  .turn-sign:not([hidden]) { animation: slide 0.4s var(--spring) both; }
  .notice:not([hidden]) { animation: drop 0.4s var(--spring) both, alert 0.5s ease-in-out 0.4s 3; } /* three flashes, then it holds still */
  .timebar.critical span { animation: alert-bar 0.6s ease-in-out infinite alternate; } /* only in the last 15% of the clock */

  /* Answer feedback in coding faults. */
  .choice.wrong { animation: shake 0.35s ease; }
  .choice.right { animation: pop 0.3s var(--spring); }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 600px) {
  .over[open], .overlay:not([hidden]) .panel { animation: sheet 0.45s var(--settle) both; }
}
@keyframes drop { from { opacity: 0; transform: translateY(-14px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes sheet { from { transform: translateY(100%); } to { transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } }
@keyframes callout { from { opacity: 0; transform: translateX(-50%) scale(0.7); } to { opacity: 1; transform: translateX(-50%) scale(1); } }
@keyframes slide { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes alert { 50% { background: var(--signal); border-color: var(--signal); } }
@keyframes alert-bar { to { opacity: 0.55; } }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(2px); } }

/* Circuit board: boat engines (inputs) and the steamboat at its dock (output) */
.steam-pipe { stroke: #b8642f; stroke-width: 3; stroke-linecap: round; }
.water { fill: #7fa9c6; }
.water-line { fill: none; stroke: #f4fbff; stroke-width: 1.5; }
.paddle { fill: #7a2418; stroke: var(--brass); stroke-width: 2; }
.paddle-spoke { stroke: #d9a45a; stroke-width: 1.4; }
.flywheel { transform-box: fill-box; transform-origin: center; }
@media (prefers-reduced-motion: no-preference) {
  .boiler.hot .flywheel { animation: spin 1.4s linear infinite; } /* a running engine visibly turns */
}
@keyframes spin { to { transform: rotate(360deg); } }
