/* ================================================================
   ZONA — 1980s Soviet CRT terminal
   Pure CSS, no external assets. Theme via [data-theme] on #crt.
   ================================================================ */

:root {
  --bg:        #000600;
  --bg-soft:   #01120a;
  --phos:      #33ff66;          /* primary phosphor */
  --phos-dim:  #1c9c44;          /* dimmed text */
  --phos-fade: #0e5228;          /* tracks / borders */
  --glow:      rgba(51,255,102,0.55);
  --glow-soft: rgba(51,255,102,0.18);
  --warn:      #ff5a48;
  --warn-glow: rgba(255,90,72,0.5);
  --scan-op:   0.22;
  --font: "Cascadia Mono", "Consolas", "SFMono-Regular", "DejaVu Sans Mono",
          "Liberation Mono", "Courier New", ui-monospace, monospace;
}

#crt[data-theme="amber"] {
  --bg:        #0a0500;
  --bg-soft:   #150c00;
  --phos:      #ffb63c;
  --phos-dim:  #b97a12;
  --phos-fade: #5c3a06;
  --glow:      rgba(255,182,60,0.55);
  --glow-soft: rgba(255,182,60,0.18);
  --warn:      #ff5a48;
  --warn-glow: rgba(255,90,72,0.5);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #000;
  color: var(--phos);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: none;
  overflow: hidden;
}

/* ---------- CRT shell ---------- */
#crt {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 120% 130% at 50% 40%, var(--bg-soft) 0%, var(--bg) 62%, #000 100%);
  color: var(--phos);
  overflow: hidden;
  animation: crt-flicker 6s infinite steps(60);
}

#frame {
  position: relative;
  z-index: 2;
  height: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(10px, 2.4vw, 26px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-shadow: 0 0 4px var(--glow), 0 0 14px var(--glow-soft);
}

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--phos-fade);
  padding-bottom: 10px;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { animation: blink 1.1s steps(1) infinite; }
.brand-name { font-weight: 700; letter-spacing: 0.42em; font-size: 1.15rem; }
.brand-sub  { color: var(--phos-dim); font-size: 0.72rem; letter-spacing: 0.22em; text-transform: uppercase; }

.controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.tbtn {
  font: inherit;
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--phos);
  background: transparent;
  border: 1px solid var(--phos-fade);
  padding: 5px 9px;
  cursor: pointer;
  text-shadow: inherit;
  transition: background 90ms linear, box-shadow 90ms linear;
}
.tbtn:hover, .tbtn:focus-visible {
  background: var(--glow-soft);
  border-color: var(--phos-dim);
  box-shadow: 0 0 8px var(--glow-soft);
  outline: none;
}
.tbtn:active { transform: translateY(1px); }

.acct { font-size: 0.74rem; letter-spacing: 0.1em; color: var(--phos-dim); display: inline-flex; align-items: center; gap: 8px; }
.acct .who { color: var(--phos); }

/* ---------- Status bar ---------- */
#statusbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto auto;
  gap: clamp(10px, 2.4vw, 30px);
  border: 1px solid var(--phos-fade);
  padding: 10px 14px;
  background: rgba(0,0,0,0.35);
}
.stat { position: relative; display: flex; align-items: center; gap: 10px; min-width: 0; }
.stat-label {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  color: var(--phos-dim);
  white-space: nowrap;
  width: 5.4em;
  text-align: right;
}
.stat-track {
  position: relative;
  flex: 1 1 auto;
  height: 12px;
  min-width: 40px;
  border: 1px solid var(--phos-fade);
  background:
    repeating-linear-gradient(90deg, transparent 0 3px, rgba(0,0,0,0.5) 3px 4px);
  overflow: hidden;
}
.stat-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--phos);
  box-shadow: 0 0 8px var(--glow);
  transition: width 320ms ease, background 200ms linear;
}
.stat-val { font-size: 0.8rem; width: 2.6em; text-align: right; font-variant-numeric: tabular-nums; }

#stat-rad.danger .stat-fill { background: var(--warn); box-shadow: 0 0 10px var(--warn-glow); }
#stat-rad.danger .stat-val,
#stat-health.danger .stat-val { color: var(--warn); text-shadow: 0 0 6px var(--warn-glow); }
#stat-health.danger .stat-fill { background: var(--warn); box-shadow: 0 0 10px var(--warn-glow); }

/* Medkit — a count, not a bar, with an inline USE button. */
.stat-item { gap: 8px; white-space: nowrap; }
.stat-item .stat-val { width: auto; min-width: 2.2em; color: var(--phos); }
.use-btn {
  font: inherit;
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  color: var(--phos);
  background: transparent;
  border: 1px solid var(--phos-fade);
  padding: 2px 8px;
  cursor: pointer;
  transition: background 140ms linear, box-shadow 140ms linear, opacity 140ms linear;
}
.use-btn:hover:not(:disabled) { background: rgba(51,255,102,0.12); box-shadow: 0 0 8px var(--glow); }
.use-btn:disabled { opacity: 0.35; cursor: default; }

/* Floating stat delta (surface the cost/gain of a choice). */
.stat-delta {
  position: absolute;
  right: 0;
  top: -0.35rem;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  opacity: 0;
  color: var(--phos);
  text-shadow: 0 0 6px var(--glow);
}
.stat-delta.down { color: var(--warn); text-shadow: 0 0 6px var(--warn-glow); }
.stat-delta.flash { animation: statDelta 1150ms ease-out; }
@keyframes statDelta {
  0%   { opacity: 0; transform: translateY(6px); }
  18%  { opacity: 1; transform: translateY(-2px); }
  70%  { opacity: 1; transform: translateY(-12px); }
  100% { opacity: 0; transform: translateY(-20px); }
}
@media (prefers-reduced-motion: reduce) {
  .stat-delta.flash { animation: none; }
}

/* ---------- Screen ---------- */
#screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--phos-fade);
  background: rgba(0,0,0,0.28);
}
#viewport {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: clamp(14px, 3vw, 30px);
  scrollbar-width: thin;
  scrollbar-color: var(--phos-fade) transparent;
}
#viewport::-webkit-scrollbar { width: 10px; }
#viewport::-webkit-scrollbar-thumb { background: var(--phos-fade); }
#viewport::-webkit-scrollbar-track { background: transparent; }

.view { animation: fade-in 240ms ease; }
[hidden] { display: none !important; }

/* ---------- Boot ---------- */
#boot { white-space: pre-wrap; font-size: 0.92rem; }
.boot-line { min-height: 1.5em; }
.boot-ok { color: var(--phos); }
.boot-title {
  display: block;
  white-space: pre;
  line-height: 1.02;
  font-size: clamp(6px, 1.9vw, 15px);
  margin: 18px 0 8px;
  letter-spacing: 0;
  filter: drop-shadow(0 0 6px var(--glow));
  overflow-x: auto;
}
.boot-tag { color: var(--phos-dim); letter-spacing: 0.24em; font-size: 0.8rem; }
.boot-prompt { margin-top: 22px; color: var(--phos); }
.boot-prompt::after { content: "\2588"; animation: blink 1s steps(1) infinite; margin-left: 2px; }

/* ---------- Scene ---------- */
.location {
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--phos-dim);
  border-bottom: 1px dashed var(--phos-fade);
  padding-bottom: 8px;
  margin-bottom: 16px;
}
.location::before { content: "\25B8  "; }

/* Consequence line — narrates what a costly choice did to you, on arrival. */
.consequence {
  font-size: clamp(0.85rem, 2.2vw, 0.96rem);
  font-style: italic;
  color: var(--warn);
  opacity: 0.9;
  margin: -8px 0 16px;
  min-height: 1.3em;
  text-shadow: 0 0 6px var(--warn-glow);
}
.consequence[hidden] { display: none; }
.consequence::before { content: "\2500  "; opacity: 0.55; font-style: normal; }
.consequence .tag { font-style: normal; font-variant-numeric: tabular-nums; opacity: 0.85; }

.scene-text {
  font-size: clamp(0.95rem, 2.5vw, 1.06rem);
  white-space: pre-wrap;
  margin-bottom: 22px;
  min-height: 1.5em;
}
.scene-text.typing::after {
  content: "\2588";
  animation: blink 0.8s steps(1) infinite;
  margin-left: 1px;
}

.choices { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.choice {
  font: inherit;
  text-align: left;
  width: 100%;
  color: var(--phos);
  background: transparent;
  border: 1px solid transparent;
  border-left: 2px solid var(--phos-fade);
  padding: 8px 12px;
  cursor: pointer;
  text-shadow: inherit;
  transition: background 90ms linear, border-color 90ms linear, padding-left 90ms ease;
  display: flex;
  gap: 12px;
  align-items: baseline;
}
.choice:hover, .choice:focus-visible {
  background: var(--glow-soft);
  border-color: var(--phos-dim);
  border-left-color: var(--phos);
  padding-left: 18px;
  outline: none;
}
.choice .num {
  color: var(--phos-dim);
  font-weight: 700;
  white-space: nowrap;
  min-width: 2.4em;
}
.choice:hover .num, .choice:focus-visible .num { color: var(--phos); }
.choice[disabled] { opacity: 0.35; cursor: default; }
.choice .lbl { flex: 1; }

/* ---------- Auth ---------- */
#auth { max-width: 460px; }
.auth-title { letter-spacing: 0.2em; text-transform: uppercase; margin: 0 0 6px; font-size: 0.95rem; }
.auth-sub { color: var(--phos-dim); font-size: 0.8rem; margin: 0 0 20px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--phos-dim);
  margin-bottom: 5px;
}
.field-input {
  font: inherit;
  width: 100%;
  color: var(--phos);
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--phos-fade);
  padding: 9px 11px;
  text-shadow: inherit;
  caret-color: var(--phos);
}
.field-input:focus { outline: none; border-color: var(--phos); box-shadow: 0 0 8px var(--glow-soft); }

.captcha-row { display: flex; align-items: center; gap: 12px; }
.captcha-img {
  height: 52px;
  min-width: 130px;
  border: 1px solid var(--phos-fade);
  background: #000;
  image-rendering: pixelated;
  filter: hue-rotate(0deg);
}
.captcha-img.empty { display: inline-flex; align-items: center; justify-content: center; color: var(--phos-dim); font-size: 0.7rem; }

.auth-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.btn-primary {
  font: inherit;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--phos);
  border: 1px solid var(--phos);
  padding: 9px 18px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 0 12px var(--glow-soft);
}
.btn-primary:hover, .btn-primary:focus-visible { box-shadow: 0 0 16px var(--glow); outline: none; }
.btn-ghost { font: inherit; color: var(--phos); background: transparent; border: 1px solid var(--phos-fade); padding: 9px 16px; cursor: pointer; letter-spacing: 0.12em; text-transform: uppercase; text-shadow: inherit; }
.btn-ghost:hover, .btn-ghost:focus-visible { background: var(--glow-soft); outline: none; }
.btn-ghost.on { border-color: var(--phos); color: var(--phos); background: var(--glow-soft); }

.auth-error { color: var(--warn); text-shadow: 0 0 6px var(--warn-glow); font-size: 0.82rem; min-height: 1.2em; margin-top: 12px; }

/* ---------- Overlay (menus / death / ending) ---------- */
#overlay { display: flex; flex-direction: column; justify-content: center; min-height: 100%; }
.ov-art { white-space: pre; font-size: clamp(6px, 1.6vw, 13px); line-height: 1.05; margin-bottom: 14px; overflow-x: auto; }
.ov-title { letter-spacing: 0.28em; text-transform: uppercase; font-size: 1.1rem; margin: 0 0 10px; }
.ov-text { white-space: pre-wrap; margin-bottom: 22px; color: var(--phos-dim); max-width: 60ch; }
.ov-text strong { color: var(--phos); font-weight: 400; }
.ov-endings {
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--phos-dim);
  margin: -8px 0 18px;
}

/* Journey log */
.log-list { width: 100%; max-width: 70ch; margin: 0 0 18px; }
.log-entry { border-left: 1px solid var(--phos-fade); padding: 2px 0 10px 14px; margin-bottom: 12px; }
.log-loc {
  font-size: 0.64rem; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--phos-dim); margin-bottom: 4px;
}
.log-text { white-space: pre-wrap; color: var(--phos-dim); font-size: 0.92rem; margin: 0; }

#overlay.death { color: var(--warn); }
#overlay.death .ov-title, #overlay.death .ov-art { color: var(--warn); text-shadow: 0 0 8px var(--warn-glow); }
#overlay.win .ov-title, #overlay.win .ov-art { text-shadow: 0 0 10px var(--glow); }
#overlay.alt .ov-title { color: var(--phos-dim); }

/* ---------- Message line ---------- */
.message {
  margin: 0;
  padding: 6px clamp(14px, 3vw, 30px);
  min-height: 1.6em;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  color: var(--phos-dim);
  border-top: 1px solid var(--phos-fade);
}
.message.err { color: var(--warn); text-shadow: 0 0 6px var(--warn-glow); }

/* ================================================================
   CRT overlays
   ================================================================ */
#scanlines {
  position: fixed; inset: 0; z-index: 5; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,var(--scan-op)) 3px,
    rgba(0,0,0,var(--scan-op)) 3px
  );
  background-size: 100% 3px;
  mix-blend-mode: multiply;
  animation: scan-roll 9s linear infinite;
}
#vignette {
  position: fixed; inset: 0; z-index: 4; pointer-events: none;
  background: radial-gradient(ellipse 100% 100% at 50% 50%, transparent 55%, rgba(0,0,0,0.55) 100%);
}
#glare {
  position: fixed; inset: 0; z-index: 6; pointer-events: none;
  background: radial-gradient(ellipse 70% 55% at 50% 8%, var(--glow-soft) 0%, transparent 60%);
  opacity: 0.4;
}
#flicker {
  position: fixed; inset: 0; z-index: 7; pointer-events: none;
  background: var(--phos);
  opacity: 0;
  mix-blend-mode: overlay;
  animation: soft-flicker 130ms infinite steps(2);
}

/* Curvature illusion */
#crt::after {
  content: "";
  position: fixed; inset: 0; z-index: 8; pointer-events: none;
  box-shadow: inset 0 0 120px rgba(0,0,0,0.7), inset 0 0 30px rgba(0,0,0,0.5);
  border-radius: 8px;
}

/* State-reactive overlays: low health bleeds red, high radiation glows sickly. */
#crt.low-health #vignette { animation: lowHealthPulse 1.9s ease-in-out infinite; }
#crt.high-rad #scanlines { animation-duration: 3.4s; }
#crt.high-rad #glare { animation: radPulse 1.25s ease-in-out infinite; }
@keyframes lowHealthPulse {
  0%, 100% { box-shadow: inset 0 0 90px 8px rgba(255,30,24,0); }
  50%      { box-shadow: inset 0 0 210px 46px rgba(255,30,24,0.30); }
}
@keyframes radPulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 0.72; background: radial-gradient(ellipse 80% 60% at 50% 10%, rgba(90,255,120,0.5) 0%, transparent 62%); }
}

/* ---------- Keyframes ---------- */
@keyframes blink { 0%,50% { opacity: 1; } 50.01%,100% { opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scan-roll { from { background-position: 0 0; } to { background-position: 0 100vh; } }
@keyframes soft-flicker {
  0%   { opacity: 0.010; }
  100% { opacity: 0.028; }
}
@keyframes crt-flicker {
  0%,100% { filter: brightness(1.00); }
  47%     { filter: brightness(1.00); }
  48%     { filter: brightness(1.06); }
  49%     { filter: brightness(0.96); }
  50%     { filter: brightness(1.03); }
  51%     { filter: brightness(1.00); }
  92%     { filter: brightness(1.00); }
  93%     { filter: brightness(0.94); }
  94%     { filter: brightness(1.02); }
  95%     { filter: brightness(1.00); }
}

@media (prefers-reduced-motion: reduce) {
  #crt, #flicker, #scanlines { animation: none; }
  .scene-text.typing::after, .boot-prompt::after, .brand-mark { animation: none; }
  #crt.low-health #vignette, #crt.high-rad #glare { animation: none; }
}

@media (max-width: 620px) {
  html, body { font-size: 15px; }
  .brand-sub { display: none; }
  /* Tighter controls so the button row wraps to at most two lines. */
  .controls { gap: 4px; justify-content: flex-start; }
  .tbtn { font-size: 0.66rem; padding: 4px 7px; letter-spacing: 0.06em; }
  /* Bars stay full-width (readable); the two item counters share a row. */
  #statusbar { grid-template-columns: 1fr 1fr; gap: 6px 14px; padding: 8px 10px; }
  #stat-health, #stat-rad, #stat-ammo { grid-column: 1 / -1; }
  .stat-label { width: auto; }
}

/* ---------- Terminal auth gate ---------- */
#auth .term { line-height: 1.6; }
.term-line {
  margin: 0;
  min-height: 1.25em;
  white-space: pre-wrap;
  word-break: break-word;
}
.term-line.term-dim { color: var(--phos-dim); }
.term-line.term-ok  { color: var(--phos); text-shadow: 0 0 6px var(--glow); }
.term-line.term-warn{ color: var(--phos); text-shadow: 0 0 8px var(--glow); letter-spacing: 0.05em; }
.term-line.term-err { color: var(--warn); text-shadow: 0 0 6px var(--warn-glow); }

.term-ask { display: flex; align-items: baseline; flex-wrap: wrap; }
.term-prompt { color: var(--phos-dim); white-space: pre; }
.term-input {
  flex: 1 1 8ch;
  min-width: 8ch;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--phos);
  font: inherit;
  letter-spacing: inherit;
  caret-color: var(--phos);
  text-shadow: 0 0 6px var(--glow);
}
.term-echo { color: var(--phos); text-shadow: 0 0 6px var(--glow); }

.term-captcha-line { margin: 0.5rem 0; }
.term-captcha {
  height: 54px;
  width: auto;
  display: inline-block;
  padding: 4px 10px;
  background: #000;
  border: 1px solid var(--phos-fade);
  image-rendering: pixelated;
}

/* Sound toggle: dim + struck through when muted. */
#btn-sound.muted { opacity: 0.42; text-decoration: line-through; }
