/* ═══════════════════════════════════════════════════════════════════
   BEAT THE ROBOT — base: tokens, reset, HUD layers, docks, controls
   Visual language: neon game-show broadcast — glass panels, chunky
   buttons, lower thirds. Portrait phone first; landscape/desktop turns
   panel docks into a full-height broadcast sidebar.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --c-bg: #06060f;
  --c-cyan: #00f0ff;
  --c-pink: #ff006e;
  --c-green: #00ff88;
  --c-red: #ff3355;
  --c-yellow: #ffcc00;
  --c-text: #eef3ff;
  /* Alphas are picked for contrast over a --glass panel, worst case the stage behind it being pure white:
     dim 4.8:1, faint 4.6:1 — both clear WCAG AA for normal text (4.5:1), and both are far better over a dark stage.
     Every consumer of --c-faint is small text (the Enter hint, the pack counts, placeholders, the rank number), so
     the large-text floor of 3:1 is not the one that applies. Over a --field layer (inputs, chips) the same worst case
     drops to 4.2:1 / 4.1:1: keep --field surfaces off the brightest part of the stage rather than fading text further. */
  --c-dim: rgba(238, 243, 255, 0.64);
  --c-faint: rgba(238, 243, 255, 0.62);

  --glass: rgba(9, 11, 28, 0.78);
  --glass-strong: rgba(7, 8, 22, 0.92);
  --glass-line: rgba(0, 240, 255, 0.24);
  --field: rgba(255, 255, 255, 0.06);
  --field-line: rgba(255, 255, 255, 0.16);

  --font-display: 'Unbounded', 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --radius: 18px;
  --radius-sm: 12px;
  --gap: 12px;
  --topbar-h: 56px;
  --reactions-h: 60px;
  --sidebar-w: clamp(340px, 31vw, 440px);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);

  /* Maintained by hud/viewport.js */
  --vv-w: 100vw;
  --vv-h: 100vh;
  --vv-top: 0px;
  --vv-left: 0px;
  --safe-x: 0px;
  --safe-y: 0px;
  --safe-w: 100vw;
  --safe-h: 55vh;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

h1, h2, h3, p, ul, ol, blockquote { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--c-cyan); }

/* The ring sits 3 px clear of the control, so it lands on the dark panel instead of on a cyan button's own fill. */
:focus-visible { outline: 3px solid var(--c-cyan); outline-offset: 3px; }

/* ── Stage + lite backdrop ─────────────────────────────────────────── */

.stage-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

/* Only visible while the canvas is transparent (NullStage / before the first frame). */
.backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(0, 240, 255, 0.16), transparent 60%),
    radial-gradient(90% 50% at 50% 108%, rgba(255, 0, 110, 0.22), transparent 65%),
    linear-gradient(180deg, #0a0b22 0%, #06060f 70%);
}
.backdrop::after {
  content: '';
  position: absolute;
  left: -50%;
  right: -50%;
  bottom: 0;
  height: 46%;
  background-image:
    linear-gradient(rgba(0, 240, 255, 0.22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 240, 255, 0.22) 1px, transparent 1px);
  background-size: 56px 56px;
  transform: perspective(420px) rotateX(62deg);
  transform-origin: 50% 100%;
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 70%);
  mask-image: linear-gradient(180deg, transparent, #000 70%);
  animation: grid-scroll 6s linear infinite;
}
@keyframes grid-scroll { to { background-position: 0 56px, 0 0; } }

/* ── HUD layers ────────────────────────────────────────────────────── */

.hud {
  position: fixed;
  left: var(--vv-left);
  top: var(--vv-top);
  width: var(--vv-w);
  height: var(--vv-h);
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}
.hud-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.hud button, .hud input, .hud textarea, .hud a, .panel { pointer-events: auto; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
}

/* ── Panels & docks ────────────────────────────────────────────────── */

.panel {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 -12px 48px -12px rgba(0, 240, 255, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  backdrop-filter: blur(16px) saturate(1.3);
}

.dock {
  position: relative;
  width: 100%;
  max-height: 45%;
  pointer-events: auto;
}
/* Bands (captions, judging toy) hug the bottom edge in every layout; only panel docks become sidebars. */
.dock:not(.panel) { position: absolute; left: 0; right: 0; bottom: 0; }
.panel.dock {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: 16px max(16px, var(--safe-r)) calc(14px + var(--safe-b)) max(16px, var(--safe-l));
  border-width: 1px 0 0;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 240, 255, 0.3) transparent;
  animation: dock-in 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
}
/* Opacity only: the box must not move, the camera frames against it. */
@keyframes dock-in { from { opacity: 0; } to { opacity: 1; } }

/* Split dock: the content scrolls, the primary action stays pinned and reachable at any height. */
.panel.dock.dock-split { overflow: hidden; }
.dock-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  margin: -4px calc(-1 * var(--dock-body-bleed, 4px));
  padding: 4px var(--dock-body-bleed, 4px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 240, 255, 0.3) transparent;
}
.dock-foot { flex: none; display: flex; flex-direction: column; gap: 10px; }

.panel-title, .sheet-title, .dialog-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.section-label, .field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--c-dim);
}
.section-count { color: var(--c-cyan); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label output { color: var(--c-cyan); font-size: 0.72rem; letter-spacing: 0.04em; }
.field-hint { font-size: 0.78rem; color: var(--c-dim); }

/* ── Controls ──────────────────────────────────────────────────────── */

.btn {
  --btn-shade: rgba(0, 0, 0, 0.55);
  --btn-glow: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  user-select: none;
  box-shadow: 0 5px 0 var(--btn-shade), 0 14px 26px -10px var(--btn-glow);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--btn-shade), 0 6px 14px -8px var(--btn-glow); }
.btn:disabled { opacity: 0.45; filter: saturate(0.4); }

.btn-primary {
  --btn-shade: #00808f;
  --btn-glow: rgba(0, 240, 255, 0.7);
  background: linear-gradient(180deg, #7dfcff 0%, #00d6ea 100%);
  color: #021218;
}
.btn-secondary {
  background: rgba(0, 240, 255, 0.08);
  color: var(--c-cyan);
  box-shadow: inset 0 0 0 1.5px rgba(0, 240, 255, 0.55), 0 5px 0 var(--btn-shade);
}
.btn-secondary:active:not(:disabled) { box-shadow: inset 0 0 0 1.5px rgba(0, 240, 255, 0.55), 0 1px 0 var(--btn-shade); }
.btn-danger {
  --btn-shade: #8a0030;
  --btn-glow: rgba(255, 0, 110, 0.6);
  background: linear-gradient(180deg, #ff5c9d 0%, #ff006e 100%);
  color: #fff;
}
.btn-ghost {
  background: transparent;
  color: var(--c-dim);
  box-shadow: none;
  font-weight: 500;
}
.btn-ghost:active:not(:disabled) { transform: none; box-shadow: none; color: var(--c-text); }
.btn-lg { min-height: 58px; font-size: 0.98rem; border-radius: 16px; }
.btn-sm { min-height: 44px; padding: 0 14px; font-size: 0.68rem; border-radius: 12px; }
.btn-icon { width: 44px; min-height: 44px; padding: 0; font-size: 1rem; }
.btn-icon-lg { width: 58px; min-height: 58px; padding: 0; font-size: 1.35rem; flex: none; border-radius: 16px; }

.input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--field-line);
  background: var(--field);
  color: var(--c-text);
  font-size: 1rem;           /* ≥16px: iOS must not zoom on focus */
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input::placeholder { color: var(--c-faint); }
.input:focus { border-color: var(--c-cyan); box-shadow: 0 0 0 3px rgba(0, 240, 255, 0.18); }
.input:disabled { opacity: 0.6; }
textarea.input { resize: none; line-height: 1.35; }

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  background: transparent;
}
.range::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.16); }
.range::-moz-range-track { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.16); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px; margin-top: -10px;
  border-radius: 50%; border: 0;
  background: var(--c-cyan);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.7), 0 3px 0 #00808f;
}
.range::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: var(--c-cyan);
  box-shadow: 0 0 14px rgba(0, 240, 255, 0.7);
}
.range:disabled { opacity: 0.5; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--field);
  border: 1px solid var(--field-line);
}
.segment {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--c-dim);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 0.15s ease, color 0.15s ease;
}
.segment.is-on { background: var(--c-cyan); color: #021218; box-shadow: 0 0 18px rgba(0, 240, 255, 0.45); }
.segment[data-difficulty="hard"].is-on { background: var(--c-pink); color: #fff; box-shadow: 0 0 18px rgba(255, 0, 110, 0.5); }
.segment[data-difficulty="easy"].is-on { background: var(--c-green); box-shadow: 0 0 18px rgba(0, 255, 136, 0.45); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-host { background: rgba(255, 204, 0, 0.16); color: var(--c-yellow); }
.badge-off { background: rgba(255, 51, 85, 0.16); color: var(--c-red); }
.badge-watch { background: rgba(238, 243, 255, 0.1); color: var(--c-text); }

.kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-bottom-width: 2px;
  font-family: var(--font-body);
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  color: var(--c-dim);
  text-transform: none;
  letter-spacing: 0;
}

.pulse-dot {
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--c-cyan);
  box-shadow: 0 0 10px var(--c-cyan);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; transform: scale(0.7); } }

.dots i {
  display: inline-block;
  width: 0.28em; height: 0.28em;
  margin-left: 0.18em;
  border-radius: 50%;
  background: currentColor;
  animation: dot-bounce 1s ease-in-out infinite;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-0.35em); opacity: 1; } }

.result-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.result-tag[data-result="survived"] { background: rgba(0, 255, 136, 0.14); color: var(--c-green); }
.result-tag[data-result="death"] { background: rgba(255, 51, 85, 0.16); color: var(--c-red); }

/* ── Loading ───────────────────────────────────────────────────────── */

.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
  background:
    radial-gradient(80% 50% at 50% 40%, rgba(0, 240, 255, 0.14), transparent 70%),
    var(--c-bg);
  transition: opacity 0.5s ease, visibility 0.5s;
}
.loading.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-logo {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(1.6rem, 7vw, 3rem);
  letter-spacing: 0.02em;
  text-align: center;
  color: var(--c-text);
  text-shadow: 0 0 28px rgba(0, 240, 255, 0.55);
}
.loading-logo span:nth-child(2) { color: var(--c-pink); font-size: 0.55em; vertical-align: middle; }
.loading-logo span:nth-child(3) { color: var(--c-cyan); }
.loading-bar {
  width: min(320px, 70vw);
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.loading-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--c-pink), var(--c-cyan));
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.7);
  transform: scaleX(0);
  transform-origin: 0 50%;
  transition: transform 0.25s ease-out;
}
.loading-text {
  min-height: 1.4em;
  font-family: var(--font-display);
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--c-dim);
}
.loading.is-failed .loading-text { color: var(--c-red); }
.noscript { position: fixed; inset: auto 0 0 0; z-index: 200; padding: 16px; text-align: center; background: var(--c-red); color: #fff; }

/* ── Landscape / desktop: panel docks become a broadcast sidebar ───── */

@media (orientation: landscape) and (min-width: 700px) {
  .screen { flex-direction: row; justify-content: flex-end; align-items: stretch; }
  .panel.dock {
    width: var(--sidebar-w);
    max-height: none;
    height: 100%;
    /* Centre short content; `safe` lets tall content start at the top and scroll. */
    justify-content: center;
    justify-content: safe center;
    padding: calc(var(--topbar-h) + var(--safe-t) + 8px) max(22px, var(--safe-r)) calc(20px + var(--safe-b)) 22px;
    border-width: 0 0 0 1px;
    border-radius: 0;
    box-shadow: -18px 0 60px -20px rgba(0, 240, 255, 0.25), inset 1px 0 0 rgba(255, 255, 255, 0.06);
  }
  /* In the sidebar the body only takes what it needs, so body + pinned actions stay one centred group. */
  .dock-body { flex: 0 1 auto; }
}

/* ── Reduced motion: keep information, drop the fireworks ──────────── */

@media (prefers-reduced-motion: reduce) {
  /* The auto-advance ring and the verdict stamp carry timing information; they keep their clocks (without motion). */
  *:not(.advance-fill):not(.stamp), *:not(.advance-fill):not(.stamp)::before, *:not(.advance-fill):not(.stamp)::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

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