:root {
  --player-bg: #000;
  --player-fg: #fff;
  --player-muted: #b7bcc5;
  --player-accent: #e50914;
  --player-surface: rgba(12, 14, 18, .94);
  --player-line: rgba(255, 255, 255, .16);
  --player-shadow: 0 20px 60px rgba(0, 0, 0, .52);
  --control-size: 44px;
  --touch-target: 44px;
  --edge-x: clamp(14px, 3vw, 42px);
  --ease: cubic-bezier(.2, .8, .2, 1);
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; background: var(--player-bg); color: var(--player-fg); font-family: "Cairo", system-ui, sans-serif; overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.player-root { position: relative; width: 100vw; height: 100dvh; min-height: 280px; overflow: hidden; isolation: isolate; background: var(--player-bg); outline: none; touch-action: manipulation; }
.player-root video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; -webkit-touch-callout: none; user-select: none; }
.player-root .player-preview-video { position: fixed !important; inset: auto auto -240px -320px !important; width: 192px !important; height: 108px !important; opacity: 0 !important; pointer-events: none !important; z-index: -1 !important; }
.player-shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, rgba(0,0,0,.72), transparent 24%, transparent 62%, rgba(0,0,0,.8)); transition: opacity .22s var(--ease); }
.player-chrome { transition: opacity .22s var(--ease), transform .22s var(--ease); }
.player-icon { width: 24px; height: 24px; display: block; flex: 0 0 auto; }
[dir="rtl"] .player-icon--back, [dir="rtl"] .player-icon--chevron { transform: scaleX(-1); }

.top-bar { position: absolute; z-index: 20; inset: 0 0 auto; min-height: 76px; display: flex; align-items: center; gap: 12px; padding: max(14px, env(safe-area-inset-top)) var(--edge-x) 20px; background: linear-gradient(180deg, rgba(0,0,0,.76), transparent); }
.media-heading { min-width: 0; flex: 1; display: grid; gap: 2px; }
.media-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: clamp(15px, 1.7vw, 22px); font-weight: 700; }
.media-heading span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--player-muted); font-size: 11px; }
.top-actions, .control-group, .volume-group, .error-actions { display: flex; align-items: center; }
.top-actions { gap: 8px; }
.icon-button, .center-play, .center-skip, .text-action, .drawer-close { min-width: var(--touch-target); min-height: var(--touch-target); border: 0; border-radius: 999px; background: transparent; color: var(--player-fg); display: inline-grid; place-items: center; cursor: pointer; }
.icon-button:focus-visible, .center-play:focus-visible, .center-skip:focus-visible, .text-action:focus-visible, .drawer-close:focus-visible, .settings-panel button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.icon-button:hover, .text-action:hover, .drawer-close:hover { background: rgba(255,255,255,.12); }
.text-action { grid-auto-flow: column; gap: 7px; width: auto; padding: 0 13px; border: 1px solid rgba(255,255,255,.14); background: rgba(0,0,0,.28); font-size: 12px; }
.action-icon { width: 18px; height: 18px; display: inline-grid; place-items: center; }
.action-icon .player-icon { width: 18px; height: 18px; }

.center-controls { position: absolute; z-index: 17; inset: 50% auto auto 50%; transform: translate(-50%, -50%); display: flex; align-items: center; gap: clamp(18px, 4vw, 44px); }
.center-play { width: 76px; height: 76px; background: rgba(255,255,255,.96); color: #070707; box-shadow: var(--player-shadow); }
.center-play .player-icon { width: 30px; height: 30px; }
.center-skip { width: 58px; height: 58px; background: rgba(0,0,0,.48); border: 1px solid rgba(255,255,255,.12); }
.center-skip .player-icon { width: 29px; height: 29px; }

.controls-layer { position: absolute; z-index: 19; inset: auto 0 0; padding: 46px var(--edge-x) calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.88) 55%); }
.timeline-zone { position: relative; height: 32px; display: flex; align-items: center; direction: ltr; }
.timeline-hit { position: relative; z-index: 2; width: 100%; min-height: 32px; display: flex; align-items: center; cursor: pointer; touch-action: none; outline: none; direction: ltr; }
.timeline-hit:focus-visible { outline: 2px solid rgba(255,255,255,.9); outline-offset: 2px; border-radius: 6px; }
.timeline-track { position: absolute; left: 0; right: 0; height: 4px; border-radius: 999px; background: rgba(255,255,255,.24); direction: ltr; }
.buffered-bar, .played-bar { position: absolute; top: 0; bottom: 0; left: 0; right: auto; width: 0; border-radius: inherit; }
.buffered-bar { background: rgba(255,255,255,.48); }
.played-bar { background: var(--player-accent); }
.timeline-thumb { position: absolute; top: 50%; left: 0; width: 12px; height: 12px; margin-left: -6px; transform: translateY(-50%) scale(.75); border-radius: 50%; background: var(--player-accent); opacity: 0; transition: opacity .12s var(--ease), transform .12s var(--ease); }
.timeline-hit:hover .timeline-thumb, .timeline-hit:focus-visible .timeline-thumb, .timeline-hit.is-seeking .timeline-thumb { opacity: 1; transform: translateY(-50%) scale(1); }
.timeline-hit:hover .timeline-track, .timeline-hit.is-seeking .timeline-track { height: 6px; }
.thumb-preview { position: absolute; z-index: 5; bottom: 30px; width: 176px; transform: translateX(-50%); overflow: hidden; border: 1px solid var(--player-line); border-radius: 10px; background: #0b0d11; box-shadow: var(--player-shadow); pointer-events: none; }
.thumb-image { aspect-ratio: 16/9; background: #111 center/cover no-repeat; }
.thumb-preview.is-loading .thumb-image { background: linear-gradient(110deg,#111 22%,#20242b 38%,#111 54%); background-size: 200% 100%; animation: preview-shimmer 1s linear infinite; }
.thumb-preview span { display: block; padding: 4px 8px; text-align: center; font-size: 11px; background: rgba(0,0,0,.9); }
.control-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.control-group { gap: 2px; }
.volume-group { gap: 0; }
.volume-group input { width: 0; opacity: 0; accent-color: #fff; transition: width .18s var(--ease), opacity .18s var(--ease); }
.volume-group:hover input, .volume-group:focus-within input { width: 88px; opacity: 1; }
.time-display { display: flex; align-items: center; gap: 5px; margin-inline-start: 5px; color: #f2f3f5; font-size: 11px; white-space: nowrap; }
.time-display i { color: #8d939c; font-style: normal; }

.skip-actions { position: absolute; z-index: 18; inset-inline-start: var(--edge-x); bottom: calc(104px + env(safe-area-inset-bottom)); display: flex; gap: 8px; }
.skip-chip, .next-episode, .drawer-refresh, .primary-action, .soft-action { border: 0; cursor: pointer; }
.skip-chip { min-height: 40px; padding: 0 16px; border-radius: 10px; background: #fff; color: #080808; font-weight: 700; }
.next-episode { position: absolute; z-index: 18; inset-inline-end: var(--edge-x); bottom: calc(104px + env(safe-area-inset-bottom)); min-width: 0; max-width: min(320px,72vw); padding: 9px 13px; border: 1px solid rgba(255,255,255,.18); border-radius: 12px; background: rgba(8,10,14,.82); color: #fff; text-align: start; box-shadow: var(--player-shadow); }
.next-episode span { display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; font-size: 11px; font-weight: 700; }
.next-episode b { display: block; margin-top: 2px; color: #b9c0ca; font-size: 10px; font-weight: 600; }

.loading-overlay, .error-overlay { position: absolute; z-index: 26; inset: 0; display: grid; place-items: center; }
.loading-overlay { align-content: center; gap: 9px; pointer-events: none; background: rgba(0,0,0,.24); }
.loading-overlay strong { font-size: 14px; }
.loading-overlay small { color: var(--player-muted); font-size: 11px; }
.spinner { width: 38px; height: 38px; border: 3px solid rgba(255,255,255,.22); border-top-color: #fff; border-radius: 50%; animation: player-spin .8s linear infinite; }
.error-overlay { background: rgba(0,0,0,.62); }
.error-card { width: min(420px, calc(100vw - 32px)); padding: 26px; border: 1px solid var(--player-line); border-radius: 18px; background: rgba(12,14,18,.96); box-shadow: var(--player-shadow); text-align: center; }
.error-mark { display: grid; place-items: center; width: 44px; height: 44px; margin: 0 auto 12px; border: 1px solid rgba(229,9,20,.45); border-radius: 50%; color: #ff7b82; background: rgba(229,9,20,.12); font-weight: 800; }
.error-card h2 { margin: 0 0 7px; font-size: 20px; }
.error-card p { margin: 0 0 17px; color: var(--player-muted); line-height: 1.7; font-size: 12px; }
.error-actions { justify-content: center; gap: 8px; }
.primary-action, .soft-action { min-height: 42px; padding: 0 15px; border-radius: 10px; font-weight: 700; }
.primary-action { background: #fff; color: #080808; }
.soft-action { border: 1px solid var(--player-line); background: rgba(255,255,255,.08); color: #fff; }

.settings-panel { position: absolute; z-index: 30; inset-inline-end: var(--edge-x); bottom: calc(76px + env(safe-area-inset-bottom)); width: min(310px, calc(100vw - 28px)); max-height: min(60vh, 520px); padding: 7px; overflow: auto; border: 1px solid var(--player-line); border-radius: 15px; background: var(--player-surface); box-shadow: var(--player-shadow); }
.settings-home, .settings-subpanel, .settings-options { display: grid; gap: 2px; }
.settings-home button, .settings-subpanel button { min-height: 42px; padding: 10px 12px; border: 0; border-radius: 9px; background: transparent; color: #fff; display: flex; align-items: center; justify-content: space-between; text-align: start; cursor: pointer; }
.settings-home button:hover, .settings-subpanel button:hover { background: rgba(255,255,255,.08); }
.settings-home b { color: var(--player-muted); font-size: 11px; font-weight: 500; }
.settings-back { justify-content: flex-start !important; border-bottom: 1px solid var(--player-line) !important; border-radius: 0 !important; font-weight: 700; }
.settings-options button.active { background: rgba(255,255,255,.1); }

.drawer { position: absolute; z-index: 34; inset-block: 0; inset-inline-start: 0; width: min(420px, 92vw); padding: max(20px, env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom)); overflow: auto; border-inline-end: 1px solid var(--player-line); background: rgba(8,10,14,.97); box-shadow: var(--player-shadow); transform: translateX(-105%); transition: transform .26s var(--ease); }
[dir="rtl"] .drawer { transform: translateX(105%); border-inline-end: 0; border-inline-start: 1px solid var(--player-line); }
.drawer.open, [dir="rtl"] .drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.drawer-head small { color: #ff666d; font-size: 9px; letter-spacing: 1px; }
.drawer-head h2 { margin: 3px 0 0; font-size: 24px; }
.drawer-note { margin: 0 0 14px; color: var(--player-muted); font-size: 11px; line-height: 1.7; }
.drawer-list, .episode-list { display: grid; gap: 8px; }
.server-item, .episode-item { min-height: 54px; padding: 11px; border: 1px solid rgba(255,255,255,.1); border-radius: 12px; background: rgba(255,255,255,.05); color: #fff; text-align: start; cursor: pointer; }
.server-item.active, .episode-item.active { border-color: rgba(255,255,255,.42); background: rgba(255,255,255,.1); }
.server-item b, .episode-item b { display: block; font-size: 13px; }
.server-item small, .episode-item small { color: #9da4ae; font-size: 10px; }
.drawer-refresh { width: 100%; min-height: 43px; margin-top: 13px; border: 1px solid var(--player-line); border-radius: 10px; background: rgba(255,255,255,.07); color: #fff; }
.season-tabs { display: flex; gap: 6px; overflow: auto; padding-bottom: 9px; }
.season-tabs button { min-height: 36px; padding: 0 11px; border: 1px solid var(--player-line); border-radius: 999px; background: rgba(255,255,255,.06); color: #fff; white-space: nowrap; }
.season-tabs button.active { background: #fff; color: #090909; }
.episode-item { display: grid; grid-template-columns: 76px 1fr auto; align-items: center; gap: 10px; }
.episode-still { aspect-ratio: 16/9; border-radius: 7px; background: #181b20 center/cover no-repeat; }

.ad-overlay, .skip-ad { position: absolute; z-index: 22; bottom: calc(94px + env(safe-area-inset-bottom)); }
.ad-overlay { inset-inline-start: 20px; padding: 8px 10px; border-radius: 8px; background: #fff; color: #111; text-decoration: none; font-size: 10px; }
.ad-overlay button { margin-inline-start: 6px; border: 0; background: transparent; color: #111; }
.skip-ad { inset-inline-end: 20px; padding: 8px 12px; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; background: rgba(0,0,0,.75); color: #fff; }
.mobile-lock { display: none; }
.locked-hint { position: absolute; z-index: 40; inset: 50% auto auto 50%; transform: translate(-50%,-50%); padding: 9px 12px; border-radius: 10px; background: rgba(0,0,0,.78); font-size: 11px; }
.locked-unlock { display: none; position: absolute; z-index: 42; inset-block-start: 50%; inset-inline-end: max(14px, env(safe-area-inset-right)); transform: translateY(-50%); background: rgba(0,0,0,.64); border: 1px solid var(--player-line); }
.player-root.locked .locked-unlock:not(.hidden) { display: inline-grid; }
.player-root.locked .top-bar, .player-root.locked .controls-layer, .player-root.locked .center-controls, .player-root.locked .skip-actions, .player-root.locked .next-episode { display: none; }

.player-root.controls-hidden .top-bar, .player-root.controls-hidden .controls-layer, .player-root.controls-hidden .center-controls, .player-root.controls-hidden .player-shade { opacity: 0; pointer-events: none; }
.player-root.controls-hidden .center-controls { transform: translate(-50%, -46%); }
.player-root.is-blocking .center-controls { opacity: 0; pointer-events: none; }
@keyframes player-spin { to { transform: rotate(360deg); } }
@keyframes preview-shimmer { to { background-position-x: -200%; } }

@media (max-width: 900px) {
  :root { --control-size: 42px; --edge-x: 10px; }
  .top-bar { min-height: 62px; padding-block-start: max(8px, env(safe-area-inset-top)); gap: 7px; }
  .media-heading strong { font-size: 14px; }
  .media-heading span { font-size: 9px; }
  .text-action { width: var(--touch-target); padding: 0; font-size: 0; }
  .center-play { width: 64px; height: 64px; }
  .center-skip { width: 50px; height: 50px; }
  .controls-layer { padding: 38px 8px calc(8px + env(safe-area-inset-bottom)); }
  .timeline-zone { height: 44px; }
  .timeline-hit { min-height: 44px; }
  .desktop-skip, #captionsBtn { display: none; }
  .volume-group input { display: none; }
  .mobile-lock { display: inline-grid; }
  .settings-panel { inset-inline: 8px; bottom: calc(60px + env(safe-area-inset-bottom)); width: auto; border-radius: 16px 16px 8px 8px; }
  .drawer { inset: auto 6px 6px; width: auto; max-height: min(78dvh, 620px); border: 1px solid var(--player-line); border-radius: 18px; transform: translateY(108%); }
  [dir="rtl"] .drawer { transform: translateY(108%); border: 1px solid var(--player-line); }
  .drawer.open, [dir="rtl"] .drawer.open { transform: translateY(0); }
  .skip-actions, .next-episode { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .thumb-preview { width: 142px; }
}

@media (max-width: 560px) {
  .media-heading { max-width: 52vw; }
  .center-controls { gap: 14px; }
  .center-play { width: 60px; height: 60px; }
  .center-skip { width: 46px; height: 46px; }
  #pipBtn { display: none; }
  .time-display { gap: 3px; margin-inline-start: 2px; font-size: 9px; }
  .error-actions { flex-direction: column; }
  .error-actions button { width: 100%; }
}


@media (orientation: portrait) and (max-width: 900px) {
  #pipBtn { display: none; }
  .desktop-skip { display: none; }
  .top-actions { gap: 4px; }
  .secondary-controls { gap: 0; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .top-bar { min-height: 52px; padding-block: max(6px, env(safe-area-inset-top)) 10px; padding-inline-start: max(10px, env(safe-area-inset-left)); padding-inline-end: max(10px, env(safe-area-inset-right)); }
  .controls-layer { padding-top: 26px; padding-inline-start: max(8px, env(safe-area-inset-left)); padding-inline-end: max(8px, env(safe-area-inset-right)); }
  .timeline-zone { height: 44px; }
  .center-play { width: 58px; height: 58px; }
  .drawer { max-height: calc(100dvh - 12px); }
}

@media (hover: none) {
  .icon-button:hover, .text-action:hover { background: transparent; }
  .timeline-zone { height: 44px; }
  .timeline-hit { min-height: 44px; }
  .timeline-track { height: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* Player v5 unified settings surface */
.player-menu-surface { position: absolute; }
.player-menu-surface [role="menuitemradio"][aria-checked="true"] { background: rgba(255,255,255,.11); font-weight: 700; }
@media (max-width: 900px) {
  .player-menu-surface { position: fixed; inset-inline: 0; top: auto; bottom: 0; width: 100%; max-height: min(72dvh, 560px); border-radius: 18px 18px 0 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

/* Player v5 drawer/sheet behavior */
.server-item[aria-current="true"], .episode-item[aria-current="true"] { border-color: rgba(255,255,255,.55); background: rgba(255,255,255,.12); }
.episode-active-mark { font-size: 24px; line-height: 1; color: var(--player-accent); }
@media (max-width: 900px) {
  .drawer { position: fixed; inset-inline: 6px; top: auto; bottom: 0; max-height: min(82dvh, 680px); border-radius: 20px 20px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}

/* Player v5 touch/lock safe-area polish */
@media (orientation: landscape) and (max-height: 560px) {
  .locked-unlock { inset-inline-end: max(18px, env(safe-area-inset-right)); }
}

/* Player v5 non-blocking recovery status */
.player-transient-status { position: absolute; z-index: 28; inset-inline-start: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); padding: 7px 11px; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; background: rgba(0,0,0,.68); color: #fff; font-size: 11px; pointer-events: none; backdrop-filter: blur(8px); }
/* Global typography: keep Cairo consistent across every control and page. */
html,body,button,input,select,textarea{font-family:"Cairo",system-ui,sans-serif!important}

/* Trailer fallback when content servers are unavailable. */
.trailer-fallback{position:absolute;z-index:15;inset:0;background:#000;display:grid;place-items:stretch}.trailer-fallback iframe{width:100%;height:100%;border:0;background:#000}.trailer-fallback-label{position:absolute;z-index:2;inset-block-end:calc(18px + env(safe-area-inset-bottom));inset-inline-start:var(--edge-x);padding:6px 10px;border-radius:999px;background:rgba(0,0,0,.62);border:1px solid rgba(255,255,255,.15);font-size:11px;font-weight:700;pointer-events:none}.player-root.is-trailer-fallback #centerControls,.player-root.is-trailer-fallback #controlsLayer,.player-root.is-trailer-fallback .skip-actions,.player-root.is-trailer-fallback .next-episode{opacity:0;pointer-events:none}.player-root.is-trailer-fallback .player-shade{opacity:0}
