/* 短剧库 — immersive player. Always dark (its own tokens), picture kept at its
   original ratio (object-fit: contain) on black / over a blurred cover.
   Desktop: picture in the middle, action column on the right, 选集 panel
   sliding in from the right. Phone portrait: full screen, action column,
   caption bottom-left, thin progress line, panels from the bottom. Phone
   landscape: 红果-style bottom bar, panels from the right. */

.player {
  --page-surface: #252632;
  --foreground: rgba(255, 255, 255, 0.9);
  --muted: rgba(255, 255, 255, 0.5);
  --faint: rgba(255, 255, 255, 0.3);
  --fill: rgba(255, 255, 255, 0.08);
  --fill-strong: rgba(255, 255, 255, 0.14);
  --divider: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.12);
  --accent-soft: rgba(254, 44, 85, 0.18);
  --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
  position: fixed;
  inset: 0;
  z-index: var(--z-player);
  overflow: hidden;
  background: #000;
  color: var(--foreground);
}
.player__backdrop { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.player__backdrop-image { position: absolute; inset: -60px; width: calc(100% + 120px); height: calc(100% + 120px); object-fit: cover; filter: blur(48px) saturate(1.2) brightness(.42); opacity: .9; }
.player__frame { position: absolute; inset: 0; display: flex; }
.player__main { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: max(16px, env(safe-area-inset-top)) 112px max(10px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); }
.player__header { position: absolute; top: 16px; left: 24px; z-index: 7; display: flex; align-items: center; gap: 10px; }
.player__header .icon-btn { --icon-button: 40px; background: rgba(255, 255, 255, 0.12); color: #fff; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.player__heading { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.player__stage { position: relative; flex: 1 1 auto; min-height: 240px; overflow: hidden; background: transparent; color: #fff; isolation: isolate; outline: none; }
.player__video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: transparent; }
.player__surface { position: absolute; inset: 0; z-index: 2; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: pointer; }
.danmaku { position: absolute; inset: 7% 0 auto; z-index: 1; height: 55%; overflow: hidden; pointer-events: none; font-size: var(--danmaku-size, 17px); }
.danmaku__item { position: absolute; top: 0; left: 0; white-space: nowrap; color: #fff; font-weight: 500; line-height: 1.6; text-shadow: 0 1px 2px rgba(0, 0, 0, .8), 0 0 1px rgba(0, 0, 0, .9); will-change: transform; }
.player__big-play { position: absolute; z-index: 3; left: 50%; top: 50%; width: 84px; height: 84px; margin: -42px 0 0 -42px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: rgba(255, 255, 255, .78); filter: drop-shadow(0 2px 10px rgba(0, 0, 0, .45)); pointer-events: none; }
.player__big-play .icon { width: 72px; height: 72px; margin-left: 8px; }
.player__status { position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 10px; color: rgba(255, 255, 255, .86); font-size: 13px; pointer-events: none; text-align: center; }
.spinner { width: 32px; height: 32px; border: 3px solid rgba(255, 255, 255, .2); border-top-color: var(--accent); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.player__error { position: absolute; z-index: 6; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 32px)); display: grid; justify-items: center; gap: 12px; padding: 18px; border-radius: var(--radius-lg); background: rgba(22, 24, 35, .82); color: #fff; text-align: center; font-size: 14px; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.player__hint { position: absolute; z-index: 8; left: 50%; top: 32%; transform: translateX(-50%); max-width: calc(100% - 48px); padding: 10px 18px; border-radius: var(--radius); background: rgba(0, 0, 0, .66); color: #fff; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }

/* caption: title, episode, synopsis (two lines, tap to expand) */
.player__caption { position: absolute; z-index: 3; left: 16px; right: 16px; bottom: 14px; display: grid; gap: 6px; max-width: 520px; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .55); pointer-events: none; transition: opacity 160ms ease; }
.player__caption-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; font-weight: 600; line-height: 1.35; }
.player__caption-meta { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; color: rgba(255, 255, 255, .9); font-variant-numeric: tabular-nums; }
.player__caption-meta .player__buffer { color: rgba(255, 255, 255, .6); font-size: 12px; font-weight: 400; }
.player__desc { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-size: 13px; line-height: 1.5; color: rgba(255, 255, 255, .82); pointer-events: auto; cursor: pointer; white-space: pre-line; }
.player__desc.is-open { -webkit-line-clamp: unset; max-height: 40vh; max-height: 40dvh; overflow-y: auto; }

/* right-hand action column */
.player__actions { position: absolute; z-index: 6; right: 24px; bottom: 96px; display: flex; flex-direction: column; align-items: center; gap: 18px; transition: right 220ms ease, opacity 160ms ease; }
.player:not(.side-closed):not(.player--mobile) .player__actions { right: 384px; }
.action { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 56px; padding: 0; border: 0; background: transparent; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .45); }
.action__icon { width: 46px; height: 46px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: rgba(255, 255, 255, .14); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); transition: background-color 150ms ease, color 150ms ease, transform 150ms ease; }
.action__icon .icon { width: 24px; height: 24px; stroke-width: 1.9; }
.action__label { font-size: 12px; font-weight: 500; line-height: 1.2; white-space: nowrap; color: rgba(255, 255, 255, .92); }
.action[aria-pressed="true"] .action__icon { color: var(--accent-cyan); }
.action[aria-expanded="true"] .action__icon { background: var(--accent); color: #fff; }
.action:disabled { opacity: .4; }
@media (hover: hover) and (pointer: fine) { .action:hover:not(:disabled) .action__icon { background: rgba(255, 255, 255, .24); } }
.action:active:not(:disabled) .action__icon { transform: scale(.92); }
.player.is-scrubbing .player__actions, .player.is-scrubbing .player__caption { opacity: 0; pointer-events: none; }

/* desktop control bar */
.player__controls { position: relative; z-index: 5; display: grid; gap: 6px; padding: 8px 0 0; color: #fff; }
/* narrow players (tablet with the 选集 panel open): the buffer text shrinks first, then the right group wraps */
.player__bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px; min-width: 0; }
.player__bar-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
.player__bar-group:first-child { flex: 1 1 auto; }
.player__bar-group:last-child { flex: none; margin-left: auto; }
.player__bar .player__time { flex: none; }
.player__bar .player__buffer { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.player__controls .icon-btn { background: transparent; color: #fff; }
@media (hover: hover) and (pointer: fine) { .player__controls .icon-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .12); } }
.player__play { --icon-button: 40px; background: transparent; color: #fff; }
.player__play .icon { width: 24px; height: 24px; }
.player__time { color: rgba(255, 255, 255, .9); font-size: 13px; font-weight: 500; white-space: nowrap; font-variant-numeric: tabular-nums; }
.player__buffer { color: rgba(255, 255, 255, .55); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.player__chip { height: 30px; padding: 0 12px; border: 0; border-radius: var(--radius-pill); background: rgba(255, 255, 255, .12); color: #fff; font-size: 13px; font-weight: 500; white-space: nowrap; font-variant-numeric: tabular-nums; }
.player__chip[aria-expanded="true"] { background: var(--accent); color: #fff; }
@media (hover: hover) and (pointer: fine) { .player__chip:hover { background: rgba(255, 255, 255, .2); } }

/* progress: thin line, thicker with a time bubble while dragging */
.progress { position: relative; height: 16px; }
.progress__track { position: absolute; left: 0; right: 0; top: 50%; height: 3px; margin-top: -1.5px; overflow: hidden; border-radius: var(--radius-pill); background: rgba(255, 255, 255, .22); transition: height 120ms ease, margin-top 120ms ease; }
.progress__buffered > span { position: absolute; top: 0; bottom: 0; background: rgba(255, 255, 255, .28); }
.progress__played { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: var(--accent); }
.progress__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; -webkit-appearance: none; appearance: none; background: transparent; opacity: 0; cursor: pointer; }
.progress__input:disabled { cursor: default; }
.progress:hover .progress__track, .progress:focus-within .progress__track, .progress.is-dragging .progress__track { height: 6px; margin-top: -3px; }
.progress__bubble { position: absolute; left: 50%; bottom: calc(100% + 18px); transform: translateX(-50%); padding: 6px 14px; border-radius: var(--radius); background: rgba(0, 0, 0, .55); color: #fff; font-size: 22px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; opacity: 0; pointer-events: none; transition: opacity 120ms ease; }
.progress.is-dragging .progress__bubble { opacity: 1; }

/* 选集 panel (desktop: from the right) */
.player__side { flex: none; width: 360px; min-height: 0; display: flex; flex-direction: column; padding: 18px 18px 14px; border-left: 1px solid var(--divider); background: rgba(22, 24, 35, .9); -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px); overflow: hidden; animation: side-in 220ms cubic-bezier(.2, .8, .2, 1); }
@keyframes side-in { from { transform: translateX(40px); opacity: 0; } }
.player.side-closed .player__side { display: none; }
.episode-panel { min-height: 0; display: flex; flex-direction: column; gap: 12px; flex: 1 1 auto; }
.episode-panel__head { display: flex; align-items: center; gap: 10px; }
.episode-panel__head .section-title { font-size: 16px; }
.episode-panel__head .note { flex: 1 1 auto; font-size: 13px; }
.episode-panel__head .icon-btn { background: transparent; }
.episode-grid--player { grid-template-columns: repeat(5, minmax(0, 1fr)); align-content: start; gap: 8px; overflow: auto; flex: 1 1 auto; padding: 1px; }
.player .episode-cell { height: 44px; border: 0; border-radius: var(--radius); background: var(--fill); color: var(--foreground); font-size: 14px; font-weight: 500; }
.player .episode-cell[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset 0 0 0 1px var(--accent); }
.player .episode-cell.is-done:not([aria-current="true"]) { color: var(--muted); }
@media (hover: hover) and (pointer: fine) { .player .episode-cell:hover:not([aria-current="true"]) { background: var(--fill-strong); } }
.jump { display: flex; align-items: center; gap: 8px; padding-top: 10px; border-top: 1px solid var(--divider); font-size: 13px; color: var(--muted); }
.input--jump { width: 76px; height: 34px; text-align: center; }
.player-more { display: grid; gap: 2px; }
.player-more .toggle { padding: 9px 0; }
.player-more__block { display: grid; gap: 8px; padding: 8px 0 10px; }
.player-more__label { color: var(--muted); font-size: 13px; font-weight: 500; }
.player-more__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; font-size: 14px; font-weight: 500; }
.player-more__row small { color: var(--muted); font-size: 12px; font-weight: 400; }
.player-more__facts { display: grid; gap: 6px; margin: 6px 0 0; padding: 12px 0 0; border-top: 1px solid var(--divider); font-size: 13px; }
.player-more__facts div { display: flex; justify-content: space-between; gap: 12px; }
.player-more__facts dt { color: var(--muted); }
.player-more__facts dd { margin: 0; text-align: right; font-weight: 500; }
.player-more__keys { padding-top: 10px; border-top: 1px solid var(--divider); font-size: 12px; }
.rate-slider { width: 100%; }
.popover .rate-slider { min-width: 280px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { height: 32px; padding: 0 14px; border: 0; border-radius: var(--radius-pill); background: var(--fill); color: var(--foreground); font-size: 13px; font-weight: 500; }
.chip[data-active="true"] { background: var(--accent); color: #fff; }

/* mobile overlay pieces are hidden on desktop */
.m-overlay, .m-sheet, .m-scrim { display: none; }

/* ------------------------------------------------------------------ fullscreen (desktop) */
.player__main:fullscreen { padding: 0; background: #000; }
.player__main:fullscreen .player__header { display: none; }
.player__main:fullscreen .player__controls { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 20px 14px; background: linear-gradient(transparent, rgba(0, 0, 0, .6)); }
.player__main:fullscreen .player__caption { bottom: 84px; }

/* ------------------------------------------------------------------ phones */
.player--mobile .player__backdrop { display: none; }
.player--mobile .player__frame { display: block; position: absolute; left: 50%; top: 50%; width: var(--frame-w, 100vw); height: var(--frame-h, 100dvh); transform: translate(-50%, -50%) rotate(var(--rotation, 0deg)); }
.player--mobile .player__side { display: none; }
.player--mobile .player__main { position: absolute; inset: 0; padding: 0; }
.player--mobile .player__header, .player--mobile .player__controls { display: none; }
.player--mobile .player__stage { position: absolute; inset: 0; min-height: 0; background: #000; }
.player--mobile .player__video { background: #000; }
.player--mobile .m-overlay { display: block; position: absolute; inset: 0; z-index: 4; pointer-events: none; color: #fff; }
.player--mobile .m-overlay > * { pointer-events: auto; }
.m-icon { width: 36px; height: 36px; flex: 0 0 36px; position: relative; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: #fff; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5)); }
.m-icon::after { content: ''; position: absolute; inset: -4px; }
.m-icon .icon { width: 24px; height: 24px; }
.m-icon[aria-pressed="true"] { color: var(--accent); }
.m-chip { height: 28px; padding: 0 12px; border: 0; border-radius: var(--radius-pill); background: rgba(255, 255, 255, .16); color: #fff; font-size: 12px; font-weight: 500; white-space: nowrap; font-variant-numeric: tabular-nums; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
.m-top { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(6px + env(safe-area-inset-left)); }
.m-top__heading { flex: 1 1 auto; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.m-top__title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 600; }
.m-top__episode { font-size: 13px; font-weight: 500; white-space: nowrap; color: rgba(255, 255, 255, .8); }
.m-caption { position: absolute; left: 0; right: 0; bottom: 0; display: grid; gap: 0; padding: 0 0 env(safe-area-inset-bottom); }
.m-caption .progress { height: 14px; margin: 0 0 -2px; }
.m-rail { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left)); border: 0; border-radius: 0; background: rgba(255, 255, 255, .1); color: #fff; font-size: 14px; font-weight: 500; text-align: left; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.m-rail small { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: rgba(255, 255, 255, .62); font-size: 13px; font-weight: 400; }
.m-rail .icon { width: 18px; height: 18px; }
.m-landscape { display: none; }

/* portrait: action column + caption; the top bar keeps back / rotate */
.player--portrait .player__actions { right: calc(8px + env(safe-area-inset-right)); bottom: calc(150px + env(safe-area-inset-bottom)); gap: 16px; }
.player--portrait .action__icon { width: 44px; height: 44px; background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .5)); }
.player--portrait .action__icon .icon { width: 30px; height: 30px; stroke-width: 1.8; }
.player--portrait .action__label { font-size: 12px; }
.player--portrait .player__caption { left: calc(14px + env(safe-area-inset-left)); right: 84px; bottom: calc(62px + env(safe-area-inset-bottom)); max-width: none; }
.player--portrait .m-top .m-chip, .player--portrait .m-top .m-icon[aria-label="更多"], .player--portrait .m-top__heading { display: none; }
.player--portrait .m-top { justify-content: space-between; }
.player--portrait .player__hint { top: 40%; }
.player--portrait .player__error { left: calc(12px + env(safe-area-inset-left)); right: calc(84px + env(safe-area-inset-right)); width: auto; transform: translateY(-50%); }

/* landscape: 红果-style bottom bar, panels from the right */
.player--landscape .player__actions, .player--landscape .player__caption, .player--landscape .m-caption { display: none; }
.player--landscape .m-top { padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px calc(10px + env(safe-area-inset-left)); background: linear-gradient(rgba(0, 0, 0, .55), transparent); }
.player--landscape .m-landscape { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 10px; padding: 18px calc(16px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); background: linear-gradient(transparent, rgba(0, 0, 0, .6)); }
.player--landscape .m-landscape .progress { flex: 1 1 auto; }
.player--landscape .m-landscape .player__time { color: #fff; font-size: 12px; }
.player.controls-hidden .m-overlay { opacity: 0; pointer-events: none; }
.player.controls-hidden .m-overlay > * { pointer-events: none; }
.m-overlay { transition: opacity 200ms ease; }

.player--mobile .m-scrim:not([hidden]) { display: block; position: absolute; inset: 0; z-index: 9; background: rgba(0, 0, 0, .4); }
.player--mobile .m-sheet:not([hidden]) { display: flex; position: absolute; z-index: 10; flex-direction: column; overflow: hidden; background: var(--page-surface); color: var(--foreground); box-shadow: var(--shadow-pop); }
.m-sheet[data-side="bottom"] { left: 0; right: 0; bottom: 0; max-height: 70%; border-radius: var(--radius-xl) var(--radius-xl) 0 0; padding-bottom: env(safe-area-inset-bottom); animation: sheet-up 220ms cubic-bezier(.2, .8, .2, 1); }
.m-sheet[data-side="right"] { top: 0; right: 0; bottom: 0; width: min(360px, 52%); border-radius: var(--radius-xl) 0 0 var(--radius-xl); padding-right: env(safe-area-inset-right); animation: sheet-left 220ms cubic-bezier(.2, .8, .2, 1); }
@keyframes sheet-up { from { transform: translateY(40%); } }
@keyframes sheet-left { from { transform: translateX(40%); } }
.m-sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 12px 10px 18px; }
.m-sheet__title { font-size: 16px; font-weight: 600; }
.m-sheet__head .icon-btn { background: transparent; }
.m-sheet__body { min-height: 0; overflow: auto; padding: 4px 18px 18px; }
.m-sheet--episodes .m-sheet__body { display: flex; flex-direction: column; }
.m-sheet .episode-panel__head { display: none; }
.m-sheet .episode-grid--player { grid-template-columns: repeat(6, minmax(0, 1fr)); overflow: visible; }
.m-sheet[data-side="right"] .episode-grid--player { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.m-sheet .episode-cell { height: 40px; }

@media (max-width: 1023px) and (min-width: 768px) {
  .player__side { width: 300px; }
  .player:not(.side-closed):not(.player--mobile) .player__actions { right: 324px; }
  .episode-grid--player { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Portrait episode paging: the media/caption/progress move together; navigation
   and tools stay fixed. The adjacent screen is black or a cached real frame, never another video. */
.player__swipe-preview { position: absolute; inset: 0; z-index: 0; overflow: hidden; background: #000; pointer-events: none; }
.player__swipe-frame { width: 100%; height: 100%; object-fit: contain; }
.player--portrait .player__surface { touch-action: auto; }
.player--portrait.swipe-moving .player__video,
.player--portrait.swipe-moving .danmaku,
.player--portrait.swipe-moving .player__big-play,
.player--portrait.swipe-moving .player__caption,
.player--portrait.swipe-moving .m-caption { transform: translate3d(0, var(--swipe-y, 0px), 0); will-change: transform; }
.player--portrait.swipe-settling .player__video,
.player--portrait.swipe-settling .danmaku,
.player--portrait.swipe-settling .player__big-play,
.player--portrait.swipe-settling .player__caption,
.player--portrait.swipe-settling .m-caption,
.player--portrait.swipe-settling .player__swipe-preview { transition: transform 220ms cubic-bezier(.22, .75, .25, 1); }
.player--portrait.swipe-waiting .player__video,
.player--portrait.swipe-waiting .danmaku,
.player--portrait.swipe-waiting .player__big-play,
.player--portrait.swipe-waiting .player__caption,
.player--portrait.swipe-waiting .m-caption { visibility: hidden; }
@media (prefers-reduced-motion: reduce) {
  .player--portrait.swipe-settling .player__video,
  .player--portrait.swipe-settling .danmaku,
  .player--portrait.swipe-settling .player__big-play,
  .player--portrait.swipe-settling .player__caption,
  .player--portrait.swipe-settling .m-caption,
  .player--portrait.swipe-settling .player__swipe-preview { transition: none; }
}
/* Keep the already scroll-locked portrait modal from turning horizontal touch
   into browser back/refresh; panel scrolling and control events remain native. */
html:has(body.has-player .player--portrait:not([hidden])) { overscroll-behavior: none; }
