/* ==========================================================================
   VCR theme: shared by zero.rocks, its error pages (/__vcr/err/*.html)
   and anything else that wants the "tape on a CRT" look.

   Layers, back to front (like the real signal chain):
     .picture   what is recorded on the tape: soft, chroma-bled, jittery
     .osd       the VCR's on-screen display: crisp, generated after the tape
     .crt       the television glass: scanlines, mask, vignette, curvature
   ========================================================================== */

@font-face {
  font-family: "VT323";
  src: url("/__vcr/vt323.woff2") format("woff2");
  font-display: swap;
}

:root {
  --vcr-blue: #0d1fc4;          /* "no signal" blue screen */
  --vcr-blue-hi: #2639e0;
  --osd: #f2f4ff;               /* on-screen display white */
  --osd-dim: #b9c0ff;
  --osd-green: #7dff9a;
  --rec: #ff3b30;
  --cam: #ffe7a3;               /* camcorder date stamp */
  --phosphor: #e9fff0;
  --osd-edge:
    2px 0 0 #000, -2px 0 0 #000, 0 2px 0 #000, 0 -2px 0 #000,
    2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
  --osd-font: "VT323", "Lucida Console", "Courier New", monospace;
  --title-font: "Arial Black", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

body.vcr {
  color: var(--osd);
  font-family: var(--osd-font);
  -webkit-font-smoothing: none;
  font-smooth: never;
}

/* --------------------------------------------------------------------------
   The television
   -------------------------------------------------------------------------- */
.tv {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
  isolation: isolate;
}

/* ----- Tape picture ------------------------------------------------------ */
.picture {
  position: absolute;
  inset: -3%;                       /* overscan: edges sit outside the glass */
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 45%, #10202a 0%, #070c10 55%, #020304 100%);
  filter: blur(0.55px) saturate(1.2) contrast(1.06);
  transform: translate3d(var(--jx, 0px), var(--jy, 0px), 0);
  will-change: transform;
}

[data-mode="blue"] .picture,
[data-mode="clog"] .picture {
  background:
    radial-gradient(130% 100% at 50% 40%, var(--vcr-blue-hi) 0%, var(--vcr-blue) 60%, #08128a 100%);
}

[data-mode="snow"] .picture,
[data-mode="scramble"] .picture {
  background: #0b0b0b;
}

/* Macrovision-style copy protection: brightness pumps, picture rolls */
[data-mode="scramble"] .picture {
  animation: vcr-agc 2.6s ease-in-out infinite, vcr-roll 9s steps(1) infinite;
}

@keyframes vcr-agc {
  0%, 100% { filter: blur(0.6px) brightness(0.55) contrast(1.3); }
  45%      { filter: blur(0.6px) brightness(1.45) contrast(0.9); }
  55%      { filter: blur(0.6px) brightness(1.2) contrast(1); }
}

@keyframes vcr-roll {
  0%, 82%, 100% { transform: translate3d(var(--jx, 0px), 0, 0); }
  83% { transform: translate3d(var(--jx, 0px), -18%, 0); }
  84% { transform: translate3d(var(--jx, 0px), -46%, 0); }
  85% { transform: translate3d(var(--jx, 0px), -71%, 0); }
  86% { transform: translate3d(var(--jx, 0px), 12%, 0); }
  87% { transform: translate3d(var(--jx, 0px), 3%, 0); }
}

/* 60 Hz hum bar slowly rolling down the picture */
.picture::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -30%;
  height: 30%;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    transparent,
    rgba(255, 255, 255, 0.045) 45%,
    rgba(255, 255, 255, 0.06) 55%,
    transparent
  );
  animation: vcr-hum 11s linear infinite;
}

@keyframes vcr-hum {
  to { transform: translateY(460%); }
}

.noise {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.content {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 6vh 6vw;
  text-align: center;
}

/* Title as recorded on the tape: luma is sharp-ish, chroma smeared sideways */
.title {
  position: relative;
  font-family: var(--title-font);
  font-weight: 900;
  font-size: clamp(2.3rem, 10.5vw, 8.5rem);
  line-height: 1;
  letter-spacing: 0.035em;
  white-space: nowrap;
  color: var(--phosphor);
  text-shadow:
    0 0 1px #fff,
    4px 0 3px rgba(255, 30, 70, 0.62),
    -4px 0 3px rgba(0, 170, 255, 0.55),
    0 0 18px rgba(140, 255, 190, 0.35),
    0 0 42px rgba(90, 200, 255, 0.18),
    16px 0 5px rgba(220, 255, 235, 0.09);          /* multipath ghost */
  filter: url(#vcr-timebase);
}

.title.glitch {
  animation: vcr-tear 0.42s steps(1) 1;
}

@keyframes vcr-tear {
  0%   { transform: translateX(0); clip-path: none; }
  12%  { transform: translateX(-10px) skewX(-6deg); }
  24%  { transform: translateX(7px); clip-path: inset(0 0 42% 0); }
  36%  { transform: translateX(-3px) skewX(3deg); clip-path: inset(38% 0 0 0); }
  52%  { transform: translateX(4px); clip-path: none; text-shadow:
           0 0 1px #fff, 9px 0 4px rgba(255, 30, 70, 0.8), -9px 0 4px rgba(0, 170, 255, 0.75); }
  70%  { transform: translateX(-1px); }
  100% { transform: translateX(0); }
}

/* Camcorder date/time burned into the recording (so it is soft, too) */
.camstamp {
  position: absolute;
  right: 7%;
  bottom: 10%;
  font-family: var(--osd-font);
  font-size: clamp(1.3rem, 3.4vw, 2.6rem);
  line-height: 0.95;
  text-align: right;
  letter-spacing: 0.06em;
  color: var(--cam);
  text-shadow:
    2px 0 0 #2a1500, -2px 0 0 #2a1500, 0 2px 0 #2a1500, 0 -2px 0 #2a1500,
    3px 0 2px rgba(255, 40, 40, 0.45), -3px 0 2px rgba(0, 160, 255, 0.35);
}

/* ----- On-screen display ------------------------------------------------- */
.osd {
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: max(5.5vh, 22px) max(6.5vw, 22px);
  font-family: var(--osd-font);
  font-size: clamp(1.6rem, 4.6vw, 3.3rem);
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--osd);
  text-shadow: var(--osd-edge);
  pointer-events: none;
}

.osd-corner {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 0.35em;
}

.osd-tl { top: max(5.5vh, 22px); left: max(6.5vw, 22px); }
.osd-tr { top: max(5.5vh, 22px); right: max(6.5vw, 22px); }
.osd-bl { bottom: max(7vh, 26px); left: max(6.5vw, 22px); }
.osd-br { bottom: max(7vh, 26px); right: max(6.5vw, 22px); }

.osd .icon {
  width: 0.72em;
  height: 0.72em;
  flex: none;
  fill: currentColor;
  filter:
    drop-shadow(2px 0 0 #000) drop-shadow(-2px 0 0 #000)
    drop-shadow(0 2px 0 #000) drop-shadow(0 -2px 0 #000);
}

.osd .rec { color: var(--rec); }

.osd-fade {
  transition: opacity 0.5s steps(4);
}

.osd-fade.gone {
  opacity: 0;
}

/* Centered OSD message used by the error pages */
.osd-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.55em;
  padding: 0 6vw;
  text-align: center;
}

.osd-headline {
  font-size: clamp(2.6rem, 11vw, 7.5rem);
  line-height: 0.9;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.osd-headline.blink {
  animation: vcr-blink 1.1s steps(1) infinite;
}

@keyframes vcr-blink {
  0%, 62% { opacity: 1; }
  63%, 100% { opacity: 0; }
}

.osd-sub {
  max-width: 34em;
  font-size: clamp(1.15rem, 3.1vw, 2rem);
  line-height: 1.15;
  letter-spacing: 0.05em;
  color: var(--osd);
}

/* VCR set-up menu style actions */
.osd-menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4em 1.1em;
  margin-top: 0.6em;
  font-size: clamp(1.3rem, 3.4vw, 2.2rem);
  pointer-events: auto;
}

.osd-menu a,
.osd-menu button {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.12em 0.45em 0.08em;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  text-decoration: none;
  text-shadow: var(--osd-edge);
  cursor: pointer;
}


.osd-menu a:hover,
.osd-menu a:focus-visible,
.osd-menu button:hover,
.osd-menu button:focus-visible {
  outline: none;
  background: var(--osd);
  color: var(--vcr-blue);
  text-shadow: none;
}


.osd-menu .icon {
  filter: none;
}

.osd-retry {
  font-size: clamp(1rem, 2.6vw, 1.6rem);
  color: var(--osd-dim);
}

/* ----- CRT glass --------------------------------------------------------- */
.crt {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    /* glass reflection */
    radial-gradient(70% 45% at 22% 12%, rgba(255, 255, 255, 0.07), transparent 70%),
    /* scanlines */
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0) 0px,
      rgba(0, 0, 0, 0) 1px,
      rgba(0, 0, 0, 0.32) 2px,
      rgba(0, 0, 0, 0.32) 3px
    ),
    /* aperture grille */
    repeating-linear-gradient(
      to right,
      rgba(255, 0, 60, 0.05) 0px,
      rgba(255, 0, 60, 0.05) 1px,
      rgba(0, 255, 120, 0.04) 1px,
      rgba(0, 255, 120, 0.04) 2px,
      rgba(40, 90, 255, 0.05) 2px,
      rgba(40, 90, 255, 0.05) 3px
    ),
    /* tube vignette */
    radial-gradient(
      ellipse at center,
      transparent 52%,
      rgba(0, 0, 0, 0.32) 80%,
      rgba(0, 0, 0, 0.9) 118%
    );
}

/* Rounded corners + curvature shading of the tube face */
.crt::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 3.2% / 4.4%;
  box-shadow:
    0 0 0 60px #000,
    inset 0 0 6vmin 1.5vmin rgba(0, 0, 0, 0.75),
    inset 0 0 1px 1px rgba(0, 0, 0, 0.9);
}

/* Faint 60 Hz shimmer of the whole tube */
.crt::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.018);
  animation: vcr-shimmer 0.12s steps(2) infinite;
}

@keyframes vcr-shimmer {
  50% { opacity: 0; }
}

/* ----- Boot: blue screen -> tracking lock -> picture --------------------- */
.tv.boot .picture > :not(.noise) { opacity: 0; }
.tv.boot .picture { background: var(--vcr-blue); }
.tv.locking .picture { filter: blur(1.2px) brightness(1.15); }

/* ----- Pixel cursor ------------------------------------------------------ */
html.custom-cursor,
html.custom-cursor * { cursor: none !important; }

.cursor-pixel {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s steps(3);
  will-change: transform;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 4px rgba(200, 220, 255, 0.55));
}

.cursor-pixel svg { display: block; }
html.cursor-visible .cursor-pixel { opacity: 1; }

/* ----- Small screens / accessibility ------------------------------------ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 520px) {
  .osd-headline { white-space: normal; }
  .camstamp { right: 9%; bottom: 13%; }
}

@media (prefers-reduced-motion: reduce) {
  .picture,
  .picture::after,
  [data-mode="scramble"] .picture,
  .title.glitch,
  .osd-headline.blink,
  .crt::before {
    animation: none !important;
  }
  .title { filter: none; }
}
