:root {
  --bg: #000;
  --fg: #eceef2;
  --dim: #8b90a0;
  --faint: #4a4e5a;
  --panel: rgba(22, 23, 28, 0.82);
  --line: rgba(255, 255, 255, 0.09);
  --accent: #7aa2ff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- 书架 ---------- */
.page { padding: calc(var(--safe-top) + 20px) 16px calc(var(--safe-bottom) + 32px); max-width: 900px; margin: 0 auto; }
.page h1 { font-size: 28px; font-weight: 700; margin: 8px 0 20px; letter-spacing: 0.5px; }
/* 大厅顶部的分区：漫画 / 影视，大字标题样式，当前分区亮、另一个暗 */
.tabs { display: flex; gap: 18px; margin: 8px 0 20px; }
.tab { font-size: 28px; font-weight: 700; letter-spacing: 0.5px; color: var(--faint); }
.tab.active { color: var(--fg); }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 20px 14px; }
.book { text-align: left; }
.cover {
  display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: 10px; background: #15161b; border: 1px solid var(--line);
}
.book-title { margin-top: 8px; font-size: 14px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-sub { font-size: 12px; color: var(--dim); }
.empty { color: var(--dim); padding: 40px 0; text-align: center; }

/* ---------- 章节目录页 ---------- */
.detail-head { display: flex; gap: 16px; align-items: flex-end; margin-bottom: 20px; }
.detail-head .cover { width: 112px; flex: none; }
.detail-head h1 { margin: 0 0 6px; font-size: 22px; }
.back-link { display: inline-flex; align-items: center; gap: 2px; color: var(--dim); font-size: 15px; margin-bottom: 12px; }
.back-link svg { width: 20px; height: 20px; }
.primary {
  display: block; width: 100%; padding: 14px; border-radius: 12px; margin: 4px 0 22px;
  background: var(--fg); color: #000; font-weight: 600; font-size: 16px; text-align: center;
}
.chapters { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chapters button {
  width: 100%; text-align: left; padding: 11px 12px; border-radius: 10px;
  background: #111217; border: 1px solid var(--line); font-size: 14px;
  display: flex; justify-content: space-between; gap: 6px;
}
.chapters button.current { border-color: var(--accent); color: #fff; }
.chapters button:disabled { color: var(--faint); cursor: default; }
.chapters .tag { font-size: 11px; color: var(--dim); flex: none; align-self: center; }
.chapters .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 阅读页 ---------- */
.reader { min-height: 100vh; }
.reader img { display: block; width: 100%; height: auto; background: #0b0b0e; }
.reader img.no-size { min-height: 60vh; }
.chapter-end { padding: 48px 20px calc(var(--safe-bottom) + 64px); text-align: center; color: var(--dim); }
.chapter-end .primary { max-width: 360px; margin: 16px auto 12px; }
.chapter-end .ghost { color: var(--dim); padding: 10px; }

/* ---------- 弹出菜单 ---------- */
.bar { position: fixed; left: 0; right: 0; z-index: 10; transition: opacity .18s ease, transform .18s ease; }
.bar.top {
  top: 0; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 6px) 8px 10px;
  background: linear-gradient(rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.55));
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.bar-title { flex: 1; font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar.bottom { bottom: 0; padding: 0 12px calc(var(--safe-bottom) + 12px); }
.panel {
  max-width: 560px; margin: 0 auto; padding: 12px 10px 8px; border-radius: 18px;
  background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.row { display: flex; align-items: center; gap: 6px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; flex: none; }
.icon-btn:active { background: rgba(255, 255, 255, 0.08); }
.icon-btn:disabled { opacity: .3; }
.icon-btn svg, .back-link svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg { width: 22px; height: 22px; }
.page-label { text-align: center; font-size: 12px; color: var(--dim); padding-top: 2px; font-variant-numeric: tabular-nums; }

input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 44px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.18); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%;
  background: #d9dbe2; box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.18); }
input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: #d9dbe2; }

/* ---------- 目录抽屉 ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 72vh; display: flex; flex-direction: column;
  background: #121318; border-radius: 18px 18px 0 0; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.sheet-head { padding: 16px 20px 10px; font-weight: 600; }
.toc-list { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.toc-list button {
  width: 100%; text-align: left; padding: 12px; border-radius: 10px; display: flex; justify-content: space-between;
}
.toc-list button.current { color: var(--accent); background: rgba(122, 162, 255, 0.1); }
.toc-list button:disabled { color: var(--faint); }
.toc-list .tag { font-size: 12px; color: var(--dim); }

/* ---------- 影视播放页 ---------- */
.player-page { padding-bottom: calc(var(--safe-bottom) + 24px); }
.player-top {
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-top) + 6px) 8px 8px;
}
.player-top .icon-btn { color: var(--fg); }
#video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; }
.player-nav { display: flex; gap: 10px; padding: 14px 16px 6px; }
.ghost-btn {
  flex: 1; padding: 12px; border-radius: 12px; text-align: center;
  background: #111217; border: 1px solid var(--line); font-size: 15px;
}
.ghost-btn:disabled { color: var(--faint); }
/* 集数按钮按名字长短自动排：短的（01、02）一排多个，长的（前情提要）自己变宽，不截断 */
.player-list { padding: 10px 16px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.player-list li { flex: 1 0 auto; min-width: 56px; }
.player-list button { justify-content: center; }
.player-list .name { overflow: visible; white-space: normal; }

/* ---------- 任务页 ---------- */
.book-sub .busy { color: var(--accent); }
.add-form { display: flex; gap: 8px; align-items: stretch; }
.add-form input {
  flex: 1; min-width: 0; padding: 12px; border-radius: 12px; font: inherit; font-size: 16px; /* 16px 以下 iPhone 会自动放大 */
  color: var(--fg); background: #111217; border: 1px solid var(--line);
}
.add-form .primary { width: auto; margin: 0; padding: 12px 18px; }
.add-msg { min-height: 20px; margin: 8px 2px 10px; font-size: 13px; color: var(--dim); }
.sites { font-size: 12px; color: var(--dim); margin-bottom: 12px; }
.job { padding: 12px; margin-bottom: 10px; border-radius: 12px; background: #111217; border: 1px solid var(--line); }
.job-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.job-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.job-state { flex: none; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: rgba(122, 162, 255, 0.14); color: var(--accent); }
.job-state.ok { background: rgba(80, 200, 120, 0.14); color: #6fd49a; }
.job-state.warn { background: rgba(240, 180, 60, 0.14); color: #f0c060; }
.job-state.bad { background: rgba(240, 90, 90, 0.14); color: #f08080; }
.job-need { margin-top: 6px; font-size: 13px; color: #f0c060; }
.job-detail { margin-top: 6px; font-size: 13px; color: var(--dim); word-break: break-all; }
.job-foot { margin-top: 8px; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; color: var(--faint); }
.job-actions { display: flex; gap: 6px; flex: none; }
.job-btn { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); color: var(--fg); font-size: 13px; }
.job-btn.dim { color: var(--dim); }

/* ---------- 直播：播放器直接嵌在频道卡片里 ---------- */
.live-box {
  position: relative; margin-top: 10px; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden;
  background: #0b0b0e; border: 1px solid var(--line); display: grid; place-items: center;
}
.live-box.off { color: var(--faint); font-size: 13px; }
.live-box video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.live-play {
  width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.92); box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.live-play svg { width: 28px; height: 28px; fill: #000; margin-left: 3px; }
.live-play:active { transform: scale(0.94); }
