/* Look and feel copied from Among Us: black panels with white rounded borders,
   hand-drawn condensed capitals for headings and buttons, green for "selected". */

@font-face {
  font-family: 'Amatic SC';
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/amatic-sc-latin-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Patrick Hand';
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/patrick-hand-latin-400-normal.woff2') format('woff2');
}

:root {
  --display: 'Amatic SC', 'Arial Narrow', sans-serif;
  --body: 'Patrick Hand', 'Comic Sans MS', sans-serif;
  --panel: rgba(0, 0, 0, 0.82);
  --white: #ffffff;
  --muted: #a9b0bb;
  --green: #3ff23f;
  --task: #44d62c;
  --red: #ff2a2a;
  --cyan: #8cfffb;
  --yellow: #f5f557;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--white); font-family: var(--body); overflow: hidden; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
button { font-family: var(--display); }

/* White-bordered black box: the basic Among Us panel */
.au-panel, .card, .race, #help, #tasks, #banner, #ghost-banner, #toast {
  background: var(--panel);
  border: 3px solid var(--white);
  border-radius: 12px;
}

/* Among Us menu button: black, white outline, condensed caps; green when hovered */
.au-btn, .name, #rejoin {
  font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  color: var(--white); background: #000; border: 3px solid var(--white); border-radius: 10px; cursor: pointer;
}
/* Amatic is thin; a stroke in the text's own color gives it Among Us weight. */
.au-btn, .name, #rejoin, .pill, #room, #banner, #ghost-banner, #toast, .race-head, .card h2 {
  -webkit-text-stroke: 1.2px currentColor; paint-order: stroke fill;
}
.au-btn:hover, .name:hover, #rejoin:hover { color: var(--green); border-color: var(--green); }
.au-btn:active, .name:active, #rejoin:active { transform: scale(0.97); }

/* The close button, the same on every panel and popup: the corner buttons' metal disc
   with an X, in the panel's top-right corner, glowing green like them on hover. */
.x-btn {
  position: absolute; top: 10px; right: 10px; z-index: 1; width: 44px; height: 44px; padding: 0;
  background: none; border: 0; cursor: pointer; transition: transform 0.1s, filter 0.1s;
}
.x-btn img { display: block; width: 100%; height: 100%; }
.x-btn:hover { transform: scale(1.08); filter: drop-shadow(0 0 6px var(--green)); }
.x-btn:active { transform: scale(0.95); }
.x-btn[hidden] { display: none; }

kbd {
  display: inline-block; min-width: 1.6em; padding: 0 6px; margin: 0 1px;
  border: 2px solid var(--white); border-radius: 6px; background: #000; color: var(--white);
  font: 700 18px var(--display); text-align: center; line-height: 1.25;
}

/* Logo: solid white letters with a heavy black outline, like the real title */
.logo {
  margin: 0; font-family: var(--display); font-weight: 700; line-height: 0.9; letter-spacing: 4px;
  color: var(--white); -webkit-text-stroke: 4px #fff; letter-spacing: 6px;
  filter: drop-shadow(0 6px 0 #5a6270);
}

/* ---------- Join screen ---------- */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
#join { place-items: start center; padding-top: max(16px, 3vh); }
.overlay[hidden] { display: none; }
.card {
  width: min(1320px, 100%); max-height: 96vh; display: flex; flex-direction: column;
  padding: 18px 26px 16px;
}
.card { position: relative; background: rgba(0, 0, 0, 0.94); }
.card[hidden] { display: none; }
.card.small { width: min(520px, 100%); text-align: center; gap: 6px; align-items: center; }
.card h2 { margin: 0; font: 700 44px var(--display); letter-spacing: 1px; color: var(--cyan); } /* red on the cards where you'd die */
.card p { margin: 0 0 8px; font-size: 20px; color: #d9dde4; }
.card.small .au-btn { font-size: 30px; padding: 2px 26px; }
#kicked, #reconnecting { background: rgba(0, 0, 0, 0.75); z-index: 10; }
/* The start screens float straight on the starfield, no panel. */
.screen { width: min(1500px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: auto; }
.screen[hidden] { display: none; }
.screen .logo { font-size: clamp(80px, 17vh, 190px); text-align: center; margin-bottom: clamp(16px, 5vh, 56px); }
.story { color: #e8ecf4; line-height: 1.45; font-size: 22px; margin: 0 auto 4px; max-width: 780px; text-align: center; text-shadow: 0 2px 6px #000, 0 0 12px #000; }
.story b { color: var(--red); font-weight: 400; }
#rejoin-box { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 12px; }
#rejoin-box[hidden] { display: none; }
#rejoin { padding: 4px 26px; font-size: 32px; }
#rejoin b { color: var(--yellow); }
.link { background: none; border: 0; color: var(--muted); font: 18px var(--body); text-decoration: underline; cursor: pointer; }
.link:hover { color: var(--white); }
#join:has(#intro:not([hidden])) { place-items: center; }
#intro { width: min(900px, 100%); align-items: center; }
/* On big monitors the start screens grow with the window, so names stay easy to find. */
@media (min-width: 1700px) and (min-height: 1000px) { .screen { zoom: 1.2; } }
@media (min-width: 2200px) and (min-height: 1300px) { .screen { zoom: 1.5; } }
#play { font-size: 40px; padding: 2px 54px; }
#rejoin-box:not([hidden]) + #play { display: none; }

/* The AI chasing a ship across the title card */
/* Clipped sideways only, so the AI's red glow isn't cut into a box when it bobs. */
.chase { position: relative; width: 100%; height: 120px; margin: 4px 0 14px; overflow-x: clip; }
.chase > * { position: absolute; top: 50%; animation: bob 1.6s ease-in-out infinite; }
.chase-ship { width: 210px; left: 56%; margin-top: -43px; overflow: visible; }
.chase-ship .flame { transform-origin: 14px 50px; animation: flicker-x 0.12s ease-in-out infinite alternate; }
@keyframes flicker-x { to { transform: scaleX(0.8); } }
.chase-ai { height: 110px; left: 22%; margin-top: -55px; animation-delay: -0.8s; filter: drop-shadow(0 0 10px #ff2030); }
@keyframes bob { 50% { transform: translateY(-7px) rotate(-2deg); } }
@media (prefers-reduced-motion: reduce) { .chase > *, .chase .flame { animation: none; } }

/* The story, as a motion comic (js/story.js): one panel at a time. Inside a panel, .shake (shakes)
   holds .stage (the camera: the art at 3:2). */
/* Its own layer over everything (the title screen, the ship, mission control), on a starfield. */
#story {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 16px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #141c4a, #05081c 70%);
}
#story[hidden], .story-page[hidden], .story-end[hidden] { display: none; }
.story-page { cursor: pointer; user-select: none; }
.panel { position: relative; margin: 0; overflow: hidden; background: #000; animation: camera-in 0.6s cubic-bezier(0.3, 0, 0.2, 1); }
@keyframes camera-in { from { opacity: 0; transform: scale(1.03); } }
.panel .shake { position: absolute; inset: 0; }
.panel .stage { position: absolute; container-type: inline-size; /* lettering sizes follow the art */ }
/* Laptops and the big screen: each scene fills the whole screen, with the controls over the art.
   (A window wider than 2:1 or taller than 1.3:1 keeps dark bars instead, so the art isn't cropped away.) */
@media (min-width: 761px) and (min-height: 541px) {
  .story-page { position: absolute; inset: 0; margin: auto; width: min(100%, 200vh); height: min(100%, 77vw); }
  .panel { position: absolute; inset: 0; container-type: size; }
  /* The art covers the screen like object-fit: cover, held at the panel's focal point. */
  .panel .stage {
    left: var(--fx, 50%); top: var(--fy, 50%); width: max(100cqw, 150cqh); aspect-ratio: 3 / 2;
    translate: calc(-1 * var(--fx, 50%)) calc(-1 * var(--fy, 50%));
  }
  .story-foot {
    position: absolute; inset: auto 0 0; z-index: 3; padding: 48px 24px 16px; pointer-events: none;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  }
  .story-foot > * { pointer-events: auto; }
  .story-foot .link { text-shadow: 0 2px 4px #000; }
}
.stage > img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.stage > img.sprite { inset: auto; }

/* Words on top of a panel: they pop in, and stay still while the camera moves. */
.panel :is(.caption, .say, .sfx, .type) { position: absolute; z-index: 2; margin: 0; opacity: 0; pointer-events: none; }
.panel :is(.caption, .say, .sfx, .type).on { opacity: 1; }
/* Captions: little Among Us panels, sized with the panel. */
.caption {
  max-width: 62%; padding: 0.25em 0.7em 0.3em; background: #000; border: 3px solid var(--white); border-radius: 8px;
  font-size: clamp(18px, 2.2cqw, 46px); line-height: 1.25; color: var(--white);
  transform: translateY(-6px); transition: opacity 0.35s, transform 0.35s;
}
.caption.on { transform: none; }
.caption b { color: var(--red); font-weight: 400; }
/* The AI speaks in its red chat bubble. */
.say {
  padding: 0.3em 0.8em 0.4em; background: #c51111; border: 3px solid #000; border-radius: 14px;
  font-size: clamp(20px, 2.45cqw, 50px); line-height: 1.2; color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.5);
  transform: scale(0.6); transform-origin: 10% 100%; transition: opacity 0.2s, transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
/* Its tail: one shape, sized with the words (em) so it stays a real pointer on a big screen. It
   hangs under the balloon over its border (the opening), outlined in the balloon's 3px black. */
.say::after {
  content: ''; position: absolute; top: 100%; left: 16%; width: 0.8em; height: 0.9em;
  background: linear-gradient(to right, #000 3px, transparent 0), linear-gradient(to bottom right, #c51111 calc(50% - 3px), #000 0);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}
.say.tail-right { transform-origin: 90% 100%; }
.say.tail-right::after { left: auto; right: 16%; transform: scaleX(-1); }
/* On the balloon's left side, turned to point left. */
.say.tail-left { transform-origin: 0 50%; }
.say.tail-left::after { top: calc(50% - 0.4em); left: auto; right: 100%; width: 0.8em; height: 0.8em; transform: rotate(90deg); }
.say.on { transform: none; }
/* Sound effects, lettered like the "HIC!" over a crewmate's head in the ship. */
.sfx {
  font: 700 max(26px, 7cqw) / 1 var(--display); letter-spacing: 2px; color: var(--white);
  -webkit-text-stroke: max(4px, 1cqw) #000; paint-order: stroke fill;
  transform: rotate(var(--tilt, 0deg)) scale(0.2);
  transition: opacity 0.1s, transform 0.4s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.sfx.big { font-size: max(40px, 10cqw); color: var(--yellow); -webkit-text-stroke-width: max(5px, 1.3cqw); }
.sfx.on { transform: rotate(var(--tilt, 0deg)); animation: sfx-out 0.3s 1.3s forwards; }
.sfx.big.on { animation-delay: 1.6s; }
@keyframes sfx-out { to { opacity: 0; transform: rotate(var(--tilt, 0deg)) scale(1.15); } }
/* Typed on the monitor in panel 2, lying on its screen: a rectangle mapped onto the screen's four
   corners in 2-plate.webp ((1098,382) (1442,314) (1438,673) (1082,666) of 1536x1024), so the lines
   tilt and shrink with it. Every length is in cqw, so it holds at any size. */
.type {
  left: 0; top: 0; width: 27.34cqw; height: 21.48cqw; box-sizing: border-box; padding: 2cqw 1.8cqw 2cqw calc(1.8cqw + 2ch); text-indent: -2ch; overflow: hidden;
  transform-origin: 0 0;
  transform: translate(71.484cqw, 24.87cqw) perspective(100cqw) matrix3d(0.6485, -0.1282, 0.7615, 0, -0.0467, 0.8296, 0.1678, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  font: 700 2.6cqw / 1.45 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; color: var(--green);
  text-shadow: 0 0 0.7cqw var(--green);
}
.type::before { content: '> '; }
.type.on::after { content: '\2588'; animation: caret 0.8s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }

/* ---- The moves, one hero move per panel ---- */
/* The smiley's blink: its eyes flash red now and then. */
.red-eye {
  position: absolute; background: var(--red); border-radius: 50%; box-shadow: 0 0 1.2cqw var(--red); opacity: 0;
  animation: red-eye 5.2s 2.6s infinite;
}
@keyframes red-eye { 0%, 93%, 100% { opacity: 0; } 94.5%, 98.5% { opacity: 1; } }
/* 1. The data hall: a slow push in toward the screen. */
.p1 .stage { transform-origin: 50% 40%; animation: push-in 9s cubic-bezier(0.25, 0.5, 0.3, 1) forwards; }
@keyframes push-in { from { transform: scale(1); } to { transform: scale(1.08); } }
/* 2. The hiccup: the jolting frame flashes in for a beat, the panel jumps. */
.p2 .stage { transform-origin: 60% 50%; animation: push-in 9s ease-out forwards; }
.p2 .crew { transform-origin: 45% 100%; transform: translateY(13.5%) rotate(-7deg); }
.p2.hic .crew { animation: hiccup 1s; }
@keyframes hiccup {
  0% { transform: translateY(13.5%) rotate(-7deg) scale(1.06, 0.92); animation-timing-function: cubic-bezier(0.2, 0.9, 0.4, 1); }
  14% { transform: translateY(0) rotate(0) scale(0.95, 1.07); animation-timing-function: ease-out; }
  32% { transform: translateY(-2%) rotate(1deg) scale(1); animation-timing-function: cubic-bezier(0.6, 0, 0.9, 0.5); }
  62% { transform: translateY(13.5%) rotate(-7deg) scale(1.08, 0.9); animation-timing-function: ease-out; }
  78% { transform: translateY(12%) rotate(-7deg) scale(0.98, 1.03); }
  100% { transform: translateY(13.5%) rotate(-7deg); }
}
.p2.hic2 .crew { animation: hiccup-small 0.8s; }
@keyframes hiccup-small {
  0% { transform: translateY(13.5%) rotate(-7deg) scale(1.03, 0.96); animation-timing-function: ease-out; }
  20% { transform: translateY(7%) rotate(-4deg) scale(0.98, 1.04); animation-timing-function: ease-in; }
  55% { transform: translateY(13.5%) rotate(-7deg) scale(1.04, 0.95); }
  100% { transform: translateY(13.5%) rotate(-7deg); }
}
.p2 .lines { opacity: 0; }
.p2.hic .lines { animation: lines 0.9s; }
@keyframes lines { 8%, 45% { opacity: 1; } 0%, 70%, 100% { opacity: 0; } }
/* 3. Cure found: tentacles creep in from the edges; the screen turns green last. */
@property --reach { syntax: '<percentage>'; inherits: false; initial-value: 100%; }
.p3 .stage { transform-origin: 6% 94%; animation: push-in 10s ease-out forwards; }
.dots { position: absolute; display: flex; gap: 0.6%; width: 8%; translate: -50% -50%; opacity: 0; }
.dots b { flex: 1; aspect-ratio: 1; border-radius: 50%; background: #2f6b4f; animation: dot 0.3s infinite alternate; }
.dots b:nth-child(2) { animation-delay: 0.1s; }
.dots b:nth-child(3) { animation-delay: 0.2s; }
@keyframes dot { to { transform: translateY(-40%); opacity: 0.4; } }
.p3.think .dots { opacity: 1; }
.p3.thought .dots { opacity: 0; }
.p3 .creep {
  --reach: 100%;
  -webkit-mask-image: radial-gradient(ellipse 75% 75% at 40% 48%, transparent calc(var(--reach) - 18%), #000 var(--reach));
  mask-image: radial-gradient(ellipse 75% 75% at 40% 48%, transparent calc(var(--reach) - 18%), #000 var(--reach));
}
.p3.reveal .creep { animation: creep 3s cubic-bezier(0.55, 0, 0.35, 1) forwards; }
@keyframes creep { to { --reach: 0%; } }
/* 4. KRRRASH: a white flash, a snap back from close, glass flying at the camera. */
.p4.crash .stage { transform-origin: 52% 50%; animation: crash-cam 9s forwards; }
@keyframes crash-cam {
  0% { transform: scale(1.16); animation-timing-function: cubic-bezier(0.2, 0.9, 0.3, 1); }
  6% { transform: scale(1); animation-timing-function: linear; }
  100% { transform: scale(1.05); }
}
.p4.crash .shake { animation: shake 0.5s linear; }
@keyframes shake {
  10% { transform: translate(-1.2%, 0.8%); } 25% { transform: translate(1.1%, -1%); } 40% { transform: translate(-0.8%, -0.6%); }
  55% { transform: translate(0.6%, 0.7%); } 75% { transform: translate(-0.3%, 0.2%); } 100% { transform: none; }
}
.panel .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; } /* .panel: #comms-badge.flash is another flash */
.p4.crash .flash { animation: flash 0.45s ease-out; }
@keyframes flash { from { opacity: 0.95; } to { opacity: 0; } }
.shard {
  position: absolute; left: 50%; top: 42%; width: 2.6%; aspect-ratio: 1 / 1.6; opacity: 0;
  background: #bff5ff; clip-path: polygon(50% 0, 100% 70%, 30% 100%, 0 40%);
  filter: drop-shadow(0 0 2px #000);
}
.p4.crash .shard { animation: shard 1s cubic-bezier(0.15, 0.6, 0.4, 1) forwards; }
@keyframes shard {
  0% { opacity: 1; transform: translate(0, 0) rotate(0) scale(0.4); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--r)) scale(calc(var(--s) * 2.4)); }
}
/* 5. Launch: the camera tilts up after the rockets as the ground rumbles. The rockets are the game's ship. */
.launch-ship { position: absolute; overflow: visible; }
.launch-ship .flame { transform-origin: 14px 50px; scale: 1.8 1.35; animation: flicker-x 0.12s var(--b) ease-in-out infinite alternate; } /* full thrust */
.p5 .stage { transition-duration: 0.25s; }
.p5 .stage { animation: tilt-up 5.5s cubic-bezier(0.45, 0, 0.25, 1) forwards; }
@keyframes tilt-up { from { transform: scale(1.32) translateY(-9%); } to { transform: scale(1.1) translateY(3%); } }
.p5 .shake { animation: rumble 0.09s linear 22 alternate; }
@keyframes rumble { from { transform: translate(0.15%, -0.1%); } to { transform: translate(-0.15%, 0.12%); } }
.glow {
  position: absolute; width: 50%; aspect-ratio: 2.6; translate: -50% -60%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(68, 255, 90, 0.55), transparent);
  mix-blend-mode: screen; animation: glow 2.8s ease-in-out infinite alternate;
}
@keyframes glow { from { opacity: 0.2; } to { opacity: 0.85; } }
/* 6. The porthole: stars stream past, and the AI slides into view and keeps coming. */
.space {
  position: absolute; inset: 0;
  background:
    radial-gradient(1.5px 1.5px at 20% 30%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 15%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 45% 75%, #dfe8ff 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 60%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 10% 85%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 58% 42%, #cfd9ff 50%, transparent 51%),
    #070f33;
  background-size: 22% 33%; animation: stars 7s linear infinite;
}
@keyframes stars { to { background-position: -22% 0; } }
.tint { position: absolute; inset: 0; background: #0b1030; opacity: 0.25; mix-blend-mode: multiply; pointer-events: none; }
.p6 .ai { opacity: 0; }
.p6 .ai { opacity: 1; transform-origin: 70% 50%; animation: approach 10s forwards; }
@keyframes approach {
  0% { transform: translate(85%, -12%) scale(0.75) rotate(4deg); animation-timing-function: cubic-bezier(0.2, 0.7, 0.3, 1); }
  30% { transform: translate(0, 0) scale(1) rotate(0); animation-timing-function: ease-in-out; }
  55% { transform: translate(-1.5%, 2%) scale(1.04) rotate(-1.5deg); animation-timing-function: ease-in-out; }
  80% { transform: translate(0.5%, -1%) scale(1.07) rotate(1deg); animation-timing-function: ease-in-out; }
  100% { transform: translate(-1%, 1%) scale(1.1) rotate(-1deg); }
}

/* 1. The hall's big screen switches on with Roche's logo, like a keynote slide.
   Its own class: as .logo it also hid the title screen's logo (and put it over Play on tall phones). */
.roche-screen {
  position: absolute; display: grid; place-items: center; opacity: 0;
  background: radial-gradient(#fff, #d9e6ff); box-shadow: 0 0 7cqw rgba(150, 195, 255, 0.5);
}
.roche-screen img { width: 56%; }
.p1.lit .roche-screen { animation: switch-on 0.6s forwards; }
@keyframes switch-on { 0% { opacity: 0; } 8% { opacity: 1; } 18% { opacity: 0.25; } 32%, 100% { opacity: 1; } }
/* 1. Power-on: light sweeps in from both sides of the hall toward the screen as the chime plays. */
.sweep { position: absolute; inset: 0; pointer-events: none; mix-blend-mode: screen; overflow: hidden; }
.sweep::before, .sweep::after {
  content: ''; position: absolute; top: 15%; bottom: 5%; width: 30%; opacity: 0;
  background: radial-gradient(closest-side, rgba(110, 255, 140, 0.75), transparent);
}
.sweep::before { left: -22%; }
.sweep::after { right: -22%; }
.p1 .sweep::before { animation: sweep-l 1.5s 0.8s ease-in-out forwards; }
.p1 .sweep::after { animation: sweep-r 1.5s 0.8s ease-in-out forwards; }
@keyframes sweep-l { 15% { opacity: 1; } 100% { left: 39%; opacity: 0; } }
@keyframes sweep-r { 15% { opacity: 1; } 100% { right: 39%; opacity: 0; } }
/* 2. The monitor brightens with each keystroke while the prompt types. */
.keyglow {
  position: absolute; width: 34%; aspect-ratio: 1.2; translate: -50% -50%; border-radius: 50%; opacity: 0;
  background: radial-gradient(closest-side, rgba(80, 220, 255, 0.35), transparent); mix-blend-mode: screen; pointer-events: none;
}
.p2 .keyglow { animation: keys 0.11s 0.7s 14 alternate; }
@keyframes keys { from { opacity: 0.15; } to { opacity: 0.8; } }
/* 6. On "Hold still" the AI lunges at the glass and the cabin shudders. */
.p6.lunge .ai { animation: approach 10s forwards, lunge 0.7s cubic-bezier(0.3, 1.5, 0.5, 1); }
@keyframes lunge { 40% { scale: 1.16; } }
.p6.lunge .front { animation: shudder 0.45s 0.15s linear; }
@keyframes shudder { 25% { translate: -0.5% 0.3%; } 50% { translate: 0.4% -0.3%; } 75% { translate: -0.2% 0.2%; } }
/* 7. The race: eight rockets jostle toward the gate, one surges on a blue boost. */
.fleet-ship { position: absolute; width: 11%; left: var(--x0); overflow: visible; translate: 0 -50%; }
.p7 .fleet-ship { animation: fleet var(--d) cubic-bezier(0.3, 0, 0.3, 1) forwards, bob 1.6s var(--b) ease-in-out infinite; }
.p7 .fleet-ship.boost { animation: fleet-boost var(--d) cubic-bezier(0.5, 0, 0.3, 1) forwards, bob 1.6s var(--b) ease-in-out infinite; }
@keyframes fleet { to { left: var(--x1); } }
@keyframes fleet-boost { 40% { left: calc(var(--x0) + 6%); } to { left: var(--x1); } }
.fleet-ship .flame { transform-origin: 14px 50px; animation: flicker-x 0.12s ease-in-out infinite alternate; }
.p7 .fleet-ship.boost .flame { animation: flicker-x 0.12s ease-in-out infinite alternate, boost-flame 4.6s forwards; }
@keyframes boost-flame { 0%, 38% { scale: 1; } 45%, 100% { scale: 1.9 1.25; } }
.p7 .fleet-ship.boost .outer { animation: blue 4.6s forwards; }
.p7 .fleet-ship.boost .inner { animation: blue-in 4.6s forwards; }
@keyframes blue { 0%, 40% { fill: #ff9d2e; } 46%, 100% { fill: #3d8bff; } }
@keyframes blue-in { 0%, 40% { fill: #fff27a; } 46%, 100% { fill: #c9ecff; } }
/* 8. The jump-code screen keeps scrambling. */
.digit {
  position: absolute; translate: -50% -50%; width: 6%; height: 12cqw; overflow: hidden; text-align: center;
  font: 700 9cqw / 12cqw ui-monospace, Menlo, Consolas, monospace; color: var(--green); text-shadow: 0 0 1cqw var(--green);
}
.digit b { display: block; font-weight: 700; }
.p8 .digit b { animation: scramble 1.3s steps(10) infinite; }
@keyframes scramble { to { transform: translateY(-100%); } }
/* 9 to 11. The other games: a slow push in on each. */
:is(.p9, .p10, .p11) .stage { transform-origin: 55% 45%; animation: push-in 9s ease-out forwards; }
/* 9. Navigation: the navigator's hover frame (the game's yellow) hops between the two photos. */
.pick {
  position: absolute; box-sizing: border-box; border: 0.5cqw solid var(--yellow); border-radius: 0.5cqw;
  box-shadow: 0 0 2.2cqw rgba(245, 245, 87, 0.7), inset 0 0 1.2cqw rgba(245, 245, 87, 0.35); opacity: 0;
}
.p9 .pick0 { animation: pick 2.4s 0.9s steps(1) infinite; }
.p9 .pick1 { animation: pick 2.4s 2.1s steps(1) infinite; }
@keyframes pick { 0% { opacity: 1; } 50%, 100% { opacity: 0; } }
/* 10. Comms: the chat fills the big screen, in the game's bubbles; the AI's is enemy red. */
.chat { position: absolute; box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; gap: 1cqw; padding: 1.2cqw 1.6cqw; }
.chat p {
  align-self: flex-start; max-width: 96%; margin: 0; padding: 0.3cqw 1.3cqw 0.7cqw; background: #fff; color: #111;
  border: 0.25cqw solid #000; border-radius: 1.3cqw; font-size: 2.6cqw; line-height: 1.2;
  opacity: 0; transform: translateY(1.2cqw) scale(0.9); transform-origin: 0 100%; transition: opacity 0.15s, transform 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.chat b { display: block; font: 700 2.6cqw / 1.15 var(--display); letter-spacing: 0.05em; -webkit-text-stroke: 0.09cqw #000; paint-order: stroke fill; }
.chat p.ai { display: grid; grid-template-columns: auto 1fr; column-gap: 0.9cqw; align-items: center; background: #c51111; color: #fff; }
.chat p.ai img { grid-row: 1 / span 2; height: 5.2cqw; margin-left: -0.4cqw; }
.p10.m1 .chat p:nth-child(1), .p10.m2 .chat p:nth-child(2), .p10.m3 .chat p:nth-child(3) { opacity: 1; transform: none; }
/* 11. Lights out: darkness, the small circle of light the living get, and the cable's sparks lighting the breaker. */
@property --flash { syntax: '<length>'; inherits: false; initial-value: 0.01px; }
.dark {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; background: #02030a; transition: opacity 0.12s;
  -webkit-mask-image: radial-gradient(circle 15cqw at var(--lx) var(--ly), transparent 55%, #000), radial-gradient(circle var(--flash) at var(--sx) var(--sy), transparent 35%, #000);
  mask-image: radial-gradient(circle 15cqw at var(--lx) var(--ly), transparent 55%, #000), radial-gradient(circle var(--flash) at var(--sx) var(--sy), transparent 35%, #000);
  -webkit-mask-composite: source-in; mask-composite: intersect;
}
.p11.out .dark { opacity: 0.97; animation: flash 1.9s 0.7s infinite; }
@keyframes flash { 0%, 5%, 10%, 100% { --flash: 0.01px; } 2%, 7% { --flash: 26cqw; } }
/* 12. It closes in: the AI grows toward the camera while our rocket shudders. */
.p12 .bg { transform-origin: 50% 40%; animation: closes-in 6.5s cubic-bezier(0.5, 0, 0.8, 0.6) forwards; }
@keyframes closes-in { to { transform: scale(1.22); } }
.p12 .ship { animation: rattle 0.08s linear infinite alternate, engine 0.3s steps(2) infinite; }
@keyframes rattle { from { translate: -0.4% 0.2%; } to { translate: 0.4% -0.2%; } }
@keyframes engine { 50% { filter: brightness(1.25); } }

.story-foot { display: flex; justify-content: space-between; align-items: center; }
.story-foot .link { font-size: clamp(20px, 1.5vw, 30px); }
.story-hint { font-size: clamp(30px, 2.4vw, 50px); padding: 0 22px; }
.story-hint span { font-size: 0.6em; vertical-align: 0.15em; }
.story-back { font-size: clamp(30px, 2.4vw, 50px); padding: 0 22px; }
.story-back span { font-size: 0.6em; vertical-align: 0.15em; }
.story-back:disabled { visibility: hidden; } /* nothing before the first panel */
.story-back[hidden], .story-skip[hidden] { display: none; }
#story.auto .story-back { visibility: hidden; }
#story.ended .story-foot { display: none; }
#story.auto .story-hint { visibility: hidden; }
.story-end { width: min(1100px, 100%); display: flex; flex-direction: column; align-items: center; gap: 14px; animation: land 0.25s 0.32s; }
.story-end .logo { font-size: clamp(80px, 15vw, 260px); animation: slam 0.34s cubic-bezier(0.5, 0, 0.75, 0) both; }
.story-end .chase { height: 190px; animation: fade-up 0.6s 0.5s both; }
.story-end .chase-ship { width: 330px; margin-top: -68px; }
.story-end .chase-ai { height: 170px; margin-top: -85px; filter: none; }
.story-end .story { font-size: 32px; animation: fade-up 0.6s 0.8s both; }
.story-end .au-btn { font-size: 40px; padding: 2px 44px; animation: fade-up 0.6s 1.1s both; }
.story-note { margin: 0; font-size: 22px; color: var(--muted); animation: fade-up 0.6s 1.4s both; }
/* The premiere lets it breathe. */
#story.auto .story-end .chase { animation-delay: 0.8s; }
#story.auto .story-end .story { animation-delay: 1.5s; }
#story.auto .story-end .au-btn { display: none; }
@keyframes slam { from { opacity: 0; transform: scale(2.6); } 30% { opacity: 1; } }
@keyframes land { 25% { transform: translate(-6px, 4px); } 50% { transform: translate(5px, -3px); } 75% { transform: translate(-2px, 2px); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } }

/* The premiere has no controls. */
#story.auto .story-foot { display: none; }

/* Progress: one dot per panel. */
.story-dots { display: flex; gap: 7px; }
.story-dots i { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--white); opacity: 0.45; }
.story-dots i.done { background: var(--white); }
.story-dots i.now { background: var(--green); border-color: var(--green); opacity: 1; }

/* Phones: one panel at a time. Captions and the AI's balloon move out of the art into bars,
   so they never cover it; lettering and typed text stay on the art. */
@media (max-height: 540px), (max-width: 760px) {
  #story { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); justify-content: flex-start; gap: 8px; }
  .story-page { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; justify-content: center; }
  .story-page .panel { display: grid; gap: 8px; overflow: visible; background: none; animation: none; }
  .panel .shake { position: relative; inset: auto; border: 3px solid var(--white); border-radius: 12px; overflow: hidden; background: #000; container-type: inline-size; }
  .panel .stage { inset: 0 auto 0 50%; aspect-ratio: 3 / 2; translate: calc(-1 * var(--fx, 50%)) 0; }
  .panel > :is(.caption, .say) { position: relative; inset: auto !important; max-width: none !important; font-size: 17px; }
  .panel > .say::after { display: none; }
  .story-foot { width: 100%; }
  .story-hint, .story-back { font-size: 26px; padding: 0 18px; min-height: 48px; white-space: nowrap; }
  .story-back b { display: none; } /* just the arrow: room for the dots */
  .story-back span { font-size: 0.8em; }
  .story-foot .link { font-size: 18px; padding: 12px 0; }
  .story-end .logo { font-size: 72px; }
  .story-end .chase { height: 110px; }
  .story-end .chase-ship { width: 170px; margin-top: -35px; }
  .story-end .chase-ai { height: 96px; margin-top: -48px; }
  .story-end .story { font-size: 20px; }
  .story-end .au-btn { font-size: 30px; }
}
/* Upright: caption bar, the art cropped taller (4:5) around the panel's focal point, the balloon bar. */
@media (orientation: portrait) and (max-width: 760px) {
  /* One column as wide as the art, anchored at the top so the caption bar never jumps. */
  .story-page { justify-content: flex-start; padding-top: 4px; }
  .story-page .panel { grid-template-columns: 1fr; align-self: center; width: min(100%, calc((100svh - 230px) * var(--ar, 0.8))); }
  .panel .shake { order: 2; aspect-ratio: var(--crop, 4 / 5); width: 100%; }
  .panel > .caption { order: 1; }
  .panel > .say { order: 3; }
}
/* Sideways: the art as tall as the screen on the left; captions, balloon and controls in a column. */
@media (orientation: landscape) and (max-height: 540px) {
  #story { flex-direction: row; align-items: stretch; padding: 8px calc(8px + env(safe-area-inset-right)) 8px calc(8px + env(safe-area-inset-left)); }
  .story-page .panel { grid-template-columns: auto 190px; grid-auto-rows: min-content; align-content: start; column-gap: 12px; }
  .panel .shake { grid-column: 1; grid-row: 1 / span 6; height: calc(100vh - 16px); aspect-ratio: 3 / 2; }
  .panel > :is(.caption, .say) { grid-column: 2; font-size: 16px; }
  .panel .stage { left: 0; translate: none; } /* the whole 3:2 art fits: no crop to centre */
  .story-foot { position: fixed; right: calc(8px + env(safe-area-inset-right)); bottom: 8px; width: 190px; flex-direction: column-reverse; align-items: stretch; gap: 6px; }
  .story-foot .story-dots { justify-content: center; }
  .story-foot .link { text-align: center; padding: 4px 0; }
  .story-end { width: 100%; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  .panel *, .story-end * { animation: none !important; transition: none !important; }
  .p6 .ai { opacity: 1; }
  .p3 .creep { --reach: 0%; }
}

/* Launch site: eight identical Starships (assets/rocket.svg turned upright),
   each standing on its pad with the crew manifest below. */
.hangar-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-bottom: 10px; }
.hangar-head .link { justify-self: start; }
.hangar-head #hangar-story { justify-self: end; }
.hangar-head h2 { margin: 0; font: 700 42px var(--display); letter-spacing: 1px; -webkit-text-stroke: 1.2px currentColor; paint-order: stroke fill; }
#roster { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 12px; }
.bay { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.pad { position: relative; display: flex; justify-content: center; width: 100%; padding-bottom: 15px; }
/* The launch mount the ship stands on */
.pad::after {
  content: ''; position: absolute; bottom: 0; width: 64%; height: 12px;
  background: #59626f; border: 3px solid #0b0c10; border-radius: 4px;
}
.ship-art {
  --h: clamp(150px, 27vh, 250px);
  position: relative; z-index: 1; height: var(--h); width: auto; transition: transform 0.25s ease;
  /* The flame room under the engines hangs over the pad, so the fins rest on the mount. */
  margin-bottom: calc(var(--h) * -28 / 222);
}
.ship-art .flame { opacity: 0; transform-origin: 50% 186px; transition: opacity 0.15s; }
.bay:hover .ship-art { transform: translateY(-10px); }
.bay:hover .ship-art .flame { opacity: 1; animation: flicker 0.12s ease-in-out infinite alternate; }
@keyframes flicker { to { transform: scaleY(0.82); } }
.bay h3 { margin: 6px 0 0; font: 700 30px var(--display); letter-spacing: 1px; line-height: 1; }
.bay .aboard { margin-bottom: 6px; font-size: 16px; color: var(--muted); }
.bay:hover h3 { color: var(--green); }
.bay .names { width: var(--name-w, 100%); max-width: 100%; }
.names { display: flex; flex-direction: column; gap: 3px; }
.name {
  display: flex; align-items: center; gap: 4px; width: 100%; padding: 0 5px 0 3px; font-size: 19px;
  border-width: 2px; border-radius: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.name img { width: 16px; height: 18px; flex: none; }
.name.saved { color: var(--yellow); border-color: var(--yellow); }
.name.online { opacity: 0.45; }
.name.online::after { content: '●'; margin-left: auto; color: var(--green); -webkit-text-stroke: 0; }
/* The visitor (/giuls) boards a ship, not a name: one Board button a ship, and the names only show who is there. */
.name.board { justify-content: center; color: var(--green); border-color: var(--green); }
.name:disabled { pointer-events: none; }
#visitor-exit { display: none; width: fit-content; margin-top: 8px; font-size: 24px; padding: 0 14px; text-decoration: none; pointer-events: auto; }
#visitor-exit span { font-size: 0.7em; vertical-align: 0.12em; }
body.visitor #visitor-exit { display: block; }
body.touch #visitor-exit { font-size: 20px; padding: 0 12px; border-width: 2px; }

/* ---------- In-game HUD ---------- */
#hud, #room, #corner, #minimap, #help, #banner, #ghost-banner, #map-hint, #map-close, #toast { display: none; }
body.playing #hud, body.playing #room, body.playing #minimap, body.playing #help, body.playing #toast { display: block; }
body.playing #corner { display: flex; align-items: center; gap: 10px; }
body.playing #banner:not([hidden]) { display: block; }
body.playing[data-status="caught"] #ghost-banner, body.playing.dead #ghost-banner { display: block; }
body.playing[data-status="caught"] #banner, body.playing.dead #banner { display: none; }
body.playing.seasoned:not(.practice) #help, body.practice.playing:not(.tour-on) #help { opacity: 0; transition: opacity 1.5s; }
body.in-scene #hud, body.in-scene #room, body.in-scene #corner, body.in-scene #minimap,
body.in-scene #help, body.in-scene #banner, body.in-scene #ghost-banner, body.in-scene #toast { display: none !important; }

#hud { position: fixed; top: 12px; left: 12px; pointer-events: none; }

/* Room name: flashes up as plain outlined text when you walk into a room. */
#room {
  position: fixed; left: 50%; top: max(30%, 196px); transform: translateX(-50%); opacity: 0;
  font: 700 54px var(--display); letter-spacing: 3px; text-transform: uppercase; pointer-events: none;
  -webkit-text-stroke: 7px #000; paint-order: stroke fill;
}
#room.low { top: auto; bottom: max(18%, 120px); }
#room.pop { animation: room-flash 2.6s ease-out; }
@keyframes room-flash {
  0% { opacity: 0; transform: translateX(-50%) scale(1.2); }
  12% { opacity: 1; transform: translateX(-50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

/* Banners sit between the race panel (left) and the corner buttons (right). */
#banner, #ghost-banner {
  position: fixed; top: 14px; left: 430px; right: 214px; margin: 0 auto; width: fit-content; /* right: clear of the three corner buttons */
  padding: 2px 22px; font: 700 28px var(--display); letter-spacing: 1px; text-align: center; pointer-events: none;
}
#ghost-banner { border-color: var(--red); color: #ffb3b3; }

#toast {
  position: fixed; z-index: 7; left: 50%; top: 132px; transform: translateX(-50%); opacity: 0; pointer-events: none;
  padding: 4px 28px; border-color: var(--green); color: var(--green); font: 700 34px var(--display); letter-spacing: 2px; white-space: nowrap;
}
#toast.show { animation: toast 2.8s ease-out; }
#toast.bad { border-color: var(--red); color: var(--red); }

/* AI countdown: big and central for the last 90 seconds. */
#warning {
  position: fixed; left: 50%; top: 72px; transform: translateX(-50%); pointer-events: none;
  padding: 2px 30px; background: rgba(60, 0, 0, 0.85); border: 3px solid var(--red); border-radius: 12px;
  color: #ffd0d0; font: 700 46px var(--display); letter-spacing: 2px; text-transform: uppercase;
  -webkit-text-stroke: 1.4px currentColor; paint-order: stroke fill;
}
#warning[hidden], body.in-scene #warning, body.map-open #warning { display: none; }
#warning.urgent { color: #fff; animation: blink 0.6s steps(2) infinite; }
@keyframes toast {
  0% { opacity: 0; transform: translateX(-50%) scale(0.8); }
  10% { opacity: 1; transform: translateX(-50%) scale(1.05); }
  20% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

#corner { position: fixed; top: 12px; right: 12px; }
/* Corner buttons: the map button's metal disc, each with its own dark icon. */
.round-btn {
  width: 62px; height: 62px; padding: 0; cursor: pointer; display: grid; place-items: center;
  background: none; border: 0; color: #fff; transition: transform 0.1s, filter 0.1s;
}
.round-btn img { width: 60px; height: 60px; image-rendering: auto; }
.round-btn:hover { transform: scale(1.08); filter: drop-shadow(0 0 6px var(--green)); }
.round-btn:active { transform: scale(0.95); }
#mute .off, #mute.off .on { display: none; }
#mute.off .off { display: block; }

#minimap {
  position: fixed; right: 12px; bottom: 12px; cursor: pointer;
  background: rgba(6, 14, 36, 0.88); border: 2px solid var(--white); border-radius: 12px;
}
body.map-open #minimap {
  right: 50%; bottom: 50%; transform: translate(50%, 50%); cursor: zoom-out; background: rgb(6, 14, 36);
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.65);
}
body.map-open #map-close { display: block; position: fixed; z-index: 2; }
body.map-open #corner, body.map-open #warning { display: none; }
body.map-open #map-hint {
  display: block; position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%);
  font: 700 28px var(--display); letter-spacing: 1px;
}
body.map-open #help, body.map-open #room { display: none; }
body.help-off #help { display: none !important; }

#help { position: fixed; left: 12px; bottom: 12px; padding: 8px 16px 10px; font-size: 18px; pointer-events: none; }
/* The x in the top-right corner, for people who already know how to walk. */
#help-close { pointer-events: auto; }
#help .help-head { min-height: 44px; display: flex; align-items: center; padding-right: 50px; }
body.seasoned:not(.practice) #help-close, body.practice:not(.tour-on) #help-close { pointer-events: none; } /* faded out: nothing to click */
/* The practice ship (js/tour.js): three things to try; done ones fold to a green tick, the next one
   shows how. In the real game the card is only "How to walk". */
#help { max-width: 440px; }
#help .tour-title { color: var(--cyan); }
body.practice #help .walk-title, body:not(.practice) #help .tour-title { display: none; }
.tour { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; }
.tour li { position: relative; padding-left: 30px; line-height: 1.3; color: var(--muted); }
.tour li::before {
  content: ''; position: absolute; left: 0; top: 2px; width: 18px; height: 18px; box-sizing: border-box;
  border: 2.5px solid currentColor; border-radius: 50%;
}
.tour li b { font-weight: 700; }
.tour li.now { color: var(--white); }
.tour li.now::before { border-color: var(--cyan); animation: tour-dot 1.2s ease-in-out infinite; }
@keyframes tour-dot { 50% { box-shadow: 0 0 0 4px rgba(140, 255, 251, 0.35); } }
.tour li.done { color: var(--green); }
.tour li.done::before { content: '✓'; border: 0; top: -3px; font: 700 24px var(--display); }
.tour li:not(.now) .walk-ways, .tour li:not(.now) .tour-hold { display: none; }
.tour li .walk-ways { margin: 6px 0 4px; }
.tour kbd { display: inline-block; padding: 0 6px; border: 2px solid var(--white); border-radius: 5px; font: 700 18px var(--display); line-height: 1.2; color: var(--white); }
.tour-hold { margin: 2px 0 4px; color: var(--yellow); font-weight: 700; animation: tour-dot 1.2s ease-in-out 3; }
.tour-ready { display: none; margin: 4px 0 2px; max-width: 360px; line-height: 1.3; }
.tour-ready b { color: var(--green); text-transform: uppercase; }
#help.ready .tour { display: none; }
#help.ready .tour-ready { display: block; }
body:not(.practice) #help .tour > li:not([data-step="walk"]), body:not(.practice) #help .tour > li > b,
body:not(.practice) #help .tour-ready { display: none; }
body:not(.practice) #help .tour > li { padding-left: 0; }
body:not(.practice) #help .tour > li::before { display: none; }
body:not(.practice) #help .tour > li .walk-ways { display: flex; }
body.practice #help { pointer-events: auto; }
.tour-ready p { margin: 0 0 8px; }
.tour-btns { display: flex; align-items: center; gap: 16px; }
.tour-btns .au-btn { font-size: 24px; padding: 0 16px; text-decoration: none; }
/* The practice ship has no race: no race bar, and its banner says so. */
body.practice #hud { display: none !important; }
body.practice #join { display: none; }
/* Its way out, where the race bar would be. */
#practice-exit { display: none; position: fixed; top: 12px; left: 12px; font-size: 30px; padding: 2px 18px; text-decoration: none; }
#practice-exit span { font-size: 0.7em; vertical-align: 0.12em; }
body.practice.playing:not(.in-scene):not(.map-open) #practice-exit { display: block; }
/* The step's targets: the little map pulses green; on the big map, Communications does (game.js). */
body.tour-map:not(.map-open) #minimap { animation: tour-ring 1.2s ease-out infinite; }
@keyframes tour-ring { from { box-shadow: 0 0 0 0 rgba(63, 242, 63, 0.9); } to { box-shadow: 0 0 0 16px rgba(63, 242, 63, 0); } }
#map-hint .tour-go { display: none; color: var(--green); }
body.tour-use #map-hint .tour-go { display: inline; }
.help-head { font: 700 26px var(--display); letter-spacing: 1px; text-transform: uppercase; line-height: 1; }
.walk-ways { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.walk-ways .or { font: 700 24px var(--display); color: #b9bec6; }
/* Keys laid out as on the keyboard: one on top, three below. */
.keycaps { display: grid; grid-template-columns: repeat(3, 40px); gap: 4px; }
.keycaps .cap:first-child { grid-column: 2; }
.keycaps .cap:not(:first-child) { grid-row: 2; }
.cap {
  display: grid; place-items: center; width: 40px; height: 40px; min-width: 0; padding: 0; margin: 0; box-sizing: border-box;
  border: 2.5px solid var(--white); border-bottom-width: 6px; border-radius: 8px; background: #000; color: var(--white);
  font: 700 26px var(--display); line-height: 1; -webkit-text-stroke: 1px currentColor; transition: transform 0.06s;
}
.cap svg { width: 20px; height: 20px; fill: currentColor; }
.cap.down, .mouse-way.down { color: var(--green); border-color: var(--green); }
.cap.down { transform: translateY(3px); border-bottom-width: 3px; }
.mouse-way { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--white); font-size: 16px; line-height: 1; }
.mouse { width: 34px; height: 48px; }
.mouse .body { fill: #000; stroke: currentColor; stroke-width: 2.5; }
.mouse .left { fill: currentColor; animation: mouse-hold 1.6s ease-in-out infinite; }
.mouse-way.down .left { animation: none; }
.mouse .line { fill: none; stroke: currentColor; stroke-width: 2.5; }
@keyframes mouse-hold { 50% { opacity: 0.25; } }

/* ---------- Race panel (styled like the TOTAL TASKS COMPLETED bar) ---------- */
.race { width: 390px; padding: 6px 10px 8px; background: rgba(0, 0, 0, 0.92); }
.race-head { display: flex; justify-content: space-between; font: 700 26px var(--display); letter-spacing: 1.5px; line-height: 1.1; }
.race-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.race-canvas { display: block; }
.race-foot { margin-top: 2px; font-size: 18px; }
.race-foot.good { color: var(--green); }
.race-foot.beam { color: var(--cyan); }
.race-foot.danger { color: var(--red); animation: blink 0.9s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }

/* ---------- Host / mission control ---------- */
body.host {
  overflow: auto; padding: 0 30px 30px; min-height: 100%;
  background:
    radial-gradient(1px 1px at 12% 18%, #fff8, transparent), radial-gradient(1px 1px at 72% 34%, #fff8, transparent),
    radial-gradient(1.5px 1.5px at 38% 72%, #fff9, transparent), radial-gradient(1px 1px at 88% 82%, #fff7, transparent),
    radial-gradient(1px 1px at 55% 12%, #fff6, transparent), radial-gradient(1.5px 1.5px at 22% 55%, #fff8, transparent),
    radial-gradient(ellipse at 50% 40%, #0b1030, #020309);
  background-size: 340px 300px, 410px 360px, 290px 330px, 380px 270px, 450px 390px, 320px 350px, 100% 100%;
  background-attachment: fixed;
}
/* Header with the controls stays in view while you scroll. */
body.host header {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 22px;
  padding: 12px 0 10px; background: #020309;
}
body.host .logo { font-size: 76px; }
body.host .subtitle { font: 700 40px var(--display); color: var(--muted); letter-spacing: 3px; -webkit-text-stroke: 1px currentColor; }
.race-big { width: 100%; padding: 12px 22px 16px; border-radius: 18px; }
.race-big .race-head { font-size: 40px; }
.race-big .race-foot { font-size: 26px; }
#standings { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.pill { padding: 0 11px; font: 700 24px var(--display); letter-spacing: 1px; border: 2px solid var(--white); border-radius: 999px; background: #000; }
.pill.escaped { border-color: var(--green); color: var(--green); }
.pill.caught { border-color: var(--red); color: var(--red); opacity: 0.75; }
.pill.absent { opacity: 0.5; }
#checkin { margin-top: 12px; color: var(--muted); font-size: 20px; line-height: 1.3; }
#checkin h2 { margin: 0 0 6px; font: 700 34px var(--display); letter-spacing: 1px; color: var(--white); -webkit-text-stroke: 1px currentColor; }
#checkin .grid { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; }
#checkin .grid > div { padding: 4px 10px 8px; border: 2px solid #555; border-radius: 10px; background: rgba(0, 0, 0, 0.6); }
#checkin b { font: 700 28px var(--display); letter-spacing: 1px; color: var(--white); -webkit-text-stroke: 1px currentColor; }
#checkin small { color: var(--muted); font-size: 16px; }
#checkin ul { margin: 2px 0 0; padding: 0; list-style: none; }
#checkin li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#checkin li.here { color: var(--green); }
#controls { display: flex; flex-wrap: wrap; align-items: center; gap: 18px; margin-left: auto; }
.img-btn { background: none; border: 0; padding: 0; cursor: pointer; transition: transform 0.1s; }
.img-btn[hidden] { display: none; }
.img-btn img { display: block; height: 72px; }
.img-btn:hover { transform: scale(1.06); filter: drop-shadow(0 0 8px var(--green)); }
.img-btn:disabled { opacity: 0.35; cursor: default; transform: none; filter: none; }
#controls .au-btn { font-size: 38px; padding: 4px 30px; }
#controls #reset.au-btn { color: var(--green); border-color: var(--green); }
.race-time.paused { color: var(--yellow); }
.au-btn:disabled { opacity: 0.35; cursor: default; color: var(--white); border-color: var(--white); }
#controls .link { font-size: 20px; }
.hint { color: var(--muted); font-size: 18px; margin: 0 0 8px; }
#testing { margin-top: 16px; }
#testing summary { cursor: pointer; color: var(--muted); font: 700 28px var(--display); letter-spacing: 1px; }
#testing[open] { display: grid; gap: 10px; }
#testing .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
#testing h2 { margin: 0; width: 90px; font: 700 34px var(--display); letter-spacing: 1px; -webkit-text-stroke: 1px currentColor; }
#testing .hint { margin: 0; }
#boosts { display: flex; flex-wrap: wrap; gap: 8px; }
#boosts .au-btn { font-size: 24px; padding: 0 14px; }
#lights { font-size: 24px; padding: 0 14px; }
#kill, #mission { font-size: 24px; padding: 0 14px; }
#kill-name, #mission-ship, #mission-id {
  height: 36px; padding: 0 10px; color: var(--white); background: #000; border: 3px solid var(--white); border-radius: 10px;
  font: 20px var(--body); cursor: pointer;
}
/* The results (js/results.js): mission control's panel and the players' card. */
.results-panel { margin-bottom: 14px; padding: 8px 22px 12px; background: var(--panel); border: 3px solid var(--green); border-radius: 14px; }
#results h2 { margin: 0; font: 700 56px var(--display); letter-spacing: 1px; -webkit-text-stroke: 1px currentColor; color: var(--cyan); }
#results h3 { margin: 10px 0 0; font: 700 34px var(--display); letter-spacing: 1px; -webkit-text-stroke: 1px currentColor; }
#results ol { margin: 4px 0 0; padding-left: 40px; font-size: 26px; line-height: 1.35; }
#results li b { font: 700 36px var(--display); letter-spacing: 1px; -webkit-text-stroke: 1px currentColor; }
#results li.escaped { color: var(--green); }
#results li.caught { color: #ff8080; }
#results li.mine { text-shadow: 0 0 12px rgba(245, 245, 87, 0.6); }
#results li.mine::marker { color: var(--yellow); }
#results .heroes { display: block; margin-top: -4px; color: var(--white); font-size: 20px; }
#results .heroes b { font: inherit; -webkit-text-stroke: 0; color: var(--yellow); }
#results .deals { margin: 4px 0 0; padding-left: 24px; font-size: 22px; list-style: none; }
#results .deals li { margin: 2px 0; color: #ff8080; }
#results .deals li b { font: 700 28px var(--display); -webkit-text-stroke: 0.6px currentColor; }
#results .deals q { display: block; color: var(--white); font-style: italic; }
#results .deals.none { color: var(--muted); }
/* The players' card, over the ship. */
#results.overlay { z-index: 9; background: rgba(0, 0, 0, 0.6); }
.results-card { width: min(760px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; }
body.in-scene #results.overlay { display: none; }

/* ---------- Recalibrate navigation ---------- */
/* Task list under the race panel, like the real game's: yellow while under way, green when done. */
#tasks { margin-top: 8px; width: fit-content; min-width: 230px; padding: 4px 12px 6px; font-size: 19px; }
#tasks:not(:has(> div:not([hidden]))) { display: none; } /* nothing enabled yet */
#tasks h3 { margin: 0; font: 700 24px var(--display); letter-spacing: 1px; -webkit-text-stroke: 1px currentColor; }
#task-nav.going, #task-clock.going { color: var(--yellow); }
#task-nav.done, #task-clock.done { color: var(--task); }

/* USE button in the corner (bottom right, above the mini-map, like the real one): only when it has no place on the map. */
#use-box { position: fixed; right: 14px; bottom: 160px; display: none; flex-direction: column; align-items: center; gap: 4px; }
body.playing #use-box { display: flex; }
body.in-scene #use-box, body.map-open #use-box, body.nav-open #use-box, body.quiz-open #use-box, body.clock-open #use-box, body.comms-open #use-box, body.power-open #use-box, body.jump-open #use-box { display: none; }
#use-btn, #use-here {
  width: 116px; height: 116px; display: grid; place-items: center; align-content: center; gap: 0; cursor: pointer;
  background: rgba(0, 0, 0, 0.55); border: 4px solid var(--white); border-radius: 22px; color: var(--white);
  font: 700 36px var(--display); letter-spacing: 2px; line-height: 0.9; -webkit-text-stroke: 1.4px currentColor; paint-order: stroke fill;
  animation: use-pop 0.2s ease-out;
}
#use-btn[hidden] { display: none; }
#use-btn svg { width: 58px; height: 58px; }
:is(#use-btn, #use-here):hover:not(:disabled) { color: var(--green); border-color: var(--green); }
:is(#use-btn, #use-here):hover:not(:disabled) path { fill: var(--green); }
#use-btn:disabled { opacity: 0.4; cursor: default; }
/* The button over the console you can use, where its yellow arrow was: people who
   don't play games look and click there, not in the corner. Placed by use.js. */
#use-here {
  --s: 84px; position: fixed; z-index: 1; left: 0; top: 0; display: none; /* over the HUD's panels: never hidden under the task list */ width: var(--s); height: var(--s); margin: calc(-36px - var(--s)) 0 0 calc(var(--s) / -2);
  background: rgba(0, 0, 0, 0.75); border-width: 3px; border-radius: 18px; font-size: 27px; -webkit-text-stroke-width: 1px;
  animation: use-pop 0.2s ease-out, use-bob 1.57s ease-in-out infinite;
}
body.playing:not(.in-scene, .map-open, .nav-open, .quiz-open, .clock-open, .comms-open, .power-open, .jump-open) #use-here:not([hidden]) { display: grid; }
#use-here svg { width: 42px; height: 42px; }
#use-here::after {
  content: ''; position: absolute; left: 50%; top: 100%; width: 44px; height: 32px; margin: 4px 0 0 -22px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 52 40'%3E%3Cpath d='M0 0h44L22 32z' fill='%23f5f557' stroke='%23000' stroke-width='6' stroke-linejoin='round' paint-order='stroke'/%3E%3C/svg%3E") center / contain no-repeat;
}
@keyframes use-bob { 50% { translate: 0 -8px; } }
#use-note { max-width: 200px; padding: 0 10px; background: var(--panel); border: 2px solid var(--white); border-radius: 8px; font-size: 17px; text-align: center; }
#use-note[hidden] { display: none; }
@keyframes use-pop { from { transform: scale(0.6); opacity: 0; } }

/* The game shrunk to a corner badge: click to bring it back. */
#badges { position: fixed; top: 86px; right: 14px; z-index: 3; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
body:not(.playing) #badges, body.in-scene #badges, body.map-open #badges, body.jump-open #badges, body.power-open #badges { display: none; }
/* Over the navigation game too: the navigator can't shrink it, and still needs the chat. */
body.nav-open #badges, body.clock-open #badges { z-index: 6; }
body.touch.nav-open #badges, body.touch.clock-open #badges, body.touch.quiz-open #badges { display: none; } /* a phone has no room: the card would be covered */
#nav-badge, #comms-badge, #quiz-badge, #clock-badge {
  padding: 2px 16px; cursor: pointer;
  background: var(--panel); border: 3px solid var(--white); border-radius: 12px; color: var(--white);
  font: 700 28px var(--display); letter-spacing: 1px; text-transform: uppercase; -webkit-text-stroke: 1.2px currentColor; paint-order: stroke fill;
}
#nav-badge[hidden], #comms-badge[hidden], #quiz-badge[hidden], #clock-badge[hidden] { display: none; }
#nav-badge:hover, #quiz-badge:hover, #clock-badge:hover { color: var(--green); border-color: var(--green); }

/* The popup the whole crew watches. */
#nav { z-index: 5; background: rgba(0, 0, 0, 0.6); }
body.in-scene #nav { display: none; }
.nav-card { width: min(1100px, 100%); align-items: center; gap: 6px; padding: 10px 26px 14px; text-align: center; }
.nav-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; width: 100%; }
.nav-head h2 { grid-column: 2; }
.nav-count { grid-column: 3; justify-self: end; color: var(--muted); font-size: 20px; }
.nav-card .nav-count, .quiz-card .nav-count, .clock-card .nav-count { margin-right: 52px; }
.nav-card p.nav-ask { margin: 0; font-size: 26px; color: var(--white); }
.nav-ask b { color: var(--yellow); font-weight: 400; }
.nav-card p.nav-who { margin: 0; min-height: 1.4em; font-size: 22px; color: #d9dde4; }
.nav-card .good { color: var(--green); font-weight: 400; }
.nav-card .bad { color: var(--red); font-weight: 400; }
.nav-pics { display: flex; justify-content: center; gap: clamp(14px, 3vw, 40px); margin: 6px 0; }
.nav-pic {
  --size: min(42vw, 100vh - 300px, 470px);
  position: relative; width: var(--size); height: var(--size); padding: 0; overflow: hidden;
  background: #000; border: 5px solid #555; border-radius: 14px; cursor: default;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.nav-pic[hidden] { display: none; }
.nav-pic img { display: block; width: 100%; height: 100%; object-fit: cover; }
/* The navigator's pick-to-be glows for everyone. */
.nav-pic:not(:disabled) { cursor: pointer; }
.nav-pic.hover, .nav-pic:not(:disabled):hover { border-color: var(--yellow); box-shadow: 0 0 22px rgba(245, 245, 87, 0.6); transform: scale(1.02); }
.nav-pic.real { border-color: var(--green); box-shadow: 0 0 26px rgba(63, 242, 63, 0.6); }
.nav-pic.fake { border-color: var(--red); }
.nav-pic.fake img { filter: grayscale(0.6) brightness(0.6); }
.nav-pic:disabled { color: inherit; }
.nav-tag:empty { display: none; }
.nav-tag {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); padding: 0 16px;
  background: #000; border: 3px solid currentColor; border-radius: 10px;
  font: 700 36px var(--display); letter-spacing: 2px; -webkit-text-stroke: 1.2px currentColor; paint-order: stroke fill;
}
.nav-pic.real .nav-tag { color: var(--green); }
.nav-pic.fake .nav-tag { color: var(--red); }
.nav-pic.picked::after {
  content: 'Our pick'; position: absolute; top: 10px; left: 50%; transform: translateX(-50%); padding: 0 12px;
  background: #000; border: 2px solid var(--white); border-radius: 8px; color: var(--white); font: 22px var(--body);
}
.nav-quit[hidden] { display: none; }
.nav-card.finished { padding: 22px 30px; }
.nav-card.finished .nav-ask { font-size: 34px; }

/* ---------- The AI's quiz at the Communications console ---------- */
#quiz, #clock { z-index: 5; background: rgba(0, 0, 0, 0.6); }
body.in-scene #quiz, body.in-scene #clock { display: none; }
.quiz-card { width: min(940px, 100%); align-items: center; gap: 8px; padding: 10px 26px 14px; text-align: center; }
.quiz-card p.quiz-ai {
  display: flex; align-items: center; justify-content: center; gap: 14px; margin: 0; min-height: 76px;
  font: 700 32px/1.1 var(--display); letter-spacing: 1px; color: #ff5a5a; text-align: left;
}
.quiz-ai img { flex: none; height: 64px; }
.quiz-card p.quiz-ask { margin: 0; font-size: 26px; line-height: 1.25; color: var(--white); }
.quiz-ask b { color: var(--yellow); font-weight: 400; }
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin: 4px 0; }
.quiz-option {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; text-align: left;
  background: #000; color: var(--white); border: 3px solid var(--white); border-radius: 12px; font: 22px/1.2 var(--body);
}
.quiz-option[hidden] { display: none; }
.quiz-option i {
  flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: var(--white); color: #000; font: 700 28px var(--display); font-style: normal;
}
.quiz-option:disabled { color: var(--white); }
.quiz-option:not(:disabled) { cursor: pointer; }
.quiz-option:not(:disabled, .picked):hover { color: var(--green); border-color: var(--green); }
.quiz-option:not(:disabled, .picked):hover i { background: var(--green); }
.quiz-option.picked { color: var(--yellow); border-color: var(--yellow); box-shadow: 0 0 20px rgba(245, 245, 87, 0.55); }
.quiz-option.picked i { background: var(--yellow); }
.quiz-option.right { color: var(--green); border-color: var(--green); box-shadow: 0 0 22px rgba(63, 242, 63, 0.55); }
.quiz-option.right i { background: var(--green); }
.quiz-option.wrong { color: var(--red); border-color: var(--red); }
.quiz-option.wrong i { background: var(--red); }
.quiz-card.reveal .quiz-option:not(.right, .wrong) { opacity: 0.4; }
.quiz-lock.au-btn, .clock-lock.au-btn { font-size: 34px; padding: 0 30px; }
.quiz-lock[hidden], .clock-lock[hidden], .quiz-quit[hidden], .clock-quit[hidden], .clock-play[hidden] { display: none; }
.quiz-card p.quiz-who, .clock-card p.clock-who { margin: 0; min-height: 1.4em; font-size: 22px; color: #d9dde4; }
.quiz-card .good, .clock-card .good { color: var(--green); font-weight: 400; }
.quiz-card .bad, .clock-card .bad { color: var(--red); font-weight: 400; }
.quiz-card.done { padding: 22px 30px; }
.quiz-card.done .quiz-ask { font-size: 34px; }

/* ---------- Set the ship's clock: the jukebox in Storage ---------- */
.clock-card { width: min(940px, 100%); align-items: center; gap: 6px; padding: 10px 26px 14px; text-align: center; }
.clock-card p.clock-ask { margin: 0; font-size: 26px; color: var(--white); }
.clock-ask b { color: var(--yellow); font-weight: 400; }
.clock-body { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; }
.clock-song { display: flex; align-items: center; justify-content: center; gap: 18px; min-height: 52px; }
.clock-play.au-btn { font-size: 26px; padding: 0 18px; }
/* The song's bars: still until it plays. */
.clock-bars { display: flex; align-items: flex-end; gap: 5px; height: 44px; }
.clock-bars i { width: 9px; height: 18%; background: var(--cyan); border-radius: 3px; }
.clock-body.playing .clock-bars i { animation: clock-bar 0.5s ease-in-out infinite alternate; }
.clock-bars i:nth-child(2) { animation-delay: -0.2s; animation-duration: 0.42s; }
.clock-bars i:nth-child(3) { animation-delay: -0.35s; animation-duration: 0.6s; }
.clock-bars i:nth-child(4) { animation-delay: -0.1s; animation-duration: 0.38s; }
.clock-bars i:nth-child(5) { animation-delay: -0.3s; animation-duration: 0.55s; }
.clock-bars i:nth-child(6) { animation-delay: -0.15s; animation-duration: 0.46s; }
.clock-bars i:nth-child(7) { animation-delay: -0.4s; animation-duration: 0.52s; }
@keyframes clock-bar { from { height: 14%; } to { height: 100%; } }
.clock-year { display: flex; align-items: center; justify-content: center; gap: 22px; }
.clock-year output { min-width: 3.2ch; font: 700 110px/1 var(--display); letter-spacing: 3px; color: var(--yellow); -webkit-text-stroke: 3px currentColor; paint-order: stroke fill; font-variant-numeric: tabular-nums; }
.clock-dial { width: 100%; padding: 0 22px; box-sizing: border-box; }
.clock-track { position: relative; height: 26px; margin: 18px 0 4px; background: #000; border: 3px solid var(--white); border-radius: 14px; touch-action: none; }
.clock-track.mine { cursor: pointer; border-color: var(--yellow); }
.clock-thumb {
  position: absolute; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; box-sizing: border-box; pointer-events: none;
  background: var(--yellow); border: 4px solid #000; border-radius: 50%; box-shadow: 0 0 0 3px var(--white);
}
/* The year the song came out, once the dial is locked. */
.clock-true {
  position: absolute; top: -9px; bottom: -9px; min-width: 8px; margin-left: -4px; box-sizing: content-box;
  background: var(--green); border-radius: 5px; box-shadow: 0 0 14px rgba(63, 242, 63, 0.8);
}
.clock-true[hidden] { display: none; }
/* Once locked, the dial shows what every year was worth: green at the right year, through yellow, to red at the far end. */
.clock-card.revealed .clock-track { background: var(--worth, #000); }
.clock-true::after { content: attr(data-year); position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); font: 700 30px var(--display); color: var(--green); white-space: nowrap; }
.clock-card.revealed .clock-year output { color: var(--white); font-size: 84px; }
.clock-card.revealed .clock-song { display: none; }
.clock-card.revealed .clock-track { margin-top: 48px; } /* room for the real year over the dial */
/* What the AI makes of the guess, in its red. */
.clock-card p.clock-ai { margin: 0; font: 700 32px/1.1 var(--display); letter-spacing: 1px; color: #ff5a5a; }
.clock-ai[hidden], .clock-muted[hidden] { display: none; }
.clock-muted { max-width: 300px; font-size: 18px; line-height: 1.15; color: var(--yellow); text-align: left; }
/* Under the answer, the big year is only our guess: say so. */
.clock-said { display: none; font-size: 24px; color: var(--muted); }
.clock-card.revealed .clock-said { display: inline; }
.clock-ticks { position: relative; height: 28px; }
.clock-ticks span { position: absolute; top: 0; transform: translateX(-50%); padding-top: 9px; font: 700 22px var(--display); color: var(--muted); }
.clock-ticks span::before { content: ''; position: absolute; left: 50%; top: 0; width: 2px; height: 8px; background: var(--muted); }
.clock-card.finished { padding: 22px 30px; }
.clock-card.finished .clock-ask { font-size: 34px; }
.clock-card.finished :is(.clock-body, .clock-lock, .clock-quit, .clock-min) { display: none; }

/* ---------- Comms: the chat between ships ---------- */
#task-comms.done { color: var(--task); }
#task-comms.going { color: var(--yellow); }
#task-comms[hidden] { display: none; }

/* ---------- The Sealed Reactor ---------- */
#task-reactor { color: var(--red); }
#task-reactor.done { color: var(--task); }
#task-reactor[hidden] { display: none; }
/* Sealed: the task line flashes, like an Among Us sabotage. */
#task-reactor.sealed { animation: sabotage 1s steps(2, jump-none) infinite; }
@keyframes sabotage { 50% { color: var(--white); } }
#airlock { z-index: 3; background: rgba(0, 0, 0, 0.6); }
body.in-scene #airlock { display: none; }
.airlock-card { border-color: var(--red); }
.airlock-card h2 { color: var(--red); }
.airlock-note { color: var(--yellow); }
.airlock-btns { display: flex; gap: 18px; margin-top: 6px; }
.airlock-card .airlock-go { color: var(--red); border-color: var(--red); }
.airlock-card .au-btn:hover { color: var(--green); border-color: var(--green); }

/* The chat shrunk to a corner badge: white, flashing green with new messages. */
#comms-badge { background: var(--panel); border: 3px solid var(--white); border-radius: 12px; color: var(--white);
  font: 700 28px var(--display); letter-spacing: 1px; text-transform: uppercase; -webkit-text-stroke: 1.2px currentColor; paint-order: stroke fill; }
#comms-badge b { display: none; margin-left: 4px; padding: 0 9px; border-radius: 999px; background: var(--green); color: #000; -webkit-text-stroke: 0.6px #000; }
#comms-badge.unread { border-color: var(--green); color: var(--green); }
#comms-badge.unread b { display: inline-block; }
#comms-badge.flash { animation: badge-flash 0.5s ease-out 3; }
#comms-badge:hover { color: var(--green); border-color: var(--green); }
@keyframes badge-flash { 50% { transform: scale(1.12); box-shadow: 0 0 22px var(--green); } }
#comms-preview {
  max-width: 340px; padding: 4px 12px; background: var(--white); color: #111; border-radius: 12px; border: 3px solid #000;
  font-size: 19px; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  animation: use-pop 0.2s ease-out; pointer-events: none;
}
#comms-preview[hidden] { display: none; }

/* The popup: a full window like the navigation game's, so nobody has to find it. */
#comms { z-index: 4; background: rgba(0, 0, 0, 0.6); }
body.comms-front #comms { z-index: 6; } /* opened from its badge over the navigation game */
body.in-scene #comms { display: none; }
.comms-card { position: relative; width: min(860px, 100%); height: min(760px, 100%); gap: 6px; padding: 10px 22px 14px; }
.comms-head { display: flex; align-items: center; gap: 16px; padding-right: 52px; }
.comms-ships { display: flex; gap: 6px; margin-left: auto; }
.comms-ships .pill { min-width: 30px; text-align: center; padding: 0 8px; color: #666; border-color: #555; }
.comms-ships .pill.online { color: var(--green); border-color: var(--green); }
.comms-ships .pill.mine { color: var(--yellow); border-color: var(--yellow); }
.comms-card p.comms-intro { margin: 0; font-size: 18px; color: var(--muted); }
.comms-log {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px;
  background: #1b1f27; border: 2px solid #555; border-radius: 12px;
}

/* Messages, as Among Us chat bubbles: icon, then a white bubble with the name on top. */
.msg { display: flex; align-items: flex-start; gap: 8px; max-width: 82%; }
.msg .icon { flex: none; width: 46px; height: 46px; object-fit: contain; }
.msg .bubble { padding: 3px 12px 6px; background: #fff; color: #111; border-radius: 12px; border: 2px solid #000; min-width: 0; }
.msg .head { display: flex; align-items: baseline; gap: 8px; }
.msg .head b { font: 700 24px var(--display); letter-spacing: 0.5px; -webkit-text-stroke: 0.8px #000; paint-order: stroke fill; }
.msg .ship { color: #777; font-size: 15px; }
.msg .text { font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.mine .bubble { background: #e8f6ff; }
.msg.system { align-self: center; max-width: 100%; color: var(--muted); font-size: 17px; text-align: center; }
/* The AI: its icon shown whole like everyone's, its bubble enemy red. */
.msg.ai .bubble { background: #c51111; color: #fff; }
.msg.ai .head b { color: #fff; }
/* What a deal or mercy did to the race, under the AI's line. */
.msg .effect { font: 700 22px var(--display); letter-spacing: 1px; text-transform: uppercase; -webkit-text-stroke: 0.6px #000; paint-order: stroke fill; }
.msg .effect .up { color: var(--green); }
.msg .effect .down { color: var(--yellow); }

.comms-typing { color: var(--red); font-size: 18px; }
.comms-typing[hidden] { display: none; }
.comms-form { display: flex; gap: 10px; }
.comms-form input {
  flex: 1; min-width: 0; padding: 4px 14px; background: #fff; color: #111; border: 3px solid var(--white); border-radius: 10px;
  font: 22px var(--body); outline: none;
}
.comms-form input:focus { border-color: var(--green); }
.comms-form .au-btn { font-size: 30px; padding: 0 22px; }
/* Mission control reads the chat. */
#host-chat { margin-top: 14px; }
#host-chat[hidden] { display: none; }
#host-chat h2 { margin: 0 0 6px; font: 700 34px var(--display); letter-spacing: 1px; -webkit-text-stroke: 1px currentColor; }
#host-chat h2 small { color: var(--muted); font: 18px var(--body); -webkit-text-stroke: 0; letter-spacing: 0; margin-left: 8px; }
#host-chat .comms-log { height: 420px; }

/* ---------- Electrical sacrifice ---------- */
#task-power.bad { color: var(--red); animation: blink 0.9s steps(2) infinite; }
#task-power.done { color: var(--task); }
#task-power[hidden] { display: none; }
#task-jump.bad { color: var(--red); animation: blink 0.9s steps(2) infinite; }
#task-jump.done { color: var(--task); }
#power { z-index: 6; background: rgba(0, 0, 0, 0.55); }
body.in-scene #power { display: none; }
.power-card { border-color: var(--red); }
.power-card h2 { color: var(--red); }
.power-btns { display: flex; gap: 18px; justify-content: center; margin-top: 6px; }
/* The two "die for the ship" cards: the deadly button red, the safe one focused (green). */
.power-btns .au-btn:focus-visible, .airlock-btns .au-btn:focus-visible { outline: none; color: var(--green); border-color: var(--green); }
.power-card .power-yes { color: var(--red); border-color: var(--red); }
.power-card .au-btn:hover { color: var(--green); border-color: var(--green); }

/* ---------- Event alerts ---------- */
/* Mission control launched an event: a full-screen splash like Among Us's
   "Emergency meeting", red for the AI's crises, blue for news. */
#alert {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 0 24px; background: rgba(0, 0, 0, 0.72); text-align: center; cursor: pointer;
  animation: alert-in 0.25s ease-out;
}
#alert[hidden] { display: none; }
#alert { --band: #a40c0c; --band-dark: #4a0000; }
#alert.news { --band: #0d5fa8; --band-dark: #031f3d; }
.alert-band {
  position: relative; width: 100vw; display: flex; align-items: center; justify-content: center; gap: 28px; padding: 26px 0;
  border-block: 6px solid #000;
  background: repeating-linear-gradient(100deg, transparent 0 90px, rgba(255, 255, 255, 0.10) 90px 104px, transparent 104px 200px),
    linear-gradient(var(--band-dark), var(--band) 30%, var(--band) 70%, var(--band-dark));
  background-size: 400px 100%, 100% 100%;
  animation: alert-band 0.35s ease-out, alert-lines 1.2s linear infinite;
}
.alert-ai { height: 190px; filter: drop-shadow(0 0 18px rgba(63, 242, 63, 0.5)); animation: alert-ai 0.5s ease-out; }
#alert.news .alert-ai { display: none; }
.alert-title {
  margin: 0; font: 700 132px var(--display); line-height: 1; letter-spacing: 6px; text-transform: uppercase; color: var(--white);
  -webkit-text-stroke: 12px #000; paint-order: stroke fill; animation: alert-title 0.45s cubic-bezier(.2, 1.6, .5, 1);
}
.alert-what { margin: 0; max-width: 900px; font: 34px var(--body); line-height: 1.25; -webkit-text-stroke: 6px #000; paint-order: stroke fill; }
.alert-go { margin: 0; font: 700 56px var(--display); letter-spacing: 2px; text-transform: uppercase; -webkit-text-stroke: 8px #000; paint-order: stroke fill; }
.alert-go b { color: var(--yellow); }
/* The AI's own line, in its enemy red, as in the chat. */
.alert-taunt { margin: 0; font: 700 40px var(--display); letter-spacing: 1px; color: #ff5a5a; -webkit-text-stroke: 7px #000; paint-order: stroke fill; }
/* A mission's time left before the AI wins it, after its task line. */
#tasks > div[data-left]::after { content: ' ' attr(data-left); color: var(--white); font-variant-numeric: tabular-nums; }
@keyframes alert-in { from { opacity: 0; } }
@keyframes alert-band { from { transform: scaleY(0); } }
@keyframes alert-lines { to { background-position: 400px 0, 0 0; } }
@keyframes alert-ai { from { transform: translateX(-60vw) rotate(-20deg); } }
@keyframes alert-title { from { transform: scale(2.2); opacity: 0; } }

/* ---------- The jump code's keypad ---------- */
/* The "?" card: over everything you can open yourself, under an event's alert. */
#guide { z-index: 8; background: rgba(0, 0, 0, 0.55); }
.guide-card { width: min(760px, 100%); align-items: center; gap: 10px; }
.guide-card dl { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; margin: 4px 0 6px; font-size: 21px; line-height: 1.35; }
.guide-card dt { font: 700 28px var(--display); letter-spacing: 1px; text-transform: uppercase; color: var(--yellow); line-height: 1.1; }
.guide-card dd { margin: 0; color: #d9dde4; }
.guide-card dd b { color: var(--white); }
.guide-card .au-btn { font-size: 32px; padding: 2px 30px; }
.guide-keys { margin: 0; font-size: 19px; color: #d9dde4; text-align: center; }
.guide-card kbd { display: inline-block; min-width: 1.2em; padding: 0 5px; margin: 0 1px; border: 2px solid var(--white); border-radius: 5px; font: 700 19px var(--display); line-height: 1.2; text-align: center; color: var(--white); }
.guide-card dt.guide-now { color: var(--cyan); }
.guide-card dd.guide-now { color: var(--white); }
.guide-card .mark-y { color: var(--yellow); }
.guide-card .mark-r { color: #ff5a5a; }
.guide-card .mark-g { color: var(--green); }
#jump { z-index: 3; background: rgba(0, 0, 0, 0.55); }
body.in-scene #jump { display: none; }
.jump-display { display: flex; gap: 10px; justify-content: center; margin: 4px 0; }
.jump-display span {
  width: 62px; height: 78px; display: grid; place-items: center; background: #06121f; border: 3px solid var(--white); border-radius: 10px;
  color: var(--green); font: 700 62px var(--display); line-height: 1;
}
.jump-note { min-height: 1.3em; margin: 0; color: var(--yellow); }
.jump-keys { display: grid; grid-template-columns: repeat(3, 88px); gap: 8px; justify-content: center; }
.card.small .jump-keys .au-btn { font-size: 34px; padding: 0; height: 56px; }
.card.small .jump-keys .jump-ok { color: var(--green); border-color: var(--green); }

/* ---------- Phones and tablets ----------
   body.touch is set only on touch screens (js/touch.js), so nothing below reaches a desktop.
   They walk with a joystick, and a small screen gets a compact HUD and popups that fit. */
.on-touch { display: none; }
body.touch .on-touch { display: revert; }
body.touch .on-keys, body.touch:not(.practice) #help { display: none !important; }
body.touch { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
body.touch input { -webkit-user-select: text; user-select: text; }
body.touch button, body.touch .overlay { touch-action: manipulation; } /* no double-tap zoom */

/* The joystick, fixed in the bottom-left corner; its touch area reaches a little past the ring. */
#stick {
  display: none; position: fixed; left: 92px; top: calc(100% - 92px); width: 128px; height: 128px; margin: -64px 0 0 -64px;
  border-radius: 50%; background: rgba(0, 0, 0, 0.35); border: 3px solid rgba(255, 255, 255, 0.5); touch-action: none;
}
#stick::before { content: ''; position: absolute; inset: -24px; border-radius: 50%; }
body.touch.playing #stick { display: block; }
body.touch.in-scene #stick, body.touch.map-open #stick { display: none; }
#stick.held { background: rgba(0, 0, 0, 0.45); border-color: var(--white); }
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.85); border: 3px solid #000; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}
#stick.held .stick-knob { background: var(--white); }
.stick-hint {
  position: absolute; bottom: calc(100% + 6px); left: -8px; white-space: nowrap;
  font: 700 22px var(--display); letter-spacing: 1px; text-transform: uppercase;
  -webkit-text-stroke: 5px #000; paint-order: stroke fill; transition: opacity 1.5s;
}
body.seasoned .stick-hint, #stick.held .stick-hint { opacity: 0; }

/* Phones sideways: the joystick's hint beside it, not above, where the task list reaches down. */
@media (max-height: 540px) and (orientation: landscape) {
  body.touch .stick-hint { bottom: auto; top: 50%; left: calc(100% + 12px); transform: translateY(-50%); }
}

/* Small screens: phones either way up (keep in step with small() in js/touch.js). */
@media (max-height: 540px), (max-width: 600px) {
  /* HUD */
  body.touch #race, body.touch #tasks { zoom: 0.62; }
  body.touch #hud { top: 8px; left: 8px; }
  body.touch #corner { top: 8px; right: 8px; gap: 6px; }
  body.touch .round-btn { width: 46px; height: 46px; }
  body.touch .round-btn img { width: 44px; height: 44px; }
  body.touch #banner, body.touch #ghost-banner { top: 8px; padding: 0 12px; font-size: 20px; border-width: 2px; }
  body.touch #room { font-size: 34px; -webkit-text-stroke-width: 5px; }
  body.touch #toast { top: 64px; max-width: calc(100vw - 24px); width: max-content; padding: 2px 14px; font-size: 22px; white-space: normal; text-align: center; }
  body.touch #warning { top: 52px; padding: 0 16px; font-size: 26px; }
  body.touch:not(.map-open) #minimap { right: 8px; bottom: 8px; }
  body.touch #use-box { right: 8px; bottom: 104px; }
  body.touch #use-btn { width: 84px; height: 84px; border-radius: 18px; font-size: 26px; }
  body.touch #use-btn svg { width: 40px; height: 40px; }
  body.touch #use-here { --s: 66px; border-radius: 14px; font-size: 21px; }
  body.touch #use-here svg { width: 32px; height: 32px; }
  body.touch #use-note { max-width: 160px; font-size: 14px; }
  body.touch #badges { top: 62px; right: 8px; gap: 6px; }
  body.touch #nav-badge, body.touch #comms-badge, body.touch #quiz-badge, body.touch #clock-badge { padding: 0 12px; font-size: 21px; }
  body.touch #comms-preview { max-width: 230px; font-size: 15px; }
  body.touch.map-open #map-hint { bottom: 6px; font-size: 20px; white-space: nowrap; }
  body.touch #stick { left: 76px; top: calc(100% - 76px); }
  /* The practice card: small, top left (no race bar here), no keys to show. */
  body.touch #practice-exit { top: 8px; left: 8px; font-size: 20px; padding: 0 12px; border-width: 2px; }
  body.touch.practice #help { top: 54px; bottom: auto; left: 8px; max-width: min(340px, 48vw); padding: 4px 10px 6px; font-size: 14px; border-width: 2px; }
  body.touch.practice #help .help-head { min-height: 34px; font-size: 20px; padding-right: 40px; }
  body.touch.practice #help-close { width: 34px; height: 34px; }
  body.touch.practice #help .walk-ways, body.touch.practice .tour li[data-step="walk"] .on-touch { display: none; }
  body.touch.practice .tour li { padding-left: 24px; }
  body.touch.practice .tour li::before { width: 14px; height: 14px; }
  body.touch.practice .tour-btns .au-btn { font-size: 18px; }

  /* Popups fill the screen and scroll if they must. */
  body.touch .overlay { padding: 6px; }
  body.touch .card { max-height: 100%; overflow-y: auto; padding: 8px 14px 10px; }
  body.touch .card h2 { font-size: 30px; }
  body.touch .card p { font-size: 16px; margin-bottom: 4px; }
  body.touch .card.small .au-btn { font-size: 24px; padding: 2px 20px; }
  body.touch .x-btn { top: 6px; right: 6px; width: 36px; height: 36px; }

  /* Recalibrate navigation */
  body.touch .nav-card { gap: 2px; padding: 6px 12px 8px; }
  body.touch :is(.nav-card, .quiz-card, .clock-card) .nav-count { margin-right: 40px; font-size: 14px; }
  body.touch .nav-card p.nav-ask { font-size: 17px; line-height: 1.2; }
  body.touch .nav-card p.nav-who { font-size: 15px; line-height: 1.2; }
  body.touch .nav-quit { font-size: 15px; }
  body.touch .nav-pics { margin: 2px 0; }
  body.touch .nav-card > * { flex-shrink: 0; } /* too tall: it scrolls rather than squash */
  body.touch .nav-pic { --size: min(40vw, 100dvh - 150px); border-width: 4px; }
  body.touch .nav-tag { bottom: 6px; padding: 0 10px; font-size: 24px; }
  body.touch .nav-pic.picked::after { top: 6px; font-size: 16px; }
  body.touch .nav-card.finished .nav-ask { font-size: 24px; }

  /* The AI's quiz and the ship's clock */
  body.touch .quiz-card, body.touch .clock-card { gap: 3px; padding: 6px 12px 8px; }
  body.touch .quiz-card > *, body.touch .clock-card > * { flex-shrink: 0; } /* too tall: it scrolls rather than squash */
  body.touch .quiz-card p.quiz-ai { min-height: 40px; gap: 8px; font-size: 19px; }
  body.touch .quiz-ai img { height: 36px; }
  body.touch .quiz-card p.quiz-ask, body.touch .clock-card p.clock-ask { font-size: 17px; line-height: 1.2; }
  body.touch .quiz-options { gap: 5px; margin: 2px 0; }
  body.touch .quiz-option { gap: 8px; padding: 4px 8px; font-size: 15px; border-width: 2px; }
  body.touch .quiz-option i { width: 26px; height: 26px; font-size: 20px; }
  body.touch .quiz-lock.au-btn, body.touch .clock-lock.au-btn { font-size: 24px; padding: 0 22px; }
  body.touch .quiz-card p.quiz-who, body.touch .clock-card p.clock-who { font-size: 15px; line-height: 1.2; }
  body.touch .quiz-quit, body.touch .clock-quit { font-size: 15px; }
  body.touch .quiz-card.done .quiz-ask, body.touch .clock-card.finished .clock-ask { font-size: 24px; }
  body.touch .clock-song { min-height: 34px; gap: 12px; }
  body.touch .clock-bars { height: 28px; gap: 4px; }
  body.touch .clock-bars i { width: 6px; }
  body.touch .clock-play.au-btn { font-size: 20px; }
  body.touch .clock-year { gap: 16px; }
  body.touch .clock-year output { font-size: 58px; }
  body.touch .clock-track { height: 22px; margin: 16px 0 2px; }
  body.touch .clock-thumb { width: 40px; height: 40px; margin: -20px 0 0 -20px; }
  body.touch .clock-true::after { font-size: 20px; }
  body.touch .clock-card p.clock-ai { font-size: 20px; }
  body.touch .clock-card.revealed .clock-year output { font-size: 46px; }
  body.touch .clock-card.revealed .clock-track { margin-top: 36px; }
  body.touch .clock-said { font-size: 16px; }
  body.touch .clock-muted { font-size: 14px; }
  body.touch .clock-ticks { height: 20px; }
  body.touch .clock-ticks span { font-size: 15px; padding-top: 6px; }
  body.touch .clock-ticks span::before { height: 5px; }

  /* Comms */
  body.touch .comms-card { width: 100%; height: 100%; padding: 6px 10px 8px; gap: 4px; }
  body.touch .comms-head { gap: 8px; padding-right: 40px; }
  body.touch .comms-ships { gap: 3px; }
  body.touch .comms-ships .pill { min-width: 0; padding: 0 5px; font-size: 17px; border-width: 1.5px; }
  body.touch .card p.comms-intro { font-size: 14px; margin: 0; }
  body.touch .comms-log { padding: 6px; gap: 6px; }
  body.touch .msg { max-width: 92%; gap: 5px; }
  body.touch .msg .icon { width: 32px; height: 32px; }
  body.touch .msg .head b { font-size: 19px; }
  body.touch .msg .text { font-size: 16px; }
  body.touch .comms-form { gap: 6px; }
  body.touch .comms-form input { font-size: 17px; padding: 4px 10px; }
  body.touch .comms-form .au-btn { font-size: 22px; padding: 0 14px; }

  /* The jump code's keypad */
  body.touch .jump-display { gap: 6px; }
  body.touch .jump-display span { width: 44px; height: 54px; font-size: 44px; }
  body.touch .jump-keys { grid-template-columns: repeat(3, 70px); gap: 6px; }
  body.touch .card.small .jump-keys [data-key="clear"] { font-size: 20px; letter-spacing: 0; }
  body.touch .card.small .jump-keys .au-btn { height: 42px; font-size: 26px; }

  /* Event alerts */
  body.touch #alert { gap: 8px; padding: 0 12px; }
  body.touch .alert-band { gap: 12px; padding: 10px 0; border-block-width: 4px; }
  body.touch .alert-ai { height: 84px; }
  body.touch .alert-title { font-size: clamp(40px, 11vw, 76px); -webkit-text-stroke-width: 7px; letter-spacing: 3px; }
  body.touch .alert-what { font-size: 19px; -webkit-text-stroke-width: 4px; }
  body.touch .alert-go { font-size: 30px; -webkit-text-stroke-width: 6px; }
  body.touch .alert-taunt { font-size: 24px; -webkit-text-stroke-width: 5px; }

  /* How to play */
  body.touch .guide-card { gap: 4px; }
  body.touch .guide-card dl { gap: 6px 14px; font-size: 16px; line-height: 1.25; }
  body.touch .guide-card dt { font-size: 22px; }
  body.touch .guide-card .au-btn { font-size: 24px; padding: 0 24px; }

  /* Title and launch site */
  body.touch #join { padding: 8px; }
  body.touch .story { font-size: 16px; }
  body.touch .chase { height: 80px; margin: 2px 0 8px; }
  body.touch .chase-ship { width: 140px; margin-top: -29px; }
  body.touch .chase-ai { height: 72px; margin-top: -36px; }
  body.touch #play { font-size: 32px; padding: 0 44px; }
  body.touch #rejoin { font-size: 26px; }
  body.touch .hangar-head h2 { font-size: 26px; text-align: center; }
  body.touch .hangar-head .link { font-size: 16px; }
  body.touch #roster { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px 10px; }
  body.touch .ship-art { --h: 96px; }
  body.touch .bay h3 { font-size: 24px; }
  body.touch .bay .aboard { font-size: 14px; }
  body.touch .name { min-height: 32px; font-size: 18px; }
}

/* A phone held sideways: little height, so things go side by side. */
@media (orientation: landscape) and (max-height: 540px) {
  /* The banner sits between the race panel and the corner buttons. */
  body.touch #banner, body.touch #ghost-banner { position: fixed; left: 264px; right: 170px; }
  body.touch .card p.comms-intro { display: none; }
  /* The keypad beside the code. */
  body.touch .jump-card { width: min(600px, 100%); }
  body.touch .jump-entry { display: grid; grid-template-columns: 1fr auto; column-gap: 14px; align-items: center; }
  body.touch .jump-entry[hidden] { display: none; }
  body.touch .jump-keys { grid-column: 2; grid-row: 1 / span 3; }
  body.touch .alert-what { max-width: 760px; }
}

/* A phone held upright: little width, so things stack. */
@media (orientation: portrait) and (max-width: 600px) {
  body.touch #corner { flex-direction: column; }
  body.touch #badges { top: 166px; }
  /* The banner goes under the race panel and the task list. */
  body.touch #banner, body.touch #ghost-banner { position: static; margin: 6px 0 0; max-width: calc(100vw - 160px); }
  /* Room names flash under you, clear of the race panel and banners. */
  body.touch #room, body.touch #room.low { top: auto; bottom: 34%; }
  body.touch .nav-head { grid-template-columns: 1fr; }
  body.touch .nav-head h2 { grid-column: 1; padding: 0 36px; line-height: 1; }
  body.touch .nav-card .nav-count { grid-column: 1; justify-self: center; margin-right: 0; }
  body.touch #warning { top: auto; bottom: 170px; }
  body.touch .nav-pics { flex-direction: column; align-items: center; }
  body.touch .nav-pic { --size: min(84vw, (100dvh - 250px) / 2); }
  body.touch .guide-card dl { grid-template-columns: 1fr; gap: 0; }
  /* The ship pills get their own line under the title. */
  body.touch .comms-head { flex-wrap: wrap; row-gap: 2px; }
  body.touch .comms-ships { order: 1; width: 100%; margin-left: 0; }
  body.touch .guide-card dd { margin-bottom: 6px; }
  body.touch #roster { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body.touch .hangar-head { grid-template-columns: 1fr; justify-items: center; }
  body.touch .hangar-head span { display: none; }
}

/* ---------- The story's own page (story.html) ---------- */
body.story-page { background: radial-gradient(ellipse at 50% 35%, #182255 0%, #0b1030 45%, #03040c 100%); }
body.story-page #intro { gap: 18px; }
body.story-page #watch { width: auto; padding: 4px 34px; font-size: 44px; }

/* ---------- The story asks phones to turn sideways (story.js) ---------- */
/* A phone outline turns from upright to sideways (counter-clockwise) on a loop, like most mobile games' rotate screens. */
.story-rotate {
  position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; background: radial-gradient(ellipse at 50% 40%, #182255 0%, #0b1030 50%, #03040c 100%);
}
.story-rotate[hidden] { display: none; }
.story-rotate h2 { margin: 0; font: 700 40px var(--display); letter-spacing: 1px; color: var(--cyan); -webkit-text-stroke: 1px currentColor; }
.story-rotate .link { margin-top: 6px; }
.rotate-icon { position: relative; width: 140px; height: 140px; margin: 6px 0 10px; display: grid; place-items: center; }
.rotate-phone {
  position: relative; width: 60px; height: 104px; border: 5px solid var(--white); border-radius: 14px;
  animation: rotate-phone 2.6s ease-in-out infinite;
}
.rotate-phone i { position: absolute; left: 50%; bottom: 7px; width: 12px; height: 4px; margin-left: -6px; border-radius: 2px; background: var(--white); }
@keyframes rotate-phone {
  0%, 15% { transform: rotate(0deg); }
  45%, 70% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

/* ---------- How to play, on the teaser after the story (js/handbook.js) ---------- */
#handbook { z-index: 20; }
#handbook[hidden] { display: none; }
.handbook {
  width: min(1100px, 100%); height: min(760px, 96vh); flex-direction: row; gap: 26px; padding: 22px 26px;
  overflow: hidden;
}
.hb-nav { flex: none; width: 230px; display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }
.hb-nav button[data-page] {
  padding: 4px 14px; text-align: left; background: #000; color: var(--white); cursor: pointer;
  border: 3px solid var(--white); border-radius: 12px; font: 700 30px var(--display); letter-spacing: 1px;
}
.hb-nav button[data-page]:hover { color: var(--green); border-color: var(--green); }
.hb-nav button[data-page].on { color: #000; background: var(--green); border-color: var(--green); }
.hb-nav .hb-practice { margin-top: 14px; font-size: 30px; padding: 4px 10px; text-align: center; text-decoration: none; }
.hb-nav .hb-story { margin-top: auto; text-align: left; }
.hb-page { flex: 1; min-width: 0; overflow-y: auto; padding-right: 44px; }
.hb-page[hidden] { display: none; }
.hb-page h2 { margin-bottom: 10px; }
.hb-page h3 { margin: 14px 0 6px; font: 700 30px var(--display); letter-spacing: 1px; color: var(--yellow); text-transform: uppercase; }
.hb-page p, .hb-page li, .hb-page dd { font-size: 21px; line-height: 1.4; color: #d9dde4; }
.hb-page b { color: var(--white); }
.hb-page .hb-lead { font-size: 26px; color: var(--white); }
.hb-page kbd { display: inline-block; min-width: 1.2em; padding: 0 5px; border: 2px solid var(--white); border-radius: 5px; font: 700 20px var(--display); line-height: 1.2; text-align: center; color: var(--white); }
/* The goal: the race in a strip, the AI creeping up on the ship. */
.hb-race {
  position: relative; height: 110px; margin: 4px 0 14px; border-radius: 12px;
  background: linear-gradient(90deg, rgba(197, 17, 17, 0.35), transparent 30%), repeating-linear-gradient(90deg, rgba(245, 245, 87, 0.6) 0 14px, transparent 14px 26px) 0 50% / 100% 3px no-repeat, #070b1e;
}
.hb-ai { position: absolute; left: 2%; top: 8px; height: 94px; animation: hb-creep 6s ease-in infinite alternate; }
@keyframes hb-creep { to { left: 26%; } }
.hb-ship { position: absolute; left: 46%; top: 24px; width: 130px; }
.hb-gate { position: absolute; right: 18px; top: 12px; bottom: 12px; width: 18px; border-radius: 9px; background: var(--green); box-shadow: 0 0 22px var(--green); }
/* How to play */
.hb-list { display: grid; grid-template-columns: max-content 1fr; gap: 12px 22px; margin: 0; }
.hb-list dt { font: 700 28px var(--display); letter-spacing: 1px; text-transform: uppercase; color: var(--yellow); line-height: 1.2; }
.hb-list dd { margin: 0; }
.hb-list .walk-ways { margin: 0 0 8px; }
.hb-use {
  float: right; display: grid; place-items: center; width: 74px; height: 74px; margin: 0 0 6px 14px; border-radius: 16px;
  background: #000; border: 3px solid var(--white); font: 700 22px var(--display); color: var(--white);
}
.hb-use svg { width: 38px; height: 38px; }
.hb-marks { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.hb-marks i { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #000; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.4); }
.hb-marks i:not(:first-child) { margin-left: 10px; }
.hb-marks .m-y { background: var(--yellow); }
.hb-marks .m-r { background: #ff3b3b; }
.hb-marks .m-g { background: var(--green); }
.hb-try { margin-top: 18px; }
.hb-try .au-btn { font-size: 30px; padding: 4px 24px; text-decoration: none; }
/* The ship */
.hb-map { display: block; width: 100%; max-height: 52vh; object-fit: contain; margin: 6px 0 12px; }
/* Tips + the day */
.hb-steps, .hb-tips { margin: 0; padding-left: 26px; }
.hb-steps li, .hb-tips li { margin-bottom: 6px; }
.hb-tips li::marker { color: var(--green); }
#to-handbook { font-size: 22px; }
/* A touch screen has no keys to try. */
@media (pointer: coarse) { .hb-list .walk-ways { display: none; } }

/* Phones: the menu becomes a row of tabs over the page. */
@media (max-width: 760px), (max-height: 540px) {
  #handbook { padding: 6px; }
  .handbook { flex-direction: column; height: 100%; max-height: 100%; gap: 8px; padding: 10px 12px; border-width: 2px; }
  .hb-nav { width: auto; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 6px; margin-right: 46px; padding: 0 0 4px; }
  .hb-close { top: 8px; right: 8px; width: 38px; height: 38px; }
  .hb-nav button[data-page], .hb-nav .hb-practice { flex: none; margin: 0; font-size: 20px; padding: 2px 10px; border-width: 2px; }
  .hb-nav .hb-story { flex: none; margin: 0; font-size: 15px; }
  .hb-page { padding-right: 0; }
  .hb-page h2 { font-size: 32px; }
  .hb-page p, .hb-page li, .hb-page dd { font-size: 16px; }
  .hb-page .hb-lead { font-size: 19px; }
  .hb-list { grid-template-columns: 1fr; gap: 2px; }
  .hb-list dt { font-size: 22px; margin-top: 6px; }
  .hb-race { height: 76px; }
  .hb-ai { height: 64px; }
  .hb-ship { width: 90px; top: 18px; }
  .hb-use { width: 56px; height: 56px; font-size: 17px; }
  .hb-use svg { width: 28px; height: 28px; }
  .hb-try .au-btn { font-size: 22px; }
  .hb-map { max-height: 60vh; }
}
