:root {
  --bg: #0b0b14;
  --bg-2: #12121f;
  --surface: #181826;
  --surface-2: #20202f;
  --surface-3: #2a2a3d;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #ececf4;
  --text-dim: #a0a0b8;
  --text-faint: #6c6c82;
  --accent: #7c5cff;
  --accent-2: #e055a0;
  --accent-glow: rgba(124, 92, 255, 0.45);
  --gold: #f5b94a;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --maxw: 1280px;
  --header-h: 64px;
}

/* ---------- Light theme ---------- */
[data-theme="light"] {
  --bg: #f4f5fa;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --surface-3: #e2e5ef;
  --border: rgba(24, 26, 48, 0.10);
  --border-strong: rgba(24, 26, 48, 0.16);
  --text: #1a1c2e;
  --text-dim: #565a72;
  --text-faint: #8b8fa6;
  --accent-glow: rgba(124, 92, 255, 0.30);
  --shadow: 0 10px 30px rgba(40, 44, 80, 0.14);
}
[data-theme="light"] body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124, 92, 255, 0.10), transparent 60%),
    radial-gradient(900px 500px at 10% 10%, rgba(224, 85, 160, 0.08), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
[data-theme="light"] .topbar { background: rgba(244, 245, 250, 0.82); }
[data-theme="light"] .brand-text {
  background: linear-gradient(92deg, #6b54e6, #d0458f);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
[data-theme="light"] .hero {
  background: linear-gradient(120deg, #ece8ff, #fde8f3 60%, #fff3e8);
}
[data-theme="light"] .hero p { color: var(--text-dim); }
[data-theme="light"] .hero h1 span {
  background: linear-gradient(92deg, #6b54e6, #d0458f);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
[data-theme="light"] .modal-backdrop { background: rgba(60, 64, 90, 0.45); }
[data-theme="light"] .modal-close { background: rgba(255,255,255,.85); }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(124, 92, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 10% 10%, rgba(224, 85, 160, 0.10), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

::selection { background: var(--accent-glow); color: #fff; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(11, 11, 20, 0.82);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 0 rgba(124, 92, 255, 0.08);
}
.topbar-inner {
  max-width: var(--maxw);
  height: var(--header-h);
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.brand-mark { display: grid; place-items: center; }
.brand-text {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(92deg, #b6a3ff, #ff9ed1);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.search-slot {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  justify-content: center;
}
.search {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 6px 6px 6px 14px;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
  background: var(--surface-2);
}
.search-icon { color: var(--text-faint); flex-shrink: 0; }
.search-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 15px;
  height: 36px;
}
.search-input::placeholder { color: var(--text-faint); }
.search-input::-webkit-search-cancel-button { display: none; }
.search-btn {
  flex-shrink: 0;
  border: 0;
  cursor: pointer;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 0 18px;
  height: 36px;
  border-radius: 999px;
  background: linear-gradient(92deg, var(--accent), var(--accent-2));
  transition: filter .2s, transform .1s;
}
.search-btn:hover { filter: brightness(1.1); }
.search-btn:active { transform: scale(0.97); }

.theme-toggle {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: color .2s, background .2s, border-color .2s, transform .15s;
}
.theme-toggle:hover {
  color: var(--text);
  background: var(--surface-3);
  border-color: var(--accent);
}
.theme-toggle:active { transform: scale(0.92); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="light"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: none; }

/* ---------- App ---------- */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px 16px 80px;
  min-height: calc(100vh - var(--header-h));
}
.view { animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 16px;
}
.section-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}
.section-title::before {
  content: "";
  width: 4px; height: 18px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}
.section-sub { color: var(--text-faint); font-size: 13px; }

/* ---------- Quick tags ---------- */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 22px;
}
.tag {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-dim);
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: color .18s, border-color .18s, background .18s, transform .18s, box-shadow .18s;
  white-space: nowrap;
}
.tag:hover {
  color: #fff;
  border-color: var(--accent);
  background: linear-gradient(92deg, rgba(124,92,255,.18), rgba(224,85,160,.18));
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(124, 92, 255, 0.2);
}

/* ---------- Hero banner ---------- */
.hero {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  margin-bottom: 26px;
  min-height: 188px;
  border: 1px solid var(--border);
  background: linear-gradient(120deg, #1a1430, #2a1230 50%, #301a22 100%);
  background-size: 200% 100%;
  animation: heroShift 14s ease-in-out infinite alternate;
}
@keyframes heroShift {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}
.hero::before {
  content: "";
  position: absolute;
  width: 320px; height: 320px;
  border-radius: 50%;
  top: -120px; left: -60px;
  background: radial-gradient(circle, rgba(124,92,255,.55), transparent 70%);
  filter: blur(20px);
  animation: floatA 12s ease-in-out infinite alternate;
}
.hero::after {
  content: "";
  position: absolute;
  width: 300px; height: 300px;
  border-radius: 50%;
  bottom: -140px; right: -40px;
  background: radial-gradient(circle, rgba(224,85,160,.45), transparent 70%);
  filter: blur(24px);
  animation: floatB 15s ease-in-out infinite alternate;
}
@keyframes floatA { from { transform: translate(0,0); } to { transform: translate(40px, 30px); } }
@keyframes floatB { from { transform: translate(0,0); } to { transform: translate(-30px, -24px); } }
.hero-content {
  position: relative;
  z-index: 1;
  padding: 32px 28px;
  max-width: 640px;
}
.hero h1 {
  font-size: clamp(22px, 4.2vw, 32px);
  margin: 0 0 10px;
  font-weight: 800;
  letter-spacing: .5px;
}
.hero h1 span {
  background: linear-gradient(92deg, #c4b6ff, #ff9ed1);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { color: var(--text-dim); margin: 0; font-size: 14px; line-height: 1.65; max-width: 460px; }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 16px;
}
@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 18px; }
}
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 22px; }
}

.card {
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
  text-align: left;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform .2s ease;
}
.card:hover { transform: translateY(-5px); }
.card:active { transform: translateY(-2px); }

.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: box-shadow .25s, border-color .25s;
}
.card:hover .poster {
  border-color: rgba(124, 92, 255, 0.5);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(124, 92, 255, 0.25), 0 0 24px rgba(124, 92, 255, 0.18);
}
.poster img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform .4s ease, opacity .3s;
}
.card:hover .poster img { transform: scale(1.08); }
.poster::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 50%, rgba(0,0,0,.6));
  opacity: .65;
  transition: opacity .25s;
}
.card:hover .poster::after { opacity: 1; }
.poster-play {
  position: absolute;
  inset: 0;
  display: grid; place-items: center;
  opacity: 0;
  transition: opacity .22s, transform .22s;
  transform: scale(.85);
  z-index: 2;
}
.poster-play svg {
  width: 48px; height: 48px;
  filter: drop-shadow(0 4px 14px rgba(0,0,0,.55));
}
.card:hover .poster-play { opacity: 1; transform: scale(1); }

.badge {
  position: absolute;
  top: 8px; left: 8px;
  z-index: 3;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
}
.badge.year { left: auto; right: 8px; }

.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
}
.card-meta {
  font-size: 12px;
  color: var(--text-faint);
  display: flex; align-items: center; gap: 6px;
}
.card-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-faint); }

/* ---------- Skeleton ---------- */
.skeleton-card .poster,
.skel {
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-3) 50%, var(--surface) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
.skeleton-card .poster::after { display: none; }
.skel-line { height: 12px; border-radius: 6px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- States ---------- */
.state {
  text-align: center;
  padding: 70px 20px;
  color: var(--text-dim);
}
.state svg { margin-bottom: 16px; opacity: .85; }
.state h3 { margin: 0 0 8px; font-size: 18px; color: var(--text); font-weight: 700; }
.state p { margin: 0; font-size: 14px; }
.welcome-state svg { opacity: 1; animation: pulse 3s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: .9; } 50% { transform: scale(1.08); opacity: 1; } }
.spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-grid { display: grid; grid-template-columns: inherit; gap: inherit; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal.open { display: flex; animation: fade .25s ease; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(5, 5, 12, 0.7);
  backdrop-filter: blur(6px);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 860px;
  max-height: 90vh;
  overflow: auto;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  box-shadow: var(--shadow);
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
.modal-panel::-webkit-scrollbar { width: 8px; }
.modal-panel::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  z-index: 5;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: rgba(20,20,32,.8);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background .2s, transform .15s;
}
.modal-close:hover { background: var(--surface-3); transform: rotate(90deg); }

.modal-body { padding: 0; }
.detail-head {
  display: flex;
  gap: 20px;
  padding: 26px 24px 18px;
  background:
    linear-gradient(180deg, rgba(124,92,255,.10), transparent 280px),
    var(--bg-2);
}
.detail-poster {
  width: 150px;
  flex-shrink: 0;
  aspect-ratio: 2/3;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  background: var(--surface-2);
}
.detail-poster img { width: 100%; height: 100%; object-fit: cover; }
.detail-info { flex: 1; min-width: 0; }
.detail-info h2 { margin: 0 0 10px; font-size: 22px; line-height: 1.3; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.chip.accent { background: linear-gradient(92deg, rgba(124,92,255,.25), rgba(224,85,160,.25)); border-color: rgba(124,92,255,.4); color: #d7c9ff; }
.chip.gold { color: var(--gold); border-color: rgba(245,185,74,.3); background: rgba(245,185,74,.1); }
.detail-desc {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.75;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0 0 16px;
}
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-primary {
  border: 0; cursor: pointer;
  color: #fff; font-weight: 600; font-size: 14px;
  padding: 10px 22px; border-radius: 10px;
  background: linear-gradient(92deg, var(--accent), var(--accent-2));
  display: inline-flex; align-items: center; gap: 8px;
  transition: filter .2s, transform .1s;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: scale(.97); }
.btn-ghost {
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 14px; font-weight: 500;
  padding: 10px 18px; border-radius: 10px;
  transition: background .2s;
}
.btn-ghost:hover { background: var(--surface-3); }

.detail-eps { padding: 8px 24px 24px; }
.detail-eps h3 {
  font-size: 15px; margin: 0 0 14px;
  display: flex; align-items: center; gap: 8px;
}
.eps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 8px;
}
.ep-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13px;
  padding: 9px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.ep-btn:hover { color: #fff; border-color: var(--accent); background: var(--surface-3); }
.ep-btn.active {
  background: linear-gradient(92deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff; font-weight: 600;
}

@media (max-width: 560px) {
  .detail-head { flex-direction: column; align-items: center; text-align: center; padding: 24px 18px 14px; }
  .detail-poster { width: 120px; }
  .detail-meta { justify-content: center; }
  .detail-actions { justify-content: center; }
  .detail-desc { text-align: left; -webkit-line-clamp: 6; }
  .detail-eps { padding: 8px 18px 20px; }
}

/* ---------- Player ---------- */
.player-view {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #000;
  display: none;
  flex-direction: column;
  overflow: auto;
}
.player-view.open { display: flex; }
.player-wrap {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 14px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.player-top {
  display: flex; align-items: center; gap: 14px;
  padding-top: 6px;
}
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: background .2s;
}
.icon-btn:hover { background: var(--surface-3); }
.player-title {
  font-size: 16px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text);
}
.player-stage {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
}
.player-stage video { width: 100%; height: 100%; display: block; background: #000; }
.player-loading,
.player-error {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 14px;
  background: rgba(0,0,0,.6);
}
.player-error { display: none; }
.player-error.show { display: flex; }
.player-eps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow: auto;
  padding: 4px;
}

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  padding: 26px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  line-height: 1.8;
  max-width: var(--maxw);
  margin: 0 auto;
}
.footer p { margin: 0; }

/* ---------- Misc ---------- */
.hidden { display: none !important; }

@media (max-width: 480px) {
  .brand-text { display: none; }
  .topbar-inner { gap: 10px; padding: 0 12px; }
  .search-btn { padding: 0 14px; }
  .app { padding: 18px 12px 60px; }
  .hero-content { padding: 22px 18px; }
}
