/* Veridia — phosphor terminal.
   Fonts: VT323 (display: titles, tabs, speaker names), Red Hat Mono (text, controls).
   Shape: square corners, 1px rules, inverse video for the active/primary thing. */

@font-face { font-family: "VT323"; src: url("/fonts/vt323-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Red Hat Mono"; src: url("/fonts/red-hat-mono-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Red Hat Mono"; src: url("/fonts/red-hat-mono-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  color-scheme: dark;
  /* phosphor (P1 green) */
  --case: #10120D;
  --bg: #040A06;
  --surface: #08150C;
  --text: #86FFA6;
  --muted: #4FB86C;
  --accent: #33FF66;
  --accent-ink: #021407;
  --rule: rgba(130, 255, 165, .38);
  --border: rgba(130, 255, 165, .16);
  --alert: #FFB347;
  --glow-c: rgba(61, 255, 122, .42);

  --f-display: "VT323", ui-monospace, Consolas, monospace;
  --f-text: "Red Hat Mono", ui-monospace, Consolas, monospace;
  --fs-xs: .78rem;
  --fs-s: .88rem;
  --fs-base: 1rem;
  --fs-l: 1.6rem;   /* VT323 sits small; display sizes are larger on purpose */
  --fs-xl: 2.4rem;
  --fs-xxl: clamp(3.2rem, 11vw, 6.5rem);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 40px;
  --d1: .12s; --d2: .3s; --d3: .55s;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

:root[data-theme="printout"] {
  color-scheme: light;
  --case: #C9CCBE;
  --bg: #EEF0E4;
  --surface: #DCE9D5;     /* green-bar band */
  --text: #0F2A17;
  --muted: #3F5C47;
  --accent: #0A6B2E;
  --accent-ink: #F3F6EC;
  --rule: rgba(15, 42, 23, .5);
  --border: rgba(15, 42, 23, .16);
  --alert: #8A4B00;
  --glow-c: transparent;
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--case);
  color: var(--text);
  font: 400 var(--fs-base)/1.6 var(--f-text);
  touch-action: manipulation;
}
::selection { background: var(--accent); color: var(--accent-ink); text-shadow: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: var(--s4); top: -100px; z-index: 10; background: var(--accent); color: var(--accent-ink); padding: var(--s2) var(--s3); }
.skip:focus { top: var(--s4); }
kbd { font: inherit; border: 1px solid var(--border); padding: 0 .35em; font-size: var(--fs-xs); color: var(--muted); }

/* ---------------------------------------------------------------- monitor */

.case {
  min-height: 100dvh;
  padding: max(var(--s3), env(safe-area-inset-top)) max(var(--s3), env(safe-area-inset-right))
           max(var(--s3), env(safe-area-inset-bottom)) max(var(--s3), env(safe-area-inset-left));
  display: flex;
}
.screen {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 1180px;
  margin: 0 auto;
  background: var(--bg);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.6), inset 0 0 90px rgba(0,0,0,.65);
  isolation: isolate;
}
:root[data-theme="printout"] .screen { border-radius: 0; box-shadow: 0 1px 0 rgba(0,0,0,.1); }

/* Scanlines + vignette sit on top of everything and never take clicks. */
.screen::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    radial-gradient(ellipse at center, transparent 58%, rgba(0,0,0,.45) 100%);
}
.fx-scan .screen::after {
  background:
    repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0,0,0,.28) 2px 3px),
    radial-gradient(ellipse at center, transparent 58%, rgba(0,0,0,.45) 100%);
}
:root[data-theme="printout"] .screen::after { display: none; }

.fx-glow .screen { text-shadow: 0 0 .35em var(--glow-c); }
.fx-flicker .screen { animation: flicker 7s steps(1) infinite; }
@keyframes flicker { 0%, 100% { opacity: 1; } 41% { opacity: .965; } 42% { opacity: 1; } 77% { opacity: .98; } 78% { opacity: 1; } }

/* Power-on: the beam opens from a line to the full raster. */
.screen.boot { animation: power-on var(--d3) var(--ease) both; }
@keyframes power-on {
  0% { transform: scale(1, .004); filter: brightness(3); }
  45% { transform: scale(1, .004); filter: brightness(3); }
  100% { transform: none; filter: none; }
}

/* ------------------------------------------------------------- status bar */

.bar {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4);
  padding: var(--s3) var(--s5) var(--s2);
  border-bottom: 1px solid var(--rule);
}
.brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0; font: 400 var(--fs-l)/1 var(--f-display); letter-spacing: .06em; text-transform: uppercase; }
.readout { display: flex; gap: var(--s5); margin: 0; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; }
.readout { flex: none; }
.readout div { display: flex; gap: var(--s2); white-space: nowrap; }
.readout dt { color: var(--muted); }
.readout dd { margin: 0; font-variant-numeric: tabular-nums; }
#link-state[data-state="online"]::before { content: "■ "; color: var(--accent); }
#link-state[data-state="offline"] { color: var(--alert); }
#link-state[data-state="offline"]::before { content: "□ "; }

/* ------------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--rule);
  padding: 0 var(--s4);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none;
  min-height: 44px;
  padding: 0 var(--s3);
  background: none; border: 0;
  font: 400 1.35rem/1 var(--f-display);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); text-shadow: none; }
.tabs button:focus-visible { outline-offset: -4px; }

/* ----------------------------------------------------------------- panels */

main { flex: 1; overflow-y: auto; outline: none; }
.panel { padding: var(--s5) var(--s5) var(--s6); max-width: 920px; }
.section-title { margin: 0 0 var(--s4); font: 400 var(--fs-xl)/1 var(--f-display); letter-spacing: .04em; text-transform: uppercase; }
.display { font: 400 var(--fs-xxl)/.9 var(--f-display); letter-spacing: .02em; text-transform: uppercase; margin: 0; }
.display.small { font-size: var(--fs-xl); }
.eyebrow { margin: 0 0 var(--s2); color: var(--muted); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .12em; }
.note { color: var(--muted); font-size: var(--fs-s); max-width: 62ch; margin: 0 0 var(--s4); }
.status { min-height: 1.6em; margin: var(--s3) 0 0; font-size: var(--fs-s); color: var(--muted); }
.status.err { color: var(--alert); }
.status.busy::after { content: "█"; margin-left: .3em; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.empty {
  border: 1px dashed var(--border);
  padding: var(--s5);
  color: var(--muted);
  font-size: var(--fs-s);
}
.empty b { color: var(--text); font-weight: 500; display: block; margin-bottom: var(--s1); }
.empty code { color: var(--text); }

/* --------------------------------------------------------------- commands */

.menu { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s5) 0 0; }
.cmd {
  min-height: 44px;
  padding: var(--s2) var(--s4);
  background: none;
  border: 1px solid var(--rule);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: var(--fs-s);
  font-weight: 500;
  display: inline-flex; align-items: center; gap: var(--s2);
}
.cmd::before { content: ">"; color: var(--muted); }
.cmd:hover:not(:disabled) { background: var(--surface); }
.cmd.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); text-shadow: none; }
.cmd.primary::before { color: inherit; }
.cmd.primary:hover:not(:disabled) { background: var(--text); border-color: var(--text); }
.cmd.danger { border-color: var(--alert); color: var(--alert); }
.cmd:disabled { opacity: 1; color: var(--muted); border-style: dashed; cursor: not-allowed; background: none; border-color: var(--border); }
.cmd.small { min-height: 36px; padding: var(--s1) var(--s3); font-size: var(--fs-xs); }
.file-btn { cursor: pointer; position: relative; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.file-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ----------------------------------------------------------- title screen */

.title-screen { padding-top: var(--s5); }
.premise { max-width: 60ch; margin: var(--s4) 0 0; }
.syscheck {
  margin: var(--s6) 0 0;
  font: 400 var(--fs-s)/1.7 var(--f-text);
  color: var(--muted);
  white-space: pre-wrap;
}
.syscheck .ok { color: var(--text); }
.syscheck .warn { color: var(--alert); }

/* ------------------------------------------------------------------ stage */

#p-play:has(.game:not([hidden])) { max-width: none; }
.stage {
  position: relative;
  margin: 0;
  aspect-ratio: 16 / 8;
  max-height: min(40dvh, 520px);
  width: 100%;
  border: 1px solid var(--rule);
  overflow: hidden;
  background:
    linear-gradient(var(--border) 1px, transparent 1px) 0 0 / 100% 24px,
    linear-gradient(90deg, var(--border) 1px, transparent 1px) 0 0 / 24px 100%,
    var(--surface);
}
.stage .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: grayscale(1) sepia(1) hue-rotate(70deg) saturate(2.2) brightness(.8) contrast(1.15); }
.stage .portrait { position: absolute; right: 4%; bottom: 0; height: 92%; width: auto; max-width: 45%; object-fit: contain; object-position: bottom; filter: grayscale(1) sepia(1) hue-rotate(70deg) saturate(2.2) brightness(.95); }
:root[data-theme="printout"] .stage .bg, :root[data-theme="printout"] .stage .portrait { filter: grayscale(1) contrast(1.1); }
.stage-cap {
  position: absolute; left: 0; top: 0; right: 0;
  display: flex; justify-content: space-between; gap: var(--s4);
  padding: var(--s2) var(--s3);
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .1em;
  background: linear-gradient(var(--bg), transparent);
}

.dialogue {
  position: relative;
  margin-top: var(--s3);
  border: 1px solid var(--rule);
  padding: var(--s4) var(--s5) var(--s6);
  min-height: 9.5em;
  cursor: pointer;
}
.speaker { margin: 0 0 var(--s2); font: 400 var(--fs-l)/1 var(--f-display); letter-spacing: .05em; text-transform: uppercase; color: var(--accent); }
.line { margin: 0; max-width: 72ch; font-size: 1.05rem; min-height: 3.2em; }
.line.typing::after, .line.waiting::after { content: "█"; margin-left: .15em; }
.line.waiting::after { animation: blink 1s steps(1) infinite; }
.advance {
  position: absolute; right: var(--s3); bottom: var(--s2);
  background: none; border: 0; padding: var(--s2);
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.advance:hover { color: var(--text); }

.choices { list-style: none; margin: var(--s3) 0 0; padding: 0; border-top: 1px solid var(--rule); }
.choices li { border-bottom: 1px solid var(--border); }
.choices button {
  width: 100%; text-align: left;
  min-height: 48px;
  padding: var(--s3) var(--s3);
  background: none; border: 0;
  display: grid; grid-template-columns: 3ch 1fr; gap: var(--s3);
}
.choices button span:first-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.choices button:hover, .choices button:focus-visible { background: var(--text); color: var(--bg); text-shadow: none; outline: none; }
.choices button:hover span:first-child, .choices button:focus-visible span:first-child { color: inherit; }
.choices button:disabled { color: var(--muted); cursor: progress; background: none; }

.end { margin-top: var(--s5); }

/* ---------------------------------------------------------------- dossier */

.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--s1) var(--s5); margin: 0 0 var(--s5); font-size: var(--fs-s); }
.facts dt { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: var(--fs-xs); padding-top: .15em; }
.facts dd { margin: 0; }

.stat-group { margin: var(--s5) 0 0; }
.stat-group h3 { margin: 0 0 var(--s2); font: 400 1.35rem/1 var(--f-display); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat-rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.stat-rows li {
  display: grid; grid-template-columns: minmax(10ch, 1fr) auto 5ch; gap: var(--s4); align-items: center;
  padding: var(--s2) 0; border-bottom: 1px solid var(--border);
  font-size: var(--fs-s);
}
.meter { font-variant-numeric: tabular-nums; letter-spacing: -.02em; white-space: pre; }
.meter .off { color: var(--border); }
:root[data-theme="printout"] .meter .off { color: var(--rule); opacity: .5; }
.stat-rows .val { text-align: right; font-variant-numeric: tabular-nums; }
.delta-up { color: var(--accent); }
.delta-down { color: var(--alert); }

/* ------------------------------------------------------------------ codex */

.seg { display: inline-flex; border: 1px solid var(--rule); margin-bottom: var(--s4); flex-wrap: wrap; }
.seg button { min-height: 40px; padding: 0 var(--s4); background: none; border: 0; font-size: var(--fs-s); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--bg); text-shadow: none; }

.codex { display: grid; grid-template-columns: minmax(0, 15rem) minmax(0, 1fr); gap: var(--s5); align-items: start; }
.index { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.index li { border-bottom: 1px solid var(--border); }
.index button { width: 100%; text-align: left; min-height: 44px; padding: var(--s2) var(--s2); background: none; border: 0; }
.index button small { display: block; color: var(--muted); font-size: var(--fs-xs); }
.index button[aria-current="true"] { background: var(--surface); box-shadow: inset 3px 0 var(--accent); }
.index button:hover { background: var(--surface); }
.entry h3 { margin: 0; font: 400 var(--fs-xl)/1 var(--f-display); text-transform: uppercase; letter-spacing: .03em; }
.entry .role { margin: var(--s1) 0 var(--s4); color: var(--muted); font-size: var(--fs-s); }
.entry p { max-width: 64ch; }
.entry img { display: block; max-width: 220px; width: 100%; border: 1px solid var(--rule); margin-bottom: var(--s4); filter: grayscale(1) sepia(1) hue-rotate(70deg) saturate(2.2) brightness(.9); }
:root[data-theme="printout"] .entry img { filter: grayscale(1); }
.codex:has(.index:empty) { grid-template-columns: 1fr; }
.codex:has(.index:empty) .index { display: none; }

/* -------------------------------------------------------------------- map */

.map-frame { position: relative; border: 1px solid var(--rule); }
.map-frame img { display: block; width: 100%; height: auto; filter: grayscale(1) sepia(1) hue-rotate(70deg) saturate(2.2) brightness(.85); }
:root[data-theme="printout"] .map-frame img { filter: grayscale(1); }
.marker {
  position: absolute; transform: translate(-50%, -50%);
  background: var(--bg); border: 1px solid var(--accent);
  padding: 2px var(--s2); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em;
  min-height: 28px;
}
.marker::before { content: "+ "; color: var(--accent); }
.marker:hover, .marker:focus-visible { background: var(--accent); color: var(--accent-ink); text-shadow: none; }

/* -------------------------------------------------------------------- log */

.log { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.log li { display: grid; grid-template-columns: 5ch 1fr; gap: var(--s4); padding: var(--s3) var(--s2); border-bottom: 1px solid var(--border); }
:root[data-theme="printout"] .log li:nth-child(even) { background: var(--surface); }
.log li.empty-row { display: block; padding: var(--s3) 0; }
.log .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.log h3 { margin: 0; font-size: var(--fs-base); font-weight: 500; }
.log p { margin: var(--s1) 0 0; font-size: var(--fs-s); color: var(--muted); max-width: 68ch; }
.log .pick { color: var(--text); }
.log .pick::before { content: "» "; color: var(--accent); }

/* ------------------------------------------------------------------ files */

.slots { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.slots li { display: grid; grid-template-columns: 9ch 1fr auto; gap: var(--s4); align-items: center; padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.slots .name { text-transform: uppercase; letter-spacing: .08em; font-size: var(--fs-s); }
.slots .meta { color: var(--muted); font-size: var(--fs-s); font-variant-numeric: tabular-nums; }
.slots .acts { display: flex; gap: var(--s2); flex-wrap: wrap; justify-content: flex-end; }

/* ------------------------------------------------------------------ setup */

.setup { display: grid; gap: var(--s5); max-width: 40rem; }
.setup fieldset { border: 0; border-top: 1px solid var(--rule); margin: 0; padding: var(--s3) 0 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s5); }
.setup legend { padding: 0 var(--s2) 0 0; font: 400 1.35rem/1 var(--f-display); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.setup label { display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; cursor: pointer; }
.setup input { accent-color: var(--accent); width: 1.1rem; height: 1.1rem; margin: 0; }

/* ----------------------------------------------------------------- narrow */

@media (max-width: 720px) {
  .case { padding: 0; }
  .screen { border-radius: 0; }
  .bar { padding: var(--s3) var(--s4) var(--s2); }
  .tabs { padding: 0 var(--s2); }
  .panel { padding: var(--s4) var(--s4) var(--s6); }
  .stage { aspect-ratio: 4 / 3; }
  .dialogue { padding: var(--s3) var(--s4) var(--s6); }
  .codex { grid-template-columns: 1fr; }
  .slots li { grid-template-columns: 1fr; gap: var(--s2); }
  .slots .acts { justify-content: flex-start; }
  .readout { gap: var(--s3); }
}

/* ------------------------------------------------- motion and accessibility */

@media (prefers-reduced-motion: reduce) {
  .screen.boot, .fx-flicker .screen { animation: none; }
  .status.busy::after, .line.waiting::after { animation: none; }
}
@media (prefers-contrast: more) {
  :root { --muted: var(--text); --border: var(--rule); }
  .fx-glow .screen { text-shadow: none; }
  .screen::after { display: none; }
}
@media (forced-colors: active) {
  .screen::after { display: none; }
  .tabs button[aria-selected="true"], .seg button[aria-pressed="true"] { outline: 2px solid CanvasText; }
}
