/* ═══════════════════════════════════════════════════════════════════════
   tv.css — The "Virtual Anchor Desk" TV Experience
   Wraps the existing HLS player (player.js) inside the real Soulaan TV
   frame + remote photography from /opt/assets/tvScreen (Otis's originals).
   See BLACKOPRECONN/BROADCAST_CONTROL_SPEC.md for the graphic-layer model
   this implements (Bug / Lower Third / Ticker / Interstitial / Alert).
   ═══════════════════════════════════════════════════════════════════════ */

.tv-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background: radial-gradient(ellipse at 50% 30%, #17130a 0%, #050505 70%);
  padding: 28px 20px;
  flex-wrap: wrap;
}

/* ═══ TV Unit ═══ */
.tv-unit {
  position: relative;
  width: min(920px, 62vw);
  aspect-ratio: 1536 / 1024;
  filter: drop-shadow(0 30px 60px rgba(0, 0, 0, 0.65));
}

.tv-frame-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

/* Screen cutout — measured directly from TVSCREEN.jpg via connected-component
   analysis (screen bbox 93,75 → 1225,852 out of a 1536x1024 source). This is
   the *exact* punched-out transparent hole baked into tv_frame.png, so the
   video sits flush behind the real photographed bezel with no seams. */
.tv-screen {
  position: absolute;
  left: 6.05%;
  top: 7.32%;
  width: 73.70%;
  height: 75.88%;
  overflow: hidden;
  background: #000;
  z-index: 1;
}


.tv-screen #player {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

/* ═══ Movies (YouTube) channel, relocated into the TV screen cutout by
   tv.js. Overrides youtube_channel.js's default full-page-overlay styling
   (position:fixed; inset:0) so the movie plays framed inside the real TV
   bezel instead of covering the whole page. ═══ */
.tv-screen .yt-channel-panel {
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: 0;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tv-screen .yt-channel-panel.hidden {
  display: none;
}

/* Selection UI (disclaimer/now-playing text/close button) is redundant once
   framed in the TV — the remote's LIVE button is how you "change the
   channel" back, exactly like a real TV, and the sole enabled title
   auto-plays on open (see youtube_channel.js autoplayFirstIfNeeded). If more
   titles get enabled later, re-surface .yt-video-list as a bottom chip strip
   here rather than removing this rule. */
.tv-screen .yt-channel-disclaimer,
.tv-screen .yt-now-playing,
.tv-screen .yt-video-list,
.tv-screen .yt-channel-close {
  display: none;
}


.tv-screen .yt-player-mount {
  width: 100%;
  height: 100%;
  max-width: none;
  aspect-ratio: auto;
  margin: 0;
}

.tv-screen .yt-player-mount iframe {
  width: 100%;
  height: 100%;
  display: block;
}

/* ═══ External curated YouTube CHANNEL panel (news/podcast/sports/music/
   paid sponsors) — external_channels.js. Same treatment as the Movies
   panel above: relocated into the TV screen cutout, disclaimer hidden
   (redundant with the remote), iframe fills the cutout. ═══ */
.tv-screen .ext-channel-panel {
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: 0;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tv-screen .ext-channel-panel.hidden {
  display: none;
}

.tv-screen .ext-channel-disclaimer {
  display: none;
}

.tv-screen .ext-player-mount {
  width: 100%;
  height: 100%;
}

.tv-screen .ext-player-mount iframe {
  width: 100%;
  height: 100%;
  display: block;
}

/* Fallback styling for the panel when NOT inside the TV cutout (shouldn't
   normally be visible — tv.js always relocates it — but keep sane defaults
   in case JS hasn't run yet / for non-TV pages that reuse this module). */
.ext-channel-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
}
.ext-channel-panel.hidden { display: none; }
.ext-channel-disclaimer {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 8px 14px;
  background: rgba(5, 4, 2, 0.85);
  color: #f5f1e8;
  font-size: 12px;
  z-index: 1;
}
.ext-player-mount {
  width: 100%;
  height: 100%;
}
.ext-player-mount iframe {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
}

/* TikTok prev/next navigation (inside .tv-screen) */
.tv-screen .ext-tiktok-controls {
  position: absolute;
  bottom: 10%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 3;
  background: rgba(5, 4, 2, 0.82);
  border: 1px solid rgba(212, 160, 23, 0.4);
  border-radius: 6px;
  padding: 5px 12px;
}
.tv-screen .ext-tiktok-controls.hidden { display: none; }
.ext-tiktok-btn {
  background: transparent;
  border: none;
  color: #f4c752;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  padding: 3px 6px;
}
.ext-tiktok-btn:hover { color: #fff; }
.ext-tiktok-label {
  color: #a9a49a;
  font-size: 11px;
  min-width: 40px;
  text-align: center;
}

/* Link-out card (when no TikTok video IDs available) */
.ext-linkout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 14px;
  padding: 20px;
  text-align: center;
}
.ext-linkout-name {
  color: #f4c752;
  font-size: clamp(14px, 2vw, 20px);
  font-weight: 700;
  margin: 0;
}
.ext-linkout-sub {
  color: #a9a49a;
  font-size: clamp(10px, 1.3vw, 13px);
  margin: 0;
}
.ext-linkout-btn {
  display: inline-block;
  background: linear-gradient(135deg, #d4a017, #f4c752);
  color: #050402;
  font-weight: 800;
  font-size: clamp(10px, 1.4vw, 14px);
  letter-spacing: 0.5px;
  padding: 10px 22px;
  border-radius: 6px;
  text-decoration: none;
}
.ext-linkout-btn:hover { filter: brightness(1.1); }
.ext-linkout-hint {
  color: rgba(169, 164, 154, 0.6);
  font-size: 10px;
  margin: 0;
  letter-spacing: 0.5px;
}



/* CRT phosphor glow, drawn above video, below the frame image */
.tv-crt-glow {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.55), inset 0 0 18px rgba(255, 210, 120, 0.08);
}

/* ═══ TV Static (power-on / channel-change / buffer) ═══ */
/* GIF layer — authentic tvstatic.gif for channel-change bursts */
.tv-static-gif {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  opacity: 0;
  background: url('../tv/tvstatic.gif') center/cover repeat;
  mix-blend-mode: overlay;
  transition: opacity 0.1s ease;
  pointer-events: none;
}
.tv-static-gif.active { opacity: 0.88; }

/* Canvas layer — kept for power-on variety (canvas noise) */
.tv-static {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 4;
  opacity: 0;
  image-rendering: pixelated;
  mix-blend-mode: overlay;
  transition: opacity 0.12s ease;
  pointer-events: none;
}

.tv-static.active { opacity: 0.9; }

/* ═══ Power-off state ═══ */
.tv-off-screen {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: #000;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.tv-unit.tv-off .tv-off-screen { display: flex; }
.tv-unit.tv-off .tv-screen #player,
.tv-unit.tv-off .ov-layer { opacity: 0 !important; }

.tv-off-msg {
  color: #3a3630;
  font-size: 13px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 600;
}

/* ═══ Broadcast Graphics Layers ═══ */
.ov-layer {
  position: absolute;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.35s ease, transform 0.45s ease;
}

/* L1: Bug (station DOG), always on while powered */
.ov-bug {
  top: 4%;
  right: 4%;
  width: 13%;
  opacity: 0;
}
.ov-bug img { width: 100%; height: auto; display: block; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.6)); }
.tv-unit:not(.tv-off) .ov-bug { opacity: 0.92; }

/* L2: Lower Third */
.ov-lower-third {
  left: 3%;
  bottom: 12%;
  max-width: 74%;
  padding: 7px 14px;
  background: linear-gradient(90deg, rgba(10, 9, 6, 0.92), rgba(10, 9, 6, 0.55));
  border-left: 3px solid #d4a017;
  color: #f5f1e8;
  font-size: clamp(10px, 1.4vw, 15px);
  font-weight: 600;
  opacity: 0;
  transform: translateX(-16px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ov-lower-third.active { opacity: 1; transform: translateX(0); }

/* L3: Ticker */
.ov-ticker {
  left: 0;
  right: 0;
  bottom: 0;
  height: 7.5%;
  background: rgba(5, 4, 2, 0.88);
  border-top: 2px solid #d4a017;
  overflow: hidden;
  display: flex;
  align-items: center;
}
.ov-ticker .crawl-text {
  white-space: nowrap;
  color: #f5f1e8;
  font-size: clamp(9px, 1.2vw, 13px);
  padding-left: 100%;
  animation: tv-crawl 22s linear infinite;
}
@keyframes tv-crawl {
  from { transform: translateX(0); }
  to   { transform: translateX(-100%); }
}

/* L4: Full-screen interstitial card */
.ov-interstitial {
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  opacity: 0;
}
.ov-interstitial.active { opacity: 1; }
.ov-interstitial img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* L6: Breaking news alert */
.ov-alert {
  top: 0; left: 0; right: 0;
  height: 11%;
  background: linear-gradient(90deg, #6e0000, #d4141c, #6e0000);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  letter-spacing: 1px;
  font-size: clamp(9px, 1.5vw, 15px);
  text-transform: uppercase;
  opacity: 0;
}
.ov-alert.active {
  opacity: 1;
  animation: tv-alert-pulse 0.9s ease-in-out infinite alternate;
}
@keyframes tv-alert-pulse { from { filter: brightness(1); } to { filter: brightness(1.25); } }

/* Channel label toast (top-left, brief) */
.ov-channel-toast {
  top: 4%;
  left: 4%;
  padding: 5px 12px;
  background: rgba(5, 4, 2, 0.85);
  border: 1px solid #d4a017;
  color: #f4c752;
  font-size: clamp(9px, 1.3vw, 13px);
  font-weight: 700;
  letter-spacing: 1px;
  border-radius: 4px;
  opacity: 0;
}
.ov-channel-toast.active { opacity: 1; }

/* ═══ Remote Control ═══ */
.tv-remote {
  position: relative;
  width: min(190px, 13vw);
  min-width: 130px;
  aspect-ratio: 380 / 794;
  flex-shrink: 0;
}

.remote-base {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.6));
  border-radius: 10px;
}

.remote-hot {
  position: absolute;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.remote-hot:focus-visible {
  outline: 2px solid #f4c752;
  outline-offset: 2px;
  border-radius: 6px;
}

.remote-hot-power   { left: 10.13%; top: 22.78%; width: 80.30%; height: 11.12%; }
.remote-hot-chup    { left: 10.13%; top: 32.83%; width: 80.30%; height: 11.12%; }
.remote-hot-chdown  { left: 10.13%; top: 41.43%; width: 78.80%; height: 11.12%; }
.remote-hot-volup   { left: 10.13%; top: 50.76%; width: 81.80%; height: 10.40%; }
.remote-hot-voldown { left: 10.13%; top: 60.81%; width: 80.30%; height: 9.69%;  }
.remote-hot-menu    { left: 10.13%; top: 69.42%; width: 80.30%; height: 9.69%;  }
.remote-hot-youtube { left: 10.13%; top: 78.74%; width: 41.27%; height: 16.86%; }
.remote-hot-web     { left: 49.15%; top: 78.74%; width: 39.77%; height: 17.58%; }

/* ═══ TV Guide / Schedule overlay (MENU button) ═══ */
.tv-guide-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(6, 6, 7, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.tv-guide-overlay.hidden { display: none; }

.tv-guide-panel {
  width: 100%;
  max-width: 520px;
  background: #16161a;
  border: 1px solid rgba(244, 199, 82, 0.3);
  border-radius: 10px;
  padding: 20px 22px;
}

.tv-guide-panel h3 {
  margin: 0 0 4px;
  color: #f4c752;
  font-size: 16px;
  letter-spacing: 0.5px;
}

.tv-guide-panel .tv-guide-sub {
  color: #a9a49a;
  font-size: 12px;
  margin-bottom: 14px;
}

.tv-guide-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 45vh;
  overflow-y: auto;
  margin-bottom: 16px;
}

.tv-guide-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: #1c1c20;
  border: 1px solid rgba(244, 199, 82, 0.12);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  color: #f5f1e8;
}
.tv-guide-item .cat {
  color: #2a8c4a;
  font-size: 11px;
  white-space: nowrap;
}

.tv-guide-close {
  width: 100%;
  background: transparent;
  color: #a9a49a;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 9px;
  font-size: 13px;
  cursor: pointer;
}
.tv-guide-close:hover { color: #f5f1e8; border-color: #d4941e; }

/* ═══ Responsive ═══ */
@media (max-width: 860px) {
  .tv-stage { flex-direction: column; padding: 16px 10px; gap: 16px; }
  .tv-unit { width: 96vw; }
  .tv-remote {
    width: min(340px, 70vw);
    aspect-ratio: unset;
    height: auto;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
  }
  .remote-base { display: none; }
  .remote-hot {
    position: static;
    width: auto !important;
    height: auto !important;
    background: #1c1c20;
    border: 1px solid rgba(244, 199, 82, 0.25);
    color: #f4c752;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 700;
  }
  .remote-hot::after { content: attr(aria-label); }
}
