/* ═══════════════════════════════════════════════════════════════════════
   CYNEFLIX v218 — EPISODE CENTER + FEATURES
   ---------------------------------------------------------------------
   1. Episode selector is ALWAYS reachable (the v217 specificity bug that
      hid #ep-section on every desktop width is fixed here).
   2. New "Episode Center" drawer (right panel / bottom sheet).
   3. Season pills, watched state, progress, filters.
   4. Source-bar Episodes + Subtitle controls.
   5. Resume chip, share sheet, calendar, continue-watching labels.
   Palette is untouched — only existing CSS variables are used.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── 1. EPISODE SECTION — ALWAYS VISIBLE ─────────────────────────── */
/* style.css ships `#ep-section{display:none!important}` for >=900px and a
   higher-specificity `#watch-layout.has-sidebar #ep-section` rule. v218
   drops the `has-sidebar` class and overrides both with the same-or-higher
   specificity so the list is never hidden again. */
#ep-section {
  display: block !important;
  padding: 16px var(--px) 12px !important;
}
#watch-layout.has-sidebar #ep-section {
  display: block !important;
}
#ep-sidebar { display: none !important; }

/* Sticky section header so the list header stays visible while scrolling */
.ep-header {
  position: sticky;
  top: calc(var(--nav-h) + 54px);
  z-index: 20;
  margin: 0 0 10px;
  padding: 8px 0;
  background: linear-gradient(180deg, var(--bg) 68%, rgba(8, 8, 8, 0));
}
.ep-heading { letter-spacing: .2px; }

/* ── 2. SEASON PILLS ─────────────────────────────────────────────── */
.ep-seasons {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 2px 0 10px;
  width: 100%;
}
.ep-seasons::-webkit-scrollbar { display: none; }
.ep-season-pill {
  flex: 0 0 auto;
  background: rgba(255, 255, 255, .07);
  border: 1.5px solid transparent;
  color: rgba(255, 255, 255, .72);
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .3px;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s, transform .2s;
  white-space: nowrap;
}
.ep-season-pill:hover { background: rgba(255, 255, 255, .13); color: #fff; }
.ep-season-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px rgba(229, 9, 20, .32);
}
.ep-season-pill .ep-season-count {
  opacity: .65;
  font-weight: 600;
  margin-left: 6px;
  font-size: 11px;
}
.ep-season-pill.active .ep-season-count { opacity: .85; }

/* ── 3. EPISODE CARDS (watched state + progress + next-up) ───────── */
.ep-card { position: relative; }
.ep-card .ep-play-overlay { transition: opacity .2s, transform .2s; }

.ep-watched {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(221,60,68, .92);
  color: #04140a;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .5);
  z-index: 3;
}
.ep-card.is-watched .ep-watched { display: flex; }

.ep-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, .16);
  border-radius: 0 0 12px 12px;
  overflow: hidden;
  z-index: 3;
}
.ep-progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--glow);
}

.ep-next-tag {
  display: inline-block;
  background: rgba(229, 9, 20, .16);
  border: 1px solid rgba(229, 9, 20, .5);
  color: #ff8a90;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .8px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 5px;
  margin-left: 7px;
  vertical-align: middle;
}

/* Always visible (touch devices have no hover) — dimmed until hovered */
.ep-mark-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1.5px solid rgba(255, 255, 255, .14);
  background: rgba(255, 255, 255, .04);
  color: rgba(255, 255, 255, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .18s;
  align-self: center;
  opacity: .4;
}
.ep-card:hover .ep-mark-btn,
.ep-card:focus-within .ep-mark-btn { opacity: 1; }
.ep-mark-btn:hover { border-color: var(--green); color: var(--green); }
.ep-mark-btn.on { border-color: var(--green); color: var(--green); background: rgba(221,60,68, .12); }

/* Episode filters */
.ep-filters { display: flex; gap: 6px; flex: 0 0 auto; flex-wrap: wrap; }
.ep-filter {
  background: rgba(255, 255, 255, .05);
  border: 1.5px solid transparent;
  color: rgba(255, 255, 255, .6);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all .18s;
  white-space: nowrap;
}
.ep-filter:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.ep-filter.active {
  background: rgba(229, 9, 20, .16);
  border-color: rgba(229, 9, 20, .55);
  color: #ffb3b6;
}

/* ── 4. EPISODE CENTER DRAWER ────────────────────────────────────── */
.ep-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .66);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .28s ease, visibility .28s;
  z-index: 1400;
}
.ep-drawer-backdrop.open { opacity: 1; visibility: visible; }

.ep-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(430px, 100vw);
  background: #0d0d0d;
  border-left: 1px solid rgba(255, 255, 255, .08);
  box-shadow: -24px 0 60px rgba(0, 0, 0, .6);
  transform: translateX(102%);
  transition: transform .32s cubic-bezier(.22, 1, .36, 1);
  z-index: 1401;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}
.ep-drawer.open { transform: translateX(0); pointer-events: auto; }

.ep-drawer-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
  flex: 0 0 auto;
}
.ep-drawer-kicker {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--accent);
}
.ep-drawer-title {
  display: block;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  margin-top: 2px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ep-drawer-close {
  margin-left: auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .05);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.ep-drawer-close:hover { background: var(--accent); border-color: var(--accent); }

.ep-drawer-seasons { flex: 0 0 auto; padding: 12px 14px 4px; }
.ep-drawer-tools {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px 14px 12px;
  flex: 0 0 auto;
}
.ep-drawer-search { width: 100%; }
.ep-drawer-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 12px 26px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .12) transparent;
}
.ep-drawer-list::-webkit-scrollbar { width: 4px; }
.ep-drawer-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); border-radius: 4px; }
.ep-drawer-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 26px 10px;
}

/* Bottom-sheet variant on small screens */
@media (max-width: 640px) {
  .ep-drawer {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 86vh;
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, .1);
    border-radius: 18px 18px 0 0;
    transform: translateY(102%);
  }
  .ep-drawer.open { transform: translateY(0); }
  .ep-drawer-head { padding-top: 18px; }
  .ep-drawer-head::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    border-radius: 3px;
    background: rgba(255, 255, 255, .2);
  }
  .ep-drawer-list { padding-bottom: 34px; }
}

/* ── 5. SOURCE BAR — EPISODES + SUBTITLE CONTROLS ───────────────── */
.srv-bar-right { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; position: relative; }

.srv-bar-ep {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .05);
  color: rgba(255, 255, 255, .85);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .3px;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.srv-bar-ep:hover { background: rgba(229, 9, 20, .16); border-color: rgba(229, 9, 20, .5); color: #fff; }
.srv-bar-ep .srv-bar-ep-label { color: #fff; }
.srv-bar-ep .srv-bar-ep-sub { color: rgba(255, 255, 255, .55); font-weight: 600; }

.srv-bar-sub {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .05);
  color: rgba(255, 255, 255, .75);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .6px;
  cursor: pointer;
  transition: all .2s;
}
.srv-bar-sub:hover { color: #fff; border-color: rgba(255, 255, 255, .28); }
.srv-bar-sub.on { color: #fff; border-color: rgba(229, 9, 20, .55); background: rgba(229, 9, 20, .16); }

.srv-sub-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 168px;
  background: #151515;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .6);
  padding: 6px;
  z-index: 1300;
  display: none;
}
.srv-sub-menu.open { display: block; animation: v218Pop .18s ease both; }
.srv-sub-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 0;
  color: rgba(255, 255, 255, .78);
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .16s;
}
.srv-sub-item:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.srv-sub-item.on { color: #fff; }
.srv-sub-item .srv-sub-check { margin-left: auto; color: var(--accent); font-weight: 900; }

@keyframes v218Pop {
  from { opacity: 0; transform: translateY(-6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── 6. RESUME CHIP (player caption) ─────────────────────────────── */
.player-cap-resume {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  pointer-events: auto;
}
.player-cap-resume.show { display: inline-flex; }
.resume-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(10, 10, 10, .82);
  border: 1px solid rgba(255, 255, 255, .14);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all .2s;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.resume-chip:hover { border-color: var(--accent); }
.resume-chip b { color: #ff8a90; font-weight: 800; }
.resume-chip.startover {
  background: transparent;
  border-color: rgba(255, 255, 255, .18);
  color: rgba(255, 255, 255, .7);
  font-size: 11.5px;
}
.resume-chip.startover:hover { color: #fff; border-color: rgba(255, 255, 255, .4); }

/* Clickable "you're watching" caption → opens the Episode Center */
.player-cap { pointer-events: auto; }
.player-cap-title { cursor: pointer; }
.player-cap-title:hover { color: #fff; }

/* ── 7. SHARE SHEET ──────────────────────────────────────────────── */
.v218-modal {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.v218-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.v218-modal-box {
  position: relative;
  width: min(420px, 100%);
  background: #141414;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7);
  padding: 20px;
  animation: v218Pop .22s ease both;
}
.v218-modal-title {
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  margin: 0 0 4px;
}
.v218-modal-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.v218-share-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.v218-share-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, .09);
  background: rgba(255, 255, 255, .04);
  color: rgba(255, 255, 255, .8);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  text-decoration: none;
}
.v218-share-btn:hover { transform: translateY(-2px); border-color: rgba(229, 9, 20, .5); color: #fff; }
.v218-share-ico {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .07);
}
.v218-copy-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.v218-copy-input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, .45);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  color: rgba(255, 255, 255, .8);
  font-size: 12px;
  padding: 10px 12px;
}
.v218-btn {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 800;
  padding: 10px 16px;
  cursor: pointer;
  transition: filter .2s, transform .2s;
}
.v218-btn:hover { filter: brightness(1.12); }
.v218-btn.ghost {
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .14);
}

/* ── 8. WATCH-PAGE ACTION BUTTONS (v218 extras) ──────────────────── */
.btn-episodes {
  background: linear-gradient(135deg, rgba(229, 9, 20, .95), rgba(229, 9, 20, .75));
  border-color: rgba(229, 9, 20, .7) !important;
  color: #fff !important;
  font-weight: 800;
}
.btn-episodes:hover { box-shadow: 0 8px 24px rgba(229, 9, 20, .35); }
.btn-calendar { color: #fff !important; }

/* Rail: quick episode jump button */
.ws-ep-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  margin: 4px 0 2px;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid rgba(229, 9, 20, .34);
  background: rgba(229, 9, 20, .1);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: all .2s;
  text-align: left;
}
.ws-ep-btn:hover { background: rgba(229, 9, 20, .2); border-color: rgba(229, 9, 20, .6); }
.ws-ep-btn .ws-ep-btn-sub {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 700;
  color: #ff8a90;
}

/* ── 9. CONTINUE WATCHING EPISODE LABEL ──────────────────────────── */
.cw-ep-label {
  display: inline-block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
  color: #ff8a90;
  letter-spacing: .3px;
}

/* ── 10. TOAST (shared) ──────────────────────────────────────────── */
.v218-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 18px);
  background: rgba(18, 18, 18, .96);
  border: 1px solid rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 11px 18px;
  border-radius: 12px;
  z-index: 1600;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .6);
  max-width: min(420px, calc(100vw - 32px));
  text-align: center;
}
.v218-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── 11. RESPONSIVE TWEAKS ───────────────────────────────────────── */
@media (max-width: 900px) {
  .srv-bar-ep .srv-bar-ep-label { display: none; }
  .srv-bar-ep { padding: 0 10px; }
}
@media (max-width: 560px) {
  .ep-header { top: calc(var(--nav-h) + 50px); }
  .ep-filters { width: 100%; }
  .ep-filter { flex: 1 1 0; text-align: center; }
  .v218-share-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 380px) {
  .srv-bar-badge--shield { display: none; }
}

/* Reduced motion — respect the OS setting */
@media (prefers-reduced-motion: reduce) {
  .ep-drawer, .ep-drawer-backdrop, .v218-modal-box { transition: none !important; }
}

/* ── 12. "EPISODE GUIDE" BUTTON (inline section) ──────────────────── */
.ep-open-drawer {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .13);
  color: rgba(255, 255, 255, .85);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .3px;
  padding: 7px 13px;
  border-radius: 9px;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.ep-open-drawer:hover {
  background: rgba(229, 9, 20, .16);
  border-color: rgba(229, 9, 20, .5);
  color: #fff;
}
@media (max-width: 420px) {
  .ep-open-drawer { padding: 7px 10px; font-size: 11px; }
}

/* ── 13. "MARK ALL" FILTER CHIP ───────────────────────────────────── */
.ep-mark-all {
  color: #d8d8d8;
  border-color: rgba(221,60,68, .3);
  background: rgba(221,60,68, .08);
  margin-left: auto;
}
.ep-mark-all:hover { background: rgba(221,60,68, .18); color: #ececec; }
