/* The Watch page shares Cinema's surfaces while keeping its live layout and controls. */
html:not(.route-pending) body:has(#watch-view:not([hidden])) {
  --bg: #090d14;
  --watch-surface: #101722;
  --watch-line: #293344;
  --text: #f3f5fa;
  --bright: #f3f5fa;
  --muted: #b4c0d0;
  --divider: var(--watch-line);
  background: var(--bg);
}

html:not(.route-pending) body:has(#watch-view:not([hidden])) {
  .shell {
    width: min(100% - 48px, 1640px);
    max-width: none;
    margin: 0 auto;
    padding: 0 0 24px;
    border: 0;
    background: none;
    box-shadow: none;
    font-family: system-ui, sans-serif;
  }

  .workspace { display: block; }
  .workspace > .sidebar { display: none; }

  .topbar.panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas: "brand nav tools";
    align-items: center;
    gap: 4px 16px;
    min-height: 72px;
    padding: 8px 0;
    margin-bottom: 16px;
    border: 0;
    border-bottom: 1px solid var(--watch-line);
    border-image: none;
    background: var(--bg);
    box-shadow: none;
  }

  .topbar.panel::before, .topbar.panel::after,
  .topnav :is([data-route="studio"], [data-route="analytics"]),
  .brand small, .prototype-label { display: none; }

  .topbar .brand { grid-area: brand; justify-self: start; max-width: 100%; min-width: 0; gap: 8px; }
  .brand > div { min-width: 0; }
  .brand .wordmark { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .brand-mark { width: 32px; height: 32px; flex-shrink: 0; }

  .topbar .topnav {
    display: flex;
    grid-area: nav;
    align-items: center;
    gap: 4px;
    width: auto;
    font: 600 14px/1.2 system-ui, sans-serif;
  }

  .topnav a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 12px;
    border: 0;
    border-radius: 99px;
    color: var(--muted);
    white-space: nowrap;
  }

  .topnav a:hover { background: var(--watch-surface); color: var(--text); }
  .topnav a[aria-current="page"] { background: var(--text); color: var(--bg); }
  .topbar .top-tools { grid-area: tools; justify-self: end; margin-left: 0; gap: 6px; }
  .top-tools :is(summary, .account-tools > a) { border-radius: 99px; }
}

#watch-view {
  font-family: system-ui, sans-serif;

  .watch-grid, .watch-stack, .right-rail { gap: 16px; }

  :is(.player, .chat, .identity).panel {
    border: 1px solid var(--watch-line);
    border-image: none;
    border-radius: 16px;
    background: var(--watch-surface);
    box-shadow: none;
  }

  :is(.player, .chat, .identity).panel::before,
  :is(.player, .chat, .identity).panel::after { display: none; }

  .player.panel { padding: 0; background: #070a0e; }
  .watch-session:not([data-keyboard-open="true"]) > .identity { margin-top: 12px; }

  .player:not(:fullscreen):not(.poko-expanded-player) :is(.native-stage, .player-stage) {
    width: 100%;
    border-radius: 15px;
  }

  .player:not(:fullscreen):not(.poko-expanded-player) .native-controls { border-radius: 0 0 15px 15px; }

  .identity.panel { padding: 14px; }
  .identity .channel-profile { min-width: 0; }
  .identity .channel-heading h2 { font: 700 17px/1.3 system-ui, sans-serif; overflow-wrap: anywhere; }
  .identity .channel-badges .tag {
    padding: 4px 8px;
    border: 0;
    border-radius: 99px;
    background: #232e3e;
    color: var(--text);
  }

  .identity .identity-actions .button {
    min-height: 44px;
    border: 1px solid var(--watch-line);
    border-radius: 99px;
    background: transparent;
    box-shadow: none;
    font: 650 13px/1.2 system-ui, sans-serif;
    color: var(--text);
  }

  .identity .identity-actions #follow-channel { background: var(--text); color: var(--bg); }
  .identity .identity-actions #follow-channel[aria-pressed="true"] { background: transparent; color: var(--text); }

  .chat > .section-heading { border-bottom: 1px solid var(--watch-line); }
  .chat > .section-heading h2 { color: var(--text); font: 700 15px/1.3 system-ui, sans-serif; text-shadow: none; }
  .chat > a.button {
    border-color: var(--watch-line);
    border-radius: 99px;
    background: var(--bg);
    color: var(--text);
    box-shadow: none;
  }

  .chat-composer { border: 1px solid var(--watch-line); border-radius: 12px; background: var(--bg); }
  .chat-composer :is(input, button) { border-color: transparent; }
}

body:not(.live) #watch-view {
  .player:not(:fullscreen):not(.poko-expanded-player)
    :is(.native-overlay[data-mode="status"], .offline-overlay):not([hidden]) {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-start;
    gap: 5px;
    padding: clamp(18px, 3.5vw, 44px);
    padding-bottom: max(clamp(18px, 3.5vw, 44px), var(--watch-overlay-bottom, 0px));
    border-radius: inherit;
    background: linear-gradient(0deg, rgb(7 10 14 / 96%), rgb(7 10 14 / 36%) 66%, rgb(7 10 14 / 20%)),
      url("/assets/night-drive.jpg") center / cover;
    text-align: left;
  }

  .native-overlay[data-mode="status"] h1, .offline-overlay h1 {
    margin: 0;
    color: var(--text);
    font: 700 clamp(19px, 3vw, 40px)/1.14 system-ui, sans-serif;
    letter-spacing: -.025em;
  }

  .native-overlay[data-mode="status"] p, .offline-overlay p {
    color: var(--muted);
    font: 400 clamp(12px, 1.5vw, 16px)/1.5 system-ui, sans-serif;
  }

  .native-overlay[data-mode="status"] .overlay-status-code,
  .offline-overlay :is(.signal-icon, .terminal),
  .player-stage:has(.offline-overlay:not([hidden])) > .preview-pill { display: none; }

  .watch-session .player:not(:fullscreen):not(.poko-expanded-player) .native-stage:has(.native-overlay[data-mode="status"]:not([hidden])) {
    min-height: var(--watch-standby-min-height, min(48vw, 220px));
  }
}

@media (max-width: 1200px) {
  html:not(.route-pending) body:has(#watch-view:not([hidden])) {
    .brand .wordmark { font-size: clamp(20px, 3.2vw, 28px); }
    .topbar :is(.appearance-menu, .account-menu) > summary {
      justify-content: center;
      width: 44px;
      padding: 0;
    }
    .topbar :is(.appearance-menu summary span, .account-display-name, .account-menu summary > .tag) {
      display: none;
    }
  }
}

@media (max-width: 700px) {
  html:not(.route-pending) body:has(#watch-view:not([hidden])) {
    .topbar.panel {
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas: "brand tools" "nav nav";
      gap: 4px 8px;
      margin-bottom: 10px;
    }

    .topbar .topnav { width: 100%; flex-wrap: wrap; justify-content: center; }
    .topnav a { padding-inline: clamp(7px, 1.4vw, 14px); }
  }
}

@media (max-width: 960px) {
  html:not(.route-pending) body:has(#watch-view:not([hidden])) .shell { width: calc(100% - 24px); }

  #watch-view {
    --watch-overlay-bottom: 60px;

    .watch-session > .identity { flex-shrink: 0; }
    .watch-session > .chat { margin-top: 12px; }
    .watch-session[data-keyboard-open="true"] > .identity { display: none; }
    .watch-session[data-keyboard-open="true"] > .chat { margin-top: 0; }
    .watch-session:not([data-keyboard-open="true"]) {
      min-height: max(580px, calc(100svh - var(--watch-top-height, 144px)));
      height: auto;
    }

    .watch-session:not([data-keyboard-open="true"]) > .chat { flex-basis: 250px; min-height: 250px; }
    .watch-session:not([data-keyboard-open="true"]) .chat-body { height: 0; }
  }
}

@media (max-width: 700px) {
  #watch-view .identity .identity-actions .channel-schedule { display: inline-flex; }
}

@media (max-width: 480px) {
  html:not(.route-pending) body:has(#watch-view:not([hidden])) {
    .topnav a { font-size: 13px; padding-inline: 7px; }
    .topbar .brand { gap: 4px; }
    .brand .wordmark { font-size: clamp(15px, 4.7vw, 20px); }
    .brand-mark { width: 24px; height: 24px; }
  }

  #watch-view {
    .identity.panel { padding: 10px; gap: 8px; }
    .identity :is(.channel-profile, .identity-actions) { grid-column: 1 / -1; }
    .identity .identity-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .identity .identity-actions .button { width: 100%; white-space: normal; padding-inline: 8px; }
    .identity .identity-actions .channel-schedule .icon { display: none; }
  }
}

@media (max-width: 960px) and (max-height: 540px) and (orientation: landscape) {
  #watch-view .watch-session:not([data-keyboard-open="true"])
    .player:not(:fullscreen):not(.poko-expanded-player):not(.using-compatibility-player) .native-stage {
    height: max(170px, calc(100svh - 132px));
    --watch-standby-min-height: 0px;
  }

  #watch-view .watch-session:not([data-keyboard-open="true"])
    .player:not(:fullscreen):not(.poko-expanded-player):not(.using-compatibility-player) .native-stage video {
    height: 100%;
  }
}
