/* mattsbench.com — CRT terminal
   Monochrome by design: a real tube carries a single phosphor, so everything
   varies by brightness, never by hue. Swapping the phosphor is a token change.
   No dependencies, no network requests. */

/* ---------- phosphors ---------- */

:root {
  --phos:     #5cd8ff;      /* cyan phosphor */
  --phos-rgb: 92 216 255;
  --hot:      #d6f4ff;      /* freshly painted, before it decays */
  --dim:      #3a90b0;      /* secondary lines — kept above 4.5:1 on --screen */
  --screen:   #03080d;
  --room:     6 20 30;      /* ambient glow the tube throws on the room */
}

:root {
  --mono: ui-monospace, "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono",
          Menlo, "DejaVu Sans Mono", "Liberation Mono", monospace;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 3vw, 2.5rem);
  background: radial-gradient(ellipse 72% 58% at 50% 44%,
    rgb(var(--room)) 0%, #0a0a0c 58%, #050506 100%);
  font-family: var(--mono);
  transition: background 0.45s ease;
}

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

/* ---------- housing ---------- */

.crt {
  position: relative;
  width: min(64rem, 100%);
  padding: clamp(13px, 2vw, 22px);
  border-radius: 20px;
  background: linear-gradient(#2b2b30 0%, #17171b 34%, #101013 70%, #0a0a0d 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.10),
    inset 0 -1px 0 rgba(0, 0, 0, 0.70),
    0 0 0 1px #000,
    0 48px 90px -34px #000,
    0 0 120px -30px rgb(var(--phos-rgb) / 0.22);
}

.screw {
  position: absolute;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #71717a, #2b2b31 58%, #141418);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.75), 0 1px 1px rgba(255, 255, 255, 0.05);
}
.screw::after {
  content: "";
  position: absolute;
  inset: 3.2px 1px;
  background: #0e0e12;
  border-radius: 1px;
  transform: rotate(34deg);
}
.screw--tl { top: 9px; left: 9px; }
.screw--tr { top: 9px; right: 9px; }
.screw--bl { bottom: 9px; left: 9px; }
.screw--br { bottom: 9px; right: 9px; }

/* ---------- tube ---------- */

.tube {
  position: relative;
  overflow: hidden;
  padding: clamp(1.15rem, 3vw, 2.4rem);
  min-height: min(66svh, 30rem);
  /* Elliptical radii read as tube curvature far more cheaply than any
     distortion filter, and they cost nothing in support. */
  border-radius: 5% / 7%;
  background: radial-gradient(ellipse 100% 88% at 50% 46%,
    rgb(var(--room)) 0%, var(--screen) 68%, #040406 100%);
  box-shadow:
    inset 0 0 0 1px rgb(var(--phos-rgb) / 0.06),
    inset 0 0 40px rgba(0, 0, 0, 0.9);
  transition: background 0.45s ease;
}

/* Power-on: the raster collapses to a bright line, then opens. */
.tube::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 7;
  background: var(--hot);
  mix-blend-mode: screen;
  pointer-events: none;
  animation: flash 820ms ease-out both;
}

@keyframes flash {
  0%   { opacity: 0.50; }
  16%  { opacity: 0.20; }
  100% { opacity: 0; }
}

/* ---------- text ---------- */

.term {
  position: relative;
  z-index: 1;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: 400 clamp(0.7rem, 1.5vw, 0.95rem)/1.62 var(--mono);
  color: var(--phos);
  text-shadow:
    0 0 1px rgb(var(--phos-rgb) / 0.95),
    0 0 7px rgb(var(--phos-rgb) / 0.50),
    0 0 20px rgb(var(--phos-rgb) / 0.24);
  transform-origin: 50% 50%;
  animation:
    power-on 820ms cubic-bezier(0.2, 0.85, 0.2, 1) both,
    flicker 9s 900ms steps(1, end) infinite;
}

@keyframes power-on {
  0%   { transform: scaleY(0.005) scaleX(0.55); opacity: 0; filter: brightness(5) blur(1.2px); }
  20%  { transform: scaleY(0.005) scaleX(1);    opacity: 1; filter: brightness(5) blur(1.2px); }
  52%  { transform: scaleY(1)     scaleX(1);                filter: brightness(2.4) blur(0.5px); }
  100% { transform: none;                                   filter: none; }
}

/* Mains hum, roughly. Irregular on purpose — an even pulse reads as a CSS
   animation, an uneven one reads as a tube. */
@keyframes flicker {
  0%, 88%, 100% { opacity: 1; }
  89%  { opacity: 0.88; }
  90%  { opacity: 1; }
  93%  { opacity: 0.94; }
  94%  { opacity: 1; }
  96%  { opacity: 0.90; }
  97%  { opacity: 1; }
}

.dim  { color: var(--dim); text-shadow: 0 0 5px rgb(var(--phos-rgb) / 0.22); }
.tag  { color: var(--hot); text-shadow: 0 0 8px rgb(var(--phos-rgb) / 0.75); }

.warn .tag { animation: warn-pulse 1.9s ease-in-out infinite; }
@keyframes warn-pulse { 50% { opacity: 0.45; } }

/* Freshly-painted text is hot, then settles as the phosphor decays. */
.fresh { animation: phosphor 620ms ease-out both; }
@keyframes phosphor {
  0%   { color: var(--hot); filter: brightness(1.9); }
  100% { filter: none; }
}

.wordmark {
  display: inline-block;
  margin: 0.35em 0;
  font-size: clamp(1.5rem, 5.4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--hot);
  text-shadow:
    0 0 2px rgba(255, 255, 255, 0.55),
    0 0 12px rgb(var(--phos-rgb) / 0.90),
    0 0 34px rgb(var(--phos-rgb) / 0.60),
    0 0 72px rgb(var(--phos-rgb) / 0.35);
}

.cursor {
  display: inline-block;
  width: 0.62em;
  height: 1.02em;
  background: var(--phos);
  vertical-align: -0.17em;
  box-shadow: 0 0 9px rgb(var(--phos-rgb) / 0.85);
  animation: blink 1.06s steps(1, end) infinite;
}
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ---------- tube overlays ---------- */

.scan, .roll, .glare, .vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
}

.scan {
  z-index: 3;
  background: repeating-linear-gradient(
    to bottom, rgba(0, 0, 0, 0.34) 0 1px, transparent 1px 3px);
}

/* The refresh band: a slow bright roll, like a camera out of sync with the
   tube. Cheap, and it does more for believability than the scanlines do. */
.roll {
  z-index: 4;
  height: 26%;
  inset: auto 0 auto 0;
  background: linear-gradient(to bottom,
    transparent 0%,
    rgb(var(--phos-rgb) / 0.05) 44%,
    rgb(var(--phos-rgb) / 0.09) 54%,
    transparent 100%);
  animation: roll 7.5s linear infinite;
}
@keyframes roll {
  from { transform: translateY(-130%); }
  to   { transform: translateY(430%); }
}

.glare {
  z-index: 5;
  background: linear-gradient(128deg,
    rgba(255, 255, 255, 0.055) 0%,
    rgba(255, 255, 255, 0.014) 20%,
    transparent 44%);
}

.vignette {
  z-index: 6;
  background: radial-gradient(ellipse 94% 90% at 50% 50%,
    transparent 48%, rgba(0, 0, 0, 0.62) 100%);
  box-shadow: inset 0 0 70px 18px rgba(0, 0, 0, 0.8);
}

/* ---------- bezel ---------- */

.bezel {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.75rem 0.4rem 0.15rem;
  font-size: 0.6rem;
  letter-spacing: 0.22em;
  color: #55555e;
}

.led {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #26262a;
  box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.9);
  transition: background 0.35s ease, box-shadow 0.35s ease;
  flex: none;
}
.led.on {
  background: var(--phos);
  box-shadow: 0 0 6px var(--phos), 0 0 16px rgb(var(--phos-rgb) / 0.55);
}

.plate { flex: 1; }

.hint {
  opacity: 0;
  transition: opacity 0.6s ease;
  cursor: pointer;
}
.hint.show { opacity: 1; }

/* ---------- the LIVE line ---------- */

.live {
  color: var(--phos);
  text-decoration: none;
  cursor: pointer;
  border-bottom: 1px dashed rgb(var(--phos-rgb) / 0.32);
  transition: color 0.18s ease, border-color 0.18s ease, text-shadow 0.18s ease;
}
.live::after {
  content: "  ↗";
  opacity: 0.55;
}
.live:hover,
.live:focus-visible {
  color: var(--hot);
  border-bottom-color: rgb(var(--phos-rgb) / 0.85);
  text-shadow:
    0 0 10px rgb(var(--phos-rgb) / 0.90),
    0 0 26px rgb(var(--phos-rgb) / 0.50);
  outline: none;
}

/* The screen-reader block is the only reachable link on the page, since the
   terminal is aria-hidden. Surface it on focus so keyboard users aren't
   tabbing into something invisible. */
.sr-only:focus-within {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100;
  width: auto;
  height: auto;
  max-width: min(90vw, 30rem);
  margin: 0;
  padding: 0.85rem 1.1rem;
  overflow: visible;
  clip-path: none;
  white-space: normal;
  background: var(--screen);
  border: 1px solid var(--phos);
  border-radius: 8px;
  color: var(--phos);
  font: 400 0.8rem/1.55 var(--mono);
}
.sr-only a { color: var(--hot); }

/* ---------- preview panel ---------- */

body.is-locked { overflow: hidden; }

.preview {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: clamp(0.6rem, 2.5vw, 2rem);
}
.preview[hidden] { display: none; }

.preview__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 4, 8, 0.84);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.25s ease both;
}

.preview__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1180px, 100%);
  height: min(820px, 88svh);
  overflow: hidden;
  border: 1px solid rgb(var(--phos-rgb) / 0.26);
  border-radius: 14px;
  background: #0c0e13;
  box-shadow:
    0 40px 90px -30px #000,
    0 0 90px -40px rgb(var(--phos-rgb) / 0.55);
  animation: panel-in 0.28s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}

.preview__bar {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex: none;
  padding: 0.6rem 0.7rem 0.6rem 0.95rem;
  background: linear-gradient(#1a1d24, #12151b);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font: 400 0.68rem/1 var(--mono);
  color: var(--dim);
}

.preview__dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--phos);
  box-shadow: 0 0 6px var(--phos);
  animation: live-pulse 2.4s ease-in-out infinite;
}

.preview__url {
  flex: 1;
  color: var(--phos);
  letter-spacing: 0.06em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview__btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--dim);
  font-size: 0.78rem;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}
.preview__btn:hover,
.preview__btn:focus-visible {
  color: var(--hot);
  background: rgb(var(--phos-rgb) / 0.14);
  border-color: rgb(var(--phos-rgb) / 0.50);
  outline: none;
}

.preview__viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #fff;
}

/* Deliberately wider than its container: a cross-origin frame's scrollbar
   can't be styled from here, so the only way to hide it without touching the
   other site is to push it past the clip edge. Costs ~20px of the right
   margin, which centred layouts never miss. */
.preview__frame {
  display: block;
  width: calc(100% + 20px);
  height: 100%;
  border: 0;
}

.preview__status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1rem;
  text-align: center;
  background: var(--screen);
  color: var(--phos);
  font: 400 0.72rem/1.6 var(--mono);
  letter-spacing: 0.18em;
  text-shadow: 0 0 10px rgb(var(--phos-rgb) / 0.55);
}
.preview__status[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }
@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
}
@keyframes live-pulse { 50% { opacity: 0.35; } }

/* ---------- motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .term, .tube::before, .roll, .cursor, .warn .tag, .fresh,
  .preview__backdrop, .preview__panel, .preview__dot {
    animation: none !important;
  }
  .tube::before { opacity: 0; }
  .term { opacity: 1; transform: none; filter: none; }
}
