/* Player — two forms from one DOM.
 *
 * `#playerPage[data-layout]` is the only switch. The attribute is set from
 * web/js/layout.js, which owns the media query; CSS never re-derives it, so the
 * layout the user sees and the layout the gesture layer believes in can't drift
 * apart.
 *
 *   mobile  — full-screen fixed layer, gestures attached
 *   desktop — an inline 9:16 block inside the page's two-column grid
 *
 * Everything below `.playerFrame` is the stable core: the engine and seekbar hold
 * references to those nodes permanently, so they may only be restyled, never
 * rebuilt.
 */

.playerPage { display: none; }
.playerPage.show { display: block; }

/* ---------------------------------------------------------------- core */

.playerFrame { position: relative; overflow: hidden; }

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  /* Removing this would make descendant position:fixed elements resolve against
     .playerFrame instead of the viewport — the ad overlays live outside this
     subtree for exactly that reason. Keep it, and don't move the overlays in. */
  will-change: transform;
  transform: translate3d(0, 0, 0);
}
.stage.gestureAnimating { transition: transform .28s cubic-bezier(.22, .72, .18, 1); }

.stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  outline: none;
}

.poster {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 48% 32%, #3c2637 0, #17121b 34%, #050505 78%);
  transition: opacity .35s;
}
.poster.hidden { opacity: 0; pointer-events: none; }
.posterArt {
  width: min(70%, 340px);
  aspect-ratio: 2 / 3;
  max-height: 58vh;
  border-radius: 20px;
  background: linear-gradient(150deg, #5a1830, #19192d 55%, #0e6670);
  background-size: cover;
  background-position: center;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .55);
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-weight: 900;
  font-size: 21px;
  line-height: 1.28;
  text-shadow: 0 3px 10px #000;
}
.posterArt.alt1 { background: linear-gradient(150deg, #2e4d89, #151827 56%, #612f6e); }
.posterArt.alt2 { background: linear-gradient(150deg, #243e22, #121b16 56%, #745429); }
.posterArt.alt3 { background: linear-gradient(150deg, #6a3421, #211512 56%, #5d163d); }
.posterArt.alt4 { background: linear-gradient(150deg, #3f225f, #151422 56%, #184c63); }

.playIcon {
  position: absolute;
  z-index: 4;
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .5);
  display: grid;
  place-items: center;
  font-size: 27px;
  padding-left: 5px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.playerPage.paused .playIcon { opacity: 1; }

.playerGradient {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, .5) 0%, transparent 22%,
                              transparent 55%, rgba(0, 0, 0, .88) 100%);
}

.sideActions {
  position: absolute;
  right: 12px;
  bottom: calc(118px + var(--safe-bottom));
  z-index: 11;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sideAction { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.action {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .46);
  border: 1px solid rgba(255, 255, 255, .14);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  display: grid;
  place-items: center;
  transition: background .15s;
}
.action:hover { background: rgba(0, 0, 0, .72); }
.actionLabel { font-size: 10px; color: #ddd; text-align: center; }

.info {
  position: absolute;
  z-index: 10;
  left: 16px;
  right: 76px;
  bottom: calc(66px + var(--safe-bottom));
  pointer-events: none;
}
.info h2 { font-size: 24px; margin-bottom: 6px; text-shadow: 0 2px 12px rgba(0, 0, 0, .85); }
.info .episode { font-size: 14px; color: #fff; margin-bottom: 5px; text-shadow: 0 2px 10px rgba(0, 0, 0, .85); }
.info .desc {
  font-size: 13px;
  color: #d0d0d6;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .85);
}

.swipeHint {
  position: absolute;
  top: calc(18px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  color: rgba(255, 255, 255, .55);
  font-size: 11px;
  pointer-events: none;
  transition: opacity .6s;
  white-space: nowrap;
}
.swipeHint.fade { opacity: 0; }

.backBtn { position: absolute; left: 14px; top: calc(14px + var(--safe-top)); z-index: 12; }

/* ---------------------------------------------------------------- seek */

.progressWrap {
  position: absolute;
  z-index: 13;
  left: 0; right: 0; bottom: 0;
  padding: 14px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(0deg, rgba(0, 0, 0, .8), transparent);
}
.progress { position: relative; height: 20px; cursor: pointer; touch-action: none; }
.progress::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 8px;
  height: 4px;
  background: rgba(255, 255, 255, .24);
  border-radius: 999px;
}
.progress .buffered {
  position: absolute;
  left: 0; top: 8px;
  height: 4px;
  width: 0;
  background: rgba(255, 255, 255, .38);
  border-radius: 999px;
}
.progress .bar {
  position: absolute;
  left: 0; top: 8px;
  height: 4px;
  width: 0;
  background: #fff;
  border-radius: 999px;
}
.progress .bar::after {
  content: "";
  position: absolute;
  right: -6px; top: 50%;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #fff;
  transform: translateY(-50%);
  box-shadow: 0 1px 8px rgba(0, 0, 0, .5);
}
.progress.dragging .bar::after { transform: translateY(-50%) scale(1.3); }

.progressText {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #c4c4cc;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- states */

.playerError {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 32px;
  background: rgba(0, 0, 0, .9);
}
.playerError.show { display: flex; }
.playerError h3 { font-size: 19px; }
.playerError p { color: var(--muted); font-size: 14px; margin: 0; max-width: 420px; line-height: 1.6; }
.playerError .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.playerLoading {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .45);
  pointer-events: none;
}
.playerLoading.show { display: flex; }

.unmutePill {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translateX(-50%);
  z-index: 14;
}

/* ================================================================ MOBILE */

.playerPage[data-layout="mobile"] {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000;
  overflow: hidden;
  /* This — not preventDefault — is what stops the page scrolling under a swipe. */
  touch-action: none;
}
.playerPage[data-layout="mobile"] .watchGrid,
.playerPage[data-layout="mobile"] .watchMain { display: block; margin: 0; padding: 0; }
.playerPage[data-layout="mobile"] .playerFrame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: 0;
}
/* Desktop-only chrome: display:none keeps it out of the render tree AND the tab
   order, unlike visibility. */
.playerPage[data-layout="mobile"] .crumbs,
.playerPage[data-layout="mobile"] .epHead,
.playerPage[data-layout="mobile"] .watchSide { display: none; }

/* ================================================================ DESKTOP */

.playerPage[data-layout="desktop"] {
  position: static;            /* out of the fixed layer, into the page flow */
  background: transparent;
  touch-action: auto;          /* touchscreen laptops must be able to scroll */
  padding: 20px 24px 60px;
}

.playerPage[data-layout="desktop"] .watchGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 28px;
  align-items: start;
  max-width: 1280px;
  margin: 0 auto;
}
.playerPage[data-layout="desktop"] .watchMain { min-width: 0; }

.playerPage[data-layout="desktop"] .playerFrame {
  position: relative;
  inset: auto;
  /* Height-capped so it always fits the viewport; aspect-ratio needs the height
     to stay auto, so never set an explicit height here. */
  width: min(100%, calc(min(78dvh, 720px) * 9 / 16));
  aspect-ratio: 9 / 16;
  margin: 6px auto 0;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55);
}

/* Mobile-only chrome removed from rendering and tab order. */
.playerPage[data-layout="desktop"] .backBtn,
.playerPage[data-layout="desktop"] .swipeHint,
.playerPage[data-layout="desktop"] .sideActions,
.playerPage[data-layout="desktop"] .info { display: none; }

.playerPage[data-layout="desktop"] .progressWrap { padding: 14px 14px 12px; }

/* ---- desktop chrome: crumbs, head, sidebar ---- */

.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}
.crumbs a { color: #c9c9d3; }
.crumbs a:hover { color: #fff; text-decoration: underline; }
.crumbs .sep { opacity: .5; }

.epHead { margin-bottom: 16px; }
.epHeadTitle { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.epHeadTitle h1 { font-size: 24px; line-height: 1.25; }
.epHeadTitle .epSuffix { font-size: 16px; color: var(--muted); font-weight: 600; }

.epHeadNav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.epNavBtn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  border: 0;
}
.epNavBtn:hover { background: #ff5c83; }
.epNavBtn.disabled { opacity: .35; pointer-events: none; }
.epNavBtn.hidden { display: none; }

.tagRow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.tagPill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12px;
  font-weight: 700;
  color: #d6d6de;
}
.tagPill.hidden { display: none; }

.watchSide { display: grid; gap: 16px; align-content: start; }

.sideAbout {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  transition: border-color .15s;
}
.sideAbout:hover { border-color: rgba(255, 255, 255, .26); }
.sideAbout img,
.sideAbout .sideThumb {
  width: 46px;
  aspect-ratio: 2 / 3;
  border-radius: 7px;
  object-fit: cover;
  background: linear-gradient(150deg, #5a1830, #19192d 55%, #0e6670);
  flex: 0 0 auto;
}
.sideAboutText { min-width: 0; display: grid; gap: 3px; }
.sideAboutText b { font-size: 13px; line-height: 1.3; }
.sideAboutText small { color: var(--muted); font-size: 11px; }
.sideAbout .chev { margin-left: auto; color: var(--muted); font-size: 18px; }

.sideCard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.sideCard h3 { font-size: 14px; margin-bottom: 12px; }

.shareRow { display: flex; gap: 8px; flex-wrap: wrap; }
.shareIcon {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: #e6e6ee;
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, transform .15s;
}
.shareIcon:hover { background: #2b2b34; transform: translateY(-1px); }

.chipGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.chip {
  display: block;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 11px;
  font-weight: 700;
  color: #cfcfd8;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip:hover { background: #2b2b34; color: #fff; }

.epChips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow-y: auto; }
.epChip {
  min-width: 34px;
  text-align: center;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--panel2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  color: #cfcfd8;
}
.epChip:hover { background: #2b2b34; color: #fff; }
.epChip.active { background: var(--accent); border-color: transparent; color: #fff; }
.epChip.locked::after { content: "🔒"; font-size: 8px; margin-left: 3px; }

@media (max-width: 1100px) {
  .playerPage[data-layout="desktop"] .watchGrid {
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 20px;
  }
}

/* ================================================================ AD GATE
   Three surfaces, one state machine (see the gate object in pages/player.js):

     .playerLocked   the wall — the episode is locked and stays locked
     .nextPrompt     a one-time offer, shown when an episode ends into a lock
     .pickBtn         the episode selector's entry point

   They are separate elements because they mean different things. Folding them
   into one dialog is what produced the old "cancel → dialog → cancel" loop. */

.playerLocked {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 32px 24px;
  background: rgba(0, 0, 0, .92);
}
.playerLocked.show { display: flex; }
.lockedLock { font-size: 34px; line-height: 1; opacity: .9; }
.playerLocked h3 { font-size: 20px; margin: 0; }
.playerLocked p { color: var(--muted); font-size: 14px; margin: 0; }
.playerLocked .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.playerLocked small { color: var(--muted); font-size: 12px; opacity: .75; max-width: 300px; }
/* `.hidden` is defined per component in this codebase, not globally — so a
   rule is needed here too, or toggling the class silently does nothing. */
.playerLocked .btn.hidden { display: none; }

.nextPrompt {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  z-index: 26;
  display: none;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100% - 32px));
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(21, 21, 27, .97);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
.nextPrompt.show { display: flex; }
.nextPrompt b { font-size: 15px; }
.nextPrompt p { color: var(--muted); font-size: 13px; margin: 0; line-height: 1.5; }
.nextPrompt .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

.pickBtn {
  position: absolute;
  right: 14px;
  bottom: 74px;
  z-index: 24;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.pickBtn:hover { background: rgba(0, 0, 0, .75); }

/* ================================================================ EPISODE SHEET */

.episodeSheet { position: fixed; inset: 0; z-index: 220; display: none; }
.episodeSheet.show { display: block; }
.sheetScrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }

/* Mobile: a bottom sheet. */
.sheetPanel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  background: var(--panel);
  animation: sheetUp .22s cubic-bezier(.22, .72, .18, 1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheetHead { display: flex; align-items: flex-start; gap: 12px; padding-bottom: 12px; }
.sheetHeadText { flex: 1; min-width: 0; }
.sheetTitle { font-size: 16px; display: block; }
.sheetMeta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.sheetClose {
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.sheetGrid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px;
  overflow-y: auto;
  padding: 4px 0;
  overscroll-behavior: contain;
}
.sheetEp {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.sheetEp:hover { border-color: rgba(255, 255, 255, .3); }
.sheetEp.current { border-color: var(--accent); background: var(--accent); color: #fff; }
.sheetEp.locked { color: var(--muted); background: rgba(255, 255, 255, .04); }
.sheetLock { position: absolute; right: 4px; bottom: 3px; font-size: 9px; opacity: .85; }

.sheetBack {
  margin-top: 12px;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  background: var(--panel2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* Desktop: centred dialog rather than a sheet pinned to the bottom.
   Driven by an attribute the caller sets, not by DOM position — the sheet is
   appended to <body> while the player lives inside #app, so the two are not
   siblings and a `~` selector would match nothing. */
.episodeSheet[data-layout="desktop"] .sheetPanel {
  left: 50%;
  right: auto;
  bottom: auto;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 48px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  animation: none;
}
