/* SPNCR-14 video display terminal
   One family (VT323, a DEC VT320 revival), one phosphor color at a time,
   everything on a character grid. The case is putty plastic; the glass is
   the phosphor's own dark. */

@property --ph { syntax: "<color>"; inherits: true; initial-value: #5cff8a; }
@property --ph-dim { syntax: "<color>"; inherits: true; initial-value: #2a8a47; }
@property --ph-hot { syntax: "<color>"; inherits: true; initial-value: #dcffe6; }
@property --glass { syntax: "<color>"; inherits: true; initial-value: #020904; }

:root {
  /* case plastic */
  --case: #aaa28b;
  --case-hi: #cbc4ad;
  --case-lo: #7a735f;
  --recess: #1c1a15;
  --led-on: #ff4a1c;
  --led-off: #5b2a1c;

  /* phosphor P1 (green) */
  --ph: #5cff8a;
  --ph-dim: #2a8a47;
  --ph-hot: #dcffe6;
  --glass: #020904;

  --glow: color-mix(in srgb, var(--ph) 55%, transparent);
  --faint: color-mix(in srgb, var(--ph) 9%, transparent);

  --fs: clamp(19px, 0.7vw + 12.5px, 28px);
  --lh: 1.22;
  --ring: 14px;
  color-scheme: dark;
  transition: --ph 0.7s, --ph-dim 0.7s, --ph-hot 0.7s, --glass 0.7s;
}
:root[data-phosphor="amber"] {
  --ph: #ffb02e;
  --ph-dim: #98620f;
  --ph-hot: #fff1cf;
  --glass: #0a0602;
}
:root[data-phosphor="white"] {
  --ph: #e6ecf6;
  --ph-dim: #79828f;
  --ph-hot: #ffffff;
  --glass: #05070b;
}

*,
*::before,
*::after { box-sizing: border-box; }

html,
body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--case);
  font-family: "VT323", "Monaspace Neon", ui-monospace, monospace;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

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

/* ---------- the case ---------- */

.case {
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: calc(var(--ring) + 18px) calc(var(--ring) + 18px) 0;
  background:
    radial-gradient(120% 80% at 50% 0%, var(--case-hi) 0%, transparent 55%),
    linear-gradient(180deg, var(--case) 0%, #9d957e 100%);
  position: relative;
}
/* molded plastic grain */
.case::before {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0.35;
  mix-blend-mode: multiply;
  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='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .42 0 0 0 0 .35 0 0 0 .5 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.screen {
  position: relative;
  min-height: 0;
  border-radius: 26px / 30px;
  overflow: hidden;
  background: radial-gradient(130% 120% at 50% 45%, color-mix(in srgb, var(--glass), var(--ph) 4%) 0%, var(--glass) 60%, #000 100%);
  box-shadow:
    0 0 0 var(--ring) var(--recess),
    0 0 0 calc(var(--ring) + 2px) var(--case-lo),
    0 -2px 0 calc(var(--ring) + 3px) var(--case-lo),
    0 2px 0 calc(var(--ring) + 3px) var(--case-hi);
  isolation: isolate;
}

.plate {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2ch;
  padding: 14px calc(var(--ring) + 6px) 14px;
  min-height: 62px;
  color: #4a4535;
  text-shadow: 0 1px 0 var(--case-hi);
}
.plate-name { font-size: 26px; letter-spacing: 0.06em; }
.plate-name b { font-weight: normal; color: #6b6450; }
.plate-sub { font-size: 17px; opacity: 0.8; }

.power {
  margin-left: auto;
  width: 46px; height: 26px;
  border: 0; border-radius: 4px;
  background: linear-gradient(180deg, #b9b199, #8e8672);
  box-shadow: inset 0 1px 0 var(--case-hi), inset 0 -2px 0 #6e6754, 0 1px 2px #0005;
  display: grid; place-items: center;
  cursor: pointer;
}
.power:active { box-shadow: inset 0 2px 3px #0006; }
.power:focus-visible { outline: 2px solid #2b281f; outline-offset: 3px; }
.led {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--led-off);
  box-shadow: inset 0 1px 1px #0008;
  transition: background 0.2s, box-shadow 0.2s;
}
.power[aria-pressed="true"] .led {
  background: var(--led-on);
  box-shadow: 0 0 6px 1px var(--led-on), inset 0 -1px 1px #0004;
}

/* ---------- the raster ---------- */

.raster {
  position: absolute; inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 1.1em 1.8ch 0.9em;
  font-size: var(--fs);
  line-height: var(--lh);
  color: var(--ph);
  text-shadow: 0 0 1px var(--ph), 0 0 7px var(--glow);
  transform-origin: 50% 50%;
}

::selection { background: var(--ph); color: var(--glass); text-shadow: none; }

.status {
  display: flex;
  gap: 2ch;
  padding: 0 1ch;
  background: var(--ph);
  color: var(--glass);
  text-shadow: none;
  box-shadow: 0 0 10px var(--glow);
  white-space: nowrap;
}
.status-prog { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; }
.status-right { display: flex; gap: 2ch; }

.term {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.8em 0.5ch 0.4em;
  scrollbar-width: thin;
  scrollbar-color: var(--ph-dim) transparent;
  container-type: inline-size;
  cursor: text;
}
.term::-webkit-scrollbar { width: 1ch; }
.term::-webkit-scrollbar-thumb { background: var(--ph-dim); }

.out > * { margin: 0 0 0.35em; }
.out > .gap { margin-bottom: 0.9em; }
.out p { margin: 0 0 0.6em; max-width: 66ch; }
.dim { color: var(--ph-dim); text-shadow: 0 0 6px color-mix(in srgb, var(--ph-dim) 50%, transparent); }
.hot { color: var(--ph-hot); }
.err { color: var(--ph-hot); }
.err::before { content: "? "; color: var(--ph-dim); }
.echo .ps1 { color: var(--ph-dim); }
pre { margin: 0; font: inherit; line-height: 1.05; white-space: pre; }

/* ---------- prompt ---------- */

.prompt {
  position: relative;
  display: flex;
  gap: 1ch;
  flex-wrap: wrap;
  margin: 0;
}
.prompt[hidden] { display: none; }
.ps1 { color: var(--ph-dim); white-space: nowrap; }
.line-edit { white-space: pre-wrap; word-break: break-all; flex: 1; min-width: 4ch; }
#cmd {
  position: absolute; inset: 0;
  opacity: 0;
  font: inherit;
  border: 0; padding: 0; margin: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  width: 100%;
}
.cursor {
  display: inline-block;
  min-width: 1ch;
  background: var(--ph);
  color: var(--glass);
  text-shadow: none;
  box-shadow: 0 0 8px var(--glow);
  animation: blink 1.06s infinite;
}
/* unfocused: hollow block, like a real terminal that has lost the keyboard */
.prompt:not(.focused) .cursor {
  background: transparent;
  color: var(--ph);
  box-shadow: inset 0 0 0 1px var(--ph);
  animation: none;
}
.typing-cursor {
  display: inline-block; width: 1ch; height: 1em; vertical-align: -0.12em;
  background: var(--ph); box-shadow: 0 0 8px var(--glow);
}
/* phosphor decay: on instantly, fades off */
@keyframes blink {
  0%, 49% { opacity: 1; }
  50% { opacity: 1; }
  62%, 100% { opacity: 0; }
}

/* ---------- command links, buttons ---------- */

.cmd,
.out a {
  display: inline;
  padding: 0 0.25ch;
  margin: 0 -0.25ch;
  border: 0;
  background: none;
  color: var(--ph-hot);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  cursor: pointer;
  text-shadow: inherit;
}
.cmd:hover,
.out a:hover,
.cmd:focus-visible,
.out a:focus-visible {
  background: var(--ph);
  color: var(--glass);
  text-decoration: none;
  text-shadow: none;
  outline: none;
  box-shadow: 0 0 10px var(--glow);
}
.cmds { display: flex; flex-wrap: wrap; gap: 0.2em 3ch; margin-top: 0.3em; }

/* ---------- function-key bar ---------- */

.fkeys {
  display: flex;
  gap: 1ch;
  padding-top: 0.5em;
  white-space: nowrap;
}
.fkeys button {
  display: flex;
  flex: 1;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
}
.fkeys kbd { font: inherit; padding-right: 0.5ch; color: var(--ph); }
.fkeys span {
  flex: 1;
  padding: 0 0.6ch;
  background: color-mix(in srgb, var(--ph) 80%, var(--glass));
  color: var(--glass);
  text-shadow: none;
}
.fkeys button:focus-visible span,
.fkeys button[aria-pressed="true"] span { background: var(--ph-hot); box-shadow: 0 0 12px var(--glow); }
@media (hover: hover) {
  .fkeys button:hover span { background: var(--ph-hot); box-shadow: 0 0 12px var(--glow); }
}
.fkeys button:focus-visible { outline: 1px solid var(--ph); outline-offset: 2px; }
.fkeys button:active span { background: var(--ph-dim); }

/* ---------- DEC double-height line ---------- */
/* A VT100 drew double-height text as two separate rows: the top half
   and the bottom half. They arrive one after the other here. */
.dhl {
  display: grid;
  margin: 0.1em 0 0.45em;
  font-size: 2.6em;
  font-weight: normal;
  line-height: 0.95;
  letter-spacing: 0.02em;
}
.dhl > span { grid-area: 1 / 1; }
.dhl .t { clip-path: inset(0 0 50% 0); }
.dhl .b { clip-path: inset(50% 0 0 0); }
.dhl.in .t { animation: dhl-t 0.42s steps(6, end) both; }
.dhl.in .b { animation: dhl-b 0.42s 0.12s steps(6, end) both; }
@keyframes dhl-t {
  0% { transform: translateX(-1.5ch); opacity: 0; clip-path: inset(0 100% 50% 0); }
  100% { transform: none; opacity: 1; clip-path: inset(0 0 50% 0); }
}
@keyframes dhl-b {
  0% { transform: translateX(1.5ch); opacity: 0; clip-path: inset(50% 0 0 100%); }
  100% { transform: none; opacity: 1; clip-path: inset(50% 0 0 0); }
}

/* ---------- pixel banner ---------- */

.banner {
  --cell: min(15px, calc((100cqw - 2ch) / var(--w)));
  display: grid;
  grid-template-columns: repeat(var(--w), var(--cell));
  grid-auto-rows: var(--cell);
  margin: 0.4em 0 0.6em;
  touch-action: pan-y;
}
.banner.small { --cell: min(9px, calc((100cqw - 2ch) / var(--w))); }
.px { position: relative; }
.px::after {
  content: "";
  position: absolute;
  inset: 44%;
  border-radius: 50%;
  background: var(--faint);
}
.px.sh::after {
  inset: 8%;
  border-radius: 0;
  background: repeating-conic-gradient(var(--ph-dim) 0 25%, transparent 0 50%) 0 0 / 4px 4px;
  opacity: 0.55;
}
.px.on::after {
  inset: 7%;
  border-radius: 1px;
  background: var(--ph);
  box-shadow: 0 0 calc(var(--cell) * 0.7) var(--glow);
  animation: lite 0.6s var(--d, 0s) both;
  transform: scale(var(--s, 1));
  transition: transform 0.15s ease-out, background 0.15s;
}
.banner.near .px.on::after {
  --dd: hypot(calc(var(--x) - var(--mx)), calc(var(--y) - var(--my)));
  --s: max(1, calc(1.55 - var(--dd) * 0.09));
}
@keyframes lite {
  0% { opacity: 0; }
  1% { opacity: 1; background: var(--ph-hot); box-shadow: 0 0 calc(var(--cell) * 1.6) var(--ph-hot); }
  100% { opacity: 1; }
}

/* ---------- listings ---------- */

.ls { display: flex; flex-wrap: wrap; gap: 0 3ch; margin: 0 0 0.9em; padding: 0; list-style: none; }

.dir { display: grid; margin: 0.2em 0 0.8em; max-width: 72ch; }
.dir .row {
  display: grid;
  grid-template-columns: 4ch 20ch 1fr;
  gap: 0 1ch;
  padding: 0 0.5ch;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.dir .head { color: var(--ph-dim); cursor: default; }
.dir button.row:hover,
.dir button.row:focus-visible {
  background: var(--ph);
  color: var(--glass);
  text-shadow: none;
  outline: none;
  box-shadow: 0 0 12px var(--glow);
}
.dir button.row:hover .dim,
.dir button.row:focus-visible .dim { color: var(--glass); text-shadow: none; }

.readme {
  display: grid;
  grid-template-columns: minmax(0, 54ch) auto;
  gap: 1em 4ch;
  align-items: start;
}
.readme pre { color: var(--ph); font-size: 0.86em; }
.readme .meta { color: var(--ph-dim); }

.matrix { display: grid; grid-template-columns: 14ch repeat(3, 8ch); margin: 0.3em 0 0.8em; }
.matrix > * { padding: 0.05em 0; }
.matrix .h { color: var(--ph-dim); }
.pip { display: inline-block; width: 0.9ch; height: 0.62em; margin-left: 2ch; background: var(--faint); vertical-align: 0.05em; }
.pip.on { background: var(--ph); box-shadow: 0 0 8px var(--glow); }

.dial { list-style: none; margin: 0.2em 0 0.8em; padding: 0; display: grid; gap: 0.25em; }
.modem { color: var(--ph-dim); }

.meter { white-space: pre; }

/* ---------- CRT effects ---------- */

.fx { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.scan {
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 2px, rgba(0, 0, 0, 0.32) 3px, transparent 4px);
  mix-blend-mode: multiply;
}
.roll { overflow: hidden; }
.roll::before {
  content: "";
  position: absolute; left: 0; right: 0; top: 0;
  height: 22%;
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--ph) 5%, transparent) 70%, color-mix(in srgb, var(--ph) 8%, transparent) 92%, transparent);
  animation: roll 9s linear infinite;
}
@keyframes roll { from { transform: translateY(-100%); } to { transform: translateY(560%); } }
.glass {
  background:
    radial-gradient(60% 45% at 28% 12%, rgba(255, 255, 255, 0.055), transparent 70%),
    radial-gradient(120% 120% at 50% 50%, transparent 58%, rgba(0, 0, 0, 0.6) 100%);
  border-radius: inherit;
  box-shadow: inset 0 0 40px 6px rgba(0, 0, 0, 0.75);
}

[data-fx="off"] .scan,
[data-fx="off"] .roll { display: none; }
[data-fx="off"] .raster { animation: none !important; text-shadow: none; }

.screen[data-state="on"] .raster { animation: flicker 5.3s infinite; }
@keyframes flicker {
  0%, 100% { opacity: 1; }
  41% { opacity: 1; }
  42% { opacity: 0.94; }
  43% { opacity: 1; }
  77% { opacity: 0.97; }
  78% { opacity: 1; }
}

/* power states */
.screen[data-state="off"] .raster,
.screen[data-state="off"] .roll,
.screen[data-state="idle"] .raster,
.screen[data-state="idle"] .roll { visibility: hidden; }
.screen[data-state="warming"] .raster { animation: warm 0.95s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.screen[data-state="cooling"] .raster { animation: cool 0.55s cubic-bezier(0.6, 0, 0.9, 0.4) both; }
.screen[data-state="cooling"] .dot { animation: afterglow 1.6s 0.5s ease-out both; }

@keyframes warm {
  0% { transform: scale(0.06, 0.004); filter: brightness(6); opacity: 0.2; }
  22% { transform: scale(1, 0.004); filter: brightness(5); opacity: 1; }
  48% { transform: scale(1, 1.03); filter: brightness(2.2) blur(0.6px); }
  70% { transform: scale(1, 0.995); filter: brightness(1.3); }
  100% { transform: none; filter: none; }
}
@keyframes cool {
  0% { transform: none; filter: none; }
  50% { transform: scale(1, 0.004); filter: brightness(5); }
  100% { transform: scale(0, 0.004); filter: brightness(8); opacity: 0.6; }
}
.dot {
  position: absolute; left: 50%; top: 50%;
  width: 6px; height: 6px; margin: -3px;
  border-radius: 50%;
  background: var(--ph-hot);
  box-shadow: 0 0 14px 4px var(--ph), 0 0 40px 10px var(--glow);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}
@keyframes afterglow {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.3); }
}

.wake {
  position: absolute; inset: 0;
  z-index: 5;
  border: 0;
  background: transparent;
  color: #8f8b7b;
  font-size: var(--fs);
  cursor: pointer;
  display: none;
  text-shadow: none;
}
.wake:focus-visible { outline: none; color: #c9c4b0; text-decoration: underline; text-underline-offset: 0.2em; }
.screen[data-state="off"] .wake { display: block; }

/* degauss: the shimmer a CRT makes when its coil fires */
.raster.degauss { animation: degauss 1.1s cubic-bezier(0.1, 0.6, 0.3, 1) both !important; }
@keyframes degauss {
  0% { transform: skewX(0) scale(1); filter: hue-rotate(0) blur(0); text-shadow: -3px 0 #ff2a55, 3px 0 #2ab8ff; }
  12% { transform: skewX(4deg) scale(1.02, 0.98); filter: hue-rotate(90deg) blur(1.2px); }
  26% { transform: skewX(-3deg) scale(0.99, 1.02); filter: hue-rotate(-60deg) blur(0.8px); text-shadow: 2px 0 #ff2a55, -2px 0 #2ab8ff; }
  42% { transform: skewX(1.6deg); filter: hue-rotate(30deg) blur(0.4px); }
  60% { transform: skewX(-0.8deg); filter: hue-rotate(-12deg); }
  80% { transform: skewX(0.3deg); filter: none; }
  100% { transform: none; filter: none; }
}

/* persistence: what was on screen lingers a moment after it is cleared */
.ghost {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  font-size: var(--fs);
  line-height: var(--lh);
  color: var(--ph);
  text-shadow: 0 0 1px var(--ph), 0 0 7px var(--glow);
  overflow: hidden;
  opacity: 0;
}
.ghost.fade { animation: ghost 0.9s ease-out both; }
@keyframes ghost {
  0% { opacity: 0.55; filter: blur(0); }
  100% { opacity: 0; filter: blur(2px); }
}

.saver { position: absolute; inset: 0; z-index: 2; display: none; background: var(--glass); }
.screen.saving .saver { display: block; }
.screen.saving .raster { visibility: hidden; }

.noscript { padding: 2em; color: #2b281f; font-size: 20px; max-width: 60ch; }

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  :root { --ring: 7px; --fs: 16px; }
  .case { padding: calc(var(--ring) + 8px) calc(var(--ring) + 8px) 0; }
  .screen { border-radius: 16px / 18px; }
  .raster { padding: 0.7em 1.2ch 0.6em; }
  .status-baud, .status-id { display: none; }
  .status-prog { text-align: left; }
  .plate { min-height: 46px; padding: 8px 10px 10px; gap: 1.5ch; }
  .plate-name { font-size: 21px; }
  .plate-sub { display: none; }
  .fkeys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.35em 1ch; }
  .fkeys kbd { display: none; }
  .fkeys span { text-align: center; padding: 0.15em 0; }
  .readme { grid-template-columns: 1fr; }
  .readme pre { font-size: 0.72em; }
  .dir .row { grid-template-columns: 3ch 1fr; }
  .dir .head { display: none; }
  .dir .row > :last-child { grid-column: 2; }
  .dhl { font-size: 2.2em; }
  .matrix { grid-template-columns: 12ch repeat(3, 6ch); }
  .pip { margin-left: 1.5ch; }
}

@media (prefers-reduced-motion: reduce) {
  .roll { display: none; }
  .screen[data-state="on"] .raster,
  .screen[data-state="warming"] .raster,
  .screen[data-state="cooling"] .raster,
  .raster.degauss { animation: none !important; }
  .px.on::after,
  .dhl.in .t,
  .dhl.in .b { animation: none; }
  .cursor { animation: none; }
  .ghost.fade { animation-duration: 0.01s; }
}

/* ---------- late additions ---------- */
.pending { visibility: hidden; }
.prompt.waiting .ps1,
.prompt.waiting .line-edit { visibility: hidden; }
.help { display: grid; grid-template-columns: 16ch 1fr; gap: 0.1em 2ch; max-width: 70ch; margin: 0 0 0.8em; }
@media (max-width: 760px) {
  .help { grid-template-columns: 1fr; gap: 0; }
  .help > .dim { margin: 0 0 0.35em 2ch; }
}
