/* Rescue Chopper: page shell and overlay screens. Same family as Neon Asteroids and NeonCrawl. */
:root {
  --bg: #04060d;
  --fg: #dfe9ff;
  --dim: #6f7ea6;
  /* Secondary text. --dim is 5:1 on the background, too little for 10 px labels over a lit
     scene; this is 8.7:1. --dim is kept for rules and other non-text detail. */
  --muted: #9aa9d0;
  --cyan: #3ee7ff;
  --magenta: #ff4fd8;
  --lime: #b8ff3c;
  --orange: #ffb23c;
  --red: #ff5a5a;
  --gold: #ffd700;
  --font: 'Orbitron', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  cursor: none;
  /* A touch screen: no double-tap zoom, pull to refresh, long-press menu or tap flash. */
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body.in-menu { cursor: default; }

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---- overlay screens ---- */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}

.screen {
  width: min(960px, 94vw);
  max-height: 100vh;
  overflow-y: auto;
  scrollbar-width: none;
  text-align: center;
  padding: 20px 24px;
  pointer-events: auto;
  animation: fadein 0.4s ease-out;
}
.screen::-webkit-scrollbar { display: none; }

/* A screen over a live mission needs a darker ground than one over the title backdrop. */
#pause, #options, #bindings, #padtest, #changelog, #scores, #tally, #failed, #gameover, #initials {
  background: radial-gradient(ellipse at center, rgba(4, 6, 13, 0.88) 0%, rgba(4, 6, 13, 0.7) 60%, rgba(4, 6, 13, 0) 100%);
}

@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.logo {
  margin: 0;
  font-weight: 900;
  font-size: clamp(34px, 7.4vw, 96px);
  letter-spacing: 0.14em;
  line-height: 1;
  color: #fff;
  text-shadow:
    0 0 6px #fff,
    0 0 18px var(--cyan),
    0 0 40px var(--cyan),
    0 0 80px rgba(62, 231, 255, 0.6);
  animation: flicker 6s infinite;
}
@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.65; }
  94% { opacity: 1; }
  97% { opacity: 0.8; }
  98% { opacity: 1; }
}

.subtitle {
  margin-top: 10px;
  font-weight: 500;
  font-size: clamp(10px, 1.4vw, 15px);
  letter-spacing: 0.32em;
  color: var(--magenta);
  text-shadow: 0 0 10px var(--magenta), 0 0 24px rgba(255, 79, 216, 0.5);
}

.prompt {
  margin: 18px 0 8px;
  font-weight: 700;
  font-size: clamp(14px, 2vw, 22px);
  letter-spacing: 0.25em;
  color: var(--lime);
  text-shadow: 0 0 10px var(--lime), 0 0 30px rgba(184, 255, 60, 0.5);
}
.prompt.bad { color: var(--red); text-shadow: 0 0 10px var(--red), 0 0 30px rgba(255, 90, 90, 0.5); }
.prompt:empty { display: none; }

h2 {
  margin: 0;
  font-size: clamp(36px, 7vw, 84px);
  font-weight: 900;
  letter-spacing: 0.2em;
  color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 20px var(--magenta), 0 0 48px var(--magenta);
}
h2.small { font-size: clamp(24px, 4vw, 44px); margin-bottom: 14px; }
h2.banner { font-size: clamp(26px, 5vw, 60px); text-shadow: 0 0 6px #fff, 0 0 20px var(--cyan), 0 0 48px var(--cyan); }
h2.good { text-shadow: 0 0 6px #fff, 0 0 20px var(--lime), 0 0 48px rgba(184, 255, 60, 0.7); }

/* ---- menus ---- */
.menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin: 22px auto 6px;
}
.menu.inline { flex-direction: row; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

button {
  font: inherit;
  font-weight: 700;
  font-size: clamp(12px, 1.5vw, 16px);
  letter-spacing: 0.22em;
  color: var(--fg);
  background: rgba(4, 6, 13, 0.6);
  border: 1px solid rgba(62, 231, 255, 0.35);
  padding: 10px 22px;
  min-width: 260px;
  cursor: pointer;
  outline: none;
  transition: box-shadow 0.12s, border-color 0.12s, color 0.12s;
}
.menu.inline button { min-width: 0; }
button:hover { border-color: rgba(62, 231, 255, 0.7); }
/* The focused control. `.is-focus` mirrors DOM focus (src/ui/menu.ts) because :focus does not
   match until the window itself has focus, and the default control must look focused on first
   load. Not colour alone: a thick outline, and arrow marks either side of the label. */
button:focus, button:focus-visible, button.is-focus {
  color: #fff;
  border-color: var(--cyan);
  outline: 2px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 14px rgba(62, 231, 255, 0.55), inset 0 0 18px rgba(62, 231, 255, 0.16);
  text-shadow: 0 0 8px var(--cyan);
}
.menu button:focus::before, .menu button.is-focus::before { content: '▸ '; }
.menu button:focus::after, .menu button.is-focus::after { content: ' ◂'; }
.row:focus .row-label::before, .row.is-focus .row-label::before { content: '▸ '; }

/* For screen readers only. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- title panels ---- */
.panels {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 20px;
}
.panel {
  flex: 1 1 340px;
  max-width: 460px;
  padding: 14px 18px 12px;
  border: 1px solid rgba(62, 231, 255, 0.35);
  box-shadow: 0 0 18px rgba(62, 231, 255, 0.15), inset 0 0 24px rgba(62, 231, 255, 0.05);
  background: rgba(4, 6, 13, 0.82);
  backdrop-filter: blur(2px);
  text-align: left;
}
.panel h3 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.3em;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan);
}
.panel table { width: 100%; border-collapse: collapse; font-size: 12px; letter-spacing: 0.05em; }
.panel th { text-align: left; color: var(--muted); font-weight: 500; font-size: 11px; letter-spacing: 0.2em; padding-bottom: 6px; }
.panel td { padding: 3px 0; color: var(--fg); vertical-align: middle; }
.panel td:first-child { color: var(--muted); }
.panel table.score td:last-child { text-align: right; color: var(--orange); font-weight: 700; white-space: nowrap; }
.panel table.score td:first-child { color: var(--fg); }

.tiny {
  margin-top: 10px;
  font-size: 11px;
  letter-spacing: 0.15em;
  color: var(--muted);
}
.tiny.warn { color: var(--orange); text-shadow: 0 0 8px rgba(255, 178, 60, 0.6); }
#audio-hint { margin-top: 10px; }
.status { min-height: 14px; }

/* ---- options ---- */
.rows { display: flex; flex-direction: column; gap: 6px; width: min(620px, 92vw); margin: 0 auto; }
button.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  min-width: 0;
  padding: 8px 16px;
  text-align: left;
  font-size: clamp(11px, 1.3vw, 14px);
}
.row-label { color: var(--muted); }
.row:focus .row-label, .row.is-focus .row-label { color: var(--fg); }
.row-note { margin-left: 12px; font-size: 10px; letter-spacing: 0.15em; color: var(--muted); font-weight: 500; }
.row-value { color: var(--orange); min-width: 9em; text-align: right; font-variant-numeric: tabular-nums; }
/* The arrows are always there, so it is plain where to click; they light when the row has focus. */
.row-value.range::before { content: '◄ '; color: var(--dim); }
.row-value.range::after { content: ' ►'; color: var(--dim); }
.row:focus .row-value.range::before, .row.is-focus .row-value.range::before,
.row:focus .row-value.range::after, .row.is-focus .row-value.range::after { color: var(--cyan); }

/* ---- key bindings ---- */
.bind-grid { display: flex; flex-direction: column; gap: 4px; width: min(860px, 94vw); margin: 0 auto; }
.bind-row { display: grid; grid-template-columns: minmax(110px, 1.2fr) 3fr 2fr; gap: 12px; align-items: center; }
.bind-label { text-align: left; font-size: 11px; letter-spacing: 0.15em; color: var(--muted); }
.bind-head .bind-group, .bind-head .bind-label { font-size: 10px; letter-spacing: 0.25em; color: var(--muted); text-align: center; }
.bind-head .bind-label { text-align: left; }
.bind-group { display: flex; gap: 6px; }
button.bind {
  flex: 1 1 0;
  min-width: 0;
  padding: 5px 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--orange);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
button.bind.waiting { color: var(--lime); border-color: var(--lime); box-shadow: 0 0 14px rgba(184, 255, 60, 0.5); }
button.bind.conflict { color: var(--red); border-color: var(--red); }

/* ---- controller test ---- */
.pad-panel { width: min(900px, 94vw); margin: 0 auto; text-align: left; font-size: 11px; letter-spacing: 0.1em; }
.pad-status { color: var(--lime); font-weight: 700; letter-spacing: 0.15em; }
.pad-name { color: var(--fg); margin-top: 4px; overflow-wrap: anywhere; }
.pad-cap { color: var(--muted); font-size: 10px; letter-spacing: 0.25em; }
.pad-num { color: var(--orange); font-variant-numeric: tabular-nums; white-space: pre; }
.pad-live { display: grid; grid-template-columns: auto auto minmax(150px, 1fr) minmax(220px, 2fr); gap: 16px; align-items: start; margin: 12px 0; }
.pad-stickbox { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.pad-stick { position: relative; width: 110px; height: 110px; border: 1px solid rgba(62, 231, 255, 0.45); border-radius: 50%; background: rgba(4, 6, 13, 0.7); }
.pad-dead { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border: 1px dashed var(--dim); border-radius: 50%; }
.pad-dot { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border-radius: 50%; }
.pad-dot.raw { width: 8px; height: 8px; border: 1px solid var(--fg); }
.pad-dot.shaped { width: 12px; height: 12px; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.pad-triggers { display: flex; flex-direction: column; gap: 8px; }
.pad-trigger { display: grid; grid-template-columns: 24px 1fr 36px; gap: 8px; align-items: center; }
.pad-bar { height: 10px; border: 1px solid rgba(62, 231, 255, 0.45); }
.pad-fill { height: 100%; width: 0; background: var(--orange); }
.pad-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 4px; }
.pad-button span:first-child { white-space: nowrap; }
.pad-button { display: flex; justify-content: space-between; gap: 4px; padding: 4px 6px; border: 1px solid rgba(62, 231, 255, 0.3); color: var(--muted); }
.pad-button.on, .pad-chip.on { color: #04060d; background: var(--lime); border-color: var(--lime); font-weight: 900; }
.pad-button.on .pad-num { color: #04060d; }
.pad-reads { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 10px; }
.pad-chip { padding: 3px 8px; border: 1px solid rgba(62, 231, 255, 0.3); color: var(--muted); font-variant-numeric: tabular-nums; white-space: pre; }
.pad-rumble { margin: 6px 0 4px; justify-content: flex-start; gap: 6px; }
.pad-rumble button { padding: 6px 12px; font-size: 11px; }
.pad-log { min-height: 5.5em; margin: 4px 0 8px; padding: 6px 8px; border: 1px solid rgba(62, 231, 255, 0.25); color: var(--fg); font-variant-numeric: tabular-nums; white-space: pre-wrap; }
@media (max-width: 760px) { .pad-live { grid-template-columns: auto auto; } }

/* ---- changelog: the version buttons and the release cards ---- */
.foot { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 8px 18px; margin-top: 8px; }
button.version-link {
  min-width: 0;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.15em;
  color: var(--muted);
  background: transparent;
  border: 1px dashed rgba(62, 231, 255, 0.4);
}
button.version-link:hover { color: var(--cyan); border-style: solid; }
/* The official page. On the title it takes focus like a button: an outline, not colour alone. */
.site-link { font-size: 11px; letter-spacing: 0.15em; color: var(--cyan); text-decoration: none; padding: 4px 6px; outline: none; }
.site-link:hover { text-decoration: underline; text-shadow: 0 0 8px var(--cyan); }
.site-link:focus, .site-link.is-focus { color: #fff; outline: 2px solid #fff; outline-offset: 2px; text-decoration: underline; text-shadow: 0 0 8px var(--cyan); }
.changelog-list {
  width: min(720px, 92vw);
  max-height: min(56vh, 560px);
  margin: 12px auto 0;
  padding: 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(62, 231, 255, 0.45) transparent;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}
.changelog-card {
  padding: 10px 16px 12px;
  background: rgba(4, 6, 13, 0.82);
  border: 1px solid rgba(62, 231, 255, 0.25);
  border-left: 3px solid rgba(62, 231, 255, 0.55);
}
.changelog-card.current { border-color: rgba(184, 255, 60, 0.5); border-left: 4px solid var(--lime); box-shadow: 0 0 14px rgba(184, 255, 60, 0.15); }
.changelog-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.changelog-badge, .changelog-now { padding: 2px 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.12em; border: 1px solid; }
.changelog-badge { color: var(--cyan); font-variant-numeric: tabular-nums; }
.changelog-card.current .changelog-badge, .changelog-now { color: var(--lime); }
.changelog-date { margin-left: auto; font-size: 11px; letter-spacing: 0.1em; color: var(--muted); font-variant-numeric: tabular-nums; }
.changelog-title { margin: 8px 0 6px; font-size: 14px; letter-spacing: 0.12em; color: #fff; }
/* Sentences, not labels: the system face reads better than Orbitron at this size. */
.changelog-notes { margin: 0; padding-left: 18px; font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif; font-size: 14px; line-height: 1.5; color: var(--fg); }
.changelog-notes li + li { margin-top: 3px; }

/* ---- tables: scores and tally ---- */
.results {
  margin: 8px auto 0;
  border-collapse: collapse;
  min-width: min(560px, 90vw);
  font-size: 14px;
  letter-spacing: 0.1em;
  background: rgba(4, 6, 13, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.results th { font-size: 10px; letter-spacing: 0.25em; color: var(--muted); font-weight: 500; padding: 10px 14px 6px; }
.results td { padding: 6px 14px; border-top: 1px solid rgba(255, 255, 255, 0.07); }
.results td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--gold); }
.results td.rank, .results td.missions, .results td.difficulty { color: var(--muted); font-size: 11px; }
.results td.name { font-weight: 900; letter-spacing: 0.3em; color: var(--cyan); }
.results tr.new td { color: #fff; text-shadow: 0 0 10px var(--lime); background: rgba(184, 255, 60, 0.08); }
.results.tally td.label { text-align: left; color: var(--fg); }
.results.tally tr.pending { visibility: hidden; }
.results.tally tr.good td.label { color: var(--lime); }
.results.tally tr.bad td.label, .results.tally tr.bad td.num { color: var(--red); }
.results.tally tr.total td { font-weight: 900; border-top: 1px solid rgba(255, 255, 255, 0.3); }

.people { min-height: 26px; display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 560px; margin: 0 auto; }
.prisoner { width: 14px; height: 22px; fill: none; stroke: var(--lime); stroke-width: 1.3; stroke-linecap: round; filter: drop-shadow(0 0 3px var(--lime)); animation: wave 0.65s ease-in-out infinite alternate; transform-origin: 50% 100%; }
@keyframes wave { from { transform: rotate(-5deg); } to { transform: rotate(5deg) translateY(-1px); } }

/* ---- initials ---- */
.initials { display: flex; justify-content: center; gap: 14px; margin: 18px 0 8px; }
button.initial {
  min-width: 0;
  width: clamp(56px, 9vw, 96px);
  padding: 8px 0;
  font-size: clamp(34px, 6vw, 68px);
  font-weight: 900;
  letter-spacing: 0;
  color: var(--muted);
  box-shadow: none;
  border-color: rgba(62, 231, 255, 0.25);
  text-shadow: none;
}
button.initial:focus, button.initial.is-focus { outline: none; }
button.initial.current {
  color: #fff;
  border-color: var(--cyan);
  outline: 2px solid #fff;
  outline-offset: 2px;
  text-shadow: 0 0 8px #fff, 0 0 24px var(--cyan);
  box-shadow: 0 0 18px rgba(62, 231, 255, 0.5), inset 0 0 18px rgba(62, 231, 255, 0.15);
}

/* ---- toast ---- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 6;
  padding: 8px 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--cyan);
  background: rgba(4, 6, 13, 0.8);
  border: 1px solid rgba(62, 231, 255, 0.45);
  text-shadow: 0 0 8px var(--cyan);
  pointer-events: none;
  white-space: nowrap;
}

/* ---- on-screen gamepad: shown in play once the screen has been touched ---- */
#touchpad {
  /* One button's width. A phone on its side is about 360 px high. */
  --u: clamp(52px, 14vh, 76px);
  --edge-r: env(safe-area-inset-right, 0px);
  --edge-b: env(safe-area-inset-bottom, 0px);
  position: fixed;
  inset: 0;
  z-index: 5;
  touch-action: none;
}
/* At rest, bottom left; under a thumb the script moves it to where the thumb landed. Twice
   TOUCH_STICK_RADIUS (src/input/touch.ts) across. */
.touch-stick {
  position: absolute;
  left: calc(env(safe-area-inset-left, 0px) + 112px);
  top: calc(100% - var(--edge-b) - 104px);
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border: 1px solid rgba(62, 231, 255, 0.45);
  border-radius: 50%;
  background: rgba(4, 6, 13, 0.25);
  box-shadow: 0 0 14px rgba(62, 231, 255, 0.2), inset 0 0 18px rgba(62, 231, 255, 0.08);
  opacity: 0.55;
  pointer-events: none;
}
.touch-stick.on { opacity: 0.95; border-color: var(--cyan); }
.touch-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border: 2px solid var(--cyan);
  border-radius: 50%;
  background: rgba(62, 231, 255, 0.18);
  box-shadow: 0 0 12px rgba(62, 231, 255, 0.6);
}
.touch-btn {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--u);
  height: var(--u);
  border: 2px solid rgba(62, 231, 255, 0.6);
  border-radius: 50%;
  color: var(--cyan);
  background: rgba(4, 6, 13, 0.35);
  box-shadow: 0 0 12px rgba(62, 231, 255, 0.25), inset 0 0 14px rgba(62, 231, 255, 0.1);
  font-weight: 900;
  font-size: calc(var(--u) * 0.26);
  letter-spacing: 0.1em;
  opacity: 0.7;
}
.touch-btn svg { width: 46%; height: 46%; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
/* Held: filled and brighter, not colour alone. */
.touch-btn.on { opacity: 1; color: #fff; border-color: #fff; background: rgba(62, 231, 255, 0.35); box-shadow: 0 0 22px var(--cyan); }
.touch-fire {
  right: calc(var(--edge-r) + var(--u) * 0.4);
  bottom: calc(var(--edge-b) + var(--u) * 0.4);
  width: calc(var(--u) * 1.5);
  height: calc(var(--u) * 1.5);
  color: var(--magenta);
  border-color: rgba(255, 79, 216, 0.65);
  box-shadow: 0 0 12px rgba(255, 79, 216, 0.3), inset 0 0 14px rgba(255, 79, 216, 0.12);
}
.touch-fire.on { background: rgba(255, 79, 216, 0.4); box-shadow: 0 0 22px var(--magenta); }
.touch-face-left, .touch-face-front, .touch-face-right { bottom: calc(var(--edge-b) + var(--u) * 2.15); }
.touch-face-right { right: calc(var(--edge-r) + var(--u) * 0.3); }
.touch-face-front { right: calc(var(--edge-r) + var(--u) * 1.45); }
.touch-face-left { right: calc(var(--edge-r) + var(--u) * 2.6); }
.touch-pause {
  right: calc(var(--edge-r) + var(--u) * 0.3);
  top: calc(env(safe-area-inset-top, 0px) + 17vh);
  width: calc(var(--u) * 0.75);
  height: calc(var(--u) * 0.75);
  color: var(--fg);
  border-color: rgba(223, 233, 255, 0.45);
  box-shadow: none;
}

/* Controls that only a touch screen needs (the initials' letter steppers). */
.touch-only { display: none; }
body.touch .touch-only { display: flex; }

/* ---- CRT dressing ---- */
#scanlines {
  position: fixed; inset: 0; z-index: 3; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0px, rgba(0, 0, 0, 0) 2px, rgba(0, 0, 0, 0.13) 3px);
  mix-blend-mode: multiply;
}
body.no-scanlines #scanlines { display: none; }
#vignette {
  position: fixed; inset: 0; z-index: 4; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.55) 100%);
}

@media (max-height: 640px) {
  .panels { display: none; }
  .menu { margin-top: 14px; gap: 7px; }
  button { padding: 7px 18px; }
}

/* The reduced-flashing option stops the logo's flicker (the renderer drops its own flashes). */
body.reduced-flash .logo { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .logo, .prisoner, .screen { animation: none; }
  button { transition: none; }
}
