:root {
  --bg: #0b0c10;
  --bg-2: #12141c;
  --bg-3: #1a1d28;
  --panel: #161822;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #f5f6fa;
  --muted: #8b90a0;
  --pink: #fb7299;
  --pink-deep: #e45a82;
  --pink-soft: rgba(251, 114, 153, 0.16);
  --ok: #52c41a;
  --danger: #ff6b81;
  --rail: 4.75rem;
  --tabbar: calc(3.6rem + env(safe-area-inset-bottom));
  --radius: 0.7rem;
  --font: "Plus Jakarta Sans", "Noto Sans SC", system-ui, sans-serif;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 420px at 12% -8%, rgba(251, 114, 153, 0.12), transparent 55%),
    radial-gradient(700px 360px at 92% 0%, rgba(88, 120, 255, 0.08), transparent 50%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { cursor: pointer; border: 0; background: none; }

#app { min-height: 100%; }

.boot-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  gap: 1.1rem;
  text-align: center;
}
.boot-mark {
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: 0.08em;
  color: var(--pink);
}
.boot-spinner,
.spin {
  width: 1.45rem;
  height: 1.45rem;
  margin: 0 auto;
  border: 2px solid rgba(255,255,255,.14);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .boot-spinner, .spin, .drama-card { animation: none !important; transition: none !important; }
}

/* ——— shell ——— */
.shell-desktop {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: 100vh;
}
.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 1rem 0.45rem;
  background: rgba(10, 12, 18, 0.92);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(14px);
  z-index: 20;
}
.brand-dot {
  width: 2.4rem;
  height: 2.4rem;
  margin-bottom: 0.65rem;
  border-radius: 0.85rem;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(145deg, var(--pink), #ff9db8);
  box-shadow: 0 8px 20px rgba(251, 114, 153, 0.28);
}
.rail-link {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.55rem 0.2rem;
  border-radius: 0.7rem;
  color: var(--muted);
  font-size: 0.68rem;
  transition: color .15s, background .15s;
}
.rail-link svg { width: 1.25rem; height: 1.25rem; }
.rail-link:hover { color: var(--text); background: rgba(255,255,255,.04); }
.rail-link.active {
  color: var(--pink);
  background: var(--pink-soft);
}

.workspace { min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 15;
  background: rgba(11, 12, 16, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.chip-all {
  margin-left: auto;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--pink-soft);
  color: var(--pink);
  font-size: 0.75rem;
  font-weight: 600;
}

.source-wrap { position: relative; }
.source-btn {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  font-weight: 600;
}
.source-menu {
  display: none;
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  min-width: 8rem;
  padding: 0.35rem;
  border-radius: 0.75rem;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 30;
}
.source-wrap.open .source-menu { display: grid; gap: 0.15rem; }
.source-item {
  text-align: left;
  padding: 0.45rem 0.65rem;
  border-radius: 0.5rem;
  color: var(--muted);
}
.source-item:hover, .source-item.active {
  background: var(--pink-soft);
  color: var(--pink);
}

.search {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1;
  max-width: 28rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
}
.search svg { width: 1rem; height: 1rem; color: var(--muted); flex: none; }
.search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.unlock-trigger {
  flex: none;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--muted);
  font-weight: 600;
}
.unlock-trigger svg { width: 1rem; height: 1rem; }
.unlock-trigger:hover { color: var(--pink); border-color: rgba(251, 114, 153, 0.35); background: var(--pink-soft); }

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(4, 5, 10, 0.62);
  backdrop-filter: blur(8px);
}
.modal-card {
  width: min(22rem, 100%);
  padding: 1.35rem 1.25rem 1.15rem;
  border-radius: 1rem;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, #1b1e2a, #141622);
  box-shadow: var(--shadow);
}
.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
}
.modal-desc {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}
.modal-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 0.75rem;
  border: 1px solid var(--line);
  background: var(--bg-3);
}
.modal-field svg { width: 1.05rem; height: 1.05rem; color: var(--muted); flex: none; }
.modal-field input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}
.modal-field.shake { animation: unlock-shake 0.35s; border-color: var(--danger); }
.modal-error {
  margin-top: 0.55rem;
  color: var(--danger);
  font-size: 0.82rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 1.15rem;
}
.btn.busy { opacity: 0.55; pointer-events: none; }
@keyframes unlock-shake {
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

.cats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.75rem 1.25rem 0.15rem;
}
.cat {
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
}
.cat:hover { color: var(--text); }
.cat.active {
  color: #fff;
  background: linear-gradient(135deg, var(--pink), #ff9db8);
  font-weight: 600;
}

.main { padding: 1rem 1.25rem 2rem; }
.main-mobile { padding-bottom: calc(var(--tabbar) + 1rem); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 1rem 0.85rem;
}
@media (min-width: 1100px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: 1.15rem 1rem; }
}

.drama-card {
  text-align: left;
  display: grid;
  gap: 0.45rem;
  transition: transform .15s;
}
.drama-card:hover { transform: translateY(-2px); }
.poster {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(160deg, #1c2030, #12141c);
  border: 1px solid var(--line);
}
.poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.poster-fade {
  position: absolute;
  inset: auto 0 0;
  height: 42%;
  background: linear-gradient(transparent, rgba(8,10,14,.9));
  pointer-events: none;
}
.badge-count,
.vip-chip,
.heat-chip {
  position: absolute;
  z-index: 1;
  padding: 0.15rem 0.4rem;
  border-radius: 0.35rem;
  font-size: 0.68rem;
  font-weight: 600;
  backdrop-filter: blur(6px);
}
.badge-count {
  right: 0.35rem;
  bottom: 0.35rem;
  background: rgba(0,0,0,.55);
  color: #fff;
}
.vip-chip {
  left: 0.35rem;
  top: 0.35rem;
  background: rgba(251, 114, 153, 0.92);
  color: #fff;
}
.heat-chip {
  right: 0.35rem;
  top: 0.35rem;
  background: rgba(0,0,0,.5);
  color: #ffd7a8;
}
.skel .poster,
.skel .card-title {
  background: linear-gradient(90deg, #1a1e2a 25%, #242a3a 50%, #1a1e2a 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
.skel .card-title { height: 0.9rem; border-radius: 0.35rem; }
@keyframes shimmer { to { background-position: -200% 0; } }

.card-title {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
}

.empty, .center-msg {
  text-align: center;
  color: var(--muted);
  padding: 3.5rem 1rem;
}
.warn {
  margin-bottom: 0.8rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.65rem;
  background: rgba(255, 184, 77, 0.1);
  border: 1px solid rgba(255, 184, 77, 0.25);
  color: #ffd7a8;
  font-size: 0.86rem;
}
.err { color: var(--danger); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
}
.btn svg { width: 1.05rem; height: 1.05rem; flex: none; }
.btn-ember {
  background: linear-gradient(135deg, var(--pink), #ff9db8);
  color: #fff;
  border: 0;
  font-weight: 600;
}
.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
}
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.more-wrap { text-align: center; padding: 1.25rem 0 0.5rem; }

.shell-mobile { min-height: 100vh; }
.mobile-tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: var(--tabbar);
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(10, 12, 18, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.tab-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  color: var(--muted);
  font-size: 0.68rem;
}
.tab-link svg { width: 1.2rem; height: 1.2rem; }
.tab-link.active { color: var(--pink); }

.library-top { justify-content: space-between; }
.library-title { font-weight: 700; font-size: 1.05rem; }
.library-actions { display: flex; gap: 0.45rem; }
.library-list { display: flex; flex-direction: column; gap: 0.65rem; }
.library-row {
  display: flex;
  align-items: stretch;
  gap: 0.55rem;
  padding: 0.55rem;
  border-radius: 0.9rem;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line);
}
.library-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-align: left;
  padding: 0;
  background: transparent;
  border: 0;
  color: inherit;
}
.library-cover {
  width: 3.4rem;
  aspect-ratio: 3 / 4;
  flex: none;
  border-radius: 0.55rem;
  overflow: hidden;
  background: #1a1e2a;
}
.library-cover img { width: 100%; height: 100%; object-fit: cover; }
.library-body { min-width: 0; }
.library-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.library-sub {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}
.library-side {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.35rem;
  flex: none;
}
.status-select,
.quality-select {
  appearance: none;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  font-size: 0.75rem;
}
.quality-select {
  padding: 0.35rem 0.7rem;
  border-color: rgba(255,255,255,.2);
  background: rgba(255,255,255,.06);
  font-size: 0.8rem;
}

.settings-panel {
  display: grid;
  gap: 0.85rem;
  max-width: 36rem;
}
.settings-card {
  padding: 1rem 1.1rem;
  border-radius: 1rem;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line);
}
.settings-label { font-weight: 700; margin-bottom: 0.35rem; }
.settings-desc { color: var(--muted); font-size: 0.86rem; line-height: 1.5; }
.settings-stats {
  display: flex;
  gap: 1rem;
  margin: 0.85rem 0 0.7rem;
  color: var(--pink);
  font-weight: 600;
  font-size: 0.9rem;
}
.settings-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ——— player ——— */
.player-page {
  min-height: 100vh;
  background: #07080c;
  display: flex;
  flex-direction: column;
}
.player-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 1rem;
  background: rgba(8, 9, 14, 0.92);
  border-bottom: 1px solid var(--line);
  flex: none;
  z-index: 5;
}
.player-back {
  flex: none;
  gap: 0.25rem;
  padding: 0.4rem 0.85rem 0.4rem 0.6rem;
  font-size: 0.9rem;
}
.player-title {
  font-weight: 700;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
}
.player-ep {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}
.player-body {
  width: min(100%, 1280px);
  margin: 0 auto;
  padding: 0 0 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1;
  min-width: 0;
}
.player-stage {
  position: relative;
  width: 100%;
  background: #000;
  overflow: hidden;
}
#xg-host {
  width: 100%;
  background: #000;
}
#xg-host .xgplayer {
  background: #000 !important;
}
#xg-host .xgplayer video {
  object-fit: contain !important;
  background: #000;
}
#xg-host .xgplayer .xgplayer-controls {
  z-index: 8;
}
#xg-host .xgplayer xg-mini-progress,
#xg-host .xgplayer .xgplayer-mini-progress,
#xg-host .xgplayer .xg-mini-progress {
  position: absolute !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  height: 2px !important;
  z-index: 9 !important;
  pointer-events: none !important;
  background: rgba(255, 255, 255, 0.18) !important;
}
#xg-host .xgplayer xg-mini-progress .xgplayer-progress-played,
#xg-host .xgplayer .xgplayer-mini-progress .xgplayer-progress-played,
#xg-host .xgplayer .xg-mini-progress .xgplayer-progress-played,
#xg-host .xgplayer xg-mini-progress .xg-mini-progress-played,
#xg-host .xgplayer .xgplayer-mini-progress .xg-mini-progress-played {
  background: var(--pink) !important;
  height: 100% !important;
}
.player-ep-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  margin-left: 0.15rem;
  flex: none;
}
.player-ep-btn {
  width: 2rem;
  height: 2rem;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  opacity: 0.92;
}
.player-ep-btn:hover {
  color: var(--pink);
  background: rgba(255, 255, 255, 0.08);
}
.player-ep-btn.is-disabled,
.player-ep-btn[disabled] {
  opacity: 0.28;
  pointer-events: none;
}
.player-decrypt-tip {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  padding: 0.65rem 1rem;
  border-radius: 999px;
  background: rgba(0,0,0,.72);
  color: #ffd0df;
  font-size: 0.86rem;
  pointer-events: none;
}
.player-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.45);
  z-index: 6;
  padding: 1rem;
  pointer-events: auto;
}
.player-overlay[hidden] { display: none !important; }
.player-error-box {
  max-width: 26rem;
  text-align: center;
  background: rgba(20, 22, 30, 0.95);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 1.1rem 1.2rem;
}
.player-error-box .err {
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
  margin-bottom: 0.9rem;
  font-size: 0.86rem;
}

.player-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 0;
}
.player-meta {
  padding: 0.95rem 1rem 0.35rem;
}
.player-meta-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}
.player-meta-sub {
  color: var(--muted);
  font-size: 0.84rem;
}
.player-note {
  padding: 0.45rem 1rem 0.85rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
}
.ep-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 1rem 0.55rem;
  color: var(--text);
  font-weight: 650;
  font-size: 0.92rem;
}
.ep-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.6rem, 1fr));
  gap: 0.45rem;
  padding: 0 1rem 1rem;
  max-height: 34vh;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(251, 114, 153, 0.45) transparent;
}
.ep-strip::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.ep-strip::-webkit-scrollbar-track {
  background: transparent;
  margin: 0.25rem 0;
}
.ep-strip::-webkit-scrollbar-thumb {
  background: rgba(251, 114, 153, 0.35);
  border-radius: 999px;
}
.ep-strip::-webkit-scrollbar-thumb:hover {
  background: rgba(251, 114, 153, 0.65);
}
.ep-strip::-webkit-scrollbar-corner {
  background: transparent;
}
.ep-btn {
  min-height: 2.2rem;
  padding: 0.4rem 0.35rem;
  border-radius: 0.45rem;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--muted);
  font-size: 0.82rem;
}
.ep-btn.active {
  color: #fff;
  background: linear-gradient(135deg, var(--pink), #ff9db8);
  border-color: transparent;
  font-weight: 700;
}
.ep-btn:hover:not(.active) {
  color: var(--text);
  border-color: var(--pink);
}

/* PC：拉满宽度，上播下选集 */
@media (min-width: 900px) {
  .player-bar {
    padding: 0.75rem 1.25rem;
  }
  .player-body {
    width: min(100% - 2rem, 1280px);
    margin-top: 0.85rem;
    border-radius: 0.85rem;
    overflow: hidden;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    flex: none;
  }
  .player-stage {
    aspect-ratio: 16 / 9;
    max-height: min(72vh, 720px);
  }
  #xg-host,
  #xg-host .xgplayer {
    height: 100% !important;
  }
  .player-panel { border: 0; border-top: 1px solid var(--line); }
  .ep-strip {
    max-height: 28vh;
    grid-template-columns: repeat(auto-fill, minmax(5.2rem, 1fr));
  }
}

/* 手机：按片源比例完整显示，不裁切；要放大再点全屏 */
@media (max-width: 899px) {
  .player-page {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
  .player-body {
    flex: 1;
    min-height: 0;
    width: 100%;
    justify-content: flex-start;
  }
  .player-stage {
    flex: none;
    width: 100%;
    min-height: 40vh;
    background: #000;
  }
  #xg-host,
  #xg-host .xgplayer {
    height: 100% !important;
  }
  .player-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 0;
    border-top: 1px solid var(--line);
  }
  .player-meta { display: none; }
  .ep-head { padding: 0.55rem 0.75rem 0.4rem; flex: none; }
  .ep-strip {
    flex: 1;
    max-height: none;
    min-height: 0;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding: 0 0.75rem 0.85rem;
  }
  .player-note { display: none; }
}

@media (max-width: 560px) {
  .library-row { flex-direction: column; }
  .library-side { flex-direction: row; justify-content: flex-end; }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.7rem 0.55rem; }
  .topbar, .cats, .main { padding-left: 0.85rem; padding-right: 0.85rem; }
  .topbar { flex-wrap: wrap; }
  .search { max-width: none; min-width: 60%; }
}
