/* ============ ShoShows stage player ============ */
/* Everything the stage draws: the picture, its controls, the captions, the
   buffering ring, the subtitle picker, the unavailable/finale/paywall
   overlays, and the theater, fullscreen and phone rules that reshape it.

   One file because there is one player. v2/js/player.js renders the same
   stage in the portal and in the classic shell at /v1, and both pages load
   this sheet — a rule that lived in either shell's own stylesheet would be
   a rule the other shell's viewers did not get. Every selector here starts
   at the stage or at the body classes the player itself sets (`theater`,
   `watching`); page layout around the stage stays with the page. */

/* ---------- watch page ---------- */
.watch {
  max-width: var(--max-w); margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 26px; padding: 12px 22px 40px; align-items: start;
}
.stage {
  /* Named container so the controls can respond to the stage's own width
     rather than the viewport's: the stage is 9/16 of its height, so a short
     window makes it narrow while the page stays wide. */
  container: stage / inline-size;
  position: relative; border-radius: 18px; overflow: hidden; background: #000;
  aspect-ratio: 9 / 16; max-height: min(78vh, 820px); margin: 0 auto; width: auto;
  height: min(78vh, 820px);
  border: 1px solid rgba(255, 255, 255, .06);
}
.stage:fullscreen { border-radius: 0; max-height: none; height: 100%; aspect-ratio: auto; width: 100%; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
/* The player draws its own controls and never sets `controls`. But a page
   with scripting disabled gets the browser's controls forced onto every
   <video> — which is how the session-replay dashboard (a script-less sandboxed
   iframe) shows this page, so its replays drew Chrome's controls and grey
   veil over ours. A no-op on the live page. */
.stage video::-webkit-media-controls { display: none !important; }
.stage .scene-bg { position: absolute; inset: 0; }
.stage .flare {
  position: absolute; width: 46vmin; height: 46vmin; border-radius: 50%;
  filter: blur(70px); opacity: .4; animation: stage-drift 9s ease-in-out infinite alternate;
}
@keyframes stage-drift { from { transform: translate(-6%, -4%) scale(1); } to { transform: translate(8%, 6%) scale(1.15); } }
@media (prefers-reduced-motion: reduce) { .stage .flare { animation: none; } }
.stage .captions {
  /* Sits clear of the control row, whose height the player measures — a fixed
     offset drifted under the controls as the row grew. */
  position: absolute; bottom: calc(var(--controls-h, 98px) + 10px);
  inset-inline: 0; z-index: 3; display: flex; justify-content: center;
  padding: 0 18px; pointer-events: none; transition: bottom .2s;
}
.cap-line {
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px); border-radius: 12px;
  padding: 9px 14px; max-width: 92%; text-align: center;
  opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .25s;
}
.cap-line.show { opacity: 1; transform: none; }
.cap-speaker { display: block; font-size: 11px; font-weight: 800; color: var(--accent-2); letter-spacing: .05em; text-transform: uppercase; }
/* Subtitle line breaks are the translator's, not the layout's: a cue that
   was split across two lines should stay split. */
.cap-text { font-size: 14.5px; line-height: 1.35; white-space: pre-line; }
.stage-tap { position: absolute; inset: 0; z-index: 2; }
.pause-badge {
  position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center;
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
.pause-badge.show { opacity: 1; }
.pause-badge svg { width: 74px; height: 74px; fill: #fff; filter: drop-shadow(0 6px 22px rgba(0,0,0,.6)); }
/* Buffering.

   A stall used to be indistinguishable from a crash: the picture stopped, the
   progress bar stopped with it — it is drawn from currentTime — and nothing
   said the app was still trying. On the link this player was rebuilt for, a
   stall is the normal weather, not a fault, and the difference between "slow"
   and "broken" is whether anything on the screen is moving. */
.buffer-spin {
  position: absolute; inset: 0; z-index: 4; display: none;
  align-items: center; justify-content: center; pointer-events: none;
}
.stage.buffering .buffer-spin { display: flex; }
/* A stall the viewer paused during is still a stall, and the element keeps
   loading through it — but two symbols stacked in the middle of the picture
   read as neither. The pause badge is the one that answers "why is nothing
   moving?", so it wins. */
.pause-badge.show ~ .buffer-spin { display: none; }
.buffer-spin i {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.24);
  border-top-color: #fff;
  animation: buffer-spin 900ms linear infinite;
  filter: drop-shadow(0 4px 18px rgba(0,0,0,.55));
}
@keyframes buffer-spin { to { transform: rotate(360deg); } }
/* A spinner that cannot spin is a dot in the middle of the picture, so give
   the reduced-motion setting a pulse instead of nothing. */
@media (prefers-reduced-motion: reduce) {
  .buffer-spin i { animation: buffer-pulse 1.4s ease-in-out infinite; }
  @keyframes buffer-pulse { 50% { opacity: .3; } }
}
/* A spinner says "trying"; it cannot say for how long, or why. Once a stall
   has outlasted a few seconds, or the device has gone offline, the player
   puts a word under the ring (the stage's data-note picks which one) so a
   viewer on a dead link is told the episode will carry on from this second
   rather than left to guess whether to reload. It only ever shows under the
   spinner, and the pause badge silences both, for the same reason as above.
   The stage clips its overflow and the note wraps inside its own padding, so
   a long translation grows downwards and never pushes the page sideways. */
.net-note { position: absolute; inset-inline: 0; top: calc(50% + 34px); z-index: 4; display: none;
  padding: 0 16px; text-align: center; font-size: 13px; line-height: 1.35; color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,.75); pointer-events: none; }
.stage.buffering[data-note] .net-note { display: block; }
.stage.buffering[data-note] .pause-badge.show ~ .net-note { display: none; } /* as specific as the rule above, and later */
.stage-controls {
  position: absolute; bottom: 0; inset-inline: 0; z-index: 5;
  padding: 26px 10px 12px;
  background: linear-gradient(to top, rgba(0, 0, 0, .78), transparent);
  display: flex; flex-direction: column; gap: 8px;
  opacity: 1; transition: opacity .25s, visibility 0s linear;
}
/* `visibility` is what takes the faded chrome out of hit-testing, and it waits
   for the fade to finish. It used to be `pointer-events`, which applied the
   instant the class landed: for the whole quarter second the back arrow was
   still on screen, still legible, and already dead — the tap fell through to
   the picture and paused it. Anything visible is tappable now. */
.stage.chrome-hidden .stage-controls, .stage.chrome-hidden .stage-top {
  opacity: 0; visibility: hidden; transition: opacity .25s, visibility 0s linear .25s;
}
.seek { position: relative; height: 18px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.seek-track { position: relative; width: 100%; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .22); }
.seek-fill { position: absolute; inset-inline-start: 0; top: 0; bottom: 0; border-radius: 2px; background: linear-gradient(100deg, var(--accent), var(--accent-2)); width: 0; }
.seek-bubble {
  position: absolute; bottom: 22px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .8); border-radius: 8px; padding: 4px 9px;
  font-size: 12px; font-weight: 700; display: none; white-space: nowrap;
}
[dir="rtl"] .seek-bubble { transform: translateX(50%); }
.stage-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
/* The stage is as narrow as 9/16 of its height, so on a short window the row
   has barely 250px to work with. The buttons are tap targets and keep their
   size; the clock is what gives way, first by shrinking and then by leaving
   altogether — the same figures are on the scrub bubble. */
.t-time { flex: 0 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; }
.stage-row .grow { flex: 1; }
.sc-btn {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; background: rgba(255, 255, 255, .12); transition: background .15s;
}
/* An explicit display beats the browser's own [hidden] rule, so a control the
   player hides stayed on screen as an empty gap in the row. */
.sc-btn[hidden] { display: none; }
.sc-btn:hover { background: rgba(255, 255, 255, .25); }
/* 34px is a comfortable button under a mouse and a miss under a thumb. Rather
   than redraw the row for phones, give each control an invisible 44px hit area
   and widen the gap so two of them meet exactly instead of overlapping. */
@media (pointer: coarse) {
  .stage-row { gap: 10px; }
  .sc-btn { position: relative; }
  .sc-btn::after { content: ""; position: absolute; inset: -5px; border-radius: inherit; }
}
.sc-btn svg { width: 17px; height: 17px; fill: currentColor; }
.sc-btn.speed { font-size: 11.5px; font-weight: 800; width: auto; padding: 0 10px; border-radius: 999px; }
.stage-top {
  position: absolute; top: 0; inset-inline: 0; z-index: 5; padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, .6), transparent);
  transition: opacity .25s, visibility 0s linear;
}
.stage-top .ep-tag { font-size: 13px; font-weight: 700; color: #fff; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.stage-top .grow { flex: 1; }
/* The episode counter doubles as the way to the episode grid: it is the one
   label on the picture that already says "which one of how many". */
.ep-tag-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px;
  background: rgba(0, 0, 0, .35); backdrop-filter: blur(6px); text-shadow: none;
}
.ep-tag-btn svg { width: 13px; height: 13px; fill: currentColor; opacity: .85; }
.stage-top .top-btn { background: rgba(0, 0, 0, .35); backdrop-filter: blur(6px); }
/* Above the paywall overlay (z 8), or the way back would be under it. */
.locked-top { z-index: 9; }
.locked-top .stage-back { display: inline-flex; }

.stage-overlay {
  position: absolute; inset: 0; z-index: 8;
  background: rgba(6, 6, 12, .88); backdrop-filter: blur(10px);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  gap: 12px; padding: 26px; text-align: center;
  /* A short phone cannot hold every option at once; the overlay scrolls
     inside the stage rather than pushing buttons off the bottom. */
  overflow-y: auto;
}
.stage-overlay > * { flex: none; }
/* Centred with auto margins rather than justify-content: the margins collapse
   to 0 once the content outgrows the overlay, so its top stays within scroll
   reach instead of being pushed above it. */
.stage-overlay > :first-child { margin-top: auto; }
.stage-overlay > :last-child { margin-bottom: auto; }
.stage-overlay .lock-ico { font-size: 40px; }
.stage-overlay h3 { font-size: 20px; }
.stage-overlay p { color: var(--text-dim); font-size: 13.5px; max-width: 300px; line-height: 1.5; }
.stage-overlay .btn-primary, .stage-overlay .btn-outline { width: min(300px, 100%); }

/* The watch page's two columns give way to one, and the stage to the width
   of a phone, at the same breakpoints the rest of the portal uses. */
@media (max-width: 960px) {
  .watch { grid-template-columns: 1fr; }
  .stage { width: 100%; max-width: 460px; }
}
@media (max-width: 720px) {
  .watch { padding-inline: 12px; }
}

/* ---------- immersive viewing ----------
   A 9:16 picture cannot fill a 16:9 screen, so the question is only what fills
   the rest. Theater mode hides the page chrome, gives the video the full height
   of the viewport, and puts the title's own artwork — blurred and dimmed — in
   the space beside it, which reads as a cinema rather than as dead space.
   The same rules apply under :fullscreen, where the whole document is the
   fullscreen element so toasts and the coin modal still render. */
body.theater { overflow: hidden; }
body.theater .topbar,
body.theater .footer,
body.theater .crumbs,
body.theater .watch > .panel,
:fullscreen .topbar,
:fullscreen .footer,
:fullscreen .crumbs,
:fullscreen .watch > .panel { display: none; }

body.theater .watch,
:fullscreen .watch {
  max-width: none; margin: 0; padding: 0;
  grid-template-columns: 1fr; gap: 0;
  height: 100dvh; place-items: center; position: relative; isolation: isolate;
}
body.theater .watch::before,
:fullscreen .watch::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: var(--stage-art, none) center / cover no-repeat, #000;
  filter: blur(46px) saturate(1.2) brightness(.34); transform: scale(1.15);
}
body.theater .stage,
:fullscreen .stage {
  height: 100dvh; max-height: none; width: auto; aspect-ratio: 9 / 16;
  border-radius: 0; border: none; box-shadow: 0 0 90px rgba(0, 0, 0, .75);
}
/* A phone in portrait already is the right shape: let the picture have it all. */
@media (max-width: 760px) {
  body.theater .stage,
  :fullscreen .stage { width: 100%; max-width: none; aspect-ratio: auto; }
}

/* Below this the clock cannot fit beside the controls without pushing one of
   them out of the stage, which is what clipped the play and fullscreen buttons
   on a short laptop window. */
@container stage (max-width: 330px) {
  .t-time { display: none; }
}

/* Subtitles. The button dims when they are off so the state is readable at a
   glance. The cues themselves are drawn into the caption block above the
   controls, not by the browser, so there is no ::cue styling to set here. */
.sc-btn.cc.off { opacity: .45; }

/* End of the last episode. Finishing a series is the moment a viewer is most
   likely to start another, so the card leads with what to watch next rather
   than with a dead end. */
.stage-overlay.finale { gap: 10px; overflow-y: auto; }
.finale-mark { font-size: 34px; }
.finale-next { width: 100%; margin: 2px 0 6px; }
.finale-label {
  font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint); margin-bottom: 8px;
}
.finale-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.finale-card { display: grid; gap: 6px; text-align: center; }
.finale-art { display: block; border-radius: 10px; overflow: hidden; aspect-ratio: 2 / 3; background: var(--bg-card); }
.finale-art img, .finale-art svg { width: 100%; height: 100%; object-fit: cover; display: block; }
.finale-name {
  font-size: 11.5px; line-height: 1.25; color: var(--text-dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.finale-card:hover .finale-name { color: var(--text); }

/* Subtitle language picker. Drawn inside the stage so it survives theater and
   fullscreen, and scrollable because a well-translated episode can carry sixty
   languages. */
.sc-btn.cclang { width: auto; padding: 0 9px; border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: .04em; }
.cc-menu {
  position: absolute; z-index: 7; right: 10px; bottom: calc(var(--controls-h, 98px) + 8px);
  width: min(230px, 78%); max-height: min(52%, 320px);
  display: flex; flex-direction: column;
  background: rgba(12, 12, 20, .96); backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, .1); border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .6); overflow: hidden;
}
.cc-menu-head {
  padding: 10px 12px 8px; font-size: 11px; font-weight: 800; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-faint); border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.cc-menu-list { overflow-y: auto; }
.cc-opt {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; font-size: 13px; color: var(--text-dim); text-align: start;
}
.cc-opt:hover { background: rgba(255, 255, 255, .07); color: var(--text); }
.cc-opt.on { color: var(--accent); font-weight: 700; }
.cc-src { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.cc-opt.cc-off { border-top: 1px solid rgba(255, 255, 255, .08); color: var(--text-faint); }

/* ---------- watching on a phone ----------
   A phone screen is already the shape of the picture, so the picture takes all
   of it: no header, no breadcrumbs, no card around it. The series details and
   the episode list stay one scroll below, which is where a viewer looks for
   them rather than at them while watching. */
.stage-back {
  display: none; width: 34px; height: 34px; flex: none; border-radius: 50%;
  align-items: center; justify-content: center; color: #fff;
  background: rgba(0, 0, 0, .35); backdrop-filter: blur(6px);
}
.stage-back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; }
[dir="rtl"] .stage-back svg { transform: scaleX(-1); }

@media (max-width: 760px) {
  body.watching .topbar { display: none; }
  body.watching .crumbs { display: none; }
  body.watching .watch { padding: 0; gap: 0; }
  body.watching .stage {
    width: 100%; max-width: none; height: 100dvh; max-height: none; aspect-ratio: auto;
    border-radius: 0; border: none;
  }
  body.watching .panel { border-radius: 0; }
  /* Back out of the episode without a browser gesture. The base rule above
     must come first, or source order would override this one. */
  body.watching .stage-back { display: inline-flex; }
  /* The picture keeps the whole screen; its controls do not. Without this the
     episode tag and the back button sit under the clock and the Dynamic
     Island — where iOS routes a tap to its own scroll-to-top gesture, so the
     back button could be seen but not pressed — and the scrubber runs into
     the home indicator. */
  body.watching .stage-top { padding-top: calc(12px + var(--sat)); }
  /* A flick on the picture is the next episode, not the page scrolling; the
     details below are reached through the ⓘ button and scroll back up from
     their own surface. */
  body.watching .stage { touch-action: pan-x; }
  body.watching .stage-controls { padding-bottom: calc(12px + var(--sab)); }
  body.watching .stage-overlay {
    padding: calc(26px + var(--sat)) 26px calc(26px + var(--sab));
  }
}
