/* Premium shell (0.49.0). Loaded last so it can reshape the header without
   rewriting older component rules. See docs/premium-shell.md. */

/* Compact page toolbars at every width: heading, tabs and search share one band. */
.source-page-heading { margin-bottom: var(--space-3); }
.source-page-heading h1 { margin-bottom: 0; }
.ui-search-label + .source-search,
.ui-search-label + .source-search-form,
.source-search-panel > .source-search { margin-top: 0; }
.source-search, .source-search-form { max-width: 560px; }
.search-submit { min-width: var(--control-min) !important; width: var(--control-min); padding: 0 !important; }
.search-submit .ui-icon { width: 22px; height: 22px; }
.source-search-status { margin-top: var(--space-2); }

/* Side rail on wide landscape screens such as the Tesla display. Height is the scarce
   axis there, and the browser already spends some on its own toolbar. */
@media (min-width: 1100px) and (min-aspect-ratio: 4/3) {
  :root { --rail-width: 96px; }
  #app { padding-left: var(--rail-width); }
  .app-header {
    --header-rail: 1;
    position: fixed; inset: 0 auto 0 0; width: var(--rail-width); min-height: 0; height: 100dvh;
    flex-direction: column; align-items: center; gap: var(--space-2);
    padding: var(--space-5) 0 max(var(--space-4), env(safe-area-inset-bottom)) env(safe-area-inset-left);
    border-bottom: 0; border-right: 1px solid rgba(255,255,255,.065);
    background: rgba(8,9,11,.97); overflow-y: auto; scrollbar-width: none;
  }
  .brand-button { margin-bottom: var(--space-4); min-height: 0; }
  .brand-wordmark { display: none; }
  .brand-mark { width: 44px; height: 44px; border-radius: 12px; }
  .brand-mark svg { width: 30px; height: 30px; }
  .main-nav { flex-direction: column; flex-wrap: nowrap; gap: var(--space-1); }
  .main-nav .nav-button {
    flex-direction: column; gap: 5px; width: 80px; min-height: 64px; padding: var(--space-2) var(--space-1);
    border-radius: 14px; font-size: .6875rem; line-height: 1.15; white-space: normal; text-align: center; box-shadow: none;
  }
  .main-nav .nav-button svg { display: block; width: 24px; height: 24px; }
  .main-nav .nav-button.active { background: rgba(255,255,255,.1); color: var(--color-text); box-shadow: none; }
  .header-actions { flex-direction: column; gap: var(--space-2); margin: auto 0 0; }
  .account-actions { flex-direction: column; gap: var(--space-2); }
  .header-icon-button, .header-settings { width: 56px; min-width: 56px; height: 56px; border-radius: 14px; }
  .account-menu { top: auto; right: auto; bottom: 0; left: calc(100% + 12px); }
  .transcode-pill { padding: 8px; }
  .transcode-pill span { display: none; }
  .transcode-popover { top: auto; right: auto; bottom: var(--space-4); left: calc(var(--rail-width) + 12px); }
  html { scroll-padding-top: var(--space-4); }
  #media-browser { width: min(100%, calc(var(--content-max) + 2 * var(--page-gutter))); }
  .app-view { padding-top: var(--space-5); }
}

@media (min-width: 1100px) and (min-aspect-ratio: 4/3) and (hover: hover) {
  .main-nav .nav-button:hover { background: rgba(255,255,255,.06); }
}

/* Title page: facts line with badges, and a Resume button that names what plays. */
.detail-facts { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-3); }
.detail-facts #detail-meta { margin: 0; }
.detail-badges { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.detail-badge { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; color: var(--color-text); font-size: .75rem; font-weight: var(--weight-semibold); letter-spacing: .03em; }
.detail-copy h1 { font-size: clamp(2rem,4vw,3.5rem); font-weight: var(--weight-bold); letter-spacing: -.045em; line-height: 1.02; }
#detail-play { min-width: 160px; }
#detail-mark-played, #detail-favorite { color: var(--color-text-muted); }
.episode-row > img, .episode-row > .episode-thumb { grid-column: 1; grid-row: 1; }
.episode-row > div { grid-column: 2; grid-row: 1; }
.episode-row > .episode-duration { grid-column: 3; grid-row: 1; }
.episode-row > .episode-progress { display: block; grid-column: 1; grid-row: 1; align-self: end; height: 4px; margin: 0 8px 8px; overflow: hidden; border-radius: var(--radius-pill); background: rgba(255,255,255,.3); }
.episode-progress > i { display: block; height: 100%; border-radius: inherit; background: var(--color-brand); }

/* Player chrome: icons in glass circles, words kept for assistive technology. */
.player-glyph { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.player-glyph-fill { fill: currentColor; stroke: none; }
#player-view .player-icon-action { display: inline-grid; place-items: center; width: 52px; min-width: 52px; height: 52px; min-height: 52px; padding: 0; border: 1px solid rgba(255,255,255,.16); border-radius: 50%; background: rgba(22,23,28,.62); color: var(--color-text); }
#player-view .player-icon-action[aria-pressed="true"] { background: rgba(255,255,255,.9); color: var(--color-background); }
#player-view .center-controls .play-button { width: 104px; height: 104px; background: rgba(255,255,255,.94); color: var(--color-background); border: 0; }
#player-view .center-controls .play-button .player-glyph { width: 40px; height: 40px; }
#player-view .center-controls button:not(.play-button) { font-variant-numeric: tabular-nums; }
#player-view .transport .player-icon-action { flex: 0 0 auto; height: 48px; min-height: 48px; width: 48px; min-width: 48px; border-radius: 12px; background: rgba(255,255,255,.1); }
#player-view .media-time { font-variant-numeric: tabular-nums; }
@media (max-width: 700px) {
  #player-view .player-icon-action { width: 48px; min-width: 48px; height: 48px; min-height: 48px; }
  #player-view .center-controls .play-button { width: 72px; height: 72px; }
  #player-view .center-controls .play-button .player-glyph { width: 30px; height: 30px; }
}

/* Live TV: time left and a progress bar for the programme airing now. */
.live-channel-progress { display: block; height: 3px; margin-top: 6px; overflow: hidden; border-radius: var(--radius-pill); background: rgba(255,255,255,.16); }
.live-channel-progress[hidden] { display: none; }
.live-channel-progress > i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--color-brand); }
.live-channel-copy strong { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.live-guide-channel-copy strong { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.2; }
#player-view #on-demand-toggle, #player-view #live-context-toggle { bottom: 168px; }
@media (max-width: 700px) { #player-view #on-demand-toggle, #player-view #live-context-toggle { bottom: 132px; } }

/* Seek preview names the chapter. */
.seek-preview { max-width: 280px; white-space: normal; text-align: center; font-variant-numeric: tabular-nums; }

/* Hidden-video screen says what is playing. */
.privacy-now-playing { display: block; max-width: 40ch; margin: 6px auto 4px; color: var(--color-text); font-size: var(--text-base); font-weight: var(--weight-semibold); }
.privacy-now-playing:empty { display: none; }

/* Ambient screen when parked and idle on Home. */
.ambient-screen { position: fixed; inset: 0; z-index: var(--layer-dialog); display: flex; align-items: flex-end; padding: clamp(32px,6vw,80px); border: 0; border-radius: 0; background: #000 center/cover no-repeat; color: #fff; text-align: left; cursor: pointer; animation: ambient-drift 60s ease-in-out infinite alternate; }
.ambient-screen[hidden] { display: none; }
.ambient-screen::before { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(0,0,0,.82), rgba(0,0,0,.15) 55%, rgba(0,0,0,.35)); }
.ambient-copy { position: relative; display: grid; gap: var(--space-2); }
.ambient-clock { font-size: clamp(3.5rem,9vw,7.5rem); font-weight: var(--weight-semibold); letter-spacing: -.05em; line-height: 1; font-variant-numeric: tabular-nums; }
.ambient-caption { color: rgba(255,255,255,.78); font-size: clamp(1rem,1.6vw,1.375rem); }
@keyframes ambient-drift { from { background-size: 105%; background-position: 40% 50%; } to { background-size: 115%; background-position: 60% 45%; } }
@media (prefers-reduced-motion: reduce) { .ambient-screen { animation: none; } }

/* Live TV preview stage (0.50.0, docs/live-preview-stage.md). The live player docks in a
   band above the channel list and expands to full screen; the same element is used for
   both sizes, so the stream never restarts. */
:root {
  --live-stage-w: min(calc(100vw - 32px), calc(40vh * 16 / 9));
  --live-stage-h: calc(var(--live-stage-w) * 9 / 16);
  --live-stage-left: 16px;
  --live-stage-top: var(--measured-header-height, 0px);
  --live-stage-band: calc(var(--live-stage-h) + 132px);
  --live-stage-ease: cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 720px) and (orientation: landscape) {
  /* Any landscape screen (the Tesla browser included, rail or not): details beside the picture. */
  :root {
    --live-stage-h: min(38vh, 340px);
    --live-stage-w: calc(var(--live-stage-h) * 16 / 9);
    --live-stage-left: var(--page-gutter, 24px);
    --live-stage-band: calc(var(--live-stage-h) + 40px);
  }
}
@media (min-width: 1100px) and (min-aspect-ratio: 4/3) {
  :root { --live-stage-left: calc(var(--rail-width) + 32px); --live-stage-top: 0px; }
}
html.live-stage-open { scroll-padding-top: calc(var(--live-stage-top) + var(--live-stage-band) + 12px); }
html.live-stage-full, html.live-stage-full body { overflow: hidden; }
html.live-stage-open #view-live { padding-top: var(--live-stage-band); }
html.live-stage-open #view-live > .live-heading { display: none; }

.live-stage {
  position: fixed; top: var(--live-stage-top); left: 0; right: 0; z-index: 30; height: var(--live-stage-band);
  display: grid; grid-template-columns: minmax(0,1fr) auto; align-content: end; gap: var(--space-2) var(--space-4);
  padding: 0 16px 14px; background: var(--color-background); border-bottom: 1px solid rgba(255,255,255,.07);
}
.live-stage[hidden] { display: none; }
.live-stage-copy { min-width: 0; display: grid; gap: 2px; }
.live-stage-channel { display: flex; align-items: center; gap: var(--space-2); margin: 0; color: var(--color-text-muted); font-size: .8125rem; font-weight: var(--weight-semibold); }
.live-stage-channel .live-channel-logo { width: 28px; height: 28px; border-radius: 7px; font-size: .625rem; }
.live-stage h2 { margin: 0; font-size: 1.0625rem; line-height: 1.2; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-stage-time, .live-stage-next { margin: 0; color: var(--color-text-muted); font-size: .8125rem; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-stage-next, .live-stage-progress { display: none; }
.live-stage-actions { display: flex; align-items: center; gap: var(--space-2); }
.live-stage-icon { display: inline-grid; place-items: center; width: var(--control-min, 48px); min-width: var(--control-min, 48px); height: var(--control-min, 48px); padding: 0; border-radius: 14px; }
.live-stage-icon[aria-pressed="true"] { background: rgba(255,255,255,.12); }
#live-stage-favorite[aria-pressed="true"] svg { fill: currentColor; }
.live-stage-icon svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
@media (min-width: 720px) and (orientation: landscape) {
  .live-stage {
    grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(0,1fr) auto; align-content: stretch;
    padding: 20px 32px 20px calc(var(--live-stage-left) + var(--live-stage-w) + 28px);
  }
  .live-stage-copy { align-content: start; gap: 4px; }
  .live-stage-channel { font-size: .875rem; }
  .live-stage-channel .live-channel-logo { width: 36px; height: 36px; border-radius: 8px; }
  .live-stage h2 { margin-top: var(--space-2); font-size: clamp(1.5rem, 2.2vw, 2rem); white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; letter-spacing: -.035em; }
  .live-stage-time, .live-stage-next { font-size: .875rem; }
  .live-stage-next { display: block; margin-top: var(--space-2); }
  .live-stage-progress { display: block; max-width: 360px; height: 4px; }
  .live-stage-progress[hidden] { display: none; }
  .live-stage-actions { min-width: 0; }
  .live-stage-icon { flex: 0 0 auto; width: 52px; min-width: 52px; height: 52px; }
  .live-stage-stop { margin-left: auto; }
  .live-stage h2 { line-height: 1.12; padding-bottom: .06em; }
  .live-stage-copy > .live-stage-time { margin-top: 2px; }
}

.live-guide-row.is-playing .live-guide-channel, .live-local-programme.is-playing { box-shadow: inset 0 0 0 2px rgba(255,255,255,.55); }
/* The Guide keeps its own scroll area; under the stage it is capped to what is left on screen. */
html.live-stage-open .live-guide-scroll { max-height: max(260px, calc(var(--viewport-height, 100dvh) - var(--live-stage-top) - var(--live-stage-band) - 150px)); min-height: 240px; }
.live-channel.is-playing { border-color: rgba(255,255,255,.55); background: var(--color-surface-raised, #1d2028); }
.live-channel.is-playing strong::after { content: "Playing"; display: inline-block; margin-left: var(--space-2); padding: 1px 6px; border-radius: 5px; background: var(--color-brand); color: #fff; font-size: .625rem; font-weight: var(--weight-bold); letter-spacing: .06em; text-transform: uppercase; vertical-align: 2px; }

#player-view.live-stage-player {
  inset: auto; top: 0; left: 0; width: 100vw; height: var(--viewport-height, 100dvh); max-height: none;
}
#player-view.live-stage-player.live-stage-animating {
  transition: top .38s var(--live-stage-ease), left .38s var(--live-stage-ease), width .38s var(--live-stage-ease), height .38s var(--live-stage-ease), border-radius .38s;
}
#player-view.live-stage-player #media-stage { touch-action: none; }
#player-view.live-stage-docked {
  top: calc(var(--live-stage-top) + 14px); left: var(--live-stage-left); width: var(--live-stage-w); height: var(--live-stage-h); min-height: 0;
  z-index: 31; padding: 0; overflow: hidden; border-radius: 16px; grid-template-rows: minmax(0,1fr); box-shadow: 0 0 0 1px rgba(255,255,255,.1), 0 18px 40px rgba(0,0,0,.45);
}
@media (min-width: 720px) and (orientation: landscape) { #player-view.live-stage-docked { top: calc(var(--live-stage-top) + 20px); } }
#player-view.live-stage-docked > :not(#media-stage):not(#privacy-screen):not(#live-stage-toggle),
#player-view.live-stage-docked #media-stage > :not(canvas):not(video):not(.subtitle-overlay):not(.player-state-pill),
#player-view.live-stage-docked .privacy-screen-copy { display: none !important; }
#player-view.live-stage-docked .subtitle-overlay { bottom: 12px; font-size: .9rem; }
#player-view.live-stage-docked .player-state-pill { top: auto; bottom: 12px; left: 12px; right: auto; transform: none; max-width: calc(100% - 72px); font-size: .75rem; }
#player-view.live-stage-docked #media-stage::before {
  content: "LIVE"; position: absolute; top: 12px; left: 12px; z-index: 2; padding: 3px 7px; border-radius: 6px;
  background: var(--color-brand); color: #fff; font-size: .6875rem; font-weight: var(--weight-bold); letter-spacing: .08em; pointer-events: none;
}
/* Enlarge / shrink: the only way to change size (tapping the picture does nothing). It
   stays in the bottom-right corner in both sizes and does not fade with the controls. */
.live-stage-toggle { display: none; }
#player-view.live-stage-player .live-stage-toggle {
  position: absolute; right: max(24px, env(safe-area-inset-right)); bottom: calc(44px + env(safe-area-inset-bottom)); z-index: 1001;
  display: grid; place-items: center; width: 52px; height: 52px; min-width: 52px; padding: 0; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.22); background: rgba(10,11,14,.66); color: var(--color-text);
}
/* One size control in the Live TV stage: the corner button, not the browser full-screen one. */
#player-view.live-stage-player #player-fullscreen { display: none; }
#player-view.live-stage-docked .live-stage-toggle { right: 12px; bottom: 12px; width: 44px; height: 44px; min-width: 44px; }
#player-view.live-stage-player:has(#player-options-panel:not([hidden])) .live-stage-toggle { display: none; }
@media (prefers-reduced-motion: reduce) { #player-view.live-stage-player.live-stage-animating { transition: none; } }
