:root {
  --bg: #0b0f17;
  --bg2: #111827;
  --bg3: #161f30;
  --card: #151c2e;
  --card2: #1b2438;
  --line: #253049;
  --line2: #33406a;
  --text: #e9eefb;
  --muted: #97a3bf;
  --muted2: #6b7894;
  --accent: #7c5cff;
  --accent2: #ff5c8a;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --header-h: 60px;
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
}

html[data-theme='light'] {
  --bg: #f4f6fb;
  --bg2: #ffffff;
  --bg3: #eef1f8;
  --card: #ffffff;
  --card2: #f2f4fa;
  --line: #e1e6f0;
  --line2: #ccd4e6;
  --text: #16203a;
  --muted: #5a6885;
  --muted2: #8a96ad;
  --shadow: 0 8px 24px rgba(30, 40, 70, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  transition: background .25s, color .25s;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Header ---------- */
.header {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  height: var(--header-h);
}
.header-inner {
  max-width: 1440px; margin: 0 auto; padding: 0 16px;
  height: 100%; display: flex; align-items: center; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 20px; letter-spacing: -.3px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center; color: #fff; font-size: 17px; font-weight: 900;
}
.brand span b { background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.nav { display: flex; align-items: center; gap: 4px; margin-left: 6px; }
.nav a {
  padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 14px;
  color: var(--muted); transition: .15s;
}
.nav a:hover { color: var(--text); background: var(--bg3); }
.nav a.active { color: var(--text); background: var(--bg3); }

.header-search { flex: 1; max-width: 460px; margin-left: auto; position: relative; }
.header-search input {
  width: 100%; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg3); color: var(--text); padding: 0 40px 0 14px; font-size: 14px; outline: none;
  transition: border-color .15s;
}
.header-search input:focus { border-color: var(--accent); }
.header-search .icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted2); font-size: 15px; pointer-events: none; }

.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg3); color: var(--text); display: grid; place-items: center; font-size: 16px;
  transition: .15s;
}
.icon-btn:hover { border-color: var(--line2); }

/* ---------- Layout ---------- */
.container { max-width: 1440px; margin: 0 auto; padding: 22px 16px 60px; }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 20px; padding: 40px 32px; margin-bottom: 26px;
  background: linear-gradient(120deg, rgba(124, 92, 255, .25), rgba(255, 92, 138, .2)), var(--bg3);
  border: 1px solid var(--line);
}
.hero h1 { font-size: clamp(24px, 4vw, 40px); font-weight: 900; letter-spacing: -.5px; margin-bottom: 8px; }
.hero p { color: var(--muted); max-width: 640px; font-size: 15px; }
.hero .badges { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

.badge {
  padding: 5px 12px; border-radius: 99px; font-size: 12.5px; font-weight: 700;
  background: var(--card2); color: var(--text); border: 1px solid var(--line);
  display: inline-flex; align-items: center; gap: 6px;
}
.badge.green { color: var(--green); }
.badge.pink { color: var(--accent2); }
.badge.purple { color: var(--accent); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Section headers ---------- */
.section-head { display: flex; align-items: center; gap: 10px; margin: 28px 0 14px; }
.section-head h2 { font-size: 18px; font-weight: 800; }
.section-head .bar { width: 4px; height: 20px; border-radius: 4px; background: linear-gradient(var(--accent), var(--accent2)); }
.section-head .more { margin-left: auto; color: var(--accent); font-size: 13px; font-weight: 700; }

/* ---------- Platform grid ---------- */
.plat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.plat-card {
  display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); transition: .15s; position: relative;
}
.plat-card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow); }
.plat-card.disabled { opacity: .55; }
.plat-logo {
  width: 44px; height: 44px; border-radius: 12px; flex: none; object-fit: cover;
  background: var(--card2); border: 1px solid var(--line);
}
.plat-logo.avatar { display: grid; place-items: center; font-weight: 800; font-size: 18px; color: var(--accent2); }
.plat-card .info { min-width: 0; }
.plat-card .name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plat-card .sub { font-size: 11.5px; color: var(--muted2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plat-card .st {
  position: absolute; top: 10px; right: 10px; font-size: 10px; font-weight: 800; padding: 2px 8px; border-radius: 99px;
}
.st.active { background: rgba(52, 211, 153, .15); color: var(--green); }
.st.maintenance, .st.coming { background: rgba(251, 191, 36, .15); color: var(--amber); }

/* ---------- Home platform picker ---------- */
.plat-row {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 12px; background: var(--bg);
}
.plat-chip {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px;
  border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--muted);
  font-weight: 700; font-size: 13px; transition: .15s; white-space: nowrap;
}
.plat-chip:hover { color: var(--text); border-color: var(--accent); }
.plat-chip.active {
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  color: #fff; border-color: transparent;
}
.plat-chip.off { opacity: .45; cursor: default; }
.plat-chip .plat-logo { width: 26px; height: 26px; border-radius: 8px; font-size: 13px; }
.plat-chip.active .plat-logo.avatar { color: #fff; }

/* ---------- Card grid ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 14px; }
.card-grid.wide { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px 16px; }

.drama-card { cursor: pointer; transition: .15s; }
.drama-card:hover .thumb { transform: scale(1.05); }
.drama-card:hover .title { color: var(--accent2); }
.thumb-wrap { position: relative; border-radius: var(--radius); overflow: hidden; aspect-ratio: 2/3; background: var(--card2); box-shadow: 0 6px 18px rgba(0,0,0,.2); }
.thumb { width: 100%; height: 100%; object-fit: cover; transition: transform .25s; }
.thumb.lazy { opacity: 0; }
.drama-card .title {
  margin-top: 8px; font-size: 13.5px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.drama-card .meta { font-size: 11.5px; color: var(--muted2); margin-top: 2px; }
.drama-card .eps-badge {
  position: absolute; right: 7px; bottom: 7px; font-size: 10.5px; font-weight: 800;
  background: rgba(8, 12, 22, .75); color: #fff; padding: 3px 8px; border-radius: 8px; backdrop-filter: blur(4px);
}
.drama-card .src-tag {
  position: absolute; left: 7px; top: 7px; font-size: 10px; font-weight: 800;
  background: rgba(8, 12, 22, .75); color: #fff; padding: 3px 8px; border-radius: 8px; backdrop-filter: blur(4px);
  max-width: 70%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin: 18px 0 4px; scrollbar-width: none; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.tabs::-webkit-scrollbar { display: none; }
.tabs .tab { touch-action: pan-x; }
.tab {
  flex: none; padding: 9px 18px; border-radius: 99px; font-size: 13.5px; font-weight: 700;
  background: var(--card); color: var(--muted); border: 1px solid var(--line); transition: .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: linear-gradient(120deg, var(--accent), var(--accent2)); color: #fff; border-color: transparent; }

/* ---------- Search ---------- */
.search-bar { display: flex; gap: 10px; margin: 18px 0; }
.search-bar input {
  flex: 1; height: 46px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); padding: 0 18px; font-size: 15px; outline: none;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar button {
  height: 46px; padding: 0 24px; border: none; border-radius: 14px; font-weight: 700; font-size: 14px; color: #fff;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
}
.search-bar button:disabled { opacity: .6; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 20px; }
.chip {
  padding: 7px 14px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: var(--card); border: 1px solid var(--line); color: var(--muted); transition: .15s;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Detail ---------- */
.detail-head { display: flex; gap: 24px; margin-bottom: 26px; }
.detail-poster {
  flex: none; width: 220px; border-radius: var(--radius); overflow: hidden; aspect-ratio: 2/3;
  box-shadow: var(--shadow); background: var(--card2);
}
.detail-info { min-width: 0; display: flex; flex-direction: column; }
.detail-info h1 { font-size: clamp(20px, 3vw, 30px); font-weight: 900; letter-spacing: -.4px; line-height: 1.2; }
.detail-info .tags { display: flex; gap: 7px; flex-wrap: wrap; margin: 12px 0; }
.detail-info .desc { color: var(--muted); font-size: 14px; max-height: 96px; overflow: hidden; position: relative; }
.detail-info .desc.open { max-height: none; }
.detail-info .desc-toggle { color: var(--accent); font-size: 13px; font-weight: 700; cursor: pointer; margin-top: 4px; align-self: flex-start; }
.detail-meta { display: flex; gap: 14px; flex-wrap: wrap; margin: 14px 0; font-size: 13px; color: var(--muted); }
.detail-meta b { color: var(--text); }

.ep-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.ep-btn {
  padding: 12px 10px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-weight: 700; font-size: 13.5px;
  display: flex; align-items: center; justify-content: center; gap: 7px; transition: .15s;
}
.ep-btn:hover { border-color: var(--accent); }

.ep-btn.playing { background: linear-gradient(120deg, var(--accent), var(--accent2)); color: #fff; border-color: transparent; }

/* ---------- Player ---------- */
.player-layout { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
.video-wrap {
  position: relative; width: 100%; aspect-ratio: 16/9; background: #000; border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.video-wrap video { width: 100%; height: 100%; outline: none; }
.video-wrap video::cue {
  background: rgba(0, 0, 0, .72); color: #fff; font-size: clamp(12px, 2.2vmin, 20px); font-weight: 500;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, .8);
}
.sub-overlay {
  position: absolute; z-index: 1; box-sizing: border-box;
  flex-direction: column; align-items: center; justify-content: flex-end;
  text-align: center; pointer-events: none; overflow: hidden;
  padding: 0 6px 6%; line-height: 1.35; color: #fff; font-weight: 500;
}
.sub-overlay .cue {
  background: rgba(0, 0, 0, .72); border-radius: 4px; padding: 1px 7px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, .9); white-space: pre-wrap; word-break: break-word;
}
.sub-overlay br { line-height: 0; }
.video-wrap #video-err {
  position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center;
  padding: 20px; text-align: center; color: #fff; background: rgba(0, 0, 0, .62); font-size: 14px;
}
.player-side { min-width: 0; }
.player-side h3 { font-size: 15px; font-weight: 800; margin: 0 0 10px; }
.ep-rail { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; max-height: 420px; overflow-y: auto; padding-right: 4px; }
.ep-rail .ep-btn { padding: 10px 6px; font-size: 12.5px; }
.watch-title { font-size: 18px; font-weight: 800; margin: 16px 0 4px; }
.watch-sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

/* ---------- Banners ---------- */
.banner-row { display: flex; gap: 12px; overflow-x: auto; padding: 4px 0 10px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.banner-row::-webkit-scrollbar { display: none; }
.banner-card {
  flex: none; width: 320px; height: 150px; border-radius: var(--radius); overflow: hidden; position: relative;
  scroll-snap-align: start; cursor: pointer;
}
.banner-card img { width: 100%; height: 100%; object-fit: cover; }
.banner-card .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 14px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,.85)); color: #fff; font-weight: 700; font-size: 13.5px;
}

/* ---------- States ---------- */
.skeleton { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px 14px; }
.skel {
  border-radius: var(--radius); aspect-ratio: 2/3;
  background: linear-gradient(100deg, var(--card) 40%, var(--card2) 50%, var(--card) 60%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.empty, .error-box, .loading {
  text-align: center; padding: 50px 20px; color: var(--muted); font-size: 15px;
}
.error-box { color: var(--red); }
.error-box .retry {
  margin-top: 14px; padding: 10px 22px; border-radius: 12px; border: none; font-weight: 700;
  background: linear-gradient(120deg, var(--accent), var(--accent2)); color: #fff;
}
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.section-head h2 .plat-logo { width: 28px; height: 28px; font-size: 13px; border-radius: 8px; }

.btn-primary {
  padding: 12px 26px; border-radius: 14px; border: none; font-weight: 800; font-size: 15px; color: #fff;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  box-shadow: 0 8px 20px rgba(124, 92, 255, .35); transition: .15s;
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* ---------- Pager ---------- */
.pager {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  margin: 28px 0 8px; flex-wrap: wrap;
}
.pg-btn {
  padding: 10px 20px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-weight: 700; font-size: 13.5px; transition: .15s;
}
.pg-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pg-btn:disabled { opacity: .4; cursor: default; }
.pg-info { font-size: 13px; color: var(--muted); font-weight: 700; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--line); padding: 26px 16px; text-align: center; color: var(--muted2); font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(80px);
  background: var(--card2); color: var(--text); border: 1px solid var(--line2); border-radius: 14px;
  padding: 12px 20px; font-size: 14px; font-weight: 600; z-index: 200; box-shadow: var(--shadow);
  transition: transform .3s; max-width: 90vw; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- Scroll top ---------- */
.to-top {
  position: fixed; right: 18px; bottom: 20px; width: 44px; height: 44px; border-radius: 14px; z-index: 90;
  border: 1px solid var(--line2); background: var(--card2); color: var(--text); font-size: 17px;
  display: none; box-shadow: var(--shadow);
}
.to-top.show { display: grid; place-items: center; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .player-layout { grid-template-columns: 1fr; }
  .ep-rail { max-height: 260px; }
}

@media (max-width: 720px) {
  :root { --header-h: 56px; }
  .header-inner { padding: 0 12px; gap: 10px; }
  .nav { display: none; }
  .header-search { max-width: none; }
  .brand .logo { width: 30px; height: 30px; font-size: 15px; }
  .brand { font-size: 18px; }
  .container { padding: 16px 12px 60px; }
  .hero { padding: 26px 20px; border-radius: 16px; }
  .hero p { font-size: 13.5px; }
  .plat-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 14px 10px; }
  .card-grid.wide { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .detail-head { flex-direction: column; gap: 16px; }
  .detail-poster { width: 160px; }
  .ep-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
  .banner-card { width: 260px; height: 130px; }
  .video-wrap { aspect-ratio: 16/9; }
}

@media (max-width: 420px) {
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  .ep-grid { grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); }
  .ep-btn { padding: 10px 6px; font-size: 12.5px; }
}
