/* Collected Space — gallery homepage.
   A white gallery wall with one wide vintage walnut television centered in the viewport.
   The TV is the interface. Deliberately empty otherwise. */

:root {
  --wood-hi: #8a5a37;
  --wood: #6d4526;
  --wood-lo: #4a2d18;
  --wood-edge: #3a2314;
  --cream: #d8cdb2;
  --cream-lo: #b6a985;
  --screen-bg: #0a0806;
  --osd: #f3ede0;
  --amber: #ff9d2e;
  --grille: #241812;
  --ink: #111;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: #fcfcfb;                 /* near-pure white gallery wall */
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ---- Minimal navigation ---- */
.nav {
  position: fixed; top: 30px; left: 48px; right: 48px; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink); pointer-events: none;
}
.nav > * { pointer-events: auto; }
.nav a { color: inherit; text-decoration: none; opacity: 0.9; transition: opacity .18s; }
.nav a:hover { opacity: 1; }
/* CULTURE IN MOTION stays at the base size. Brand + GALLERY link are larger and equal. */
.nav .center { font-weight: 700; }
.nav .brand,
.nav .right a { font-size: 18px; letter-spacing: 0.16em; }
.nav .right { display: flex; gap: 28px; }

/* ---- Stage: centers the TV with negative space ---- */
.stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  /* Generous clearance below the fixed navbar and above the bottom edge. */
  padding: 150px 48px 90px;
}

/* ---- Television (wide, walnut) ---- */
.tv {
  position: relative;
  /* Height is driven by the width cap. 150vh -> TV height ~= 76vh, which (with the stage
     padding) always leaves clear space between the navbar and the top of the TV. */
  width: min(84vw, 1600px, 150vh);
  aspect-ratio: 16 / 8.1;
  border-radius: 26px;
  background:
    linear-gradient(180deg, var(--wood-hi) 0%, var(--wood) 30%, var(--wood-lo) 100%);
  box-shadow:
    inset 0 2px 3px rgba(255,220,180,0.35),
    inset 0 -20px 50px rgba(0,0,0,0.45),
    0 40px 90px rgba(50,30,15,0.35), 0 14px 30px rgba(50,30,15,0.25);
  padding: 2.4%;
  display: flex;
  gap: 2.2%;
}
/* subtle vertical wood-grain */
.tv::before {
  content: ""; position: absolute; inset: 0; border-radius: 26px; pointer-events: none;
  background: repeating-linear-gradient(90deg,
    rgba(0,0,0,0.05) 0px, rgba(0,0,0,0.05) 2px,
    rgba(255,255,255,0.02) 3px, rgba(255,255,255,0.02) 5px);
  mix-blend-mode: overlay; opacity: 0.5;
}
/* bottom feet */
.tv::after {
  content: ""; position: absolute; left: 18%; right: 18%; bottom: -14px; height: 14px;
  background:
    linear-gradient(90deg, transparent 0 14%, var(--wood-lo) 14% 24%, transparent 24% 76%, var(--wood-lo) 76% 86%, transparent 86%);
  border-radius: 0 0 6px 6px;
}

/* ---- Left: screen area with cream bezel ---- */
.tv-screenwrap {
  position: relative; flex: 1 1 auto; min-width: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--cream) 0%, var(--cream-lo) 100%);
  padding: 1.6%;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.5), 0 2px 6px rgba(0,0,0,0.25);
}
.tv-screen {
  position: relative; width: 100%; height: 100%;
  overflow: hidden;                     /* MANDATORY: recursion clipped to the glass */
  border-radius: 12px;
  background: var(--screen-bg);
  box-shadow: inset 0 0 46px rgba(0,0,0,0.9), inset 0 0 3px rgba(120,160,200,0.12);
  transform: translateZ(0); isolation: isolate;
}

.tv-screen video,
.tv-screen .recursion {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.tv-screen video {
  transform: scale(1.015);
  filter: saturate(1.05) contrast(1.03);
  background: var(--screen-bg); z-index: 1;
}
.tv-screen .recursion { z-index: 3; pointer-events: none; }

/* ---- On-screen display (OSD): PLAY / CHANNEL / clock ---- */
.osd {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  font-family: "Courier New", ui-monospace, monospace;
  color: var(--osd);
  text-shadow: 0 0 8px rgba(220,235,255,0.25);
}
.osd .osd-play   { position: absolute; top: 6%;  left: 4.5%; font-size: clamp(12px, 2.1vw, 30px); letter-spacing: 0.14em; }
.osd .osd-ch     { position: absolute; top: 6%;  right: 4.5%; font-size: clamp(12px, 2.1vw, 30px); letter-spacing: 0.14em; }
.osd .osd-clock  { position: absolute; bottom: 7%; left: 4.5%; font-size: clamp(16px, 3.4vw, 46px); letter-spacing: 0.08em; line-height: 1.12; }
.osd .osd-date   { font-size: clamp(11px, 1.9vw, 26px); letter-spacing: 0.14em; opacity: 0.95; }
.osd .blink { animation: blink 1.4s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---- CRT overlays (non-interactive) ---- */
.crt-scanlines, .crt-noise, .crt-glass, .crt-vignette, .crt-flicker {
  position: absolute; inset: 0; pointer-events: none;
}

/* Always-on "sticky" creepy flicker over ALL video, whatever is playing.
   Two combined motions:
     1) an irregular brightness strobe (unsettling, never fully steady)
     2) a slow dark bar rolling down the screen (failing-sync feel)
   Kept subtle: the picture stays clearly visible, but the flicker is noticeable. */
.crt-flicker {
  z-index: 5;   /* above noise, below vignette/glass so it reads as part of the tube */
  mix-blend-mode: multiply;
  background:
    /* the rolling dark bar (stronger + wider) */
    linear-gradient(to bottom,
      rgba(0,0,0,0) 0%,
      rgba(0,0,0,0.30) 44%,
      rgba(0,0,0,0.44) 50%,
      rgba(0,0,0,0.30) 56%,
      rgba(0,0,0,0) 100%),
    /* base darkening the strobe modulates */
    rgba(0,0,0,0.10);
  background-size: 100% 200%, 100% 100%;
  background-repeat: no-repeat;
  background-position: 0 -60%, 0 0;
  animation:
    flickerRoll 5.5s linear infinite,
    flickerStrobe 2.9s steps(1, end) infinite;
  will-change: opacity, background-position;
}

/* slow vertical roll of the dark bar */
@keyframes flickerRoll {
  0%   { background-position: 0 -55%, 0 0; }
  100% { background-position: 0 155%, 0 0; }
}

/* irregular brightness strobe — uneven step timing reads as "creepy", not a clean pulse.
   Deeper range (0.25–1.0) with a couple of hard near-black blinks so it's clearly noticeable. */
@keyframes flickerStrobe {
  0%   { opacity: 0.75; }
  3%   { opacity: 0.30; }
  5%   { opacity: 0.95; }
  8%   { opacity: 0.55; }
  9%   { opacity: 1.00; }
  15%  { opacity: 0.70; }
  16%  { opacity: 0.25; }   /* hard blink */
  18%  { opacity: 0.90; }
  30%  { opacity: 0.65; }
  33%  { opacity: 1.00; }
  48%  { opacity: 0.60; }
  50%  { opacity: 0.35; }
  52%  { opacity: 0.92; }
  66%  { opacity: 0.72; }
  70%  { opacity: 0.28; }   /* hard blink */
  72%  { opacity: 0.96; }
  85%  { opacity: 0.62; }
  100% { opacity: 0.78; }
}
.crt-scanlines { z-index: 4;
  background: repeating-linear-gradient(to bottom,
    rgba(0,0,0,0.10) 0px, rgba(0,0,0,0.10) 1px, transparent 1px, transparent 3px);
  mix-blend-mode: multiply; opacity: 0.45;
}
.crt-noise { z-index: 5; opacity: 0.045;
  background-image: url("/img/crt-noise.svg"); background-size: 220px 220px;
  animation: noiseShift 0.6s steps(4) infinite;
}
@keyframes noiseShift {
  0%{transform:translate(0,0)}25%{transform:translate(-6px,3px)}
  50%{transform:translate(4px,-5px)}75%{transform:translate(-3px,-2px)}100%{transform:translate(2px,4px)}
}
.crt-vignette { z-index: 6;
  background: radial-gradient(120% 120% at 50% 50%, transparent 62%, rgba(0,0,0,0.5) 100%);
}
.crt-glass { z-index: 7;
  background:
    radial-gradient(55% 40% at 26% 16%, rgba(255,255,255,0.08) 0%, transparent 55%),
    radial-gradient(80% 60% at 75% 92%, rgba(120,160,200,0.04) 0%, transparent 60%);
}

.sync-bar {
  position: absolute; left: -10%; right: -10%; height: 6%; top: 40%; z-index: 6;
  pointer-events: none; opacity: 0;
  background: linear-gradient(to bottom, transparent, rgba(255,255,255,0.22) 50%, transparent);
}
.tv-screen.is-switching video { filter: brightness(1.4) contrast(1.15) saturate(0.6); }

/* ---- Right: control / speaker panel ---- */
.tv-panel {
  position: relative; flex: 0 0 20%; max-width: 260px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(0,0,0,0.18)),
              linear-gradient(180deg, var(--wood-hi), var(--wood-lo));
  padding: 5% 6%;
  display: flex; flex-direction: column; align-items: stretch; gap: 6%;
  box-shadow: inset 0 1px 2px rgba(255,220,180,0.25), inset 0 -8px 20px rgba(0,0,0,0.35);
}
.grille {
  flex: 0 0 auto; height: 34%;
  border-radius: 8px;
  background:
    radial-gradient(circle at 2px 2px, rgba(0,0,0,0.55) 1.4px, transparent 1.6px) 0 0 / 9px 9px,
    linear-gradient(180deg, #2c1d14, #1a1009);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.6);
}
.panel-brand {
  font-family: "Courier New", monospace; text-align: center;
  font-size: clamp(9px, 1.15vw, 15px); letter-spacing: 0.18em; font-weight: 700;
  color: #efe6d0; text-shadow: 0 1px 1px rgba(0,0,0,0.5);
}
.tuner {
  display: flex; align-items: center; justify-content: space-between; gap: 8%;
  font-family: "Courier New", monospace; font-size: clamp(8px, 1vw, 13px);
  letter-spacing: 0.16em; color: #e7dcc4;
}
.tuner .lamp {
  width: 10px; height: 10px; border-radius: 50%; background: #5a3a18;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.3);
  transition: background .4s, box-shadow .4s;
}
.tuner .lamp.on { background: var(--amber); box-shadow: 0 0 10px 2px rgba(255,157,46,0.85), inset 0 0 0 2px rgba(0,0,0,0.25); }
.knobs { display: flex; justify-content: space-around; gap: 8%; margin-top: auto; }
.knob {
  width: 34%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(60% 60% at 40% 35%, #4a3a2a 0%, #221812 62%, #120c08 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,0.5), inset 0 -2px 3px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.08);
  position: relative;
}
.knob::after { content:""; position:absolute; top:12%; left:47%; width:6%; height:40%; background:#e9dcc2; border-radius:2px; }
.ch-buttons { display: flex; justify-content: space-between; gap: 8%; }
.ch-btn {
  flex: 1; padding: 8% 0; border: none; border-radius: 5px; cursor: pointer;
  font-family: "Courier New", monospace; font-size: clamp(9px, 1.1vw, 14px); font-weight: 700;
  letter-spacing: 0.08em; color: #efe6d0;
  background: linear-gradient(#3a2a1c, #241812);
  box-shadow: 0 2px 3px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.08);
  transition: transform .05s, filter .1s;
}
.ch-btn:hover { filter: brightness(1.25); }
.ch-btn:active { transform: translateY(1px); filter: brightness(0.9); }

/* AUTO toggle: full-width button below CH-/CH+, with a lit dot when active. */
.auto-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-top: 4%;
}
.auto-btn .auto-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #5a3a18;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.4); transition: background .3s, box-shadow .3s;
}
.auto-btn.is-on .auto-dot {
  background: var(--amber);
  box-shadow: 0 0 8px 1px rgba(255,157,46,0.85), inset 0 0 0 1px rgba(0,0,0,0.3);
}
.auto-btn.is-on { color: #fff; }
.auto-btn:not(.is-on) { color: #b9ab90; }

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  .tv { width: min(92vw, 132vh); }
  .nav { left: 26px; right: 26px; font-size: 11px; }
}
@media (max-width: 680px) {
  .nav { top: 16px; left: 16px; right: 16px; font-size: 9px; letter-spacing: 0.1em; }
  .nav .center { display: none; }
  .nav .right { gap: 16px; }
  .stage { padding: 80px 12px; }
  .tv { width: 96vw; aspect-ratio: 16 / 10; }
  .tv-panel { flex-basis: 24%; }
}

@media (prefers-reduced-motion: reduce) {
  .crt-noise { animation: none; opacity: 0.03; }
  .osd .blink { animation: none; }
  /* No strobing for reduced-motion; keep only a faint static darkening. */
  .crt-flicker { animation: none; opacity: 0.5; }
}

/* ---- Record mode (?record=1) -------------------------------------------------
   Capture-only presentation tweaks. `hide-chrome` strips the page furniture and
   the on-screen display so the frame is just the television; `is-recording`
   stills the one piece of looping CSS animation (the blinking PLAY caret) that
   would otherwise flicker unpredictably across a cut. Neither rule changes the
   CRT treatment itself — scanlines, noise, vignette and glass all stay on,
   because that look is the point of the recording. */
html.is-recording .osd .blink { animation: none; }
html.hide-chrome .nav,
html.hide-chrome .osd { display: none; }
/* The stage normally reserves room for the nav; reclaim it so the TV sits
   centred in the captured frame instead of riding low. */
html.hide-chrome .stage { padding-top: 24px; padding-bottom: 24px; }
