/* 夜航书屋 — 深色阅读主题 */
/* 铁律：无 Inter 字体、无紫色、无 emoji 图标（纯 CSS 形状） */

:root {
  --bg: #0d1117;
  --bg-soft: #141a24;
  --bg-card: #171f2b;
  --bg-elev: #1d2735;
  --line: #26303f;
  --line-soft: #202a38;
  --ink: #d8dee9;
  --ink-strong: #f0f3f8;
  --ink-dim: #8b98ab;
  --amber: #d9a55a;
  --amber-deep: #b9833a;
  --amber-soft: rgba(217, 165, 90, 0.14);
  --teal: #4fa3a5;
  --teal-soft: rgba(79, 163, 165, 0.15);
  --red: #c96a5a;
  --green: #7fb069;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "STSong", "SimSun", Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
/* 铁律：作者样式的 display 会覆盖 UA 的 [hidden]，必须显式声明，否则多视图同时渲染 */
[hidden] { display: none !important; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  min-width: 320px;
  overflow-x: hidden;
}
button { font-family: inherit; border: none; background: none; color: inherit; cursor: pointer; }
img, svg { display: block; max-width: 100%; }
a { color: var(--amber); text-decoration: none; }

/* ---------- 骨架屏 / 书架（index 旧壳，渐进增强后由 JS 接管重渲染） ---------- */
.shelf-body { background: radial-gradient(1200px 500px at 50% -10%, #16202e 0%, var(--bg) 60%); }
.shelf-header { padding: 40px 20px 8px; max-width: 720px; margin: 0 auto; }
.shelf-brand { display: flex; gap: 14px; align-items: center; }
.shelf-logo-mark { width: 44px; height: 44px; border-radius: 12px; flex: none; background: linear-gradient(135deg, #233043, #1a2434); border: 1px solid var(--line); position: relative; }
.shelf-logo-mark::after { content: ""; position: absolute; inset: 10px 14px; background: var(--amber); border-radius: 2px; box-shadow: 0 0 14px rgba(217,165,90,.4); }
.shelf-header h1 { font-size: 22px; color: var(--ink-strong); letter-spacing: 2px; }
.shelf-sub { color: var(--ink-dim); font-size: 13px; margin-top: 3px; }
.shelf-main { max-width: 720px; margin: 18px auto 40px; padding: 0 20px; }
.skeleton-card { display: flex; gap: 14px; background: var(--bg-card); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 16px; }
.sk-cover { width: 84px; height: 118px; border-radius: 8px; background: linear-gradient(100deg, #1a2331 40%, #222d3d 50%, #1a2331 60%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.sk-lines { flex: 1; display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }
.sk-lines i { height: 12px; border-radius: 4px; background: #1c2533; animation: shimmer 1.4s infinite; }
.sk-lines i:nth-child(1) { width: 55%; } .sk-lines i:nth-child(2) { width: 92%; } .sk-lines i:nth-child(3) { width: 78%; height: 92px; }
@keyframes shimmer { 0% { opacity: .55; } 50% { opacity: 1; } 100% { opacity: .55; } }
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-dim); }
.empty-icon { width: 64px; height: 64px; margin: 0 auto 16px; border: 2px solid var(--line); border-radius: 10px; position: relative; }
.empty-icon::after { content: ""; position: absolute; left: 14px; right: 14px; top: 20px; height: 3px; background: var(--line); box-shadow: 0 9px 0 var(--line), 0 18px 0 var(--line); }
.shelf-footer { text-align: center; color: var(--ink-dim); font-size: 12px; padding: 24px 0 40px; }

/* ---------- 通用布局 ---------- */
.view { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner { display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 14px; max-width: 720px; margin: 0 auto; width: 100%; }
.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar-title strong { font-size: 15px; color: var(--ink-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-body { flex: 1; width: 100%; }
.container { max-width: 720px; margin: 0 auto; padding: 16px 16px 0; }
.site-footer { text-align: center; color: var(--ink-dim); font-size: 12px; padding: 30px 0 40px; }
.muted { color: var(--ink-dim); }
.small { font-size: 12px; }

.brand { display: flex; align-items: center; gap: 10px; }
.logo-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #233043, #1a2434); border: 1px solid var(--line); position: relative; }
.logo-mark::after { content: ""; position: absolute; inset: 8px 9px; background: var(--amber); border-radius: 2px; }
.brand-name { font-size: 17px; letter-spacing: 2px; color: var(--ink-strong); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elev); border: 1px solid var(--line);
}
.icon-btn:active { transform: scale(0.94); }

/* 纯 CSS 图标（无 emoji） */
.i-back { width: 10px; height: 10px; border-left: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: rotate(45deg); margin-left: 2px; }
.i-ajust { width: 16px; height: 10px; border: 1.6px solid var(--ink); border-radius: 2px; position: relative; }
.i-ajust::after { content: ""; position: absolute; top: -4px; bottom: -4px; left: 5px; width: 2px; background: var(--ink); border-radius: 1px; }
.i-prev, .i-next { width: 14px; height: 14px; border-left: 2.4px solid var(--ink-strong); border-bottom: 2.4px solid var(--ink-strong); }
.i-prev { transform: rotate(45deg); }
.i-next { transform: rotate(-135deg); }
.i-play, .i-pause { width: 0; height: 0; border-style: solid; }
.i-play { border-width: 9px 0 9px 15px; border-color: transparent transparent transparent #10151d; margin-left: 3px; }
.i-pause { border-width: 10px 3.5px; border-color: transparent #10151d transparent #10151d; }

/* ---------- 书架 ---------- */
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; margin: 8px 2px 14px; }
.shelf-head h2 { font-size: 18px; color: var(--ink-strong); letter-spacing: 1px; }
.book-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 560px) { .book-grid { grid-template-columns: 1fr 1fr; } }
.book-card {
  display: flex; gap: 14px; padding: 14px;
  background: var(--bg-card); border: 1px solid var(--line-soft); border-radius: var(--radius);
  transition: border-color .2s;
}
.book-card:active { border-color: var(--amber-deep); }
.book-cover {
  width: 88px; height: 124px; border-radius: 8px; flex: none; overflow: hidden;
  background: #1a2331; border: 1px solid var(--line);
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.book-title-row { display: flex; align-items: center; gap: 8px; }
.book-title { font-size: 17px; font-weight: 700; color: var(--ink-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-status { font-size: 11px; padding: 2px 8px; border-radius: 20px; flex: none; background: var(--teal-soft); color: var(--teal); border: 1px solid rgba(79,163,165,.3); }
.book-status.done { background: rgba(139,152,171,.12); color: var(--ink-dim); border-color: var(--line); }
.book-author { font-size: 12px; color: var(--ink-dim); margin-top: 4px; }
.book-desc { font-size: 13px; line-height: 1.7; color: var(--ink); margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.book-meta-row { margin-top: auto; padding-top: 10px; display: flex; align-items: center; gap: 8px; }
.book-progress { font-size: 12px; color: var(--amber); }
.book-progress.none { color: var(--ink-dim); }
.book-tags { display: flex; gap: 6px; margin-left: auto; }
.tag { font-size: 11px; color: var(--ink-dim); background: var(--bg-elev); border: 1px solid var(--line-soft); padding: 2px 8px; border-radius: 4px; }

/* ---------- 目录 ---------- */
.continue-bar { margin-bottom: 14px; }
.btn-primary {
  width: 100%; height: 46px; border-radius: 12px;
  background: linear-gradient(135deg, var(--amber), var(--amber-deep));
  color: #14181f; font-size: 15px; font-weight: 700; letter-spacing: 2px;
  box-shadow: 0 6px 18px rgba(217,165,90,.25);
}
.btn-primary:active { transform: translateY(1px); }
.toc-progress { font-size: 12px; color: var(--ink-dim); margin-bottom: 10px; padding: 0 2px; }
.toc-list { background: var(--bg-card); border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden; }
.toc-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 13px 14px; border-bottom: 1px solid var(--line-soft);
}
.toc-item:last-child { border-bottom: none; }
.toc-item:active { background: var(--bg-elev); }
.toc-no { font-size: 12px; color: var(--ink-dim); min-width: 34px; font-variant-numeric: tabular-nums; }
.toc-main { flex: 1; min-width: 0; }
.toc-title { font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toc-sub { font-size: 11px; color: var(--ink-dim); margin-top: 2px; display: flex; gap: 8px; align-items: center; }
.toc-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--line); flex: none; }
.toc-dot.read { background: var(--green); }
.toc-dot.current { background: var(--amber); box-shadow: 0 0 6px rgba(217,165,90,.8); }
.audio-mark { font-size: 11px; color: var(--teal); border: 1px solid rgba(79,163,165,.4); background: var(--teal-soft); padding: 1px 6px; border-radius: 3px; flex: none; }

/* ---------- 阅读页 ---------- */
.reader-body { background: var(--bg); }
.read-content { padding: 26px 4px 10px; }
.rc-title { font-family: var(--serif); font-size: 22px; font-weight: 700; color: var(--ink-strong); text-align: center; letter-spacing: 1px; margin-bottom: 6px; }
.rc-meta { text-align: center; color: var(--ink-dim); font-size: 12px; margin-bottom: 26px; }
.rc-sys { background: var(--bg-card); border: 1px solid var(--line-soft); border-left: 3px solid var(--amber); border-radius: 10px; padding: 14px 16px; font-size: 15px; line-height: 1.8; color: var(--ink); margin-bottom: 26px; }
.rc-p { font-family: var(--serif); font-size: var(--read-fs, 19px); line-height: var(--read-lh, 1.9); color: var(--ink); margin-bottom: 1.2em; text-align: justify; }
.rc-p.dim { color: var(--ink-dim); }
.read-foot { text-align: center; margin: 18px 0 8px; }
.chapter-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 18px 0 10px; }
.btn-ghost {
  height: 42px; padding: 0 20px; border-radius: 10px;
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--ink);
  font-size: 14px;
}
.btn-ghost:disabled { opacity: .35; }
.btn-ghost:not(:disabled):active { transform: translateY(1px); }

.read-toolbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; gap: 4px; padding: 5px;
  background: rgba(23, 31, 43, 0.96); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); z-index: 60;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.tb-btn { min-width: 52px; height: 38px; border-radius: 11px; font-size: 13px; color: var(--ink); padding: 0 10px; }
.tb-btn:active { background: var(--bg-elev); }

.settings-panel {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(74px + env(safe-area-inset-bottom));
  width: min(92vw, 340px);
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; z-index: 60; box-shadow: var(--shadow);
}
.sp-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.sp-label { font-size: 13px; color: var(--ink-dim); width: 34px; flex: none; }
.seg { display: flex; flex: 1; gap: 5px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 44px; height: 34px; border-radius: 8px;
  font-size: 12.5px; color: var(--ink); background: var(--bg-elev); border: 1px solid var(--line-soft);
}
.seg button.on { background: var(--amber-soft); border-color: var(--amber-deep); color: var(--amber); }
.seg-sm button { min-width: 40px; height: 30px; font-size: 11.5px; }

/* 主题（阅读区） */
body[data-theme="sepia"] { --bg: #1c1812; --bg-card: #241e15; --bg-elev: #2c2519; --ink: #d9cba8; --ink-strong: #ead9b0; --ink-dim: #93835f; --line: #3a3020; --line-soft: #322a1c; }
body[data-theme="light"] { --bg: #f5f2ec; --bg-card: #ffffff; --bg-elev: #efeadf; --ink: #3a3a3a; --ink-strong: #222; --ink-dim: #8d8779; --line: #ddd6c8; --line-soft: #e6e0d3; --shadow: 0 8px 28px rgba(60,50,20,.12); }
body[data-theme="light"] .topbar { background: rgba(245,242,236,.94); }

/* ---------- 听书页 ---------- */
.listen-hero { display: flex; gap: 16px; margin: 10px 0 18px; }
.listen-cover { width: 96px; height: 136px; border-radius: 10px; flex: none; overflow: hidden; background: #1a2331; border: 1px solid var(--line); }
.listen-cover img { width: 100%; height: 100%; object-fit: cover; }
.listen-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.listen-info h2 { font-size: 18px; color: var(--ink-strong); margin-bottom: 6px; }
.listen-noaudio { margin-top: 14px; background: var(--bg-card); border: 1px solid var(--line-soft); border-radius: 12px; padding: 16px; }
.listen-noaudio p { font-size: 14px; margin-bottom: 6px; }
.player-card { background: var(--bg-card); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 16px; margin-bottom: 20px; }
.ply-time-row { display: flex; align-items: center; gap: 10px; }
.ply-time { font-size: 11px; color: var(--ink-dim); font-variant-numeric: tabular-nums; min-width: 38px; }
.ply-bar { flex: 1; height: 26px; display: flex; align-items: center; position: relative; cursor: pointer; touch-action: none; }
.ply-track-hack { position: absolute; left: 0; right: 0; top: 0; bottom: 0; }
.ply-bar::before { content: ""; position: absolute; left: 0; right: 0; height: 4px; border-radius: 2px; background: var(--line); }
.ply-bar-buffer, .ply-bar-fill { position: absolute; left: 0; height: 4px; border-radius: 2px; }
.ply-bar-buffer { background: #33405433; background: rgba(139,152,171,.25); width: 0; }
.ply-bar-fill { background: linear-gradient(90deg, var(--amber), var(--amber-deep)); width: 0; }
.ply-bar-thumb { position: absolute; width: 13px; height: 13px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 8px rgba(217,165,90,.6); left: 0; transform: translateX(-50%); }
.ply-ctrls { display: flex; align-items: center; justify-content: center; gap: 34px; margin: 10px 0 14px; }
.ply-side { width: 50px; height: 50px; border-radius: 50%; background: var(--bg-elev); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.ply-side:active { transform: scale(.94); }
.ply-main { width: 64px; height: 64px; border-radius: 50%; background: linear-gradient(135deg, var(--amber), var(--amber-deep)); display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 22px rgba(217,165,90,.3); }
.ply-main:active { transform: scale(.96); }
.ply-row2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
/* 无音频章节：音频控件灰显但上/下一章仍可用 */
.player-card.no-audio .ply-main,
.player-card.no-audio .ply-bar,
.player-card.no-audio .ply-speed { opacity: .4; }
.player-card.no-audio .ply-time { opacity: .55; }
.ply-speed { flex: initial; }
.ply-toggle { font-size: 12.5px; color: var(--ink); background: var(--bg-elev); border: 1px solid var(--line); border-radius: 8px; height: 32px; padding: 0 12px; }
.ply-toggle.on { color: var(--amber); border-color: var(--amber-deep); background: var(--amber-soft); }
.listen-section h3 { font-size: 15px; color: var(--ink-strong); margin: 4px 2px 10px; }
.listen-toc { background: var(--bg-card); border: 1px solid var(--line-soft); border-radius: var(--radius); overflow: hidden; }
.lt-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line-soft); }
.lt-item:last-child { border-bottom: none; }
.lt-item:active { background: var(--bg-elev); }
.lt-item .toc-title { flex: 1; }
.lt-item.current .toc-title { color: var(--amber); }
.lt-dur { font-size: 11px; color: var(--ink-dim); }

/* toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom));
  background: rgba(29, 39, 53, .97); color: var(--ink-strong);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 18px; font-size: 13px; z-index: 99;
  box-shadow: var(--shadow); max-width: 80vw; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
#toast.show { opacity: 1; }
