:root {
  --bg: #04080a;
  --bg-tint: #061218;
  --fg: #d6ffe6;
  --fg-dim: #95d4ad;
  --fg-muted: #7ab098;
  --accent: #7df2cb;
  --warn: #ffd676;
  --danger: #ff7080;
  --info: #9bcdff;
  --hud: #e3efea;
  --survivor: #ff8de1;
  --hot: #ff7080;
  --warm: #ffd676;
  --cold: #95d4ad;
  --paraply: #ff7575;
  --mono: "IBM Plex Mono", "JetBrains Mono", "Fira Code", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 17px;
  line-height: 1.5;
  overflow: hidden;
}

.crt {
  position: relative;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at center, var(--bg-tint) 0%, var(--bg) 70%, #000 100%);
  animation: flicker 7s infinite;
  transition: background 1.4s ease-in-out;
}

/* per-level color themes — subtle radial tint shift */
.crt.theme-1 {
  background:
    radial-gradient(ellipse at center, rgba(8,28,30,0.85) 0%, var(--bg) 70%, #000 100%);
}
.crt.theme-2 {
  /* decryption — cool blue-purple */
  background:
    radial-gradient(ellipse at center, rgba(20,18,52,0.7) 0%, var(--bg) 70%, #000 100%);
}
.crt.theme-3 {
  /* engineering — amber */
  background:
    radial-gradient(ellipse at center, rgba(48,32,8,0.55) 0%, var(--bg) 70%, #000 100%);
}
.crt.theme-4 {
  /* breach — red alert */
  background:
    radial-gradient(ellipse at center, rgba(58,8,12,0.7) 0%, var(--bg) 70%, #000 100%);
  animation: flicker 5s infinite, redalert 2.4s infinite;
}
@keyframes redalert {
  0%, 100% { box-shadow: inset 0 0 60px 0 rgba(255,40,60,0.05); }
  50%      { box-shadow: inset 0 0 120px 0 rgba(255,40,60,0.18); }
}
.crt.theme-5 {
  /* extracted — calm green */
  background:
    radial-gradient(ellipse at center, rgba(8,40,28,0.7) 0%, var(--bg) 70%, #000 100%);
}

/* Hard mode (?mode=blackout) — visual cue: skull next to BLACKOUT in HUD,
   subtle red border-glow. Hints disabled, positive points doubled. */
.crt.hard-mode .hud .hud-label:first-child::after {
  content: " ☠";
  color: var(--danger);
  margin-left: 4px;
  text-shadow: 0 0 6px rgba(255,79,94,0.6);
}
.crt.hard-mode { box-shadow: inset 0 0 60px rgba(255,40,60,0.06); }

/* Click-to-establish gate — shown at fresh-session start so the user's
   click unlocks browser audio. Disappears with a fade once dismissed. */
.boot-gate {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  cursor: pointer;
  animation: gatefade 0.4s ease-out 1;
}
.boot-gate.dismissed { opacity: 0; transition: opacity 0.32s ease-in; pointer-events: none; }
.boot-gate-inner {
  text-align: center;
  font-family: var(--mono);
  text-shadow: 0 0 8px rgba(108,240,194,0.6);
}
.boot-gate-title {
  color: var(--accent); font-size: 22px; letter-spacing: 0.34em;
  font-weight: 700;
}
.boot-gate-sub {
  color: var(--fg-dim); font-size: 12px; letter-spacing: 0.24em;
  margin-top: 6px;
  text-transform: uppercase;
}
.boot-gate-cursor {
  color: var(--fg); font-size: 15px; letter-spacing: 0.04em;
  margin-top: 36px;
  animation: gateblink 1.2s steps(2) infinite;
}
@keyframes gatefade {
  0%   { opacity: 0; }
  100% { opacity: 1; }
}
@keyframes gateblink {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: 0.4; }
}

/* Cold-open — applied during the 5-6s fake boot-failure before the intro.
   Distressed look: hard flicker, slight chromatic tear, occasional full
   screen blackouts via the .cold-blackout class. */
.crt.cold-open {
  animation: coldflicker 0.4s steps(2, start) infinite, coldtear 2.6s ease-in-out infinite;
  filter: contrast(1.25) saturate(0.7);
}
.crt.cold-open .scanlines { opacity: 1.6; mix-blend-mode: multiply; }
@keyframes coldflicker {
  0%, 100% { opacity: 1; }
  18%      { opacity: 0.55; }
  36%      { opacity: 0.95; }
  52%      { opacity: 0.3; }
  70%      { opacity: 0.85; }
  88%      { opacity: 0.5; }
}
@keyframes coldtear {
  0%, 100% { transform: translate(0, 0); }
  18%      { transform: translate(-3px, 1px) skewX(-1deg); filter: contrast(1.4) saturate(0.6) hue-rotate(20deg); }
  40%      { transform: translate(4px, -2px) skewX(1deg); filter: contrast(1.1) saturate(0.8) hue-rotate(-15deg); }
  62%      { transform: translate(-2px, 2px); filter: contrast(1.3) saturate(0.5); }
  82%      { transform: translate(1px, 0); }
}

/* Brief full-screen blackout — fired at climactic moments during cold-open
   (FAILED retries, kernel panic, recovery). 360ms of darkness then return. */
.crt.cold-blackout {
  animation: coldblackout 0.36s steps(2, end) 1;
}
@keyframes coldblackout {
  0%   { opacity: 1; filter: contrast(2) brightness(2); }
  10%  { opacity: 0; background: #000; }
  85%  { opacity: 0; background: #000; }
  100% { opacity: 1; }
}

/* CDC emergency-channel skin — applied mid-game at T+30:00 when the
   primary BMS link "drops". Shifts the palette to amber/orange and
   re-tints headers and HUD. Pure cosmetic but creates a memorable beat. */
.crt.skin-cdc {
  --accent: #ffb255;
  --fg: #ffd9a8;
  --fg-dim: #c79055;
  --fg-muted: #6b4d20;
  --hud: #ffe6c2;
  --paraply: #ffb255;
  --info: #ffd28a;
  background:
    radial-gradient(ellipse at center, rgba(48,28,4,0.7) 0%, var(--bg) 70%, #000 100%);
}
.crt.skin-cdc .hud {
  border-bottom-color: #6b4d20;
  background: rgba(20,12,4,0.85);
}
.crt.skin-cdc .prompt-row {
  border-top-color: #6b4d20;
  background: rgba(20,12,4,0.85);
}
.crt.skin-cdc .ops-section { border-color: #6b4d20; }
.crt.skin-cdc .ops-brand { border-color: var(--accent); }
.crt.skin-cdc .ops-brand .brand,
.crt.skin-cdc .ops-thermite-time {
  color: var(--accent);
  text-shadow: 0 0 8px rgba(255,178,85,0.5);
}

/* Reader mode — accessibility toggle. Kills flicker, hides scanlines/vignette,
   disables glitch overlays, bumps font. Use 'reader' command. */
.crt.reader-mode {
  animation: none !important;
  background: var(--bg);
}
.crt.reader-mode .scanlines,
.crt.reader-mode .vignette,
.crt.reader-mode .glitch-overlay { display: none; }
.crt.reader-mode .terminal { font-size: 19px; line-height: 1.6; }
.crt.reader-mode .terminal .line { text-shadow: none; }
.crt.reader-mode.miniglitch { animation: none !important; }
.crt.reader-mode .floorplan .room.scanned-hot,
.crt.reader-mode .floorplan .room.survivor { animation: none; }

/* tiny screen flicker — fired ambiently every 18-40s during levels */
.crt.miniglitch { animation: flicker 7s infinite, miniglitch 0.36s ease-out 1; }
@keyframes miniglitch {
  0%   { transform: translate(0, 0); filter: hue-rotate(0deg); }
  20%  { transform: translate(-1px, 1px) skewX(-1deg); filter: hue-rotate(20deg); }
  60%  { transform: translate(1px, -1px) skewX(0.6deg); filter: hue-rotate(-15deg); }
  100% { transform: translate(0, 0); filter: hue-rotate(0deg); }
}

@keyframes flicker {
  0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% { opacity: 1; }
  20%, 24%, 55% { opacity: 0.92; }
}

.scanlines {
  position: absolute; inset: 0; pointer-events: none; z-index: 5;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.09) 3px, rgba(0,0,0,0) 4px);
  mix-blend-mode: multiply;
}

.vignette {
  position: absolute; inset: 0; pointer-events: none; z-index: 4;
  background: radial-gradient(ellipse at center, transparent 75%, rgba(0,0,0,0.5) 100%);
}

.glitch-overlay {
  position: absolute; inset: 0; pointer-events: none; z-index: 8;
  opacity: 0;
}
.glitch-overlay.active {
  animation: bigglitch 0.7s ease-out 1;
}
@keyframes bigglitch {
  0%   { opacity: 0; transform: translate(0,0); filter: hue-rotate(0deg); }
  10%  { opacity: 1; background:
           repeating-linear-gradient(to bottom,
             rgba(255,80,80,0.4) 0, rgba(255,80,80,0.4) 2px,
             transparent 2px, transparent 6px);
         transform: translate(2px,-1px) skewX(-3deg); }
  35%  { background:
           repeating-linear-gradient(to bottom,
             rgba(105,224,255,0.35) 0, rgba(105,224,255,0.35) 1px,
             transparent 1px, transparent 4px);
         transform: translate(-2px,2px) skewX(2deg); filter: hue-rotate(45deg); }
  60%  { background: rgba(0,0,0,0.6); transform: translate(0,0); }
  100% { opacity: 0; transform: translate(0,0); }
}

.hud {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--fg-muted);
  font-size: 13px; letter-spacing: 0.08em;
  color: var(--hud); text-transform: uppercase;
  background: rgba(4,12,14,0.85);
}
.hud-label { white-space: nowrap; }
.hud-sep { color: var(--fg-muted); }
.hud-label span { color: var(--accent); }
.hud-btn {
  margin-left: auto; background: transparent;
  border: 1px solid var(--fg-muted); color: var(--hud);
  font-family: var(--mono); font-size: 12px;
  padding: 5px 12px; cursor: pointer; letter-spacing: 0.08em;
}
.hud-btn:hover { border-color: var(--accent); color: var(--accent); }

.layout {
  position: relative; z-index: 3;
  display: flex; flex: 1; min-height: 0;
}

.terminal {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px 6px;
  white-space: pre-wrap; word-break: break-word;
  text-shadow: 0 0 1px rgba(108,240,194,0.4);
}
.terminal::-webkit-scrollbar { width: 8px; }
.terminal::-webkit-scrollbar-track { background: transparent; }
.terminal::-webkit-scrollbar-thumb { background: var(--fg-muted); border-radius: 4px; }

.line { white-space: pre-wrap; }
.line.dim { color: var(--fg-dim); }
.line.muted { color: var(--fg-muted); }
.line.warn { color: var(--warn); }
.line.danger { color: var(--danger); }
.line.info { color: var(--info); }
.line.accent { color: var(--accent); }
.line.echo { color: var(--fg-dim); }
.line.echo::before { content: "› "; color: var(--fg-muted); }
.line.system { color: var(--accent); letter-spacing: 0.05em; }
.line.ascii { color: var(--accent); }
.line.noise { color: var(--fg-muted); font-size: 14px; opacity: 0.85; }
.line.survivor {
  color: var(--survivor); font-weight: 600;
  text-shadow: 0 0 8px rgba(255,122,217,0.65);
  letter-spacing: 0.02em;
}
.line.survivor::before { content: "[DR. NORDLUND] "; color: var(--survivor); opacity: 0.95; font-weight: 700; }

/* Two operator voices that disagree. CONTROL = cold/grey, VEGA = warm/amber. */
.line.control { color: #8aa6a0; font-style: italic; opacity: 0.85; }
.line.vega { color: #ffb255; font-style: italic; opacity: 0.92; }

.line.glitch { animation: glitch 0.4s steps(4, end) 1; color: var(--danger); }
@keyframes glitch {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-2px); filter: hue-rotate(40deg); }
  40%  { transform: translateX(2px); }
  60%  { transform: translateX(-1px); filter: hue-rotate(-30deg); }
  100% { transform: translateX(0); }
}

.boot { color: var(--fg-dim); font-size: 14px; }

.prompt-row {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 28px 18px;
  border-top: 2px solid var(--accent);
  background:
    linear-gradient(180deg, rgba(108,240,194,0.06) 0%, rgba(4,12,14,0.92) 40%);
  box-shadow: 0 -2px 18px rgba(108,240,194,0.12);
  animation: promptglow 2.6s ease-in-out infinite;
}
@keyframes promptglow {
  0%, 100% { box-shadow: 0 -2px 14px rgba(108,240,194,0.08); }
  50%      { box-shadow: 0 -2px 24px rgba(108,240,194,0.22); }
}
.prompt-label {
  color: var(--accent); white-space: nowrap; font-weight: 700;
  text-shadow: 0 0 6px rgba(108,240,194,0.5);
}
.prompt-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--fg); font-family: var(--mono); font-size: 17px;
  caret-color: var(--accent);
}
.prompt-input::placeholder { color: var(--fg-dim); font-style: italic; opacity: 0.8; }
.prompt-input:disabled { color: var(--fg-muted); }
.prompt-input:focus::placeholder { opacity: 0.4; }

.prompt-blink {
  color: var(--accent); font-size: 18px; line-height: 1;
  animation: blink 1s steps(2, start) infinite;
  text-shadow: 0 0 6px rgba(108,240,194,0.6);
  pointer-events: none;
}
@keyframes blink { to { visibility: hidden; } }

.prompt-hint {
  color: var(--fg-muted); font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; white-space: nowrap;
  border: 1px solid var(--fg-muted); padding: 3px 8px; border-radius: 2px;
  pointer-events: none;
}

.crt.danger { animation: dangerpulse 1.2s infinite; }
@keyframes dangerpulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(255,0,50,0); }
  50%      { box-shadow: inset 0 0 80px 0 rgba(255,0,50,0.18); }
}

.chip {
  display: inline-block; padding: 1px 6px;
  border: 1px solid var(--fg-muted); border-radius: 2px;
  margin-right: 4px; color: var(--accent); font-size: 12px;
}

/* ============ OPS PANEL ============ */

.ops-panel {
  width: 380px; flex-shrink: 0;
  border-left: 1px solid var(--fg-muted);
  background: rgba(2,8,11,0.6);
  overflow-y: auto;
  padding: 16px 16px 20px;
  font-size: 13px; letter-spacing: 0.04em;
}
.ops-panel::-webkit-scrollbar { width: 6px; }
.ops-panel::-webkit-scrollbar-thumb { background: var(--fg-muted); }

.ops-section {
  border: 1px solid var(--fg-muted);
  padding: 10px 12px;
  margin-bottom: 12px;
  background: rgba(0,0,0,0.35);
}
.ops-section h4 {
  margin: 0 0 8px;
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--hud); font-weight: 600;
  border-bottom: 1px dashed var(--fg-muted); padding-bottom: 5px;
}
.ops-section .empty {
  color: var(--fg-muted); font-style: italic; font-size: 12px;
}

.ops-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-color: var(--paraply);
  background:
    linear-gradient(180deg, rgba(40,0,0,0.4), rgba(0,0,0,0.3));
}
.ops-brand .logo { width: 36px; height: 36px; flex-shrink: 0; }
.ops-brand .brand {
  color: var(--paraply); font-weight: 700; letter-spacing: 0.16em;
  font-size: 16px;
  text-shadow: 0 0 6px rgba(255,90,90,0.45);
}
.ops-brand .brand-sub {
  color: var(--hud); font-size: 10px; letter-spacing: 0.18em; opacity: 0.78;
}
.ops-brand .brand-tag {
  color: var(--fg-muted); font-size: 10px; letter-spacing: 0.06em;
  margin-top: 4px;
}

.floorplan {
  width: 100%; height: auto; display: block;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--fg-muted);
}
.floorplan .room {
  fill: rgba(95,169,127,0.05);
  stroke: var(--fg-muted);
  stroke-width: 1;
  transition: fill 0.3s, stroke 0.3s;
}
.floorplan .room.scanned-cold {
  fill: rgba(95,169,127,0.18);
  stroke: var(--cold);
}
.floorplan .room.scanned-warm {
  fill: rgba(255,205,91,0.22);
  stroke: var(--warm);
}
.floorplan .room.scanned-hot {
  fill: rgba(255,79,94,0.32);
  stroke: var(--hot);
  animation: hotpulse 1.6s infinite;
}
@keyframes hotpulse {
  0%, 100% { fill: rgba(255,79,94,0.32); }
  50%      { fill: rgba(255,79,94,0.52); }
}
.floorplan .room.survivor {
  fill: rgba(105,224,255,0.32);
  stroke: var(--survivor);
  stroke-width: 2;
  animation: survivorpulse 1.4s infinite;
}
@keyframes survivorpulse {
  0%, 100% { stroke-width: 2; filter: drop-shadow(0 0 2px var(--survivor)); }
  50%      { stroke-width: 3; filter: drop-shadow(0 0 6px var(--survivor)); }
}
.floorplan .room.marked-survivor {
  fill: rgba(108,240,194,0.25); stroke: var(--accent); stroke-dasharray: 3 2;
}
.floorplan .room.marked-hostile {
  fill: rgba(255,79,94,0.22); stroke: var(--danger); stroke-dasharray: 3 2;
}
.floorplan .label {
  fill: var(--hud); font-size: 8px; font-family: var(--mono); pointer-events: none;
  letter-spacing: 0.02em; font-weight: 700;
}
.floorplan .label-sub {
  fill: var(--fg-dim); font-size: 6px; font-family: var(--mono); pointer-events: none;
  letter-spacing: 0.04em; opacity: 0.95;
}
.floorplan .corridor-label {
  fill: var(--fg-muted); font-size: 6px; font-family: var(--mono);
  pointer-events: none; letter-spacing: 0.06em; font-style: italic;
}
.floorplan .drone {
  fill: var(--accent); stroke: #fff; stroke-width: 0.5;
  filter: drop-shadow(0 0 6px var(--accent));
}
.floorplan .radar-sweep { mix-blend-mode: screen; }

.ops-building .building-canvas {
  width: 100%; height: 200px; display: block;
  background:
    radial-gradient(ellipse at center, rgba(8,18,16,0.9) 0%, rgba(0,0,0,0.95) 100%);
  border: 1px solid var(--fg-muted);
  image-rendering: crisp-edges;
}
.building-meta {
  display: flex; justify-content: space-between;
  margin-top: 6px; font-size: 11px; color: var(--fg-muted);
  letter-spacing: 0.08em;
}
.building-meta .hf { color: var(--paraply); font-weight: 700; }
.building-coords { font-style: italic; opacity: 0.7; }

.ops-legend {
  display: flex; flex-wrap: wrap; gap: 5px 12px;
  margin-top: 8px; font-size: 11px;
  color: var(--fg-muted);
}
.ops-legend .swatch {
  display: inline-block; width: 10px; height: 10px;
  vertical-align: middle; margin-right: 5px;
  border: 1px solid currentColor;
}
.ops-legend .swatch.cold { color: var(--cold); background: rgba(95,169,127,0.4); }
.ops-legend .swatch.warm { color: var(--warm); background: rgba(255,205,91,0.4); }
.ops-legend .swatch.hot { color: var(--hot); background: rgba(255,79,94,0.5); }
.ops-legend .swatch.surv { color: var(--survivor); background: rgba(105,224,255,0.5); }

.vitals-row {
  display: flex; justify-content: space-between;
  padding: 4px 0;
  color: var(--hud);
}
.vitals-row span:first-child { color: var(--fg-muted); letter-spacing: 0.1em; font-size: 11px; }
.vitals-row span:last-child { color: var(--accent); font-weight: 600; font-size: 13px; }

.bar-track {
  position: relative;
  height: 6px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--fg-muted);
  margin: 4px 0;
}
.bar-fill {
  height: 100%; width: 100%;
  background: var(--accent);
  transition: width 0.6s, background 0.6s;
}
.bar-fill.bar-warn { background: var(--warm); }
.bar-fill.bar-danger { background: var(--danger); }
.bar-fill.bar-survivor { background: var(--survivor); }

.ops-thermite-time {
  text-align: center;
  margin-top: 8px;
  font-size: 22px; letter-spacing: 0.2em; font-weight: 700;
  color: var(--danger);
  text-shadow: 0 0 10px rgba(255,79,94,0.5);
}
.ops-thermite-time.calm {
  color: var(--accent);
  text-shadow: 0 0 6px rgba(108,240,194,0.4);
}

.heart {
  display: inline-block; margin-right: 6px;
  color: var(--survivor);
  animation: heartbeat 1s infinite;
}
@keyframes heartbeat {
  0%, 60%, 100% { transform: scale(1); }
  10%, 30%      { transform: scale(1.25); }
}

@media (max-width: 900px) {
  .ops-panel { display: none; }
  .terminal { padding: 14px 14px 6px; font-size: 13px; }
  .prompt-row { padding: 10px 14px 14px; }
  .hud { font-size: 10px; gap: 6px; padding: 8px 10px; }
}
