:root {
  --bg: #f4f1ea;
  --bg-elev: #fffdf8;
  --ink: #1c1915;
  --ink-soft: #6b6458;
  --line: #e6dfd2;
  --accent: #b4532a;
  --accent-soft: #f3e4d6;
  --ok: #3d7a4a;
  --warn: #a15c12;
  --err: #b42318;
  --shadow: 0 10px 30px rgba(28, 25, 21, 0.06);
  --radius: 16px;
  --max: 1120px;
  --max-wide: 1320px;
  --rail: 300px;
  --stage-ink: #0b0b0d;
  --chunk-cached: rgba(107, 100, 88, 0.28);
  --chunk-empty: rgba(107, 100, 88, 0.08);
  --topbar: 64px;
  --dock: 64px;
  --font: "Iowan Old Style", "Palatino Linotype", "Songti SC", "Noto Serif SC", "Source Han Serif SC", serif;
  --ui: "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color-scheme: light;
}

/* 深色主题变量。两处生效：html[data-theme="dark"]（手动切换，
   由 index.html 头部脚本与应用按钮写入）；
   @media 兜底覆盖没有 JS 的场景（没写 data-theme 时跟随系统）。 */
:root[data-theme="dark"] {
  --bg: #161411;
  --bg-elev: #1f1b16;
  --ink: #f4efe6;
  --ink-soft: #b3aa9a;
  --line: #322c24;
  --accent: #e08a5c;
  --accent-soft: #3a271c;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --chunk-cached: rgba(179, 170, 154, 0.34);
  --chunk-empty: rgba(179, 170, 154, 0.10);
  color-scheme: dark;
}
:root[data-theme="dark"] .cast__face {
  background: hsl(var(--cast-hue, 30) 22% 26%);
  color: hsl(var(--cast-hue, 30) 40% 82%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161411;
    --bg-elev: #1f1b16;
    --ink: #f4efe6;
    --ink-soft: #b3aa9a;
    --line: #322c24;
    --accent: #e08a5c;
    --accent-soft: #3a271c;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
    --chunk-cached: rgba(179, 170, 154, 0.34);
    --chunk-empty: rgba(179, 170, 154, 0.10);
    color-scheme: dark;
  }
  :root:not([data-theme="light"]) .cast__face {
    background: hsl(var(--cast-hue, 30) 22% 26%);
    color: hsl(var(--cast-hue, 30) 40% 82%);
  }
}

* { box-sizing: border-box; }
/* 让 hidden 属性始终生效：display: grid/flex 的优先级高于 hidden 的默认
   display: none，不加这条，凡是带 display 的浮层设了 hidden 也关不掉。 */
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--ui);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: 12px; top: -40px; background: var(--ink); color: var(--bg);
  padding: 8px 12px; border-radius: 8px; z-index: 20;
}
.skip:focus { top: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  max-width: var(--max); margin: 0 auto;
  min-height: var(--topbar);
  padding: 8px 20px;
  display: grid;
  grid-template-columns: auto 1fr auto auto auto auto;
  gap: 16px; align-items: center;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.08em; }
.brand__mark {
  width: 18px; height: 18px; border-radius: 5px;
  background: linear-gradient(135deg, var(--accent), #7a2e16);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.types { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.types::-webkit-scrollbar { display: none; }
.type-chip {
  border: 0; background: transparent; color: var(--ink-soft);
  padding: 8px 12px; border-radius: 999px; white-space: nowrap; cursor: pointer;
}
.type-chip.is-active { background: var(--ink); color: var(--bg); }
.search {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 4px 4px 14px; min-width: 180px;
}
.search input { border: 0; outline: 0; background: transparent; width: 180px; min-width: 0; }
.icon-btn, .btn {
  border: 0; background: var(--ink); color: var(--bg);
  border-radius: 999px; cursor: pointer;
}
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; }
.btn { padding: 8px 16px; }
.btn--ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.ghost-link { color: var(--ink-soft); font-size: 14px; }

.stage { max-width: var(--max); margin: 0 auto; padding: 24px 20px 96px; min-height: calc(100dvh - var(--topbar)); }
.hero { display: grid; gap: 8px; margin-bottom: 24px; }
.hero h1 { font-family: var(--font); font-size: clamp(28px, 4vw, 42px); margin: 0; letter-spacing: 0.02em; }
.hero p { margin: 0; color: var(--ink-soft); }

/* 发现页：一级分类组用 tab，二级分类用 chip */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 14px; white-space: nowrap; color: var(--ink-soft);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.chip {
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--ink);
  border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px;
  line-height: 22px; white-space: nowrap;
}
.chip.is-active { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* 标签很多时默认只露一行，点展开才铺开。折叠时按钮和标签同一行，
   避免再占掉第二行。 */
.chips-wrap {
  display: flex; flex-direction: column; align-items: flex-start;
  gap: 8px; margin-bottom: 24px;
}
.chips-wrap .chips { margin-bottom: 0; width: 100%; }
.chips-wrap.is-collapsed {
  flex-direction: row; align-items: center;
}
.chips-wrap.is-collapsed .chips {
  flex: 1; min-width: 0; width: auto;
  /* 22 行高 + 12 内边距 + 2 边框，刚好一行 */
  max-height: 36px; overflow: hidden;
}
.chips-toggle {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  flex-shrink: 0;
  border: 1px dashed var(--line); background: var(--bg-elev);
  color: var(--ink-soft); border-radius: 999px; padding: 6px 12px;
  cursor: pointer; font-size: 13px; white-space: nowrap;
}
.chips-toggle:hover { color: var(--ink); border-color: var(--ink-soft); }
.chips-toggle[aria-expanded="true"] { border-style: solid; }
.chips-toggle__count {
  font-variant-numeric: tabular-nums; font-size: 12px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 0 6px; line-height: 1.7;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; display: grid;
  grid-template-rows: auto 1fr; box-shadow: var(--shadow); min-width: 0;
}
.card__cover { aspect-ratio: 3 / 4; background: #d8cfc0; overflow: hidden; }
.card__cover img { width: 100%; height: 100%; object-fit: cover; }
.card__body { padding: 10px 12px 14px; display: grid; gap: 4px; }
.card__title { font-size: 14px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card__meta { color: var(--ink-soft); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pager { display: flex; justify-content: center; gap: 12px; margin-top: 28px; }
.empty, .error, .loading { text-align: center; color: var(--ink-soft); padding: 48px 12px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  margin: 0 auto 12px; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.detail { display: grid; grid-template-columns: 180px 1fr; gap: 28px; align-items: start; }
.cover-lg { border-radius: 18px; overflow: hidden; background: #d8cfc0; box-shadow: var(--shadow); }
.cover-lg img { width: 100%; aspect-ratio: 3/4; object-fit: cover; }
.meta h1 { font-family: var(--font); font-size: clamp(24px, 3vw, 36px); margin: 0 0 8px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.intro { color: var(--ink-soft); white-space: pre-wrap; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.toc { margin-top: 36px; }
.toc h2 { font-size: 16px; margin: 0; }
.toc__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.toc-sort {
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--ink-soft);
  border-radius: 999px; padding: 5px 14px; cursor: pointer; font-size: 13px;
}
.toc-sort:hover { color: var(--ink); border-color: var(--ink-soft); }
.toc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.toc-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 10px 12px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--line);
}
.toc-item__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-item__meta { flex: none; color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
.toc-item.is-current { border-color: var(--accent); }

/* 漫画：按滚动懒加载，未加载时用比例占位避免页面跳动 */
.comic { display: grid; gap: 4px; max-width: 900px; margin: 0 auto; }
.comic-page { position: relative; background: var(--bg-elev); border-radius: 4px; overflow: hidden; min-height: 120px; }
.comic-page__img { width: 100%; height: auto; display: block; opacity: 0; transition: opacity 0.25s ease; }
.comic-page__img.is-loaded { opacity: 1; }
.comic-page__no {
  position: absolute; right: 8px; bottom: 8px; font-size: 12px;
  background: color-mix(in srgb, var(--ink) 70%, transparent); color: var(--bg);
  border-radius: 999px; padding: 2px 8px; font-variant-numeric: tabular-nums;
}
.comic-page.is-failed::after {
  content: "这一页加载失败"; position: absolute; inset: 0;
  display: grid; place-items: center; color: var(--ink-soft); font-size: 13px;
}
@media (prefers-reduced-motion: reduce) {
  .comic-page__img { transition: none; opacity: 1; }
}

.reader { max-width: 720px; margin: 0 auto; }
.reader__bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; color: var(--ink-soft); font-size: 14px; }
.article {
  font-family: var(--font); font-size: clamp(17px, 2.2vw, 20px); line-height: 1.9;
  background: var(--bg-elev); padding: 28px 8%; border-radius: 20px; border: 1px solid var(--line);
}
.article p { margin: 0 0 1em; }
.article .picture { margin: 0.4em 0 1.2em; }
.article .picture img { width: 100%; height: auto; border-radius: 12px; background: var(--bg); }
.images { display: grid; gap: 8px; }
.images img { width: 100%; background: #111; }
.player { background: var(--bg-elev); border: 1px solid var(--line); border-radius: 20px; padding: 24px; display: grid; gap: 16px; }
.player audio { width: 100%; border-radius: 12px; background: var(--stage-ink); }
.field { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-soft); }
.field select {
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 10px;
}
.note { font-size: 13px; color: var(--ink-soft); background: var(--accent-soft); padding: 12px 14px; border-radius: 12px; }

/* 卡带播放器。封面即转盘，播放时随卷轴一起转；暂停即停在当前角度。 */
.cassette {
  max-width: 520px; margin: 0 auto; display: grid; gap: 22px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 22px; padding: 26px 24px 24px;
}
.cassette__body {
  border: 1px solid var(--line); border-radius: 16px; padding: 20px 18px 16px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent-soft) 55%, transparent), transparent 62%),
    var(--bg);
  display: grid; gap: 16px;
}
/* 卷轴 — 封面 — 卷轴，中间那格自适应 */
.cassette__window {
  display: grid; grid-template-columns: 44px 1fr 44px;
  align-items: center; justify-items: center; gap: 14px;
}
.cassette__reel {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--line); background: var(--bg-elev);
  position: relative; flex: none;
}
/* 卷轴上的三根齿，用来看出在转 */
.cassette__reel::before {
  content: ""; position: absolute; inset: 8px; border-radius: 50%;
  background:
    conic-gradient(from 0deg, var(--ink-soft) 0 12deg, transparent 12deg 120deg,
      var(--ink-soft) 120deg 132deg, transparent 132deg 240deg,
      var(--ink-soft) 240deg 252deg, transparent 252deg 360deg);
  opacity: 0.55;
}
.cassette__disc {
  position: relative; width: 100%; max-width: 190px; aspect-ratio: 1;
  border-radius: 50%; overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.16);
}
.cassette__cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.cassette__cover--blank { background: repeating-conic-gradient(var(--line) 0 6deg, var(--bg-elev) 6deg 12deg); }
/* 中心轴孔，让封面看起来像唱盘 */
.cassette__spindle {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 22%; aspect-ratio: 1; border-radius: 50%;
  background: var(--bg-elev); border: 2px solid var(--line);
}
.cassette__label { text-align: center; display: grid; gap: 4px; }
.cassette__title { font-size: 15px; line-height: 1.5; }
.cassette__sub { font-size: 12px; color: var(--ink-soft); }

/* 转动：播放时开跑，暂停时 paused 停在当前角度而不是跳回 0 */
.cassette__disc, .cassette__reel::before {
  animation: cassette-spin 6s linear infinite;
  animation-play-state: paused;
}
.cassette__reel::before { animation-duration: 1.6s; }
.cassette.is-playing .cassette__disc,
.cassette.is-playing .cassette__reel::before { animation-play-state: running; }
@keyframes cassette-spin { to { transform: rotate(360deg); } }
.cassette__spindle { z-index: 1; }

/* 进度条：轨道用渐变填充已播部分，滑块是个小圆点 */
.cassette__progress { display: grid; gap: 8px; }
.cassette__range {
  -webkit-appearance: none; appearance: none; width: 100%; height: 20px;
  background: transparent; cursor: pointer; margin: 0;
}
.cassette__range::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--played, 0%), var(--line) var(--played, 0%));
}
.cassette__range::-moz-range-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--played, 0%), var(--line) var(--played, 0%));
}
.cassette__range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; margin-top: -4px; border-radius: 50%;
  background: var(--bg-elev); border: 3px solid var(--accent);
}
.cassette__range::-moz-range-thumb {
  width: 14px; height: 14px; border: 3px solid var(--accent); border-radius: 50%;
  background: var(--bg-elev);
}
.cassette__range:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 999px; }
.cassette__times {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums;
}

.cassette__controls { display: flex; align-items: center; justify-content: center; gap: 12px; }
.cassette__btn {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink-soft);
  border-radius: 999px; min-height: 38px; padding: 0 14px; cursor: pointer;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.cassette__btn:hover { color: var(--ink); border-color: var(--ink-soft); }
.cassette__btn--play {
  width: 54px; height: 54px; padding: 0; display: grid; place-items: center;
  background: var(--accent); border-color: var(--accent);
}
/* 三角 / 双竖条都用纯 CSS，避免额外图标资源 */
.cassette__icon-play {
  width: 0; height: 0; margin-left: 3px;
  border-left: 15px solid var(--bg); border-top: 9px solid transparent; border-bottom: 9px solid transparent;
}
.cassette__icon-pause {
  width: 14px; height: 16px;
  border-left: 4px solid var(--bg); border-right: 4px solid var(--bg);
}
.cassette__rate { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.cassette__rate select {
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 8px; font-size: 12px;
}
.cassette.is-failed .cassette__label::after {
  content: "音频加载失败，试试下一章"; display: block;
  margin-top: 6px; font-size: 12px; color: var(--accent);
}

@media (max-width: 480px) {
  .cassette { padding: 20px 16px; gap: 18px; }
  .cassette__window { grid-template-columns: 32px 1fr 32px; gap: 10px; }
  .cassette__reel { width: 32px; height: 32px; border-width: 2px; }
  .cassette__controls { gap: 8px; flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  .cassette__disc, .cassette__reel::before { animation: none; }
}

.devices { display: grid; gap: 16px; }
.device {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 16px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px;
}
.device__id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; color: var(--ink-soft); }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-row input {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; width: 90px;
}

.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock) + 16px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 30;
}

.dock {
  display: none; position: fixed; left: 0; right: 0; bottom: 0;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(14px); border-top: 1px solid var(--line);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.dock a, .dock button {
  background: none; border: 0; color: var(--ink-soft); font-size: 11px;
  display: grid; justify-items: center; gap: 4px; padding: 6px; min-width: 56px; cursor: pointer;
}
.dock .is-active { color: var(--ink); font-weight: 600; }

/* --- 主角 / 演员 ------------------------------------------------------- */
.cast { margin: 28px 0 0; }
.cast__head { font-size: 16px; margin: 0 0 14px; }
.cast__list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.cast__item { display: grid; justify-items: center; gap: 8px; text-align: center; min-width: 0; }
/* 圆形头像：上游没有演员图，默认走本地生成的文字占位 */
.cast__face {
  width: 64px; height: 64px; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center;
  background: hsl(var(--cast-hue, 30) 34% 88%);
  color: hsl(var(--cast-hue, 30) 42% 32%);
  border: 1px solid var(--line);
  font-family: var(--font); font-size: 26px; line-height: 1;
  user-select: none;
}
.cast__img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cast__text { display: grid; gap: 2px; min-width: 0; width: 100%; }
.cast__name {
  font-size: 13.5px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cast__role {
  font-size: 12px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- 短剧 / 漫剧播放器 ------------------------------------------------- */
/* 画面比例由 --frame-w / --frame-h 驱动，值来自上游给的真实宽高。 */
.player--video { padding: 16px; gap: 12px; }
.player__stage {
  position: relative; background: var(--stage-ink);
  border-radius: 12px; overflow: hidden;
  aspect-ratio: var(--frame-w, 16) / var(--frame-h, 9);
}
.player__video { width: 100%; height: 100%; display: block; object-fit: contain; background: var(--stage-ink); }
/* 全屏（stage 容器进入）：铺满屏幕、去掉比例与圆角，视频 contain 居中，
   竖屏视频两侧黑边、方向由 JS 按宽高比锁定 */
.player__stage:fullscreen,
.player__stage:-webkit-full-screen {
  width: 100%; height: 100%;
  max-height: none;
  aspect-ratio: auto;
  border-radius: 0;
  margin: 0;
}
/* 原生控件直接全屏 <video> 时同样铺满 */
video:fullscreen { width: 100%; height: 100%; object-fit: contain; background: #000; }
/* 竖屏：播放器容器按 PC 固定宽度铺满，视频 contain 居中，
   左右留黑边（stage 本身就是黑色底），不再按比例收敛宽度 */
.player--video.is-portrait .player__stage {
  max-height: min(78dvh, 760px);
  width: 100%;
  margin: 0 auto;
}

/* 分片缓冲：叠在画面底边，每格是一个服务端分片 */
.chunks { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; pointer-events: none; }
.chunks__track { display: flex; gap: 1px; height: 100%; }
.chunks__cell { background: var(--chunk-empty); transition: background 0.2s ease; }
.chunks__cell.is-cached { background: var(--chunk-cached); }
.chunks__pulse {
  position: absolute; bottom: -2px; width: 7px; height: 7px; margin-left: -3.5px;
  border-radius: 50%; background: var(--accent);
  animation: chunk-pulse 1s ease-in-out infinite;
}
@keyframes chunk-pulse {
  0%, 100% { transform: scale(0.7); opacity: 0.5; }
  50%      { transform: scale(1.25); opacity: 1; }
}

/* 编码信息条：清晰度 / 编码 / 分片大小 */
.codecbar {
  position: relative; display: flex; align-items: center; gap: 12px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px; font-size: 13px;
}
.codecbar__group { display: flex; align-items: center; gap: 8px; }
.codecbar__label { color: var(--accent); font-size: 12px; letter-spacing: 0.02em; }
.codecbar__pick {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-elev); color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; cursor: pointer; font: inherit;
  font-variant-numeric: tabular-nums;
}
.codecbar__pick:hover { border-color: var(--ink-soft); }
.codecbar__pick[aria-expanded="true"] { border-color: var(--accent); }
.codecbar__caret {
  width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid currentColor; opacity: 0.6;
}
.codecbar__codec { color: var(--ink-soft); font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.codecbar__size { margin-left: auto; color: var(--ink-soft); font-variant-numeric: tabular-nums; font-size: 12px; }
/* 窄屏合并成一行 1080p · bytevc1 · 9.7MB */
.codecbar__compact { display: none; color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
/* 全屏按钮：视频宽高比决定锁竖屏还是横屏，逻辑在 bindVideo */
.codecbar__fs {
  flex: none; margin-left: 4px;
  width: 30px; height: 30px; display: grid; place-items: center;
  background: var(--bg-elev); color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
}
.codecbar__fs:hover { color: var(--ink); border-color: var(--ink-soft); }
.codecbar__fs[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* 清晰度菜单 */
.quality {
  position: absolute; left: 12px; bottom: calc(100% + 6px); z-index: 5;
  min-width: 190px; display: grid; gap: 2px; padding: 6px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
}
.quality__item {
  display: grid; gap: 2px; text-align: left; width: 100%;
  background: none; border: 0; border-radius: 8px;
  padding: 7px 10px; cursor: pointer; color: var(--ink); font: inherit;
}
.quality__item:hover:not([disabled]) { background: var(--accent-soft); }
.quality__item[data-current="1"] { background: var(--accent-soft); }
.quality__item[data-current="1"] .quality__def::after { content: " ✓"; color: var(--accent); }
.quality__item[disabled] { opacity: 0.45; cursor: not-allowed; }
.quality__def { font-size: 13px; }
.quality__meta { font-size: 11px; color: var(--ink-soft); font-family: ui-monospace, "SF Mono", Consolas, monospace; }

/* 流式说明条，可永久关闭 */
.streamtip {
  display: flex; align-items: flex-start; gap: 10px;
  background: color-mix(in srgb, var(--accent-soft) 60%, transparent);
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px;
}
.streamtip__icon { flex: none; color: var(--accent); margin-top: 1px; }
.streamtip__text { margin: 0; font-size: 12.5px; line-height: 1.6; color: var(--ink-soft); }
.streamtip__short { display: none; }
.streamtip__close {
  flex: none; margin-left: auto; background: none; border: 0; cursor: pointer;
  color: var(--ink-soft); border-radius: 6px; padding: 3px; line-height: 0;
}
.streamtip__close:hover { color: var(--ink); background: var(--bg); }


/* --- 播放页：左主栏（播放器 + 信息区）/ 右选集（参考 B 站番剧 ss35213） --- */
.reader--watch { max-width: var(--max-wide); }
.watch { display: grid; gap: 20px; align-items: start; }
/* 主栏：播放器在上，剧情信息区在下（B 站番剧的排布） */
.watch__main { display: grid; gap: 16px; min-width: 0; }
.watch__side { display: grid; gap: 20px; min-width: 0; align-content: start; }

/* 信息区：顶部渐变遮罩打底，标题 / 徽章 / 标签浮在上面 */
.watch__main .series {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent-soft) 75%, transparent),
    color-mix(in srgb, var(--bg) 40%, transparent) 70%,
    transparent
  );
  padding: 16px 18px 10px;
  border-radius: 16px;
}

/* 剧情信息 */
.series { display: grid; gap: 10px; }
.series__badges { display: flex; flex-wrap: wrap; gap: 8px; }
.series__title { font-size: 20px; margin: 0; line-height: 1.35; }
.series__title a { color: var(--ink); }
.series__title a:hover { color: var(--accent); }
.series__intro {
  margin: 0; font-size: 13.5px; line-height: 1.75; color: var(--ink-soft);
  white-space: pre-wrap;
  /* 默认收起三行，避免长简介把选集挤到屏外 */
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.series__intro.is-open { -webkit-line-clamp: unset; display: block; }
.series__more {
  justify-self: start; background: none; border: 0; padding: 0;
  color: var(--accent); font: inherit; font-size: 12.5px; cursor: pointer;
}
.series__more:hover { text-decoration: underline; }
.series__tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 12px; padding: 3px 9px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink-soft);
}
/* 播放页里的演员表更紧凑 */
.watch__side .cast { margin: 4px 0 0; }
.watch__side .cast__head { font-size: 14px; margin-bottom: 10px; }
.watch__side .cast__list { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 12px; }
.watch__side .cast__face { width: 48px; height: 48px; font-size: 20px; }

/* 选集目录（参考 B 站番剧：头部 标题+视图切换+倒序，可选分页，宫格/列表两种视图） */
.rail {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px; display: grid; gap: 12px;
  align-content: start; min-width: 0;
}
.rail__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rail__title { font-size: 15px; margin: 0; }
.rail__count { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.rail__modes { display: flex; gap: 2px; }
.rail__btn {
  border: 0; background: none; cursor: pointer; color: var(--ink-soft);
  width: 28px; height: 28px; display: grid; place-items: center;
  border-radius: 8px; padding: 0;
}
.rail__btn:hover { color: var(--ink); background: var(--bg); }
.rail__btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.rail__pages { display: flex; gap: 10px; }
.rail__page {
  border: 0; background: none; cursor: pointer; padding: 2px 0;
  color: var(--ink-soft); font: inherit; font-size: 13.5px;
  border-bottom: 2px solid transparent;
}
.rail__page:hover { color: var(--ink); }
.rail__page.is-active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.rail__list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 8px;
  max-height: min(58dvh, 560px); overflow-y: auto;
  /* 惯性滚动时不至于卡在半个卡片上 */
  scroll-behavior: smooth; overscroll-behavior: contain;
}
.ep { min-width: 0; }
.ep__link {
  display: grid; grid-template-columns: 54px 1fr; gap: 10px; align-items: center;
  padding: 6px; border-radius: 10px; border: 1px solid transparent;
  color: var(--ink); min-width: 0;
}
.ep__link:hover { background: var(--accent-soft); }
.ep__link.is-current { border-color: var(--accent); background: var(--accent-soft); }

/* 宫格视图（B 站默认样式）：纯序号方块，5 列，视觉轻量不抢播放器 */
.rail__list.is-grid { grid-template-columns: repeat(5, 1fr); gap: 6px; }
.rail__list.is-grid .ep__link {
  grid-template-columns: 1fr;
  aspect-ratio: 1; padding: 0;
  display: grid; place-items: center;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
}
.rail__list.is-grid .ep__link:hover { border-color: var(--ink-soft); background: transparent; }
.rail__list.is-grid .ep__link.is-current {
  background: var(--accent); border-color: var(--accent);
}
.rail__list.is-grid .ep__num {
  font-size: 14px; font-variant-numeric: tabular-nums; color: var(--ink);
}
.rail__list.is-grid .ep__link.is-current .ep__num { color: #fff; font-weight: 600; }
.rail__list.is-grid .ep__thumb,
.rail__list.is-grid .ep__meta { display: none; }

/* 列表视图（B 站另一种样式）：封面 + 「第N集」+ 剧集名 + 时长 */
.rail__list.is-list .ep__num { display: none; }
/* 封面：竖屏 9:16，服务端抽帧，未加载时用底色占位 */
.ep__thumb {
  position: relative; width: 54px; aspect-ratio: 9 / 16;
  border-radius: 8px; overflow: hidden; background: var(--stage-ink);
  display: block; flex: none;
}
.ep__img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ep__img.is-failed { visibility: hidden; }
.ep__no {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 2px 0; text-align: center;
  font-size: 11px; font-variant-numeric: tabular-nums;
  color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}
/* 当前集：封面上叠一个跳动的播放指示 */
.ep__playing {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.35);
}
.ep__playing::before {
  content: ""; width: 3px; height: 12px; border-radius: 2px;
  background: #fff;
  box-shadow: 6px 0 #fff, -6px 0 #fff;
  animation: ep-bars 1s ease-in-out infinite;
}
@keyframes ep-bars {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}
.ep__meta { display: grid; gap: 3px; min-width: 0; }
.ep__label {
  font-size: 12.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums;
}
.ep__link.is-current .ep__label { color: var(--accent); font-weight: 600; }
.ep__name {
  font-size: 13px; line-height: 1.45;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ep__link.is-current .ep__name { color: var(--accent); font-weight: 600; }
.ep__dur {
  font-size: 11.5px; color: var(--ink-soft);
  font-variant-numeric: tabular-nums; min-height: 1em;
}

@media (min-width: 900px) {
  /* 桌面端（B 站层级）：播放器永远是主导大栏，选集是固定窄侧栏。
     竖屏视频在宽栏内居中，左右黑边，视觉重心仍在播放器。 */
  .reader--watch .watch,
  .reader--watch.is-portrait .watch { grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); }
  .rail__list { max-height: min(52dvh, 520px); }
}
@media (max-width: 899px) {
  /* 手机端：竖排，播放器在上、信息其次、选集最后 */
  .reader--watch { max-width: 100%; }
  .watch { gap: 16px; }
  .series__title { font-size: 18px; }
  .rail__list { max-height: 46dvh; }
  /* 竖屏视频在手机上占满宽度，保持沉浸 */
  .reader--watch.is-portrait .player--video.is-portrait .player__stage {
    max-height: 64dvh; width: 100%; margin: 0 auto;
  }
}
@media (max-width: 560px) {
  .rail { padding: 10px; }
  .ep__link { grid-template-columns: 46px 1fr; gap: 8px; }
  .ep__thumb { width: 46px; }
  .rail__list.is-grid { grid-template-columns: repeat(4, 1fr); }
  .watch__side .cast__list { grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 10px; }
  .watch__side .cast__face { width: 44px; height: 44px; font-size: 18px; }
}
@media (max-width: 560px) {
  .player--video { padding: 10px; }
  /* 信息条精简成单行，不额外占高度 */
  .codecbar__label, .codecbar__codec, .codecbar__size { display: none; }
  .codecbar__compact { display: inline; margin-left: auto; }
  .streamtip__full { display: none; }
  .streamtip__short { display: inline; }
}

@media (max-width: 900px) {
  .topbar__inner { grid-template-columns: auto 1fr auto auto; }
  .ghost-link { display: none; }
  .search input { width: 120px; }
  .detail { grid-template-columns: 140px 1fr; }
}
@media (max-width: 720px) {
  .topbar__inner { grid-template-columns: auto 1fr auto; gap: 10px; }
  .types { display: none; }
  .search { grid-column: 2; }
  .search input { width: 100%; }
  .dock { display: flex; }
  .stage { padding-bottom: calc(var(--dock) + 32px); }
  .detail { grid-template-columns: 1fr; }
  .cover-lg { max-width: 180px; }
  .cast__list { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 12px; }
  .cast__face { width: 54px; height: 54px; font-size: 22px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .toc-list { grid-template-columns: 1fr; }
  .article { padding: 20px 18px; }
}
@media (min-width: 1100px) {
  .grid { grid-template-columns: repeat(6, 1fr); }
}

/* --- 段评 ------------------------------------------------------------- */
/* 段落相对定位，气泡绝对定位在段落右侧 */
.pc-para { position: relative; }
.pc-bubble {
  position: absolute; right: -6px; top: 50%;
  transform: translateY(-50%);
  width: 44px; height: 44px;
  border: 0; padding: 0; background: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #756645;
  background-image: var(--pc-bubble, none);
  background-repeat: no-repeat; background-size: contain;
  z-index: 2;
}
.pc-bubble:hover { transform: translateY(-50%) scale(1.08); }
.pc-bubble .pc-counts {
  font-size: 12px; font-weight: 600; line-height: 1;
  transform: translateY(0.19em); /* 与 SVG 里 dy=0.38em 的文字位置对齐 */
  font-variant-numeric: tabular-nums;
}

/* 段评抽屉：遮罩 + 面板（宽屏右侧抽屉，窄屏底部弹层） */
.pc-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0.35);
}
.pc-panel {
  position: fixed; z-index: 61;
  background: var(--bg-elev); color: var(--ink);
  border: 1px solid var(--line);
  display: flex; flex-direction: column;
}
@media (min-width: 720px) {
  .pc-panel {
    top: 0; right: 0; bottom: 0;
    width: min(420px, 86vw);
    border-right: 0; border-radius: 0;
  }
}
@media (max-width: 719.9px) {
  .pc-panel {
    left: 0; right: 0; bottom: 0;
    max-height: 76vh;
    border-radius: 16px 16px 0 0;
  }
}
.pc-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.pc-title { margin: 0; font-size: 15px; font-weight: 600; }
.pc-close {
  border: 0; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--ink-soft); padding: 4px;
}
.pc-close:hover { color: var(--ink); }
.pc-list { overflow-y: auto; padding: 8px 16px 24px; flex: 1; }
.pc-status { padding: 24px 0; text-align: center; color: var(--ink-soft); font-size: 13px; }
.pc-error { color: var(--err, #a33); }
.pc-retry {
  margin-left: 8px; border: 1px solid var(--line); background: none;
  border-radius: 8px; padding: 3px 12px; font: inherit; font-size: 12.5px;
  color: var(--ink); cursor: pointer;
}
.pc-empty { padding: 40px 0; text-align: center; color: var(--ink-soft); font-size: 13px; }

.pc-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.pc-item:last-child { border-bottom: 0; }
.pc-main { display: flex; gap: 10px; }
.pc-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  object-fit: cover; background: var(--line); flex: none;
}
.pc-body { flex: 1; min-width: 0; }
.pc-meta { display: flex; align-items: baseline; gap: 8px; }
.pc-name { font-size: 12.5px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-like { margin-left: auto; flex: none; font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.pc-text { margin: 4px 0 0; font-size: 14px; line-height: 1.7; word-break: break-word; }
.pc-imgs { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.pc-imgs img {
  max-width: 100%; max-height: 180px;
  border-radius: 8px; border: 1px solid var(--line);
}
/* 评论里的表情与图片（富文本内联） */
.c-emoji { display: inline-block; height: 1.3em; vertical-align: -0.28em; margin: 0 1px; }
.c-img {
  display: block; max-width: min(100%, 260px); max-height: 200px;
  border-radius: 8px; border: 1px solid var(--line); margin: 6px 0;
}

/* 回复区 */
.pc-reply-box { margin: 8px 0 0 44px; padding-left: 10px; border-left: 2px solid var(--line); }
.pc-reply { padding: 6px 0; }
.pc-reply .pc-name { font-size: 12px; }
.pc-reply .pc-text { font-size: 13px; }
.pc-more {
  margin: 8px 0 0 44px; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 12.5px; color: var(--accent); padding: 2px 0;
}
.pc-reply-more {
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 12.5px; color: var(--accent); padding: 2px 0;
}
/* --- 关灯模式 ---------------------------------------------------------- */
/* 按钮常驻播放页右上角；开启后除播放器（含清晰度条 / 缓冲指示）外全部隐藏 */
.lights-btn {
  position: fixed; top: 12px; right: 16px; z-index: 40;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: 13px;
  box-shadow: var(--shadow);
}
.lights-btn:hover { border-color: var(--ink-soft); }
body.lights-off { background: #000; }
body.lights-off .topbar,
body.lights-off .dock,
body.lights-off .reader__bar,
body.lights-off .watch__side,
body.lights-off .series,
body.lights-off .streamtip { display: none !important; }
body.lights-off .stage { max-width: none; padding: 0; min-height: 100dvh; }
body.lights-off .reader--watch { max-width: 980px; margin: 0 auto; }
body.lights-off .player--video { border: 0; background: #000; padding: 0; box-shadow: none; }
body.lights-off .lights-btn { opacity: 0.35; background: rgba(20, 20, 20, 0.8); color: #ddd; }
body.lights-off .lights-btn:hover { opacity: 1; }

/* --- 阅读历史页 -------------------------------------------------------- */
.history { display: grid; gap: 12px; }
.history__item {
  position: relative;
  display: grid; grid-template-columns: 1fr; align-items: center;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden;
}
.history__item:hover { border-color: var(--ink-soft); }
.history__link {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 14px;
  align-items: center; padding: 10px 44px 10px 10px; min-width: 0;
}
.history__cover {
  width: 52px; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden;
  background: var(--bg); flex: none;
}
.history__cover img { width: 100%; height: 100%; object-fit: cover; }
.history__body { display: grid; gap: 3px; min-width: 0; }
.history__title {
  font-size: 14.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history__episode {
  font-size: 13px; color: var(--accent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history__meta { font-size: 12px; color: var(--ink-soft); }
.history__continue {
  flex: none; font-size: 13px; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
}
.history__item:hover .history__continue { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.history__del {
  position: absolute; top: 6px; right: 8px;
  border: 0; background: none; cursor: pointer; color: var(--ink-soft);
  font-size: 12px; line-height: 1; padding: 4px; border-radius: 6px;
}
.history__del:hover { color: var(--err); background: var(--bg); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}