/* ==========================================================================
   TV WALL ARCHIVE (#showcase)
   Stacked CRT sets styled after the nav: indexed uppercase labels, REC HUD.
   Screens idle in black & white behind static; hover/focus (or .is-live on
   touch, set by js/tv-wall.js) tunes them to full color.
   ========================================================================== */

:root {
  --tv-noise: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --tv-plastic: linear-gradient(180deg, #1d1d21 0%, #141417 55%, #0e0e10 100%);
  --tv-plastic-edge: rgba(255, 255, 255, 0.07);
  --tv-label: #f5f5f7;
  --tv-foot: #0b0b0d;
  --tv-knob: radial-gradient(circle at 35% 30%, #3c3c44, #0c0c0e 70%);
}

[data-theme="swiss-mono"] {
  --tv-plastic: linear-gradient(180deg, #ececea 0%, #dadad6 60%, #cbcbc7 100%);
  --tv-plastic-edge: rgba(0, 0, 0, 0.1);
  --tv-label: #111111;
  --tv-foot: #b9b9b4;
  --tv-knob: radial-gradient(circle at 35% 30%, #fafafa, #a9a9a4 75%);
}

/* Header HUD (mirrors the nav's REC timecode) */
.showcase-section .section-header-row {
  flex-wrap: wrap;
  gap: 1rem;
}

.tv-wall-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.tvw-rec-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ff3344;
  box-shadow: 0 0 8px rgba(255, 51, 68, 0.7);
  animation: tvRecBlink 1.4s steps(1) infinite;
}

.tvw-rec {
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #ff3344;
}

.tvw-sep {
  opacity: 0.5;
}

@keyframes tvRecBlink {
  50% { opacity: 0.15; }
}

/* ---------- The wall ---------- */

.tv-wall {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 2.5rem; /* headroom for the antenna */
}

.tv-row {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 10px;
}

.tv-set {
  flex: 0 1 var(--w, 30%);
  min-width: 0;
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transform: rotate(var(--tilt, 0deg));
  transition: transform 500ms var(--ease-reveal);
  -webkit-tap-highlight-color: transparent;
}

.tv-set:hover,
.tv-set:focus-visible {
  transform: rotate(0deg) translateY(-6px);
  z-index: 2;
}

.tv-set:focus-visible {
  outline: none;
}

.tv-set:focus-visible .tv-body {
  outline: 2px solid #ff3344;
  outline-offset: 3px;
}

.tv-body {
  position: relative;
  display: block;
  padding: clamp(8px, 1vw, 15px) clamp(8px, 1vw, 15px) 0;
  border-radius: 14px;
  background: var(--tv-plastic);
  border: 1px solid var(--tv-plastic-edge);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -2px 0 rgba(0, 0, 0, 0.35),
    0 18px 30px -14px rgba(0, 0, 0, 0.75);
}

/* Rabbit-ear antenna */
.tv-set--antenna .tv-body::before,
.tv-set--antenna .tv-body::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  width: 2px;
  height: 46px;
  background: linear-gradient(180deg, #55555e, #1b1b1f);
  transform-origin: bottom center;
  transform: rotate(-26deg);
}
.tv-set--antenna .tv-body::after {
  transform: rotate(22deg);
}
.tv-set--antenna:hover .tv-body::before { transform: rotate(-32deg); transition: transform 600ms var(--ease-reveal); }
.tv-set--antenna:hover .tv-body::after { transform: rotate(28deg); transition: transform 600ms var(--ease-reveal); }

.tv-bezel {
  display: block;
  padding: clamp(4px, 0.5vw, 8px);
  border-radius: 12px;
  background: #070708;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    inset 0 2px 10px rgba(0, 0, 0, 0.9);
}

.tv-screen {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 18px / 22px; /* CRT bulge */
  background: #000;
  isolation: isolate;
}

.tv-set--portrait .tv-screen {
  aspect-ratio: 3 / 4;
  border-radius: 22px / 18px;
}

.tv-screen img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--focus, 50% 30%);
  filter: grayscale(1) contrast(1.15) brightness(0.62);
  transform: scale(1.02);
  transition:
    filter 600ms var(--ease-reveal),
    transform 700ms var(--ease-reveal);
}

/* Glass glare + scanlines + tube vignette */
.tv-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 30%),
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.28) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.75) 100%);
}

/* Vertical-hold roll bar, fired once when a set is tuned in */
.tv-screen::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 30%;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.16), transparent);
  transform: translateY(-110%);
  opacity: 0;
}

.tv-static {
  position: absolute;
  inset: -50%;
  z-index: 1;
  pointer-events: none;
  background-image: var(--tv-noise);
  background-size: 160px;
  mix-blend-mode: screen;
  opacity: 0.22;
  animation: tvStatic 0.45s steps(4) infinite;
  transition: opacity 400ms ease;
}

@keyframes tvStatic {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-12%, 8%); }
  50%  { transform: translate(9%, -6%); }
  75%  { transform: translate(-5%, -11%); }
  100% { transform: translate(0, 0); }
}

.tv-osd {
  position: absolute;
  z-index: 4;
  top: 7%;
  left: 7%;
  right: 7%;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: clamp(8px, 0.72vw, 11px);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 0 6px rgba(255, 255, 255, 0.35);
  pointer-events: none;
  white-space: nowrap;
}

.tv-osd--bottom {
  top: auto;
  bottom: 7%;
}

.tv-osd-rec {
  color: #ff3344;
  text-shadow: 0 0 6px rgba(255, 51, 68, 0.6);
}

.tv-osd-rec,
.tv-osd-view {
  opacity: 0;
  transition: opacity 250ms ease 150ms;
}

/* Control strip under the screen — same index/label rhythm as the nav */
.tv-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 4px 12px;
}

.tv-label {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
}

.tv-idx {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  transition: color 150ms ease;
}

[data-theme="swiss-mono"] .tv-idx {
  color: var(--text-secondary);
}

.tv-name {
  font-family: var(--font-body);
  font-size: clamp(11px, 0.9vw, 13px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tv-label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.tv-led {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3a1a1e;
  transition: background 200ms ease, box-shadow 200ms ease;
}

.tv-knob {
  position: relative;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--tv-knob);
  box-shadow: 0 0 0 1px var(--tv-plastic-edge), 0 1px 2px rgba(0, 0, 0, 0.5);
  transition: transform 600ms var(--ease-reveal);
}

.tv-knob::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 50%;
  width: 1.5px;
  height: 4px;
  margin-left: -0.75px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 1px;
}

.tv-feet {
  display: flex;
  justify-content: space-between;
  padding: 0 16%;
}

.tv-feet span {
  width: 14%;
  height: 6px;
  background: var(--tv-foot);
  border-radius: 0 0 3px 3px;
}

/* ---------- Tuned in: hover, keyboard focus, or .is-live on touch ---------- */

.tv-set:hover .tv-screen img,
.tv-set:focus-visible .tv-screen img,
.tv-set.is-live .tv-screen img {
  filter: grayscale(0) contrast(1.04) brightness(1);
  transform: scale(1.07);
}

.tv-set:hover .tv-static,
.tv-set:focus-visible .tv-static,
.tv-set.is-live .tv-static {
  opacity: 0;
}

.tv-set:hover .tv-screen::before,
.tv-set:focus-visible .tv-screen::before,
.tv-set.is-live .tv-screen::before {
  animation: tvRoll 700ms ease-out 1;
}

.tv-set:hover .tv-osd-rec,
.tv-set:hover .tv-osd-view,
.tv-set:focus-visible .tv-osd-rec,
.tv-set:focus-visible .tv-osd-view,
.tv-set.is-live .tv-osd-rec {
  opacity: 1;
}

.tv-set:hover .tv-idx,
.tv-set:focus-visible .tv-idx,
.tv-set.is-live .tv-idx {
  color: #ff3344;
}

.tv-set:hover .tv-led,
.tv-set:focus-visible .tv-led,
.tv-set.is-live .tv-led {
  background: #ff3344;
  box-shadow: 0 0 8px rgba(255, 51, 68, 0.8);
}

.tv-set:hover .tv-knob:nth-child(2),
.tv-set:focus-visible .tv-knob:nth-child(2) {
  transform: rotate(120deg); /* channel dial turns */
}

@keyframes tvRoll {
  0%   { transform: translateY(-110%); opacity: 1; }
  100% { transform: translateY(380%); opacity: 0; }
}

.tv-wall-hint {
  margin-top: 1.75rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.tv-hint-touch { display: none; }

@media (hover: none) {
  .tv-hint-pointer { display: none; }
  .tv-hint-touch { display: inline; }
}

/* ==========================================================================
   FULL-FRAME VIEWER (#tvLightbox)
   ========================================================================== */

.tv-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.tv-lightbox[hidden] {
  display: none;
}

.tvl-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 4, 6, 0.94);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: tvlFadeIn 250ms ease both;
}

.tv-lightbox.is-closing .tvl-backdrop {
  animation: tvlFadeOut 260ms ease both;
}

.tvl-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 24px;
  max-width: 100%;
}

.tvl-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: tvlFadeIn 300ms ease 250ms both;
}

.tvl-bar--end {
  justify-content: flex-end;
}

.tv-lightbox.is-closing .tvl-bar {
  animation: tvlFadeOut 150ms ease both;
}

.tvl-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 8px 12px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #f5f5f7;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.tvl-btn:hover,
.tvl-btn:focus-visible {
  background: #ff3344;
  border-color: #ff3344;
  color: #ffffff;
  transform: translateY(-1px);
  outline: none;
}

.tvl-screen {
  position: relative;
  align-self: center;
  overflow: hidden;
  border-radius: 16px;
  background: #000;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 0 10px #0d0d0f,
    0 0 0 11px rgba(255, 255, 255, 0.07),
    0 40px 80px -20px rgba(0, 0, 0, 0.9),
    0 0 140px rgba(255, 255, 255, 0.05);
  touch-action: pan-y;
}

.tvl-screen img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(calc(100vw - 54px), 1100px);
  max-height: calc(100vh - 190px);
  max-height: calc(100dvh - 190px);
}

/* Light scanlines only — the full frame should read clean */
.tvl-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.1) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 70%, rgba(0, 0, 0, 0.4) 100%);
}

.tvl-static {
  position: absolute;
  inset: -50%;
  z-index: 1;
  pointer-events: none;
  background-image: var(--tv-noise);
  background-size: 160px;
  opacity: 0;
}

/* Power-on: dot → horizontal line → full picture */
.tvl-screen.is-powering {
  animation: tvlPowerOn 560ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.tv-lightbox.is-closing .tvl-screen {
  animation: tvlPowerOff 260ms ease-in both;
}

/* Channel change: burst of static + a horizontal hold slip */
.tvl-screen.is-tuning .tvl-static {
  animation: tvlStaticBurst 380ms ease-out both, tvStatic 0.2s steps(3) infinite;
}

.tvl-screen.is-tuning img {
  animation: tvlSlip 380ms steps(5) both;
}

@keyframes tvlPowerOn {
  0%   { transform: scale(0.02, 0.004); filter: brightness(5); }
  35%  { transform: scale(1, 0.004); filter: brightness(4); }
  70%  { transform: scale(1, 1.02); filter: brightness(1.5); }
  100% { transform: scale(1, 1); filter: brightness(1); }
}

@keyframes tvlPowerOff {
  0%   { transform: scale(1, 1); filter: brightness(1); opacity: 1; }
  55%  { transform: scale(1, 0.004); filter: brightness(4); opacity: 1; }
  100% { transform: scale(0, 0.004); filter: brightness(5); opacity: 0; }
}

@keyframes tvlStaticBurst {
  0%   { opacity: 0.9; }
  100% { opacity: 0; }
}

@keyframes tvlSlip {
  0%   { transform: translateX(-3%) skewX(4deg); }
  40%  { transform: translateX(2%) skewX(-3deg); }
  70%  { transform: translateX(-1%); }
  100% { transform: none; }
}

@keyframes tvlFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes tvlFadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ---------- Responsive ---------- */

@media (max-width: 868px) {
  .tv-row {
    flex-wrap: wrap;
  }
  /* flex-basis, not --w: the per-set inline --w would win over this rule */
  .tv-set {
    flex-basis: calc(50% - 5px);
  }
  .tv-body {
    border-radius: 10px;
  }
  .tv-screen,
  .tv-set--portrait .tv-screen {
    border-radius: 12px;
  }
}

@media (max-width: 520px) {
  .tv-controls .tv-knob,
  .tv-osd--bottom {
    display: none;
  }
  .tv-panel {
    padding: 8px 2px 10px;
  }
  .tvl-btn {
    padding: 8px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tv-static,
  .tvw-rec-dot {
    animation: none;
  }
  .tv-set,
  .tv-screen img,
  .tv-knob {
    transition-duration: 1ms;
  }
  .tv-set:hover .tv-screen::before,
  .tv-set:focus-visible .tv-screen::before,
  .tv-set.is-live .tv-screen::before,
  .tvl-screen.is-powering,
  .tv-lightbox.is-closing .tvl-screen,
  .tvl-screen.is-tuning .tvl-static,
  .tvl-screen.is-tuning img {
    animation: none;
  }
}
