* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
[hidden] {
  display: none !important;
} /* .osd-item sets display, which outranks the UA [hidden] rule */
html {
  height: 100%;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: #000;
  color: #f2f2ee;
  font-family: 'VT323', 'VCR OSD Mono', ui-monospace, 'Courier New', monospace;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
.broadcast {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: #000;
}

/* ---- z-stack: bars < tv < static < scrim < crt < roll < osd ---- */

.bars {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.bars .top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 67%;
  background: linear-gradient(
    90deg,
    #c0c0c0 0 14.28%,
    #c0c000 14.28% 28.57%,
    #00c0c0 28.57% 42.85%,
    #00c000 42.85% 57.14%,
    #c000c0 57.14% 71.42%,
    #c00000 71.42% 85.71%,
    #0000c0 85.71% 100%
  );
}
.bars .mid {
  position: absolute;
  top: 67%;
  left: 0;
  right: 0;
  height: 8%;
  background: linear-gradient(
    90deg,
    #0000c0 0 14.28%,
    #131313 14.28% 28.57%,
    #c000c0 28.57% 42.85%,
    #131313 42.85% 57.14%,
    #00c0c0 57.14% 71.42%,
    #131313 71.42% 85.71%,
    #c0c0c0 85.71% 100%
  );
}
.bars .bot {
  position: absolute;
  top: 75%;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    #00214c 0 17.5%,
    #ffffff 17.5% 35%,
    #32006a 35% 52.5%,
    #131313 52.5% 75%,
    #000 75% 79%,
    #131313 79% 83%,
    #262626 83% 87%,
    #131313 87% 100%
  );
}

/* ---- tuned channel ---- */
#tv {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  background: #000;
  display: none;
}
#tv.on {
  display: block;
}
#tv iframe {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* The channel videos are square: size from the viewport's longer edge so
       the frame always covers it, cropping equally from the opposite axis. */
  width: max(100vw, 100dvh);
  height: max(100vw, 100dvh);
  border: 0;
  pointer-events: none;
}

#noise {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  opacity: 0.4;
  mix-blend-mode: screen;
  image-rendering: pixelated;
  transition: opacity 0.18s linear;
}
#noise.burst {
  opacity: 1;
}

.scrim {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(
    100deg,
    rgba(0, 0, 0, 0.88) 0%,
    rgba(0, 0, 0, 0.72) 34%,
    rgba(0, 0, 0, 0.2) 62%,
    rgba(0, 0, 0, 0.45) 100%
  );
}
.crt {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background:
      /* iOS Safari tints the status bar and the toolbar with the colour it
         samples from the page's edge, so the edges go to solid black and the
         chrome reads as a continuation of the picture, not two grey bands */
    linear-gradient(
      to bottom,
      #000 0,
      rgba(0, 0, 0, 0.6) 4%,
      rgba(0, 0, 0, 0) 13%,
      rgba(0, 0, 0, 0) 82%,
      rgba(0, 0, 0, 0.62) 95%,
      #000 100%
    ),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.5) 0 1px, rgba(0, 0, 0, 0) 1px 3px),
    radial-gradient(
      ellipse at center,
      rgba(0, 0, 0, 0) 40%,
      rgba(0, 0, 0, 0.5) 78%,
      rgba(0, 0, 0, 0.9) 100%
    );
}
.roll {
  position: absolute;
  left: 0;
  right: 0;
  height: 26vh;
  z-index: 5;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0),
    rgba(255, 255, 255, 0.055),
    rgba(255, 255, 255, 0)
  );
  animation: roll 9s linear infinite;
}
@keyframes roll {
  from {
    top: -30vh;
  }
  to {
    top: 100vh;
  }
}

/* ================= OSD: four corners ================= */
.osd {
  position: absolute;
  inset: 0;
  z-index: 6;
  padding: max(5vmin, calc(env(safe-area-inset-top) + 2vmin))
    max(5vw, calc(env(safe-area-inset-right) + 2vw))
    max(5vmin, calc(env(safe-area-inset-bottom) + 2vmin))
    max(5vw, calc(env(safe-area-inset-left) + 2vw));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 1rem;
  pointer-events: none;
}
.osd-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: clamp(0.5rem, 3vw, 2rem);
}
.osd-item {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-size: clamp(1.5rem, 4.2vw, 3rem);
  line-height: 1;
  text-transform: uppercase;
  color: #fff;
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-shadow:
    2px 2px 0 rgba(0, 0, 0, 0.95),
    -2px 0 0 rgba(255, 0, 64, 0.55),
    2px 0 0 rgba(0, 110, 255, 0.55),
    0 0 14px rgba(255, 255, 255, 0.28);
}
.osd-left {
  display: flex;
  align-items: center;
  gap: clamp(0.7rem, 2.4vw, 1.6rem);
  flex-wrap: wrap;
}
/* The playback CTA doubles as the transport-state display. Its icon is
   drawn in CSS so PLAY and PAUSE keep the same OSD weight and alignment. */
.playback-control {
  appearance: none;
  padding: 0;
  font-family: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
  pointer-events: auto;
}
.playback-control:not(:disabled):hover {
  opacity: 0.78;
}
.playback-control:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 0.18em;
}
.playback-control:not(:disabled):active {
  opacity: 0.55;
}
.playback-control:disabled {
  cursor: wait;
  opacity: 0.62;
}
.playback-icon {
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 0.58em solid currentColor;
  border-top: 0.36em solid transparent;
  border-bottom: 0.36em solid transparent;
  margin-left: 0.1em;
  transform: translateY(0.02em);
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.95));
}
.playback-control[data-state='playing'] .playback-icon {
  width: 0.58em;
  height: 0.72em;
  border: 0;
  background: linear-gradient(
    90deg,
    currentColor 0 34%,
    transparent 34% 66%,
    currentColor 66% 100%
  );
}
.playback-control[data-state='loading'] .playback-icon {
  animation: blink 0.5s steps(1) infinite;
}
.num {
  letter-spacing: 0.12em;
}
.gap {
  display: inline-block;
  width: 1.4em;
}
.blink12 {
  animation: blink 1s steps(1) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}
.broadcast.has-playback {
  cursor: pointer;
}
#chan {
  transition: opacity 0.3s;
}
#chan.flash {
  animation: chflash 0.35s steps(1) 4;
}
@keyframes chflash {
  50% {
    opacity: 0.15;
  }
}

/* ================= nameplate ================= */
.nameplate {
  align-self: center;
  width: fit-content;
  max-width: 100%;
  pointer-events: auto;
}
/* --split : rgb misconvergence, in px (JS scales it off the type size)
     --bias  : which way the beams lean — follows the pointer
     --chroma: how hot the fringe burns
     --dx    : per-band tape displacement, in em so it scales with the type */
@property --split {
  syntax: '<length>';
  inherits: true;
  initial-value: 0.6px;
}
@property --bias {
  syntax: '<length>';
  inherits: true;
  initial-value: 0px;
}
@property --chroma {
  syntax: '<number>';
  inherits: true;
  initial-value: 0.42;
}
h1 {
  font-weight: 400;
  font-size: clamp(2.75rem, 13vw, 8.5rem);
  line-height: 0.84;
  color: #fdfdf8;
  cursor: crosshair;
  position: relative;
  text-shadow:
    3px 3px 0 rgba(0, 0, 0, 0.92),
    0 0 26px rgba(255, 255, 255, 0.18);
  transform: translate3d(var(--fx, 0px), 0, 0) skewX(var(--sk, 0deg));
  transition:
    --split 0.2s linear,
    --bias 0.2s linear,
    --chroma 0.2s linear,
    transform 0.2s ease-out;
}
h1.tearing {
  transition: none;
} /* a tear is stepped, never eased */
.line {
  display: block;
  position: relative;
}
/* once JS has stacked the band layers the flat copy is only there for layout
     and for screen readers — transparent, not hidden, so it keeps its text */
h1.lit .line {
  color: transparent;
  text-shadow: none;
}
.band {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  color: #fdfdf8;
  pointer-events: none;
  /* the sides bleed so the drop shadow and the chroma fringe aren't shaved
       off; the top and bottom bands bleed too (set in JS) because line-height
       is .84 and the caps overflow the box */
  clip-path: inset(var(--t) -30% var(--b) -30%);
  transform: translate3d(var(--dx, 0em), 0, 0);
  transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.2, 1);
  will-change: transform;
  text-shadow:
    calc(var(--bias) - var(--split)) 0 0 rgba(255, 58, 88, var(--chroma)),
    calc(var(--bias) + var(--split)) 0 0 rgba(58, 146, 255, var(--chroma)),
    3px 3px 0 rgba(0, 0, 0, 0.92),
    0 0 26px rgba(255, 255, 255, 0.16);
}
/* generated content, so the name is in the DOM exactly once */
.band::before {
  content: attr(data-text);
}
/* head-switching dropout: a hot scan line that only exists mid-tear */
.dropout {
  position: absolute;
  left: -6%;
  right: -6%;
  top: var(--dy, 40%);
  height: 0.05em;
  opacity: var(--do, 0);
  mix-blend-mode: screen;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.9) 16%,
    rgba(255, 255, 255, 0.3) 52%,
    rgba(255, 255, 255, 0.95) 79%,
    rgba(255, 255, 255, 0) 100%
  );
}
h1.tearing .band {
  transition: none;
}

a.mail {
  display: inline-block;
  margin-top: clamp(0.8rem, 2vw, 1.3rem);
  font-size: clamp(1.35rem, 4.6vw, 2.4rem);
  letter-spacing: 0.05em;
  color: #eceae2;
  text-decoration: none;
  border-bottom: 2px solid rgba(236, 234, 226, 0.35);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.9);
  transition:
    color 0.15s,
    border-color 0.15s;
}
a.mail:hover,
a.mail:focus-visible {
  border-color: transparent;
}
a.mail:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 0.22em;
}

/* ================= channel changer ================= */
.tuner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: clamp(1.1rem, 3vw, 1.8rem);
  flex-wrap: wrap;
}
.tuner button {
  font: inherit;
  font-size: clamp(1.1rem, 3.4vw, 1.6rem);
  min-width: 3.4em;
  min-height: 2.4em; /* touch target */
  padding: 0.2em 0.7em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #eceae2;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid rgba(236, 234, 226, 0.5);
  cursor: pointer;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.9);
  transition:
    background 0.12s,
    color 0.12s,
    border-color 0.12s;
}
.tuner button:hover,
.tuner button:focus-visible {
  background: rgba(236, 234, 226, 0.92);
  color: #000;
  border-color: #fff;
  text-shadow: none;
  outline: none;
}
.tuner button:active {
  transform: translate(1px, 1px);
}
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ================= responsive ================= */
/* short viewports: keep the whole stack on one screen */
@media (max-height: 620px) {
  h1 {
    font-size: clamp(2.2rem, 8vh, 4rem);
  }
  .osd-item {
    font-size: clamp(1.15rem, 3.4vh, 1.7rem);
  }
  .osd {
    gap: 0.5rem;
    padding: 3vmin max(4vw, env(safe-area-inset-right)) 3vmin max(4vw, env(safe-area-inset-left));
  }
  /* the email and tuner scale on vw, so on a short-but-wide window they
       outgrow the name unless they get a vh-based cap too */
  a.mail {
    font-size: clamp(1.1rem, 4.2vh, 1.6rem);
    margin-top: 0.5rem;
  }
  .tuner {
    margin-top: 0.65rem;
    gap: 0.45rem;
  }
  .tuner button {
    font-size: clamp(1rem, 3.2vh, 1.3rem);
    min-height: 2.1em;
    padding: 0.15em 0.6em;
  }
}
/* phones: the bottom row can't fit speed + counter + datestamp side by side */
@media (max-width: 560px) {
  .osd-item {
    font-size: clamp(1.3rem, 5.6vw, 1.9rem);
  }
  .scrim {
    background: linear-gradient(
      180deg,
      rgba(0, 0, 0, 0.86) 0%,
      rgba(0, 0, 0, 0.62) 45%,
      rgba(0, 0, 0, 0.78) 100%
    );
  }
  #stamp {
    display: none;
  }
  .gap {
    width: 0.9em;
  }
}
@media (max-width: 380px) {
  #counter {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
  }
  h1,
  .band {
    transition: none !important;
  }
}
