/* LOADING SHOPIFY: a phosphor CRT around the asciinema player.
   Overlays never take pointer events, so text selection reaches the player. */

:root {
  --bg: #030503;
  --bezel: #0d0f0d;
  --screen: #020a04;
  --bright: #eaffea;
  --val: #33ff66;
  --mid: #1fbf4a;
  --dim: #127a2e;
  --faint: #0b4a1c;
  --glow: rgb(51 255 102 / 0.35);
  --mono: ui-monospace, "JetBrains Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

/* Phosphor palettes: green (default), amber, ice, white. */
[data-theme="amber"] {
  --screen: #0a0600; --bright: #fff4d6; --val: #ffb000; --mid: #cc8a00; --dim: #805600; --faint: #4d3400;
  --glow: rgb(255 176 0 / 0.35);
}
[data-theme="ice"] {
  --screen: #01070b; --bright: #f0fbff; --val: #7fdbff; --mid: #4aa8d8; --dim: #2a6a8c; --faint: #173d52;
  --glow: rgb(127 219 255 / 0.35);
}
[data-theme="white"] {
  --screen: #060606; --bright: #ffffff; --val: #c8c8c8; --mid: #a0a0a0; --dim: #6a6a6a; --faint: #3c3c3c;
  --glow: rgb(220 220 220 / 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--mid);
  font-family: var(--mono);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  gap: 16px;
}

main, .bottom {
  /* 120x40 at the player's 1.33 line height is ~1.35:1; keep it on screen. */
  width: min(100%, 1320px, calc((100vh - 170px) * 1.35 + 56px));
  min-width: min(100%, 320px);
}

/* The set: a dark bezel with a curved, vignetted glass. */
.crt {
  position: relative;
  padding: clamp(10px, 2.4vw, 28px);
  border-radius: 22px;
  background: linear-gradient(160deg, #1a1d1a, var(--bezel) 40%, #070807);
  box-shadow:
    0 0 0 1px #000,
    inset 0 1px 0 rgb(255 255 255 / 0.06),
    0 30px 80px rgb(0 0 0 / 0.7);
}

.screen {
  position: relative;
  overflow: hidden;
  border-radius: 18px / 26px;          /* a slight bulge reads as curved glass */
  background: radial-gradient(ellipse at 50% 45%, color-mix(in oklab, var(--screen) 80%, var(--faint)), var(--screen) 75%);
  box-shadow: 0 0 40px -8px var(--glow);
  aspect-ratio: 27 / 20;                /* the login keeps 120x40's shape */
}
.screen.live { aspect-ratio: auto; }  /* the player sizes itself */

.player { position: relative; width: 100%; height: 100%; }
.player > .tuning { position: absolute; inset: 0; visibility: hidden; }
.intro { width: 100%; }
.intro[hidden] { display: none; }
/* The stream connects behind the intro, laid out at the same geometry. */
.player.behind { position: absolute; inset: 0; visibility: hidden; }
.intro .ap-player { background: transparent; }
.player[hidden] { display: none; }

/* Phosphor bloom on the text layer only; canvas and symbols stay crisp. */
.player .ap-term-text { text-shadow: 0 0 3px var(--glow), 0 0 10px color-mix(in oklab, var(--glow) 40%, transparent); }

.scanlines, .vignette {
  position: absolute;
  inset: clamp(10px, 2.4vw, 28px);
  border-radius: 18px / 26px;
  pointer-events: none;
}

.scanlines {
  background: repeating-linear-gradient(to bottom, rgb(0 0 0 / 0) 0 2px, rgb(0 0 0 / 0.22) 2px 3px);
  mix-blend-mode: multiply;
}

.vignette {
  background: radial-gradient(ellipse at 50% 50%, transparent 58%, rgb(0 0 0 / 0.55) 100%);
  box-shadow: inset 0 0 60px rgb(0 0 0 / 0.8), inset 0 0 4px rgb(0 0 0 / 0.9);
}

/* Player theme: the stream sets its own truecolor; this covers defaults. */
.asciinema-player-theme-phosphor {
  --term-color-foreground: var(--val);
  --term-color-background: transparent;
  --term-color-0: #000000;  --term-color-8: var(--faint);
  --term-color-1: #ff5555;  --term-color-9: #ff6b6b;
  --term-color-2: var(--mid); --term-color-10: var(--val);
  --term-color-3: #ffd24d;  --term-color-11: #fff08a;
  --term-color-4: var(--dim); --term-color-12: var(--mid);
  --term-color-5: var(--mid); --term-color-13: var(--val);
  --term-color-6: var(--mid); --term-color-14: var(--val);
  --term-color-7: var(--mid); --term-color-15: var(--bright);
}
.player .ap-player { background: transparent; }
/* Our SIGNAL LOST tag and the frozen frame replace the player's own overlays. */
.player .ap-overlay, .intro .ap-overlay { display: none; }
.intro .ap-term-text { text-shadow: 0 0 3px var(--glow), 0 0 10px color-mix(in oklab, var(--glow) 40%, transparent); }

/* The mainframe login (app.js), typed over the glass while the stream
   connects; it also stands in until a stream is configured. */
.login {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 7% 8%;
  font: clamp(12px, 1.75vw, 22px)/1.55 var(--mono);
  letter-spacing: 0.04em;
  color: var(--val);
  text-shadow: 0 0 4px var(--glow), 0 0 14px color-mix(in oklab, var(--glow) 50%, transparent);
  white-space: pre-wrap;
}
.login[hidden] { display: none; }
.login .dim { color: var(--dim); text-shadow: none; }
.login .bright { color: var(--bright); text-shadow: 0 0 6px var(--glow), 0 0 22px var(--glow); }
/* CONNECT, once, ~300 ms: inverse video on just those cells. */
.login .inverse { color: var(--screen); background: var(--val); text-shadow: none; }
.login .cursor {
  display: inline-block;
  width: 0.6em;
  height: 1.05em;
  margin-left: 0.08em;
  vertical-align: -0.15em;
  background: var(--val);
  box-shadow: 0 0 8px var(--glow);
}

/* Interactive gate: the real input is visually hidden but focusable (the
   glass mirrors it); phones get one big [ CONNECT ] instead of a keyboard. */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.sr-only[hidden] { display: none; }
.gate-connect {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  padding: 14px 28px;
  font: 600 clamp(16px, 4vw, 22px) var(--mono);
  letter-spacing: 0.12em;
  color: var(--val);
  background: var(--screen);
  border: 2px solid var(--val);
  border-radius: 4px;
  box-shadow: 0 0 18px -4px var(--glow);
  white-space: nowrap;
  cursor: pointer;
}
.gate-connect:hover, .gate-connect:focus-visible { color: var(--screen); background: var(--val); outline: none; }
.gate-connect[hidden] { display: none; }
.flake {
  position: absolute;
  top: -1em;
  color: var(--bright);
  font: 16px var(--mono);
  text-shadow: 0 0 6px var(--glow);
  pointer-events: none;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(var(--fall, 400px)); opacity: 0.2; } }

/* The operator-code bonus: a steady badge under the glass, never over the
   terminal's own text (no blink). */
.sysop {
  margin: 0;
  padding: 3px 8px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--screen);
  background: var(--val);
  box-shadow: 0 0 12px var(--glow);
  pointer-events: none;
}
.sysop[hidden] { display: none; }

/* Over the last frame while the stream is away (app.js re-tunes). */
.signal {
  position: absolute;
  top: 14px;
  right: 18px;
  margin: 0;
  padding: 3px 8px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--bg);
  background: var(--val);
  box-shadow: 0 0 12px var(--glow);
  pointer-events: none;
}
.signal[hidden] { display: none; }

/* Skip the intro: bottom right of the glass. */
.skip {
  position: absolute;
  right: 18px;
  bottom: 14px;
  padding: 4px 10px;
  font: 12px var(--mono);
  letter-spacing: 0.08em;
  color: var(--val);
  background: var(--screen);
  border: 1px solid var(--mid);
  box-shadow: 0 0 0 4px var(--screen), 0 0 10px var(--glow);
  border-radius: 3px;
  cursor: pointer;
}
.skip:hover, .skip:focus-visible { color: var(--bg); background: var(--val); outline: none; }
.skip kbd { font: inherit; opacity: 0.7; }
.skip[hidden] { display: none; }

/* Channel change (app.js cut): static burst plus a vertical roll, ~300 ms. */
.static {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.95' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: screen;
}
.screen.channel .static { animation: static 320ms steps(8) both; }
.screen.channel .player, .screen.channel .intro { animation: roll 320ms cubic-bezier(0.5, 0, 0.5, 1) both; }
@keyframes static {
  0% { opacity: 0; }
  20% { opacity: 0.85; background-position: 0 0; }
  50% { opacity: 1; background-position: 37px 91px; }
  80% { opacity: 0.7; background-position: 83px 13px; }
  100% { opacity: 0; background-position: 11px 57px; }
}
@keyframes roll {
  0% { transform: translateY(0); filter: brightness(1); }
  43% { transform: translateY(-14%); filter: brightness(1.9) contrast(1.4); }
  44% { transform: translateY(14%); }
  100% { transform: translateY(0); filter: brightness(1); }
}

.snapshot { width: 100%; }
.snapshot[hidden] { display: none; }
.snapshot .ap-player { background: transparent; }
.snapshot .ap-overlay { display: none; }
.snapshot .ap-term-text { text-shadow: 0 0 3px var(--glow), 0 0 10px color-mix(in oklab, var(--glow) 40%, transparent); }
/* While frozen, the live player keeps running (and re-tuning) out of sight. */
.player.frozen { position: absolute; inset: 0; visibility: hidden; }

.controls { display: flex; align-items: center; gap: 12px; margin: 10px 4px 0; }
.controls .freeze { margin-left: auto; }
.freeze {
  padding: 3px 10px;
  font: 12px var(--mono);
  letter-spacing: 0.06em;
  color: var(--mid);
  background: transparent;
  border: 1px solid var(--dim);
  border-radius: 3px;
  cursor: pointer;
}
.freeze:hover, .freeze:focus-visible { color: var(--val); border-color: var(--val); outline: none; }
.freeze[hidden] { display: none; }

.bottom { font-size: 11px; letter-spacing: 0.04em; color: var(--dim); text-align: center; }

/* Narrow screens: the terminal keeps a readable size and scrolls sideways
   inside the glass; the stat card above carries the numbers. */
.screen.scroll { overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
.screen.scroll .player, .screen.scroll .snapshot, .screen.scroll .intro { width: max-content; }

.card { display: none; margin: 0 0 14px; }
.card pre {
  margin: 0;
  padding: 8px;
  overflow-x: auto;
  font: 12px/1.35 var(--mono);
  color: var(--val);
  background: var(--screen);
  border-radius: 8px;
  box-shadow: 0 0 24px -10px var(--glow);
  text-shadow: 0 0 3px var(--glow);
}
.card-copy {
  margin-top: 8px;
  padding: 3px 10px;
  font: 12px var(--mono);
  color: var(--mid);
  background: transparent;
  border: 1px solid var(--dim);
  border-radius: 3px;
  cursor: pointer;
}
.card-copy:hover, .card-copy:focus-visible { color: var(--val); border-color: var(--val); outline: none; }
@media (max-width: 760px) {
  .card:not([hidden]) { display: block; }
  /* Phones: a taller glass for the login, so [ CONNECT ] clears the text and
     the skip button; the live terminal sizes itself as before. */
  .screen:not(.live) { aspect-ratio: 4 / 5; }
  .gate-connect { bottom: 24%; }
}

@media (max-width: 640px) {
  body { padding: 16px; }
  .crt { border-radius: 14px; }
  .screen, .scanlines, .vignette { border-radius: 10px / 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .screen.channel .static, .screen.channel .player, .screen.channel .intro { animation: none; }
}
