/* Stremio-inspired, centered playback dialog. */
html.sg-player-lock,
html.sg-player-lock body { overflow: hidden !important; }

.sg-player-modal {
  position: fixed;
  inset: 0;
  z-index: 180;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(20px, var(--active-safe-top, 0px)) max(20px, var(--safe-right, 0px)) max(20px, var(--safe-bottom, 0px)) max(20px, var(--safe-left, 0px));
  background: transparent;
  -webkit-backdrop-filter: blur(22px) saturate(1.08);
  backdrop-filter: blur(22px) saturate(1.08);
}
.sg-player-modal.active { display: flex; }

.sg-player-dialog {
  width: min(1440px, calc(100vw - 40px));
  height: min(780px, calc(100vh - 40px));
  max-height: min(780px, calc(100vh - 40px));
  display: grid;
  grid-template-columns: minmax(0, 1.68fr) minmax(320px, .72fr);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px;
  background: rgba(255,255,255,.045);
  /* The overlay already blurs the page; nested filters create extra seams. */
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  box-shadow: 0 36px 110px rgba(0,0,0,.68), inset 0 1px rgba(255,255,255,.04);
  color: #f7f6ff;
  scroll-behavior: auto;
}
html.sg-player-lock { scroll-behavior: auto; }
@supports (height: 100dvh) {
  .sg-player-dialog {
    height: min(780px, calc(100dvh - 40px));
    max-height: min(780px, calc(100dvh - 40px));
  }
}

.sg-player-main,
.sg-player-side { min-width: 0; min-height: 0; }
.sg-player-main { overflow-y: auto; padding: 22px; overscroll-behavior: contain; }
.sg-player-side {
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(255,255,255,.09);
  background: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.sg-player-topbar { display: flex; flex: 0 0 auto; align-items: center; gap: 14px; margin-bottom: 16px; }
.sg-player-mobile-topbar { display: none; }
.sg-player-heading { min-width: 0; flex: 1; }
.sg-player-title {
  margin: 0;
  overflow: hidden;
  color: #fff;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(19px, 2vw, 27px);
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -.025em;
}
.sg-player-close {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.09);
  color: #fff;
  font: 600 23px/1 system-ui, sans-serif;
  cursor: pointer;
  transition: background-color 140ms ease, transform 140ms ease;
}
.sg-player-close:hover { background: rgba(255,255,255,.15); }
.sg-player-close:active { transform: scale(.95); }

.sg-player-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 15px;
  background: #000;
  box-shadow: 0 18px 48px rgba(0,0,0,.32);
}
.sg-player-stage iframe,
.sg-player-stage .sg-player-dplayer { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.sg-player-stage iframe { display: none; background: #000; }
.sg-player-dplayer { display: none; }
.sg-player-stage .dplayer { width: 100%; height: 100%; }
.sg-player-modal.sg-player-ios-native .dplayer-controller,
.sg-player-modal.sg-player-ios-native .dplayer-mobile-play { display: none !important; }
.sg-player-loading,
.sg-player-error {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 13px;
  padding: 24px;
  text-align: center;
  color: rgba(247,246,255,.84);
  background: rgba(255,255,255,.035);
}
.sg-player-error { color: #ffd8e1; }
.sg-player-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,.17);
  border-top-color: rgba(255,255,255,.82);
  border-radius: 50%;
  animation: sgPlayerSpin .8s linear infinite;
}
@keyframes sgPlayerSpin { to { transform: rotate(360deg); } }

.sg-player-toolbar {
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 13px;
}
.sg-player-toolbar button,
.sg-player-pill,
.sg-player-episode,
.sg-player-source-card,
.sg-player-captcha-submit,
.sg-player-retry,
.sg-player-log-copy,
.sg-player-log-clear {
  border: 0;
  background: rgba(255,255,255,.09);
  color: #f4f2ff;
  font: inherit;
  cursor: pointer;
  transition: background-color 140ms ease, transform 140ms ease;
}
.sg-player-toolbar button {
  min-height: 42px;
  padding: 0 17px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 730;
  white-space: nowrap;
}
.sg-player-toolbar button:disabled { opacity: .38; cursor: default; }
.sg-player-toolbar button:not(:disabled):hover,
.sg-player-source-card:hover,
.sg-player-pill:hover,
.sg-player-episode:hover,
.sg-player-retry:hover,
.sg-player-captcha-submit:hover,
.sg-player-log-copy:hover,
.sg-player-log-clear:hover {
  background-color: rgba(255,255,255,.15);
}
.sg-player-toolbar button:active:not(:disabled),
.sg-player-pill:active,
.sg-player-episode:active,
.sg-player-source-card:active { transform: scale(.97); }
.sg-player-current {
  min-width: 0;
  overflow: hidden;
  color: rgba(243,241,255,.78);
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 650;
}

.sg-player-section { padding: 17px 18px 0; }
.sg-player-section:last-child { padding-bottom: 18px; }
.sg-player-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 11px; }
.sg-player-section-title { color: #fbfaff; font-size: 13px; font-weight: 760; }
.sg-player-section-note { color: rgba(232,229,255,.48); font-size: 11px; }
.sg-player-source-group { margin: 0 0 10px; border: 1px solid rgba(255,255,255,.08); border-radius: 13px; background: rgba(255,255,255,.035); overflow: hidden; }
.sg-player-source-group > summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px; cursor: pointer; list-style: none; user-select: none; }
.sg-player-source-group > summary::-webkit-details-marker { display: none; }
.sg-player-source-group > summary::after { content: "›"; flex: 0 0 auto; color: rgba(255,255,255,.65); font-size: 19px; line-height: 1; transform: rotate(90deg); transition: transform 150ms ease; }
.sg-player-source-group[open] > summary::after { transform: rotate(-90deg); }
.sg-player-source-group[open] > summary { border-bottom: 1px solid rgba(255,255,255,.07); }
.sg-player-group-body { padding: 10px; }
.sg-player-warning { margin: 0 2px 9px; color: rgba(255,255,255,.48); font-size: 10px; }
.sg-player-scroll { min-height: 0; overflow: auto; padding-right: 4px; scrollbar-width: thin; }
.sg-player-sources { display: grid; grid-template-columns: 1fr; gap: 8px; }
.sg-player-collapsed-sources { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 0 0 10px; }
.sg-player-normal-group[open] + .sg-player-collapsed-sources { display: none; }
.sg-player-official,
.sg-player-parser { display: flex; flex-wrap: wrap; gap: 8px; }
.sg-player-official-wrap[hidden] { display: none; }
.sg-player-parser-wrap[hidden] { display: none; }
.sg-player-active-lines-wrap[hidden] { display: none; }
.sg-player-source-card {
  width: 100%;
  min-height: 51px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  text-align: left;
}
.sg-player-source-main { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; gap: 4px; }
.sg-player-source-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sg-player-source-name { color: #f9f8ff; font-size: 13px; font-weight: 740; }
.sg-player-health { display: inline-flex; align-items: center; gap: 5px; color: rgba(232,229,255,.52); font-size: 10px; line-height: 1; white-space: nowrap; }
.sg-player-health-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: #9ca3af; box-shadow: 0 0 6px currentColor; }
.sg-player-health-online { color: #53df91; }
.sg-player-health-online .sg-player-health-dot { background: #35db80; }
.sg-player-health-offline { color: #ff6b76; }
.sg-player-health-offline .sg-player-health-dot { background: #ff4d5e; }
.sg-player-health-checking { color: #b9acd9; }
.sg-player-health-checking .sg-player-health-dot { background: #a78bfa; animation: sg-health-pulse 1.2s ease-in-out infinite; }
@keyframes sg-health-pulse { 50% { opacity: .35; } }
.sg-player-source-status { color: rgba(232,229,255,.46); font-size: 11px; white-space: nowrap; }
.sg-player-source-card.active,
.sg-player-pill.active,
.sg-player-episode.active {
  border: 1px solid rgba(165,243,252,.82);
  background: linear-gradient(135deg,rgba(61,145,160,.32),rgba(82,127,164,.28));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
  color: #fff;
  font-weight: 800;
}
.sg-player-source-card.active .sg-player-source-status { color: #fff; font-weight: 800; }

.sg-player-pills { display: flex; gap: 8px; overflow-x: auto; padding: 0 2px 5px; scrollbar-width: thin; }
.sg-player-pill {
  flex: 0 0 auto;
  min-height: 35px;
  padding: 0 14px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 680;
  white-space: nowrap;
}
.sg-player-episodes {
  display: grid;
  grid-template-columns: repeat(var(--sg-episode-cols, 4), minmax(0,1fr));
  gap: 8px;
  max-height: none;
  overflow: visible;
  padding: 2px 2px 5px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.sg-player-episodes::-webkit-scrollbar { display: none; width: 0; height: 0; }
.sg-player-episode {
  min-width: 0;
  min-height: 38px;
  overflow: hidden;
  padding: 0 8px;
  border-radius: 12px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 650;
}

.sg-player-side-scroll { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; -ms-overflow-style: none; }
.sg-player-side-scroll::-webkit-scrollbar,
.sg-player-dialog::-webkit-scrollbar { display: none; width: 0; height: 0; }
.sg-player-dialog { scrollbar-width: none; -ms-overflow-style: none; }
.sg-player-empty { padding: 18px 12px; color: rgba(232,229,255,.51); font-size: 12px; text-align: center; }
.sg-player-log-section { padding-bottom: 16px; }
.sg-player-log-panel { border: 1px solid rgba(255,255,255,.08); border-radius: 13px; background: rgba(255,255,255,.035); overflow: hidden; }
.sg-player-log-panel > summary { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px; cursor: pointer; list-style: none; }
.sg-player-log-panel > summary::-webkit-details-marker { display: none; }
.sg-player-log-body { padding: 10px; border-top: 1px solid rgba(255,255,255,.07); }
.sg-player-log-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.sg-player-log-copy,.sg-player-log-clear { min-height: 34px; padding: 0 12px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.sg-player-log-output { max-height: 260px; overflow: auto; margin: 0; padding: 10px; border-radius: 9px; background: rgba(5,8,15,.72); color: rgba(229,236,255,.78); font: 10px/1.55 ui-monospace,SFMono-Regular,Consolas,monospace; white-space: pre-wrap; word-break: break-all; user-select: text; -webkit-user-select: text; }
.sg-player-retry { min-height: 40px; padding: 0 17px; border-radius: 999px; font: 680 13px/1 system-ui,sans-serif; }
.sg-player-captcha { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 9px; max-width: 420px; }
.sg-player-captcha input {
  width: 110px;
  height: 40px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  background: rgba(255,255,255,.07);
  color: #fff;
  padding: 0 13px;
  outline: 0;
}
.sg-player-captcha-submit { min-height: 40px; padding: 0 16px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.sg-player-toolbar button:focus-visible,
.sg-player-close:focus-visible,
.sg-player-source-card:focus-visible,
.sg-player-pill:focus-visible,
.sg-player-episode:focus-visible,
.sg-player-captcha input:focus-visible,
.sg-player-captcha-submit:focus-visible,
.sg-player-retry:focus-visible,
.sg-player-log-copy:focus-visible,
.sg-player-log-clear:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

@media (max-width: 760px) {
  .sg-player-modal {
    align-items: stretch;
    padding: 0;
    overflow: hidden;
    background: rgba(9,13,23,.97);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .sg-player-dialog {
    width: 100%;
    height: var(--fm-web-height, 100vh);
    max-height: none;
    display: block;
    overflow-y: auto;
    border: 0;
    border-radius: 0;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    overflow-anchor: none;
  }
  .sg-player-main,
  .sg-player-side,
  .sg-player-stage,
  .sg-player-side-scroll { overflow-anchor: none; }
  .sg-player-main { overflow: visible; padding: max(14px, var(--active-safe-top, 0px)) 14px 12px; }
  .sg-player-side {
    border-top: 1px solid rgba(255,255,255,.09);
    border-left: 0;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .sg-player-side-scroll { display: block; overflow: visible; }
  .sg-player-episodes { max-height: none; }
}
@media (max-width: 520px) {
  .sg-player-main { padding-right: 10px; padding-left: 10px; }
  .sg-player-topbar { margin: 0 3px 11px; }
  .sg-player-title { font-size: 19px; }
  .sg-player-close { width: 38px; height: 38px; }
  .sg-player-stage { border-radius: 11px; }
  .sg-player-toolbar { gap: 6px; }
  .sg-player-toolbar button { min-height: 38px; padding: 0 11px; font-size: 12px; }
  .sg-player-current { font-size: 12px; }
  .sg-player-section { padding: 14px 12px 0; }
  .sg-player-section:last-child { padding-bottom: calc(18px + var(--safe-bottom, 0px)); }
  .sg-player-sources { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .sg-player-source-card { min-height: 48px; padding: 8px 9px; }
  .sg-player-source-status { display: none; }
  .sg-player-episodes { grid-template-columns: repeat(var(--sg-episode-cols, 4), minmax(0,1fr)); }
  .sg-player-episode {
    min-height: 42px;
    height: 42px;
    padding: 0 8px;
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
  }
}
@media (max-width: 360px) { .sg-player-sources { grid-template-columns: 1fr; } }

/* Full viewport playback: video at left, playback controls at right. */
.sg-player-modal { padding: 0; }
.sg-player-dialog {
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  grid-template-columns: minmax(0, 4fr) minmax(260px, 1fr);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.sg-player-main { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; padding: 0; overflow: hidden; }
.sg-player-stage { flex: 1 1 auto; width: 100%; height: 100%; max-height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; box-shadow: none; }
.sg-player-stage video,
.sg-player-stage .dplayer-video-wrap video,
.sg-player-stage .dplayer video {
  object-fit: contain !important;
  object-position: center center !important;
}
.sg-player-side { overflow: hidden; }
.sg-player-topbar { flex: 0 0 auto; margin: 0; padding: 18px 14px 12px; border-bottom: 1px solid rgba(255,255,255,.09); }
.sg-player-title { font-size: 18px; }
.sg-player-close { width: 38px; height: 38px; }
.sg-player-toolbar { grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 8px; margin: 0; padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,.09); }
.sg-player-current { grid-column: 1 / -1; text-align: left; }
.sg-player-toolbar button { min-width: 0; padding: 0 8px; border-radius: 12px; }
@media (max-width: 760px) {
  .sg-player-dialog { display: block; height: 100vh; max-height: 100vh; overflow-y: auto; }
  .sg-player-main { height: auto; min-height: 0; aspect-ratio: auto; padding: 0; }
  .sg-player-mobile-topbar { display: flex; min-height: 62px; margin: 0; padding: max(12px, var(--active-safe-top, 0px)) 12px 10px; border-bottom: 1px solid rgba(255,255,255,.09); }
  .sg-player-desktop-topbar { display: none; }
  .sg-player-stage { flex: 0 0 auto; width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: 0; }
  .sg-player-side { display: block; min-height: calc(100vh - 56.25vw); overflow: visible; }
  .sg-player-side-scroll { min-height: auto; height: auto; flex: none; overflow: visible; }
  .sg-player-close,
  .sg-player-toolbar button,
  .sg-player-source-group > summary,
  .sg-player-source-card,
  .sg-player-pill,
  .sg-player-episode { touch-action: manipulation; }
}
@supports (height: 100dvh) {
  .sg-player-dialog { height: 100dvh; max-height: 100dvh; }
}

/* Recommendation-style short-drama feed: one full-screen item with explicit fallbacks for swipe. */
.sg-player-modal.sg-player-short-feed {
  padding: 0;
  align-items: stretch;
  justify-content: stretch;
  background: #000;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.sg-player-modal.sg-player-short-feed .sg-player-dialog {
  position: relative;
  display: block;
  width: 100vw;
  height: 100vh;
  max-height: none;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #000;
}
.sg-player-modal.sg-player-short-feed .sg-player-main {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
  padding: 0;
  overflow: hidden;
  background: #000;
}
.sg-player-modal.sg-player-short-feed .sg-player-mobile-topbar {
  position: absolute;
  z-index: 7;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  min-height: 64px;
  margin: 0;
  padding: max(12px, var(--active-safe-top, 0px)) 14px 10px;
  border: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.65), transparent);
}
.sg-player-modal.sg-player-short-feed .sg-player-mobile-topbar .sg-player-title { font-size: 16px; }
.sg-player-modal.sg-player-short-feed .sg-player-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: none;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  background: #000;
  box-shadow: none;
  touch-action: pan-y;
}
.sg-player-modal.sg-player-short-feed .sg-player-stage video,
.sg-player-modal.sg-player-short-feed .sg-player-stage .dplayer-video-wrap video,
.sg-player-modal.sg-player-short-feed .sg-player-stage .dplayer video {
  object-fit: cover !important;
  object-position: center center !important;
}
.sg-player-short-feed-swipezone {
  position: absolute;
  z-index: 5;
  top: 18%;
  bottom: 24%;
  left: 0;
  width: 22px;
  touch-action: pan-y;
  background: transparent;
}
.sg-player-short-feed-hud {
  position: absolute;
  z-index: 6;
  right: 14px;
  bottom: max(18px, var(--safe-bottom, 0px));
  left: 14px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  color: #fff;
  pointer-events: none;
  text-shadow: 0 1px 5px rgba(0,0,0,.9);
}
.sg-player-short-feed-hud[hidden] { display: none !important; }
.sg-player-short-feed-copy { display: flex; flex-direction: column; gap: 5px; max-width: min(720px, 100%); }
.sg-player-short-feed-title { font-size: 17px; line-height: 1.45; font-weight: 750; }
.sg-player-short-feed-count,
.sg-player-short-feed-hint { color: rgba(255,255,255,.78); font-size: 12px; }
.sg-player-short-feed-controls { display: flex; gap: 9px; pointer-events: auto; }
.sg-player-short-feed-controls button {
  min-width: 80px;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid rgba(255,255,255,.26);
  border-radius: 999px;
  background: rgba(18,18,20,.62);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  backdrop-filter: blur(14px);
  cursor: pointer;
}
.sg-player-short-feed-controls button:disabled { opacity: .42; cursor: default; }
.sg-player-short-feed-hint { align-self: flex-end; }
.sg-player-modal.sg-player-short-feed .sg-player-side { display: none; }
.sg-player-feed-close-episodes { display: none; }
.sg-player-modal.sg-player-short-feed.sg-player-feed-show-episodes .sg-player-side {
  position: absolute;
  z-index: 8;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  width: min(560px, 100%);
  height: min(72vh, 680px);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.15);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  background: rgba(19,19,22,.97);
  box-shadow: 0 -20px 60px rgba(0,0,0,.4);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
}
.sg-player-modal.sg-player-short-feed.sg-player-feed-show-episodes .sg-player-feed-close-episodes {
  display: block;
  flex: 0 0 auto;
  align-self: flex-end;
  margin: 12px 14px 0;
  padding: 8px 13px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: rgba(255,255,255,.09);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.sg-player-modal.sg-player-short-feed.sg-player-feed-show-episodes .sg-player-side-scroll { min-height: 0; flex: 1 1 auto; overflow-y: auto; }
.sg-player-modal.sg-player-short-feed.sg-player-feed-show-episodes .sg-player-episodes { max-height: 42vh; overflow: auto; }
@supports (height: 100dvh) {
  .sg-player-modal.sg-player-short-feed .sg-player-dialog { height: 100dvh; }
  .sg-player-modal.sg-player-short-feed .sg-player-main { height: 100dvh; min-height: 100dvh; }
}
