:root {
  --blue: #1b45b4;
  --blue-deep: #12318a;
  --blue-ink: #0b1f5c;
  --red: #e0283a;
  --red-deep: #a8162a;
  --yellow: #ffc61a;
  --yellow-deep: #d99a00;
  --table: #f3f5fb;
  --paper: #ffffff;
  --ink: #101a3d;
  --ink-soft: #3d4770;
  --on-blue: #ffffff;
  --on-blue-soft: #d6e0ff;
  --hole: #e8edfa;
  --field: #1747c4;
  --cell: clamp(2.4rem, 6.2vw, 4.1rem);
  --gap: calc(var(--cell) * 0.16);
  --display: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible Next", "Segoe UI", system-ui, sans-serif;
  --mono: "Martian Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--table);
}
::selection { background: var(--yellow); color: var(--blue-ink); }
img { max-width: 100%; height: auto; display: block; }
a { color: inherit; text-underline-offset: 0.2em; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; border-radius: 6px; }

.skip { position: absolute; left: -999px; top: 0; background: var(--yellow); color: var(--blue-ink); padding: 0.6rem 1rem; z-index: 10; font-weight: 700; }
.skip:focus { left: 1rem; top: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* top bar sits on the blue field */
.top {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  background: var(--field); color: var(--on-blue);
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.mark { display: inline-flex; gap: 3px; }
.mark i { width: 0.85rem; height: 0.85rem; border-radius: 50%; background: var(--red); display: block; }
.mark i + i { background: var(--yellow); }
.top-name { font-family: var(--display); font-weight: 800; font-size: 1.15rem; letter-spacing: 0.01em; }
.top { position: relative; z-index: 8; }
.top nav { margin-left: auto; font-weight: 600; font-size: 0.95rem; }
.top nav ol { list-style: none; margin: 0; padding: 0; display: flex; gap: clamp(0.75rem, 2.4vw, 1.75rem); }
.top nav li.more { display: none; }
.top nav a { text-decoration: none; color: var(--on-blue-soft); }
.top nav a:hover { color: var(--on-blue); text-decoration: underline; }
.menu-btn {
  display: none; margin-left: auto; min-height: 2.6rem; padding: 0 1.1rem; border-radius: 999px; cursor: pointer;
  font: inherit; font-weight: 800; font-family: var(--display); color: var(--on-blue);
  background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.5);
}
.menu-btn:hover { background: rgba(255, 255, 255, 0.2); }
/* Back to top: a yellow token with an arrow, on long scrolls. */
.to-top {
  position: fixed; z-index: 9; right: max(1rem, env(safe-area-inset-right)); bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  width: 3rem; height: 3rem; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #ffe27a, var(--yellow) 55%, var(--yellow-deep)); color: var(--blue-ink);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28), inset 0 -3px 0 var(--yellow-deep);
}
.to-top svg { width: 1.3rem; height: 1.3rem; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; }
.to-top[hidden] { display: none; }

/* hero: the whole region is board blue */
.hero {
  background: var(--field); color: var(--on-blue);
  padding: 1.9rem clamp(1rem, 4vw, 3rem) clamp(2rem, 5vw, 3.5rem);
}
.hero-copy { grid-area: copy; }
.hero h1 {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(2.2rem, 3.4vw, 3.1rem); line-height: 0.98;
  letter-spacing: -0.02em; margin: 0 0 0.6rem; text-wrap: balance;
}
.lede { font-size: clamp(1.05rem, 1.4vw, 1.15rem); color: var(--on-blue-soft); max-width: 36rem; margin: 0 0 0.75rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 3rem; padding: 0 1.4rem; border-radius: 999px;
  font-family: var(--display); font-weight: 800; font-size: 1.1rem;
  text-decoration: none; border: 2px solid transparent; cursor: pointer;
  transition: transform 160ms var(--ease), background-color 160ms var(--ease);
}
.btn:active { transform: translateY(2px); }
.btn-yellow { background: var(--yellow); color: var(--blue-ink); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28), inset 0 -3px 0 var(--yellow-deep); }
.btn-yellow:hover { background: #ffd34d; }
.btn-blue { background: var(--blue); color: var(--on-blue); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18), inset 0 -3px 0 var(--blue-deep); }
.btn-ghost-dark { color: var(--blue-ink); border-color: var(--blue); }
.fineprint { margin: 0; font-size: 0.92rem; color: var(--on-blue-soft); max-width: 34rem; }

/* the rig: the game on the left, what the robot is doing on the right */
.rig {
  max-width: 82rem; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto 1fr;
  grid-template-areas: "play copy" "play panel"; gap: 0.9rem clamp(1.25rem, 3vw, 2.5rem); align-items: start;
}
.rig-play { --rig-gap: 0.55rem; grid-area: play; position: relative; display: grid; gap: var(--rig-gap); justify-items: center; }
.rig-panel { grid-area: panel; display: grid; gap: 0.8rem; min-width: 0; }
/* settings and controls in one row under the board */
.setting { display: inline-flex; align-items: center; gap: 0.3rem; }
/* a small round "i" beside each setting opens a short note about it */
.info {
  appearance: none; flex: none; width: 1.35rem; height: 1.35rem; padding: 0; border-radius: 50%; cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.45); background: transparent; color: var(--on-blue-soft);
  display: grid; place-items: center;
}
.info svg { width: 0.85rem; height: 0.85rem; fill: currentColor; }
.info:hover, .info:focus-visible { border-color: var(--yellow); color: var(--yellow); }
.info:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.info-pop {
  width: min(21rem, calc(100vw - 2rem)); margin: 0; padding: 0.9rem 1rem 1rem; border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3); background: var(--blue-ink); color: var(--on-blue-soft);
  font-size: 0.86rem; line-height: 1.45; box-shadow: 0 16px 34px rgba(0, 0, 0, 0.45);
}
.info-pop:popover-open { display: grid; gap: 0.55rem; }
.info-title { font: 800 1.02rem var(--display); color: var(--on-blue); }
/* each option on its own row: the option in yellow, what it does beside it */
.info-rows {
  display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 0.8rem; padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}
.info-rows b { font-weight: 700; color: var(--yellow); }
.info-rows span { color: var(--on-blue); }
/* where the browser can anchor it, the note opens above its "i"; elsewhere it opens centred */
@supports (position-area: top) {
  .info-pop { position-area: top; position-try-fallbacks: flip-block; margin-bottom: 0.5rem; }
  .setting:nth-of-type(1) .info { anchor-name: --info-depth; }
  .setting:nth-of-type(2) .info { anchor-name: --info-speed; }
  .setting:nth-of-type(3) .info { anchor-name: --info-step; }
  #info-depth { position-anchor: --info-depth; }
  #info-speed { position-anchor: --info-speed; }
  #info-step { position-anchor: --info-step; }
  /* on a phone the note spans the screen above its "i", with a margin each side */
  @media (max-width: 600px) { .info-pop { position-area: top span-all; justify-self: center; } }
}
.dock { display: flex; flex-wrap: wrap; gap: 0.5rem 0.9rem; align-items: center; justify-content: center; font-size: 0.86rem; color: var(--on-blue-soft); }
.seg { border: 0; margin: 0; padding: 0; display: inline-flex; align-items: center; gap: 0.35rem; }
.seg legend { float: left; margin-right: 0.35rem; padding: 0; }
.seg label { display: inline-flex; align-items: center; gap: 0.35rem; min-height: 2.4rem; padding: 0 0.8rem; border-radius: 999px; border: 2px solid rgba(255,255,255,0.35); cursor: pointer; font-weight: 700; color: var(--on-blue); }
.seg label:has(:checked) { background: rgba(255,255,255,0.16); border-color: var(--on-blue); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(:focus-visible) { outline: 3px solid var(--yellow); outline-offset: 2px; }
.swatch { width: 1rem; height: 1rem; border-radius: 50%; }
.swatch.red { background: var(--red); }
.swatch.yellow { background: var(--yellow); }
.pick { display: inline-flex; align-items: center; gap: 0.45rem; }
.pick select {
  appearance: none; font: inherit; font-weight: 700; min-height: 2.4rem; padding: 0 2.2rem 0 0.95rem; cursor: pointer;
  border-radius: 999px; border: 2px solid rgba(255,255,255,0.35); color: var(--on-blue);
  background-color: var(--blue-deep);
  /* a chunky rounded chevron, drawn like the board's own round shapes */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 9'%3E%3Cpath d='M2 2l5 5 5-5' fill='none' stroke='%23ffc61a' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.85rem center; background-size: 0.8rem auto;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease);
}
.pick select:hover { border-color: rgba(255,255,255,0.7); background-color: #163a9e; }
.pick select:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.pick select option { background: var(--blue-ink); color: var(--on-blue); }
/* Where the browser lets the open list be styled (customizable select), it
   matches the closed pill: a deep-blue rounded panel, pill rows, and the chosen
   row in yellow like the robot's pick above the board. Elsewhere the list is
   the browser's own. */
@supports (appearance: base-select) {
  .pick select, .pick select::picker(select) { appearance: base-select; }
  .pick select { background-image: none; padding-right: 0.95rem; gap: 0.6rem; align-items: center; }
  .pick select::picker-icon {
    content: ""; width: 0.8rem; height: 0.55rem; align-self: center; transition: rotate 160ms var(--ease);
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 9'%3E%3Cpath d='M2 2l5 5 5-5' fill='none' stroke='%23ffc61a' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain;
  }
  .pick select:open::picker-icon { rotate: 180deg; }
  .pick select::picker(select) {
    margin-top: 0.4rem; padding: 0.35rem; border: 2px solid rgba(255,255,255,0.35); border-radius: 1.2rem;
    background: var(--blue-deep); color: var(--on-blue); box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4), inset 0 -3px 0 rgba(0, 0, 0, 0.25);
    transition: opacity 160ms var(--ease), translate 160ms var(--ease), overlay 160ms allow-discrete, display 160ms allow-discrete;
  }
  .pick select:not(:open)::picker(select) { opacity: 0; translate: 0 -0.3rem; }
  @starting-style { .pick select:open::picker(select) { opacity: 0; translate: 0 -0.3rem; } }
  .pick select option { padding: 0.55rem 0.95rem; border-radius: 999px; font-weight: 700; background: transparent; cursor: pointer; }
  .pick select option:hover, .pick select option:focus-visible { background: rgba(255, 255, 255, 0.12); outline: none; }
  .pick select option:checked { background: var(--yellow); color: var(--blue-ink); }
  .pick select option::checkmark { display: none; }
}
.seg label:hover { border-color: rgba(255,255,255,0.7); }

.board-wrap { position: relative; }
/* The dispenser, drawn on the board's own grid from the player's side: the
   storage, motor disk, and chute at the right over column 1, and the rail along
   the board with the carriage, a rod, inside it. At rest the rod waits out of
   the board past the storage end; for column N it slides over columns 1 to N-1,
   and the released token rolls to the first open hole. The parts at work stay
   bright while the others step back. */
.dispenser { display: grid; justify-items: center; gap: 0.35rem; margin-bottom: calc(-1 * var(--rig-gap)); } /* the rail sits on the board */
.mech { display: block; width: calc(var(--cell) * 7 + var(--gap) * 8); height: auto; overflow: visible; }
.mech .part { transition: opacity 0.25s var(--ease); }
.mech[data-phase="cover"] .part:not(.p-rod),
.mech[data-phase="hold"] .part:not(.p-rod),
.mech[data-phase="release"] .part:not(.p-store),
.mech[data-phase="roll"] .part:not(.p-rail):not(.p-chute),
.mech[data-phase="back"] .part:not(.p-rod) { opacity: 0.5; }
.mech .flat { fill: var(--token, var(--yellow)); stroke: rgba(0, 0, 0, 0.3); stroke-width: 2; }
.mx-labels { font-family: var(--body); font-size: 21px; fill: var(--on-blue-soft); }
.mx-labels path { stroke: rgba(214, 224, 255, 0.5); stroke-width: 2; }
/* the column numbers on the rail, over each column: the robot's own numbering, 1 under the chute */
.mx-nums { font: 700 28px var(--mono); fill: #59627f; text-anchor: middle; }
@media (max-width: 880px) { .mx-labels { display: none; } }

.scores-cap[hidden] { display: block; visibility: hidden; } /* keeps the board still when the scores appear */
.scores-cap { margin: 0; font-size: 0.8rem; color: var(--on-blue-soft); text-align: center; }
/* The board is drawn from the player's side: column 1, under the storage and
   chute, is at the right, so the board, its columns, and the scores run right
   to left. The camera's own picture (the Camera tab) stays as it sees it. */
.board, .cols, .scores { direction: rtl; }
.scores { display: grid; grid-template-columns: repeat(7, var(--cell)); gap: var(--gap); padding: 0 var(--gap); min-height: 1.5rem; }
.scores span { text-align: center; font-family: var(--mono); font-size: clamp(0.6rem, 1.6vw, 0.75rem); line-height: 1.5rem; border-radius: 999px; color: var(--on-blue-soft); background: rgba(11, 38, 114, 0.6); }
.scores span:empty { background: transparent; }
.scores .best { background: var(--yellow); color: var(--blue-ink); font-weight: 700; }

/* each column's hit area is one hole plus one gap wide, so its highlight centres on the holes */
.cols { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(7, 1fr); padding: 0 calc(var(--gap) / 2); z-index: 3; }
.col-btn { appearance: none; border: 0; background: transparent; cursor: pointer; padding: 0; border-radius: 999px; }
.col-btn:focus-visible { background: rgba(255, 198, 26, 0.18); }
@media (hover: hover) { .col-btn:hover:not(:disabled) { background: rgba(255, 198, 26, 0.18); } } /* a tap leaves no highlight behind */
.col-btn:disabled { cursor: not-allowed; }

.board {
  display: grid; grid-template-columns: repeat(7, var(--cell)); grid-template-rows: repeat(6, var(--cell));
  gap: var(--gap); padding: var(--gap);
  background: linear-gradient(160deg, #4a7ff5, #2e64ea 45%, #2556d6);
  outline: 3px solid rgba(255, 255, 255, 0.22); outline-offset: -3px;
  border-radius: calc(var(--cell) * 0.32);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35), inset 0 2px 0 rgba(255,255,255,0.25), inset 0 -6px 0 rgba(0,0,0,0.18);
  position: relative;
}
.cell { position: relative; border-radius: 50%; background: var(--hole); box-shadow: inset 0 5px 8px rgba(0,0,0,0.45); }
.token { position: absolute; inset: 7%; border-radius: 50%; }
.token.red, .falling.red { background: radial-gradient(circle at 35% 30%, #ff7483, var(--red) 55%, var(--red-deep)); }
.token.yellow, .falling.yellow { background: radial-gradient(circle at 35% 30%, #ffe27a, var(--yellow) 55%, var(--yellow-deep)); }
.falling { position: absolute; z-index: 4; border-radius: 50%; pointer-events: none; }
.cell.win .token { box-shadow: 0 0 0 4px var(--on-blue), 0 0 0 7px var(--yellow); animation: pulse 900ms ease-in-out 3; }
@keyframes pulse { 50% { transform: scale(0.9); } }
.result {
  position: absolute; inset: 0; z-index: 5; display: grid; place-content: center; justify-items: center; gap: 1rem;
  background: rgba(11, 31, 92, 0.72); border-radius: calc(var(--cell) * 0.32); text-align: center; padding: 1rem;
}
.result[hidden] { display: none; }
/* after a win, the four in a row pulses on its own before the result covers it */
.result[data-after-win] { animation: result-in 400ms var(--ease) 2.4s both; }
@keyframes result-in { from { opacity: 0; visibility: hidden; } }
.result p { margin: 0; font-family: var(--display); font-weight: 800; font-size: clamp(1.6rem, 4vw, 2.6rem); line-height: 1.05; max-width: 16ch; }
.confetti { position: absolute; z-index: 6; width: 0.9rem; height: 0.9rem; border-radius: 50%; pointer-events: none; }

.status { min-height: 2.7em; margin: 0; display: grid; place-items: center; text-align: center; max-width: 34rem; font-weight: 600; }
.btn-small {
  appearance: none; font: inherit; font-weight: 700; font-size: 0.92rem;
  min-height: 2.6rem; padding: 0 1rem; border-radius: 999px; cursor: pointer;
  color: var(--on-blue); background: rgba(255,255,255,0.12); border: 2px solid rgba(255,255,255,0.45);
}
.btn-small:hover { background: rgba(255,255,255,0.2); }
.btn-line { background: transparent; color: var(--on-blue); border-color: rgba(255, 255, 255, 0.6); }
.btn-line:hover { border-color: var(--on-blue); background: rgba(255, 255, 255, 0.1); }
.confirm { gap: 0.6rem; }
.confirm-text { color: var(--on-blue-soft); font-size: 0.95rem; }
.confirm-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; margin-top: 0.4rem; }
.btn-next { background: var(--yellow); border-color: var(--yellow); color: var(--blue-ink); }
.btn-next:hover { background: #ffd34d !important; }
.toggle { display: inline-flex; gap: 0.55rem; align-items: center; min-height: 2.4rem; font-size: 0.9rem; color: var(--on-blue-soft); cursor: pointer; }
/* A switch in the board's own parts: a recessed slot, an empty hole that slides into a yellow token. */
.toggle input {
  appearance: none; margin: 0; flex: none; position: relative; cursor: pointer;
  width: 2.9rem; height: 1.7rem; border-radius: 999px;
  background: rgba(5, 15, 51, 0.55); box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45), inset 0 0 0 2px rgba(255, 255, 255, 0.28);
  transition: background-color 220ms var(--ease), box-shadow 220ms var(--ease);
}
.toggle input::before {
  content: ""; position: absolute; top: 0.2rem; left: 0.2rem; width: 1.3rem; height: 1.3rem; border-radius: 999px;
  background: var(--hole); box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.35);
  transform-origin: left center;
  transition: transform 240ms var(--ease), background 220ms var(--ease);
}
.toggle input:checked { background: var(--blue-ink); box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35), inset 0 0 0 2px var(--yellow); }
.toggle input:checked::before {
  transform: translateX(1.2rem);
  background: radial-gradient(circle at 35% 30%, #ffe27a, var(--yellow) 55%, var(--yellow-deep));
  box-shadow: inset 0 -2px 0 var(--yellow-deep);
}
/* Pressed, the knob squashes toward its travel, as on iOS. */
.toggle input:active::before { transform: scaleX(1.22); }
.toggle input:checked::before { transform-origin: right center; }
.toggle input:checked:active::before { transform: translateX(1.2rem) scaleX(1.22); }
.toggle input:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.toggle:hover input:not(:checked) { box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45), inset 0 0 0 2px rgba(255, 255, 255, 0.5); }
.toggle:has(:checked) { color: var(--on-blue); }

/* the six steps of each move, grouped by the part that does them; the step
   in focus speaks in the caption under them */
.stepper { background: #0b2672; border-radius: 18px; padding: 2.1rem 1rem 0.9rem; }
.steps { counter-reset: step; list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stage { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; position: relative; text-align: center; }
.stage::before {
  content: attr(data-device); position: absolute; top: -1.45rem; left: 50%; translate: -50% 0; white-space: nowrap;
  font: 0.62rem var(--mono); text-transform: uppercase; letter-spacing: 0.04em; color: var(--on-blue-soft);
}
/* a part's label sits centred over all of its steps */
.stage[data-device="Brain"]:has(+ [data-device="Brain"])::before,
.stage[data-device="Arduino"]:has(+ [data-device="Arduino"])::before { left: 100%; }
.stage[data-device="Brain"] + [data-device="Brain"]::before,
.stage[data-device="Arduino"] + [data-device="Arduino"]::before { content: none; }
.stage:not(:last-child)::after {
  content: ""; position: absolute; top: 0.75rem; left: calc(50% + 0.95rem); right: calc(-50% + 0.95rem); height: 2px;
  background: rgba(214, 224, 255, 0.25);
}
.stage[data-state="pass"]::after { background: var(--yellow); }
.stage strong { font-size: 0.78rem; line-height: 1.15; max-width: 7.5em; color: var(--on-blue-soft); }
.stage[data-focus] strong { color: var(--on-blue); }
/* the step in focus: a short bar under its whole name, however many lines it takes */
.stage strong::after { content: ""; display: block; width: 1.6rem; height: 3px; margin: 0.35rem auto 0; border-radius: 2px; } /* every step keeps the room, so the bar never shifts */
.stage[data-focus] strong::after { background: var(--yellow); }
.stage[data-state="busy"] strong { color: var(--yellow); }
.stage-msg { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } /* read out, shown in the caption */
.stage-msg code, .focus-cap code { font-family: var(--mono); font-size: 0.76rem; }
.steps .lamp { width: 1.5rem; height: 1.5rem; margin: 0; display: grid; place-items: center; }
.steps .lamp::before { counter-increment: step; content: counter(step); font: 800 0.78rem var(--display); color: var(--on-blue-soft); }
.stage[data-state="pass"] .lamp::before, .stage[data-state="fail"] .lamp::before { color: var(--blue-ink); }
.focus-cap { margin: 0.8rem 0 0; padding: 0.6rem 0.9rem; min-height: 2.9em; border-radius: 12px; background: rgba(5, 15, 51, 0.55); font-size: 0.88rem; color: var(--on-blue-soft); }
.focus-cap b { color: var(--on-blue); }
/* a small lamp before the step's name, lit like the step lamps */
.focus-cap b::before { content: ""; display: inline-block; width: 0.6rem; height: 0.6rem; margin-right: 0.45rem; border-radius: 50%; background: var(--lamp, #34417a); vertical-align: 0.05em; }
.focus-cap[data-state="busy"] { --lamp: var(--on-blue-soft); }
.focus-cap[data-state="pass"] { --lamp: var(--yellow); }
.focus-cap[data-state="fail"] { --lamp: var(--red); }

/* one instrument window, switched to the part at work */
.instrument { background: #0b2672; border-radius: 18px; padding: 0.35rem 1rem 1rem; }
.tabs { display: flex; flex-wrap: wrap; gap: 0 0.4rem; border-bottom: 1px solid rgba(255, 255, 255, 0.14); margin-bottom: 0.75rem; }
.tabs button {
  appearance: none; background: transparent; border: 0; margin-bottom: -1px; padding: 0.6rem 0.5rem 0.5rem; position: relative;
  color: var(--on-blue-soft); font: 800 1.05rem var(--display); text-align: left; cursor: pointer;
}
.tabs button small { font: 600 0.74rem var(--body); margin-left: 0.3rem; }
.tabs button[aria-selected="true"] { color: var(--on-blue); box-shadow: inset 0 -3px 0 var(--yellow); }
.tabs button:hover { color: var(--on-blue); }
.tabs button:focus-visible { outline: 3px solid var(--yellow); outline-offset: -3px; }
.tabs button[data-live]::after { content: ""; position: absolute; top: 0.55rem; right: -0.1rem; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--yellow); animation: blink 900ms steps(2, start) 4; } /* blinks a few times, then stays lit */
.tabs #tab-boot { margin-left: auto; font-size: 0.9rem; }
.panels { display: grid; }
.tab-panel { grid-area: 1 / 1; display: grid; gap: 0.6rem; align-content: start; min-width: 0; }
.tab-panel[data-off] { visibility: hidden; }
#panel-boot { align-content: stretch; }
.serial.boot-log { height: auto; min-height: 9rem; }
.boot-log .ok { color: var(--yellow); }

/* while Python loads, the board's holes light one by one with the bytes received */
.board[data-boot] .cell { background: #2346ad; transition: background-color 300ms var(--ease); }
.board[data-boot] .cell.lit { background: var(--hole); }
.power {
  position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; justify-items: center; gap: 0.45rem;
  pointer-events: none; transition: opacity 400ms var(--ease); text-align: center;
}
.power[hidden] { display: grid; opacity: 0; }
.power p { margin: 0; }
.power-pill {
  display: inline-flex; align-items: center; gap: 0.6rem; padding: 0.55rem 1.1rem; border-radius: 999px;
  background: #050f33; font: 700 1rem var(--mono); font-variant-numeric: tabular-nums; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.power-pill .lamp { margin: 0; background: var(--yellow); animation: blink 900ms steps(2, start) infinite; }
.power-step { padding: 0.3rem 0.8rem; border-radius: 999px; background: rgba(5, 15, 51, 0.85); font-size: 0.84rem; font-variant-numeric: tabular-nums; }
.token.queued { opacity: 0.7; animation: hover 1.4s ease-in-out infinite; }
@keyframes hover { 50% { transform: translateY(-10%); } }
.lamp { flex: none; width: 1.2rem; height: 1.2rem; margin-top: 0.12rem; border-radius: 50%; background: #34417a; box-shadow: inset 0 2px 3px rgba(0,0,0,0.4); }
.stage[data-state="pass"] .lamp { background: var(--yellow); box-shadow: inset 0 -2px 0 var(--yellow-deep); }
.stage[data-state="fail"] .lamp { background: var(--red); box-shadow: inset 0 -2px 0 var(--red-deep); }
.stage[data-state="busy"] .lamp { background: var(--on-blue-soft); animation: blink 900ms steps(2, start) infinite; }
.stage[data-state="busy"] strong { color: var(--yellow); }
@keyframes blink { 50% { opacity: 0.35; } }
.cam-views { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0.6rem; align-items: start; }
.cam-views figure { margin: 0; }
.cam-views canvas, .cam-img img { display: block; width: 100%; height: auto; border-radius: 8px; background: #071a52; }
.cam-img { aspect-ratio: 1; border-radius: 8px; background: #071a52; }
.cam-views figcaption { color: var(--on-blue-soft); font-size: 0.78rem; margin-top: 0.3rem; line-height: 1.3; }
.instrument .mini { padding: 5px; gap: 3px; background: var(--blue); }
.cam-note { margin: 0; font-size: 0.78rem; color: var(--on-blue-soft); }
.cam-views .mini { aspect-ratio: 1; align-content: center; } /* square, like the warped view beside it */
.ard-live { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 0.7rem; }
.serial {
  margin: 0; height: calc(4 * 1.35em + 1rem); overflow: auto; padding: 0 0.7rem; border-block: 0.5rem solid #050f33; border-radius: 8px;
  background: #050f33; color: #b9f3c8; font-family: var(--mono); font-size: 0.74rem; line-height: 1.35; white-space: pre-wrap;
  scrollbar-width: thin; scrollbar-color: #34417a transparent;
}
.serial .tx { color: var(--yellow); }
.pins { margin: 0; display: grid; gap: 0.45rem; align-content: start; font-size: 0.82rem; }
/* each motor's name and state on one line, wrapping only when narrow */
.pins div { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.1rem 0.6rem; }
.pins dt { color: var(--on-blue-soft); }
.pins dd { margin: 0; font-family: var(--mono); font-size: 0.78rem; display: flex; align-items: center; gap: 0.4rem; }
.gear { width: 1rem; height: 1rem; border-radius: 50%; border: 3px dotted var(--on-blue); transform: rotate(var(--turn, 0deg)); }
.traces { width: 100%; height: 152px; border-radius: 8px; background: #050f33; }

/* reading sections on the table */
section:not(.hero) {
  padding: var(--space-topic) clamp(1rem, 4vw, 3rem) 0; max-width: 76rem; margin: 0 auto;
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); column-gap: clamp(0.75rem, 2vw, 1.5rem);
}
section:not(.hero) > * { grid-column: 1 / -1; }
/* Space follows the content, the same model as our other project page: a
   change of topic gets a full pause, a section that continues the one before
   it a shorter one, and each gap is one padding, never two. Both grow with the
   screen's width and height, so a short laptop screen keeps less dead space. */
:root {
  --space-topic: clamp(48px, 3vw + 4vh, 96px);
  --space-related: clamp(32px, 2vw + 2vh, 56px);
  --space-head: clamp(16px, 1vw + 1.5vh, 32px);
}
.band > section { padding-bottom: var(--space-topic); } /* the dark band needs its own bottom edge */
main > section:last-child { padding-bottom: var(--space-topic); }
/* The board's hole row is the rule above every reading heading. */
section:not(.hero) > h2::before, .build-copy > h2::before, .watch-copy > h2::before {
  content: ""; display: block; width: min(15rem, 60%); aspect-ratio: 7 / 1; margin-bottom: 1rem;
  background: radial-gradient(circle, var(--rule-hole, #c9d3ee) 36%, transparent 39%) 0 0 / calc(100% / 7) 100% repeat-x;
}
.band section > h2::before { --rule-hole: rgba(255, 255, 255, 0.3); }
h2 { font-family: var(--display); font-weight: 800; font-size: clamp(2rem, 4.2vw, 3.2rem); line-height: 1.05; letter-spacing: -0.015em; margin: 0 0 1.25rem; color: var(--blue-ink); text-wrap: balance; }
h3 { font-family: var(--display); font-weight: 800; font-size: 1.5rem; line-height: 1.15; margin: 0 0 0.5rem; color: var(--blue-ink); }
p { max-width: 68ch; }
.section-lede { color: var(--ink-soft); margin: -0.5rem 0 var(--space-head); }

.band { background: var(--blue-ink); color: var(--on-blue); }
.band h2, .band h3 { color: var(--on-blue); }
.band figcaption, .band p { color: var(--on-blue-soft); }
.how-grid { display: grid; grid-template-columns: subgrid; row-gap: 1.25rem; margin-bottom: 2.5rem; }
.how-step { grid-column: span 3; }
.how-step + .how-step { grid-column: 5 / span 3; }
.how-step h3::before { content: ""; display: inline-block; width: 0.85em; height: 0.85em; margin-right: 0.45em; border-radius: 50%; background: var(--yellow); vertical-align: -0.05em; }
.how-step + .how-step h3::before { background: var(--red); }
figcaption { font-size: 0.92rem; color: var(--ink-soft); margin-top: 0.6rem; }

/* Watch it play: the clip beside its text, about two thirds of the width, so
   the one piece of real footage stays the size of what it is. */
.watch { align-items: center; row-gap: 1rem; }
.watch > .watch-copy { grid-column: 1 / span 3; }
.watch > .watch-film { grid-column: 4 / span 4; }
.watch-copy p { color: var(--ink-soft); margin: 0; }
.watch-film { margin: 0; }
.watch-frame { position: relative; border-radius: 22px; overflow: hidden; background: var(--blue-ink); box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18); }
.watch-frame video { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; }
.watch-toggle {
  position: absolute; left: 1rem; bottom: 1rem; display: inline-flex; align-items: center; gap: 0.55rem;
  min-height: 2.75rem; padding: 0 1.15rem 0 0.95rem; border-radius: 999px; cursor: pointer;
  font-family: var(--display); font-weight: 800; font-size: 1rem; color: var(--on-blue);
  background: rgba(11, 31, 92, 0.82); border: 2px solid rgba(255, 255, 255, 0.55);
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease);
}
.watch-toggle:hover { background: var(--blue-ink); border-color: var(--on-blue); }
.watch-toggle:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
/* a play triangle, or two pause bars, in token yellow */
.watch-toggle::before { content: ""; width: 0.8rem; height: 0.9rem; background: var(--yellow); clip-path: polygon(0 0, 100% 50%, 0 100%); }
.watch-toggle[data-playing="true"]::before { clip-path: none; background: linear-gradient(90deg, var(--yellow) 0 34%, transparent 34% 66%, var(--yellow) 66%); }
.watch-film figcaption a { color: var(--blue); font-weight: 700; }

/* Diagrams and figures sit on light cards, readable without opening them. */
.loop, .states, .reads-fig { margin: 0; }
.loop img, .states img, .reads-fig img { display: block; width: 100%; height: auto; border-radius: 14px; background: var(--paper); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06); }
.band .loop img { box-shadow: none; }
.loop, .states { max-width: 54rem; } /* full detail without filling the screen */
.loop { margin-top: 0.5rem; }

/* How it works: reading the board, the states after a move, the code map. */
.reads { display: grid; grid-template-columns: subgrid; row-gap: 1.25rem; align-items: start; }
.reads-fig { grid-column: 1 / span 3; }
.reads-copy { grid-column: 4 / span 4; }
.read-steps { margin: 0; padding-left: 1.25rem; display: grid; gap: 0.7rem; max-width: 60ch; }
.after-move, .code { margin-top: var(--space-related); }
.engineers h3, .results h3 { font-size: 1.25rem; }
.zoom { display: block; cursor: zoom-in; border-radius: 14px; }
.code-map { margin: 2rem 0 0; padding: 0; list-style: none; display: grid; gap: 0.75rem; max-width: 70ch; }
.code-map li { padding-top: 0.75rem; border-top: 2px solid #d5dcef; }
.code-map a { color: var(--blue); font-weight: 700; }
.code-map code { font-family: var(--mono); font-size: 0.9em; }
.paper-card { background: var(--paper); border-radius: 22px; padding: clamp(1.1rem, 2.5vw, 1.75rem); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06); max-width: 52rem; }
.paper-kind { margin: 0 0 0.4rem; font-family: var(--mono); font-size: 0.8rem; color: var(--ink-soft); }
.paper-card h3 { font-size: clamp(1.25rem, 2.4vw, 1.6rem); }
.paper-authors { margin: 0.6rem 0 0.2rem; font-weight: 700; }
.paper-venue { margin: 0; color: var(--ink-soft); }
.viewer { width: min(96vw, 82rem); max-height: 92vh; padding: clamp(0.75rem, 2vw, 1.25rem); border: 0; border-radius: 18px; background: var(--paper); }
.viewer:not([open]) { display: none; } /* browsers without <dialog> */
.viewer::backdrop { background: rgba(11, 31, 92, 0.7); }
.viewer figure { margin: 0 0 0.75rem; }
.viewer img { width: 100%; height: auto; border-radius: 10px; }
.viewer figcaption { margin-top: 0.6rem; }
.viewer form { display: flex; justify-content: flex-end; }

/* Results and limits: plain tables at the same weight as the limits below
   them; the numbers are stated, not celebrated. */
.results-grid { display: grid; grid-template-columns: subgrid; row-gap: 1.5rem; align-items: start; }
.stat { padding-top: 0.9rem; border-top: 2px solid #d5dcef; }
.stat.reading { grid-column: 1 / span 3; grid-row: span 2; }
.stat.drops, .stat.time { grid-column: 4 / span 4; }
.stat p { color: var(--ink-soft); font-size: 0.95rem; margin: 0.6rem 0 0; }
.numbers { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.numbers th, .numbers td { padding: 0.45rem 0.5rem; border-bottom: 1px solid #e1e6f4; text-align: left; font-weight: 400; }
.numbers td { font-family: var(--mono); font-size: 0.88rem; text-align: right; white-space: nowrap; }
.by-column th, .by-column td { text-align: center; padding-inline: 0.35rem; }
.by-column th:first-child { text-align: left; white-space: nowrap; color: var(--ink-soft); }
.numbers-scroll { overflow-x: auto; }
.limits { margin-top: 2rem; padding-top: 0.9rem; border-top: 2px solid #d5dcef; }

.build { align-items: center; }
.build > .photo { grid-column: 1 / span 4; }
.build > .build-copy { grid-column: 5 / span 3; }
.photo { margin: 0; }
.photo img { border-radius: 18px; }
.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.facts li { padding-top: 0.75rem; border-top: 2px solid #d5dcef; }

.limits ul { margin: 0; padding-left: 1.25rem; display: grid; gap: 0.6rem; max-width: 70ch; }
.limits li::marker { color: var(--red); }
.paper-card .links { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem; }
/* The paper and the team: the paper card beside the search over it. */
.pt-grid { display: grid; grid-template-columns: subgrid; row-gap: 1.5rem; align-items: start; }
.pt-grid > .paper-card { grid-column: 1 / span 3; max-width: none; }
.pt-grid > .ask { grid-column: 4 / span 4; max-width: none; }
.ask-note { color: var(--ink-soft); }
.foot { background: var(--blue-ink); color: var(--on-blue-soft); text-align: center; padding: 1.5rem 1rem; font-size: 0.9rem; }
.foot p { margin: 0 auto; }

.mini { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 8px; background: var(--blue); border-radius: 12px; }
.mini span { aspect-ratio: 1; border-radius: 50%; background: var(--hole); }
.mini .m1 { background: var(--red); }
.mini .m2 { background: var(--yellow); }
.mini .wrong { box-shadow: 0 0 0 3px var(--on-blue), 0 0 0 5px var(--red-deep); }

.ask { max-width: 52rem; background: var(--paper); border-radius: 22px; padding: clamp(1.1rem, 2.5vw, 1.75rem); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06); }
.ask-form label { display: block; font-weight: 700; margin-bottom: 0.35rem; }
.ask-row { display: flex; gap: 0.5rem; }
.ask-row input { flex: 1; min-width: 0; min-height: 3rem; padding: 0 1rem; font: inherit; border: 2px solid #c7d1ec; border-radius: 999px; background: var(--table); color: var(--ink); }
.ask-row input:focus-visible { border-color: var(--blue); outline-offset: 1px; }
.ask-row input::placeholder { color: #5d678c; opacity: 1; }
.ask-try { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.9rem 0; }
.ask-try button { font: inherit; font-size: 0.9rem; min-height: 2.4rem; padding: 0 0.9rem; border-radius: 999px; border: 2px solid #c7d1ec; background: transparent; color: var(--blue-ink); cursor: pointer; }
.ask-try button:hover { border-color: var(--blue); }
.ask-status { font-weight: 600; min-height: 1.6em; }
.ask-results { margin: 0; padding-left: 1.25rem; display: grid; gap: 1rem; }
.ask-where { font-weight: 700; margin: 0; color: var(--blue-ink); }
.ask-text { margin: 0.25rem 0; color: var(--ink-soft); font-size: 0.95rem; }
.ask-results a { font-weight: 700; color: var(--blue); }
.ask-quality { font-size: 0.9rem; color: var(--ink-soft); border-top: 2px solid #e1e6f4; padding-top: 0.75rem; margin-top: 1rem; }

/* Keep the whole game column (scores, dispenser, board, status, and dock) inside
   one laptop screen: the board follows the screen's height as well as its width.
   16.9rem and the 56px header are everything in that column but the dispenser
   (2.5 cells) and the board (7.12 cells). */
@media (min-width: 960px) {
  :root { --chrome: 16.9rem; --cell: max(2.2rem, min(clamp(2.4rem, 6.2vw, 4.1rem), calc((100svh - 56px - var(--chrome)) / 9.62))); }
}
/* narrower columns wrap the dock to three or four rows */
@media (min-width: 960px) and (max-width: 1179px) { :root { --chrome: 22.9rem; } }
@media (min-width: 960px) and (max-width: 1250px) { .tabs button small { display: none; } }
/* short screens: a smaller headline and tighter panels keep the instrument in view */
@media (min-width: 960px) and (max-height: 820px) {
  .hero h1 { font-size: clamp(2rem, 3vw, 2.5rem); }
  .lede { font-size: 0.98rem; }
  .rig { row-gap: 0.7rem; }
  .stepper { padding: 1.9rem 1rem 0.75rem; }
  .instrument { padding-bottom: 0.8rem; }
  .instrument .serial:not(.boot-log) { height: calc(3 * 1.35em + 1rem); }
}
@media (max-width: 959px) {
  .rig { grid-template-columns: minmax(0, 1fr); grid-template-areas: "copy" "play" "panel"; }
  .rig-panel { max-width: 44rem; width: 100%; margin: 0 auto; }
}
@media (max-width: 880px) {
  .tabs button small { display: none; }
  .stage strong { font-size: 0.7rem; }
  .stepper { padding-inline: 0.6rem; }
  .menu-btn { display: inline-flex; align-items: center; }
  .top nav { display: none; position: absolute; top: 100%; left: 0; right: 0; margin: 0;
    background: var(--blue-ink); padding: 0.5rem clamp(1rem, 4vw, 3rem) 1rem; box-shadow: 0 14px 30px rgba(0, 0, 0, 0.3); }
  .top[data-menu="open"] nav { display: block; }
  .top nav ol { flex-direction: column; gap: 0; counter-reset: sect; }
  .top nav li, .top nav li.more { display: block; counter-increment: sect; border-top: 1px solid rgba(255, 255, 255, 0.12); }
  .top nav li:first-child { border-top: 0; }
  .top nav a { display: flex; align-items: center; gap: 0.9rem; min-height: 3rem; font-family: var(--display); font-weight: 800; font-size: 1.15rem; color: var(--on-blue); }
  .top nav a::before { content: counter(sect, decimal-leading-zero); font-family: var(--mono); font-weight: 400; font-size: 0.78rem; color: var(--yellow); }
  .how-grid > *, .results-grid > *, .build > *, .watch > *, .reads > *, .pt-grid > * { grid-column: 1 / -1 !important; }
  .stat.reading { grid-row: auto; }
  :root { --cell: min(10.6vw, 3.6rem); }
}
@media (max-width: 520px) {
  .cam-views { grid-template-columns: 1fr 1fr; }
  .cam-views figure:first-child { grid-column: 1 / -1; }
  .ard-live { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .stage[data-state="busy"] .lamp, .cell.win .token { animation: none; }
  .toggle input, .toggle input::before { transition: none; }
  .power-pill .lamp, .tabs button[data-live]::after, .token.queued, .result[data-after-win] { animation: none; }
  .board[data-boot] .cell, .power { transition: none; }
  .mech .part { transition: none; }
  .pick select::picker(select), .pick select::picker-icon { transition: none; }
}
