/* ── Capsule TV, 1985 edition ──────────────────────────────────────────────
   Palette comes from the CTV logo (yellow + hot pink) plus an 80s cyan.
   Hard offset shadows instead of soft blurs, Memphis squiggles, VHS text. */
:root {
  --ink: #0a0a0a;
  --panel: rgba(10, 10, 10, 0.94);
  --text: #f6f4ee;
  --text-2: #c9c6bd;
  --text-3: #8d8a83;
  --yellow: #fff200;
  --pink: #ff0a8c;
  --cyan: #00e5ff;
  --purple: #7a2cff;
  --live: #ff2f4d;
  --rainbow: linear-gradient(90deg, var(--pink), var(--yellow) 34%, var(--cyan) 67%, var(--pink));
  /* hard-stop version for text: 80s colour bands, no blending */
  --bands: linear-gradient(90deg, var(--pink) 0 25%, var(--yellow) 25% 50%, var(--cyan) 50% 75%, var(--pink) 75% 100%);
  /* type */
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --display: "Bungee", "Impact", sans-serif;
  --marker: "Permanent Marker", "Comic Sans MS", cursive;
  --vhs: "VT323", ui-monospace, Menlo, monospace;
  /* an unlit CRT: the tube's own dim glow, a touch brighter in the middle,
     with faint scanlines. Used for the letterbox and between channels. */
  --crt-raster:
    repeating-linear-gradient(to bottom, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse 75% 70% at 50% 48%, #262a31 0%, #1a1d22 55%, #101114 100%);
  /* character-generator text: the chyron and the program guide */
  --chy-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --chy-orange: #ffa23a;
  --chy-green: #c9f36a;
  --chy-shadow: 0.05em 0.07em 0 rgba(0, 0, 0, 0.9), 0 0 0.35em rgba(0, 0, 0, 0.55);
  /* hard 80s shadow */
  --pop: 0.5rem;
}

/* Everything is sized in rem; the root scales with the display so the TV
   looks the same on a laptop and a wall screen. 1rem ≈ 16px at 1440×900. */
html { font-size: clamp(13px, 0.7vmin + 0.62vw, 30px); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--text); overflow: hidden; }
body { font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body.idle { cursor: none; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ── frame ────────────────────────────────────────────────────────────────── */
#tv { position: fixed; inset: 0; background: #050505; overflow: hidden; }

/* ── start screen: the room photo, live screen behind the TV's tube ───────── */
/* tv.js sets --ix/--iy/--iw/--ih (the photo, scaled to cover the window) and
   --sx/--sy/--sw/--sh (the tube's transparent hole inside it). */
#scene { position: absolute; inset: 0; transform-origin: 0 0; }
#room {
  position: absolute; z-index: 2; pointer-events: none;
  left: var(--ix); top: var(--iy); width: var(--iw); height: var(--ih);
}
body.room #screen { inset: auto; left: var(--sx); top: var(--sy); width: var(--sw); height: var(--sh); }
body:not(.room) #room, body:not(.room) #hint, body:not(.room) #grain { display: none; }
/* VHS off (V): a clean picture. No colour bleed, CRT texture, colour boost,
   breathing or colour flash; static between channels stays. */
body.no-vhs #screen { --vhs-fx: opacity(1); }
body.no-vhs #screen, body.no-vhs #screen.jolt { animation: none !important; }
body.no-vhs #video { filter: none; }
body.no-vhs .crt { display: none; }
/* film grain over the room photo; tv.js jitters it every frame */
#grain {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background-size: 256px 256px;
  mix-blend-mode: overlay; opacity: 0.2;
}
#hint {
  position: absolute; z-index: 3; left: 50%; bottom: 1.5rem; margin: 0;
  transform: translateX(-50%); width: max-content; max-width: calc(100% - 2rem); text-align: center; line-height: 1.4;
  padding: 0.45rem 0.9rem; border-radius: 999px;
  background: rgba(0, 0, 0, 0.55); color: #f3e9dc;
  font: 700 0.8rem/1.4 "Archivo Narrow", "Helvetica Neue", sans-serif;
  text-transform: uppercase; letter-spacing: 0.08em;
}
body.idle #hint { opacity: 0; }
/* the small dark pills: "Sign in" (or who's signed in) and the Agent CTA */
.pill-link {
  position: absolute; z-index: 30;
  padding: 0.45rem 0.9rem; border-radius: 999px;
  background: rgba(0, 0, 0, 0.55); color: #f3e9dc; text-decoration: none; white-space: nowrap;
  font: 700 0.8rem/1.4 "Archivo Narrow", "Helvetica Neue", sans-serif;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.pill-link:hover { background: rgba(0, 0, 0, 0.8); }
#team-start { z-index: 3; top: 1.25rem; right: 1.25rem; }
body:not(.room) #team-start { display: none; }

/* ── the Agent CTA (signed out only), bottom left, always on ───────────── */
#cta { left: 1.25rem; bottom: 1.25rem; }
body.team #cta, body.guide-open #cta { display: none; }
/* on the start screen the controls hint sits bottom centre; keep clear of it */
body.room #hint { left: auto; right: 1.25rem; bottom: 1.25rem; transform: none; }

/* ── screen ───────────────────────────────────────────────────────────────── */
#screen {
  /* the VHS look is only on the picture, not the room around it */
  --vhs-fx: url(#vhs);
  filter: var(--vhs-fx);
  position: absolute; inset: 0;
  overflow: hidden;
  container-type: size; /* the ident sizes itself to the tube */
  background: var(--crt-raster);
  transform-origin: 50% 50%;
}
#screen { animation: breathe 9s ease-in-out infinite; }

#video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain;
}
#video { filter: contrast(1.1) saturate(1.25); }

#static {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; pointer-events: none; image-rendering: pixelated;
  mix-blend-mode: screen; /* cuts on and off, no fade */
}
#static.on { opacity: 1; }
/* the beat of "black" between channels: a CRT's black is the tube's own dim
   glow, a lit raster that's a touch brighter in the middle, never #000 */
#black {
  position: absolute; inset: 0; z-index: 4; opacity: 0; pointer-events: none;
  background: var(--crt-raster);
}
#black.on { opacity: 1; animation: crt-idle 0.14s steps(1) infinite; }
@keyframes crt-idle { 50% { filter: brightness(1.12); } }

/* ── CRT layers ───────────────────────────────────────────────────────────── */
.crt { position: absolute; inset: 0; pointer-events: none; transition: opacity 0.6s; }
.scanlines {
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,0.25) 2px 3px);
  animation: flicker 0.12s steps(2) infinite;
}
.mask {
  background: repeating-linear-gradient(90deg, rgba(255,0,60,0.06) 0 1px, rgba(0,255,120,0.05) 1px 2px, rgba(40,90,255,0.06) 2px 3px);
  mix-blend-mode: overlay;
}
.vignette {
  background: radial-gradient(ellipse at center, transparent 68%, rgba(0,0,0,0.45) 100%);
}

/* ── OSD: VCR on-screen text ──────────────────────────────────────────────── */
#osd {
  position: absolute; top: 1.25rem; right: 1.75rem; z-index: 6;
  text-align: right; color: #fff;
  font-family: var(--vhs);
}
#osd-ch {
  font-size: 5rem; line-height: 0.85; letter-spacing: 0.02em; text-transform: uppercase;
  text-shadow: 0.2rem 0 0 var(--pink), -0.2rem 0 0 var(--cyan);
}
#osd-sub {
  display: inline-block; margin-top: 0.4rem;
  font-size: 1.5rem; line-height: 1; letter-spacing: 0.06em; color: #000;
  background: var(--yellow); padding: 0.15rem 0.5rem 0.05rem;
  box-shadow: 0.2rem 0.2rem 0 var(--pink);
}
#osd-sub:empty { display: none; }
/* like a VCR's on-screen display: on, then off, no fade */
#osd.fade { visibility: hidden; }

/* ── lower third: an 80s promo chyron ─────────────────────────────────────
   Plain character-generator text on the picture: bold Helvetica, orange
   title, orange rule, green details, hard drop shadow, over a soft dark shade
   so it reads on bright footage. It cuts on and fades off. */
#card {
  position: absolute; left: 2.25rem; bottom: 2.25rem; z-index: 7;
  width: min(46%, 40rem);
  font-family: var(--chy-font);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.9s, visibility 0s 0.9s;
}
#card.show { opacity: 1; visibility: visible; pointer-events: auto; transition: none; }
/* the shade: dark at the bottom-left corner, gone well past the text */
#card::before {
  content: ""; position: absolute; z-index: -1; pointer-events: none;
  left: -2.25rem; bottom: -2.25rem; width: calc(100% + 12rem); height: calc(100% + 10rem);
  background: radial-gradient(ellipse 75% 85% at 0% 100%, rgba(0,0,0,0.85), rgba(0,0,0,0.66) 45%, transparent 78%);
}
/* the key guide, set like the chyron's detail lines */
#keys {
  position: absolute; right: 2.25rem; bottom: 2.25rem; z-index: 7; margin: 0;
  max-width: 46%; text-align: right; text-wrap: balance;
  font: 700 1.05rem/1.3 var(--chy-font); letter-spacing: 0.01em; text-transform: uppercase;
  color: var(--chy-green); text-shadow: var(--chy-shadow);
  opacity: 0; visibility: hidden;
  transition: opacity 0.9s, visibility 0s 0.9s;
}
/* key lists: separators belong to each key, so hiding one leaves no double dot */
.key-list .k { white-space: nowrap; }
.key-list .k + .k::before { content: " · "; }
body:not(.team) .team-only { display: none; }
#keys.show { opacity: 1; visibility: visible; transition: none; }
#card-title {
  margin: 0;
  text-wrap: balance; /* even lines, no one-word middle line */
  font-size: 3rem; font-weight: 700; line-height: 1.02; letter-spacing: -0.025em;
  color: var(--chy-orange); text-shadow: var(--chy-shadow);
}
/* the orange rule under a title (chyron and guide) */
.rule {
  height: 0.28rem; margin: 0.8rem 0 0.7rem;
  background: var(--chy-orange); box-shadow: 0.18rem 0.24rem 0 rgba(0, 0, 0, 0.9);
}
#card-meta, #card-why { margin: 0; color: var(--chy-green); text-shadow: var(--chy-shadow); }
#card-meta {
  font-size: 1.45rem; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; text-transform: uppercase;
}
#card-why {
  margin-top: 0.45rem;
  font-size: 1.15rem; font-weight: 500; line-height: 1.35;
  text-wrap: pretty;
}
#card-why:empty { display: none; }

/* ── program guide: set like the chyron ───────────────────────────────────
   Same character-generator look, over a dark shade that fades in from the
   left so the listings read over any picture. It cuts on, like the chyron. */
#guide {
  position: absolute; inset: 0 auto 0 0; z-index: 9;
  width: min(72%, 60rem);
  display: flex; flex-direction: column;
  padding: 2.25rem 4rem 2.25rem 3.25rem;
  background: linear-gradient(90deg, rgba(0,0,0,0.85), rgba(0,0,0,0.7) 65%, transparent);
  font-family: var(--chy-font); color: var(--chy-green); text-shadow: var(--chy-shadow);
}
.guide-title {
  margin: 0; color: var(--chy-orange);
  font-size: 3.6rem; font-weight: 700; line-height: 1; letter-spacing: -0.025em;
}
.guide-section {
  margin-bottom: 0.6rem;
  font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; text-transform: uppercase;
}
#guide ol { list-style: none; margin: 0 0 0 -1.5rem; padding: 0 0 0 1.5rem; overflow: auto; flex: 0 1 auto; min-height: 0; scrollbar-width: none; }
#guide li {
  position: relative;
  display: grid; grid-template-columns: 5.5rem 1fr auto; align-items: baseline; gap: 1rem;
  padding: 0.3rem 0;
  font-size: 1.8rem; font-weight: 700; line-height: 1.15; letter-spacing: -0.015em;
  white-space: nowrap; cursor: pointer;
}
#guide li span { overflow: hidden; text-overflow: ellipsis; }
#guide li span:last-child { font-size: 1.2rem; font-weight: 500; text-transform: uppercase; opacity: 0.85; }
/* the highlighted row goes orange, with a pointer like an old CG cursor */
#guide li.sel { color: var(--chy-orange); }
/* the "Commercials" heading between the channels and the ads */
#guide footer .team-link { color: var(--chy-orange); text-decoration: none; }
#guide footer .team-link:hover { text-decoration: underline; }
#guide li.guide-head {
  display: block; cursor: default;
  margin-top: 0.9rem; padding-bottom: 0.2rem;
  font-size: 1.5rem; text-transform: uppercase; letter-spacing: -0.01em;
}
#guide li.sel::before { content: "▶"; position: absolute; left: -1.5rem; top: 0.55rem; font-size: 0.7em; }
#guide li.now span:last-child::after { content: "  · ON NOW"; color: var(--chy-orange); }
#guide footer {
  display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap;
  margin-top: auto; padding-top: 1rem;
  font-size: 1.2rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; opacity: 0.85;
}

/* ── no signal ────────────────────────────────────────────────────────────── */
#no-signal { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 1rem; text-align: center; }
#no-signal .bars {
  position: absolute; inset: 0; z-index: -1; opacity: 0.85;
  background: linear-gradient(90deg, #c0c0c0 0 14.28%, #c0c000 0 28.57%, #00c0c0 0 42.85%, #00c000 0 57.14%, #c000c0 0 71.42%, #c00000 0 85.71%, #0000c0 0);
}
#no-signal p { margin: 0; padding: 0.2rem 1.5rem; background: #000; color: #fff; font: 6rem/1 var(--vhs); text-transform: uppercase; }
#no-signal small { font: 1.4rem/1 var(--vhs); color: #fff; background: #000; padding: 0.4rem 1rem; }
#no-signal code { font-family: var(--vhs); color: var(--yellow); }

/* ── power screen: a minimal MTV-style ident ───────────────────────────────
   One flat colour (picked per visit in tv.js), paper grain, logo, tagline. */
#power {
  --flat: #c4abe6;
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center; align-content: center; gap: 0;
  background: var(--flat);
  color: #000; text-align: center; cursor: pointer; overflow: hidden;
}
#power::before { /* paper grain */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.18; mix-blend-mode: multiply;
}
.power-logo {
  position: relative;
  width: 44cqw; height: auto;
  animation: logo-in 0.6s steps(6) both, boil 0.4s steps(1) 0.6s infinite;
}
.tagline {
  position: relative; margin: 1.6cqw 0 0;
  font: 700 6.4cqw/1 "Archivo Narrow", "Helvetica Neue", Arial Narrow, sans-serif;
  text-transform: uppercase; letter-spacing: -0.01em;
}
.tagline sup { font-size: 0.4em; vertical-align: 1.3em; margin-left: 0.08em; }
.press {
  position: relative; margin: 6cqw 0 0;
  font: 700 2.8cqw/1 "Archivo Narrow", "Helvetica Neue", sans-serif;
  text-transform: uppercase; letter-spacing: 0.18em;
  animation: blink 1.1s step-end infinite;
}
body:not(.off) #power { display: none; }
body.powering #screen { animation: power-on 0.9s cubic-bezier(.2,.9,.3,1) both; }

/* ── channel-change colour flash ──────────────────────────────────────────────────── */
#screen.jolt { animation: jolt 0.2s steps(3) both !important; }

/* ── keyframes ────────────────────────────────────────────────────────────── */
@keyframes hue-plain { to { filter: hue-rotate(360deg); } }
@keyframes slide { to { background-position: 300% 0; } }
@keyframes breathe { 50% { transform: scale(1.006) skewX(0.15deg); } }
@keyframes flicker { 50% { opacity: 0.85; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes wobble { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg) scale(1.02); } }
@keyframes wiggle { 50% { transform: translateX(0.3rem) scaleX(1.06); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes logo-in { from { transform: scale(0.2) rotate(-25deg); opacity: 0; } }
/* hand-drawn "line boil": the logo jitters between a few poses */
@keyframes boil {
  0%   { transform: rotate(-0.6deg) translate(0, 0); }
  33%  { transform: rotate(0.4deg) translate(1px, -1px); }
  66%  { transform: rotate(-0.2deg) translate(-1px, 1px); }
}
@keyframes crawl { to { transform: translateX(-100%); } }
@keyframes power-on {
  0%   { transform: scale(1, 0.004); filter: var(--vhs-fx) brightness(8); }
  45%  { transform: scale(1, 0.004); filter: var(--vhs-fx) brightness(8); }
  70%  { transform: scale(1, 1.04);  filter: var(--vhs-fx) brightness(2.5); }
  100% { transform: none; filter: var(--vhs-fx); }
}
@keyframes jolt {
  0%   { filter: var(--vhs-fx); }
  25%  { filter: var(--vhs-fx) hue-rotate(90deg) saturate(3); }
  50%  { filter: var(--vhs-fx) invert(0.2) hue-rotate(200deg); }
  75%  { filter: var(--vhs-fx) hue-rotate(300deg); }
  100% { filter: var(--vhs-fx); }
}


/* ── small screens: card and guide go full width ──────────────────────────── */
/* ── touch devices: on-screen controls instead of keys ───────────────────── */
.touch-only { display: none; }
body.touch .touch-only { display: inline-block; }
body.touch .kb-only, body.touch .key-list { display: none !important; }
/* the picture takes swipes for channels, so the page mustn't scroll or pull to refresh;
   the guide's list still scrolls */
html, body { overscroll-behavior: none; }
body.touch #screen { touch-action: none; }
body.touch #guide ol { touch-action: pan-y; }
#touch {
  position: absolute; z-index: 8; right: 1rem; bottom: 1rem;
  display: none; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem;
  max-width: calc(100% - 2rem);
  opacity: 0; visibility: hidden; transition: opacity 0.9s, visibility 0s 0.9s;
}
body.touch #touch { display: flex; }
#touch.show { opacity: 1; visibility: visible; transition: none; }
#touch button, .guide-close {
  min-height: 2.75rem; padding: 0 0.95rem; border: 0; border-radius: 999px;
  background: rgba(0, 0, 0, 0.62); color: var(--chy-green); text-shadow: var(--chy-shadow);
  font: 700 1rem/1 var(--chy-font); text-transform: uppercase; letter-spacing: 0.01em;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
#touch button:active, .guide-close:active { background: rgba(0, 0, 0, 0.85); }
#touch button.hot { color: var(--chy-orange); }
body:not(.team) #touch .team-only { display: none; }
.guide-close { color: var(--chy-orange); }
/* keep the chyron clear of the touch bar */
body.touch #card { bottom: 4.75rem; }
/* portrait phones: the Agent pill moves to the top left, out of the controls' way */
@media (max-aspect-ratio: 1/1) {
  body.touch #cta { bottom: auto; top: 1.25rem; }
  body.touch #touch { left: 1rem; right: 1rem; justify-content: center; }
}

@media (max-width: 760px) {
  #card { left: 1rem; right: 1rem; bottom: 1rem; width: auto; }
  #card-title { font-size: 2.6rem; }
  #card-meta { font-size: 1.2rem; }
  #keys { display: none; }
  #guide { width: 100%; padding: 1.25rem 1.25rem 1.25rem 2.25rem; }
  .guide-title { font-size: 2.6rem; }
  #guide li { font-size: 1.4rem; grid-template-columns: 4.5rem 1fr; }
  #guide li span:last-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; }
}
