:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-border: #262b36;
  --text: #e7e9ee;
  --muted: #8a90a0;
  --accent: #4ade80;
  --danger: #f87171;
  --warn: #fbbf24;
  /* 960px is exactly the canvas backing store, so at full size the board is
     1:1 with its pixels. The 104vh term caps the 4:3 height at 78vh, which
     keeps the board plus its chrome inside a laptop viewport without
     scrolling. */
  --board-w: min(92vw, 960px, 104vh);
}

* { box-sizing: border-box; }

.debug-only { display: none !important; }
/* Stripped by ?hands=1, the way .debug-only is stripped by ?debug=1. An
   element carrying both needs both flags before it shows. */
.hands-only { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #171a21, #0b0d11 70%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  justify-content: center;
  padding: 20px 16px 32px;
}

.wrap {
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

header {
  text-align: center;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.06em;
}

.board {
  position: relative;
  width: var(--board-w);
  max-width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--panel-border), 0 20px 50px rgba(0,0,0,0.45);
}

canvas#game {
  width: 100%;
  height: 100%;
  display: block;
  background: #0d0f16;
}

canvas#hud {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Sits above both overlays, so it stays reachable on the start and game-over
   screens as well as mid-run. */
.settings-btn {
  position: absolute;
  /* Sized as a share of the board rather than in fixed px, so its footprint in
     the renderer's 480x360 logical space is the same whatever the board is
     displayed at — the HUD's WAVE block is nudged clear of exactly that
     footprint (6..28 logical px) and would collide again at a smaller size.
     Percentage top resolves against height, left against width. */
  top: 1.67%;
  left: 1.25%;
  z-index: 6;
  width: 4.58%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(10, 12, 16, 0.45);
  color: rgba(231, 233, 238, 0.55);
  cursor: pointer;
}

.settings-btn svg {
  width: 68%;
  height: 68%;
}

.settings-btn:hover {
  background: rgba(10, 12, 16, 0.75);
  color: var(--text);
}

.settings-panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 16, 0.86);
  backdrop-filter: blur(2px);
}

.settings-panel.hidden { display: none; }

.settings-card {
  width: min(340px, 84%);
  max-height: 88%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 18px 20px;
  text-align: left;
}

.settings-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 12px;
}

/* min-height:0 is what actually lets a flex child scroll rather than growing
   the card past its max-height. */
.settings-body {
  overflow-y: auto;
  /* Explicit, not redundant: a box with overflow-y set and overflow-x left at
     visible computes overflow-x to auto, which was putting a horizontal
     scrollbar along the bottom of the card. */
  overflow-x: hidden;
  min-height: 0;
}

.controls-list {
  margin: 0 0 16px;
  padding-left: 18px;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--muted);
}

.controls-list b { color: var(--text); font-weight: 600; }

/* The keyboard line is the default, so a list with no mode class at all still
   reads correctly rather than losing its movement line entirely. */
.controls-list .ctrl-wheel,
.controls-list .ctrl-thumb,
.controls-list .ctrl-hands { display: none; }
.controls-list.mode-wheel .ctrl-keys,
.controls-list.mode-thumb .ctrl-keys { display: none; }
.controls-list.mode-wheel .ctrl-wheel,
.controls-list.mode-thumb .ctrl-thumb,
.controls-list.mode-wheel .ctrl-hands,
.controls-list.mode-thumb .ctrl-hands { display: list-item; }

.settings-note {
  margin: -2px 0 16px;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--muted);
}

.settings-card .btn { width: 100%; }

/* Last thing in the scrolling body, deliberately not between it and the Done
   button: that button is pinned, and a line above it eats the space it needs
   on a short viewport. */
.settings-credit {
  margin: 18px 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 16, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  backdrop-filter: blur(2px);
  transition: opacity 0.15s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px;
}

#overlayTitle {
  font-size: 1.6rem;
  font-weight: 700;
}

#overlaySub {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 320px;
}

.btn {
  padding: 10px 24px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #08210f;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.08); }

.choice-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* .overlay.hidden only fades the whole overlay, so these need their own
   display rule to swap in place while the overlay is still showing. */
.choice-row.hidden { display: none; }

.start-intro {
  margin: 0 0 4px;
  max-width: 340px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--muted);
}

.start-intro.hidden { display: none; }

.start-status {
  font-size: 0.9rem;
  color: var(--muted);
}

.start-status.hidden { display: none; }

.start-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 340px;
}

.start-error.hidden { display: none; }

.start-error p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
}

/* Shared by the two "you can't play this here" notices that replace the mode
   buttons outright: no fine pointer, and no WebAssembly. */
.start-notice {
  max-width: 320px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
}

.start-notice.hidden { display: none; }

.start-prompt {
  margin-top: 8px;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  animation: start-prompt-pulse 1.6s ease-in-out infinite;
}

.start-prompt.hidden { display: none; }

@keyframes start-prompt-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.cam-error {
  margin-top: 8px;
  color: var(--danger);
  font-size: 0.85rem;
  max-width: 320px;
}

.cam-error.hidden { display: none; }

.hud {
  display: flex;
  gap: 24px;
  width: var(--board-w);
  max-width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
}

.stat .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stat .value {
  font-size: 1.3rem;
  font-weight: 700;
}

.gaze-unknown { color: var(--muted); }
.gaze-running { color: var(--accent); }
.gaze-paused { color: var(--danger); }

.panels {
  display: flex;
  gap: 16px;
  width: var(--board-w);
  max-width: 100%;
  flex-wrap: wrap;
}

.panel {
  flex: 1 1 220px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 14px;
}

.panel-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.video-box {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

.video-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.video-box canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 10px;
}

.slider-row input[type="range"] {
  width: 100%;
  /* Range inputs carry a 2px UA margin, which at width:100% puts them 2px past
     their container and made the settings card overflow horizontally. */
  margin: 0;
}

.debug-readout {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  color: var(--muted);
  background: #0d0f14;
  border-radius: 6px;
  padding: 8px;
  margin-top: 8px;
  white-space: pre;
}

.debug-readout.hidden { display: none; }

.fallback-row {
  margin-top: 10px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover { color: var(--text); }

.calibrate-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}

.calibrate-result {
  font-size: 0.75rem;
  color: var(--accent);
}

