:root {
  color-scheme: dark;
  --ink: #020304;
  --paper: #f4fbfb;
  --muted: rgba(226, 243, 244, 0.62);
  --line: rgba(206, 243, 246, 0.19);
  --signal: #7af5ff;
  --aura-a: #7af5ff;
  --aura-b: #f8ffff;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: Bahnschrift, "Arial Narrow", "Segoe UI", sans-serif;
}

button,
input { font: inherit; }

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
}

.srOnly {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #020304;
}

#video {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#operatorPanel {
  position: fixed;
  z-index: 20;
  top: 18px;
  left: 18px;
  width: min(318px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 15px;
  border: 1px solid var(--line);
  background: rgba(3, 8, 10, 0.88);
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(16px) saturate(0.8);
  transition: opacity 180ms ease, transform 180ms ease;
  scrollbar-color: rgba(122, 245, 255, 0.34) transparent;
  scrollbar-width: thin;
}

body.panel-hidden #operatorPanel {
  opacity: 0;
  transform: translateX(calc(-100% - 28px));
  pointer-events: none;
}

.panelHeader {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 11px;
  border-bottom: 1px solid var(--line);
}

.overline,
.readingKicker {
  margin: 0;
  color: var(--muted);
  font: 600 10px/1.2 Consolas, "Courier New", monospace;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.panelHeader h1 {
  margin: 5px 0 0;
  font-size: 20px;
  line-height: 1;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}

.statusLight {
  width: 9px;
  height: 9px;
  margin-top: 4px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #637073;
  box-shadow: 0 0 0 4px rgba(99, 112, 115, 0.12);
}

.statusLight.live {
  background: var(--signal);
  box-shadow: 0 0 16px rgba(122, 245, 255, 0.8), 0 0 0 4px rgba(122, 245, 255, 0.13);
}

.operatorStatus {
  min-height: 17px;
  margin: 10px 0 12px;
  color: var(--muted);
  font: 11px/1.5 Consolas, "Courier New", monospace;
}

.controlSection {
  border-top: 1px solid var(--line);
}

.controlSection summary {
  position: relative;
  padding: 10px 18px 9px 0;
  color: rgba(239, 250, 250, 0.78);
  cursor: pointer;
  list-style: none;
  font: 700 10px/1.2 Consolas, "Courier New", monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  user-select: none;
}

.controlSection summary::-webkit-details-marker { display: none; }

.controlSection summary::after {
  content: "+";
  position: absolute;
  top: 9px;
  right: 1px;
  color: var(--signal);
  font-size: 14px;
  font-weight: 400;
}

.controlSection[open] summary::after { content: "−"; }

.controlSection summary:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.controlGrid {
  display: grid;
  gap: 7px;
  padding-bottom: 8px;
}

.layerControlGrid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 10px;
  row-gap: 3px;
}

.layerControl {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.controlGrid .layerControl label {
  min-width: 0;
  gap: 5px;
  font-size: 10px;
  letter-spacing: 0.035em;
  white-space: nowrap;
}

.layerControl output { font-size: 9px; }
.layerControl input[type="range"] { min-width: 0; }

.controlGrid label,
.bandLabel {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: rgba(239, 250, 250, 0.82);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

output {
  color: var(--signal);
  font: 11px/1.2 Consolas, "Courier New", monospace;
  letter-spacing: 0;
  text-transform: none;
}

input[type="range"] {
  width: 100%;
  height: 15px;
  margin: 0 0 4px;
  accent-color: var(--signal);
  cursor: ew-resize;
}

.dualRange {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.meter {
  height: 4px;
  margin: 3px 0 11px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.paletteSection { padding-bottom: 9px; }

.selectLabel {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.paletteSection select {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #081012;
  color: var(--paper);
  padding: 0 9px;
  font-size: 11px;
  text-transform: uppercase;
}

#paletteArchetypeInput {
  width: 100%;
  margin-bottom: 10px;
}

.colorGrid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.colorGrid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font: 9px/1.2 Consolas, "Courier New", monospace;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

.colorGrid input[type="color"] {
  width: 100%;
  height: 31px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}

.colorGrid input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.colorGrid input[type="color"]::-webkit-color-swatch { border: 0; }

.blendGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.blendGrid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font: 9px/1.2 Consolas, "Courier New", monospace;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.blendGrid select {
  width: 100%;
  height: 32px;
  min-width: 0;
  padding: 0 6px;
  font-size: 9px;
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--signal), #fff);
  box-shadow: 0 0 12px var(--signal);
  transition: width 55ms linear;
}

.buttonRow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.presetStatus {
  grid-column: 1 / -1;
  margin: 0 0 2px;
  color: rgba(226, 243, 244, 0.58);
  font: 9px/1.3 Consolas, "Courier New", monospace;
  letter-spacing: 0.1em;
  text-align: center;
  text-transform: uppercase;
}

.buttonRow button,
.startButton {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.055);
  color: var(--paper);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.buttonRow button:hover { border-color: rgba(122, 245, 255, 0.55); }

#saveDefaultsBtn {
  border-color: rgba(122, 245, 255, 0.48);
  color: var(--signal);
}

#transferDefaultsBtn {
  grid-column: 1 / -1;
  border-color: rgba(122, 245, 255, 0.48);
  color: var(--signal);
}

#resetDefaultsBtn { color: rgba(239, 250, 250, 0.62); }

.shortcutHint {
  margin: 10px 0 0;
  color: rgba(226, 243, 244, 0.4);
  font: 9px/1.4 Consolas, "Courier New", monospace;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.iconButton {
  position: fixed;
  z-index: 19;
  top: 18px;
  left: 18px;
  width: 42px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgba(3, 8, 10, 0.72);
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  font: 700 9px/1 Consolas, monospace;
  letter-spacing: 0.08em;
}

body.panel-hidden .iconButton {
  opacity: 1;
  pointer-events: auto;
}

.readingOverlay {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: clamp(32px, 7vh, 84px);
  width: min(760px, calc(100vw - 44px));
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.9);
  transition: opacity 300ms ease, transform 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.readingOverlay h2 {
  margin: 7px 0 5px;
  font-size: clamp(34px, 7vw, 94px);
  font-weight: 700;
  line-height: 0.88;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.readingOverlay p:last-of-type {
  margin: 0;
  color: rgba(245, 253, 253, 0.78);
  font: 12px/1.4 Consolas, "Courier New", monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.gameReadout {
  max-width: min(420px, 76vw);
  margin: 12px auto 0;
  text-align: center;
}

.gameReadout__copy {
  margin: 0;
  color: rgba(245, 253, 253, 0.84);
  font: 12px/1.2 Consolas, "Courier New", monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.gameReadout__bar {
  margin: 8px auto 0;
  width: min(420px, 76vw);
  height: 2px;
  overflow: hidden;
  background: rgba(230, 252, 255, 0.18);
}

.gameReadout__bar span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #71f4ff, #ffffff);
  box-shadow: 0 0 12px #71f4ff;
  transition: width 140ms linear;
}

.readingOverlay.phase-locked {
  opacity: 1;
  transform: translate(-50%, 18px);
}

.readingOverlay.phase-locked #readingKicker,
.readingOverlay.phase-locked #readingTitle,
.readingOverlay.phase-locked #readingDetail,
.readingOverlay.phase-locked .scanProgress {
  opacity: 0;
  visibility: hidden;
}

.readingOverlay.phase-locked .gameReadout {
  margin-top: 0;
}

.readingOverlay.phase-reveal {
  bottom: 50%;
  transform: translate(-50%, 50%);
}

.readingOverlay.phase-reveal h2 {
  color: var(--aura-b);
  font-size: clamp(70px, 15vw, 190px);
  text-shadow: 0 0 20px var(--aura-a), 0 0 70px var(--aura-a), 0 3px 26px #000;
}

.scanProgress {
  width: min(420px, 76vw);
  height: 2px;
  margin: 17px auto 0;
  overflow: hidden;
  background: rgba(230, 252, 255, 0.18);
  opacity: 0;
}

.phase-scanning .scanProgress { opacity: 1; }

.scanProgress span {
  display: block;
  width: 0;
  height: 100%;
  background: #eaffff;
  box-shadow: 0 0 12px #71f4ff;
  transition: width 90ms linear;
}

.archetypeBadge {
  position: fixed;
  z-index: 11;
  top: 22px;
  right: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px 9px 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(2, 5, 7, 0.54);
  backdrop-filter: blur(9px);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 260ms ease, transform 260ms ease;
  pointer-events: none;
}

.archetypeBadge.visible {
  opacity: 1;
  transform: translateY(0);
}

.archetypeBadge > span {
  width: 8px;
  height: 32px;
  background: linear-gradient(180deg, var(--aura-b), var(--aura-a));
  box-shadow: 0 0 18px var(--aura-a);
}

.archetypeBadge strong,
.archetypeBadge small { display: block; }

.archetypeBadge strong {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.archetypeBadge small {
  margin-top: 2px;
  color: var(--muted);
  font: 9px/1.2 Consolas, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.winOverlay {
  position: fixed;
  z-index: 45;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 320ms ease, transform 320ms ease;
}

.winOverlay.is-visible {
  opacity: 1;
  transform: scale(1);
}

.winCard {
  width: min(620px, calc(100vw - 52px));
  padding: 18px 24px;
  border: 1px solid rgba(122, 245, 255, 0.35);
  background: rgba(2, 5, 7, 0.84);
  text-align: center;
  box-shadow: 0 20px 72px rgba(0, 0, 0, 0.45);
}

.winCard p,
.winCard h2 {
  margin: 0;
  text-transform: uppercase;
}

.winCard p {
  color: rgba(226, 243, 244, 0.84);
  letter-spacing: 0.12em;
  font: 11px/1.4 Consolas, "Courier New", monospace;
}

.winCard h2 {
  margin-top: 6px;
  font-size: clamp(28px, 6vw, 58px);
  line-height: 0.95;
  letter-spacing: 0.08em;
  text-shadow: 0 0 22px rgba(122, 245, 255, 0.65), 0 0 72px rgba(122, 245, 255, 0.4);
}

.startOverlay {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(2, 3, 4, 0.76), rgba(2, 3, 4, 0.94)),
    repeating-linear-gradient(90deg, transparent 0 79px, rgba(122, 245, 255, 0.035) 80px),
    #020304;
  transition: opacity 360ms ease, visibility 0s linear 360ms;
}

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

.startCard {
  position: relative;
  overflow: hidden;
  width: min(560px, 100%);
  padding: clamp(26px, 5vw, 52px);
  border-left: 2px solid var(--signal);
  background: rgba(5, 12, 14, 0.82);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.36);
}

.startCard::after {
  content: "";
  position: absolute;
  right: 100%;
  bottom: 0;
  width: 42%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--signal));
  opacity: 0;
}

.startOverlay.is-loading .startCard::after {
  opacity: 1;
  animation: startupSweep 1.1s ease-in-out infinite;
}

@keyframes startupSweep {
  to { transform: translateX(340%); }
}

.startCard h2 {
  margin: 13px 0 17px;
  font-size: clamp(48px, 10vw, 100px);
  line-height: 0.82;
  letter-spacing: -0.025em;
  text-transform: uppercase;
}

.startCard > p:not(.overline):not(.startStatus) {
  max-width: 46ch;
  margin: 0 0 24px;
  color: rgba(235, 249, 250, 0.72);
  font-size: 15px;
  line-height: 1.55;
}

.startButton {
  min-width: 210px;
  min-height: 48px;
  border-color: rgba(122, 245, 255, 0.55);
  background: var(--signal);
  color: #021013;
}

.startButton:disabled { opacity: 0.5; cursor: wait; }

.startStatus {
  margin: 15px 0 0;
  color: rgba(226, 243, 244, 0.48);
  font: 10px/1.5 Consolas, monospace;
}

.startStatus.error { color: #ff8d86; }

.exitFullscreen {
  position: fixed;
  z-index: 30;
  top: 12px;
  left: 12px;
  width: 36px;
  height: 36px;
  display: none;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
}

body.projection-mode #operatorPanel,
body.projection-mode #panelToggle { display: none !important; }

body.projection-mode .exitFullscreen { display: grid; }

@media (max-width: 720px) {
  #operatorPanel {
    top: max(8px, env(safe-area-inset-top));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 10px;
    width: min(300px, calc(100vw - 20px));
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scrollbar-gutter: stable;
  }

  .buttonRow {
    position: sticky;
    z-index: 3;
    bottom: 0;
    margin: 8px -15px 0;
    padding: 10px 15px calc(15px + env(safe-area-inset-bottom));
    border-top-color: rgba(122, 245, 255, 0.3);
    background: rgba(3, 8, 10, 0.97);
    box-shadow: 0 -16px 28px rgba(2, 3, 4, 0.82);
  }

  .shortcutHint { display: none; }
  .archetypeBadge { top: 12px; right: 12px; }
  .readingOverlay { bottom: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
