:root {
  --bg: #faf8f3;
  --fg: #2b2b2b;
  --muted: #888;
  --panel: #f0ece2;
  --accent: #7a5c3a;
  --hairline: #e5e0d2;
}
html[data-theme="dark"] {
  --bg: #16181d;
  --fg: #cfd2d8;
  --muted: #6a6f78;
  --panel: #20242c;
  --accent: #c29867;
  --hairline: #2a2e36;
}
html[data-theme="sepia"] {
  --bg: #f4ecd8;
  --fg: #4a3f2e;
  --muted: #8a7a5f;
  --panel: #e9dfc5;
  --accent: #8c5a2b;
  --hairline: #dccfb1;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", Georgia, serif;
  transition: background .2s, color .2s;
}

/* 顶栏 */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: 48px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--bg); border-bottom: 1px solid var(--hairline);
}
.book-title { flex: 1; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  border: none; background: transparent; color: var(--fg); font-size: 16px;
  padding: 6px 10px; cursor: pointer; border-radius: 6px;
}
.icon-btn:hover { background: var(--panel); }

/* 目录抽屉 */
.toc {
  position: fixed; top: 0; bottom: 0; left: 0; width: 280px; z-index: 40;
  background: var(--bg); border-right: 1px solid var(--hairline);
  transform: translateX(-100%); transition: transform .2s; overflow-y: auto;
}
.toc.open { transform: translateX(0); }
.toc-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--hairline); }
.toc-head span { font-weight: 600; }
.toc ol { list-style: none; margin: 0; padding: 8px; }
.toc li { padding: 9px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; line-height: 1.4; }
.toc li:hover { background: var(--panel); }
.toc li.active { background: var(--panel); color: var(--accent); font-weight: 600; }
.mask { position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.25); display: none; }
.mask.show { display: block; }

/* 正文 */
.reader {
  max-width: 38rem; margin: 0 auto; padding: 72px 20px 96px;
  font-size: var(--fs, 18px); line-height: var(--lh, 1.9);
}
.ch-title { font-size: 1.5em; margin: 0 0 1.2em; font-weight: 700; }
.ch-body p { margin: 0 0 1em; text-align: justify; text-indent: 2em; }
.ch-body p.quote {
  text-indent: 0; background: var(--panel); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 4px; font-size: .92em; margin: 1.2em 0; color: var(--fg);
}
.ch-body img.cover { display: block; max-width: 62%; margin: 0 auto 1.6em; border-radius: 10px; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.ch-body img.scene { display: block; width: 100%; margin: 1.4em 0; border-radius: 8px; box-shadow: 0 3px 12px rgba(0,0,0,.18); }
.genre-badge { color: var(--muted); font-size: .9em; margin-bottom: 1em; }

/* 底部分页 */
.pager {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: 56px; display: flex; align-items: center; justify-content: center; gap: 16px;
  background: var(--bg); border-top: 1px solid var(--hairline);
}
.pg-btn { border: 1px solid var(--hairline); background: var(--bg); color: var(--fg);
  padding: 8px 18px; border-radius: 6px; cursor: pointer; }
.pg-btn:hover { background: var(--panel); }
.pg-btn:disabled { color: var(--muted); cursor: default; background: transparent; }
.pos { color: var(--muted); font-size: 13px; }

@media (max-width: 520px) {
  .reader { padding: 64px 16px 80px; }
  .ch-body p { text-indent: 1.5em; }
}
/* ---- 书架 ---- */
.shelf { max-width: 60rem; margin: 0 auto; padding: 24px 16px 48px; }
.shelf-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.shelf-head h1 { margin: 0; font-size: 22px; }
#search { flex: 1; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--hairline); background: var(--bg); color: var(--fg); font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.chip { border: 1px solid var(--hairline); background: var(--bg); color: var(--fg); padding: 5px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.book-card { border: 1px solid var(--hairline); border-radius: 10px; overflow: hidden; cursor: pointer; transition: transform .15s; }
.book-card:hover { transform: translateY(-3px); }
.book-card img { width: 100%; aspect-ratio: 3/4; object-fit: cover; display: block; }
.no-cover { width: 100%; aspect-ratio: 3/4; display: flex; align-items: center; justify-content: center; background: var(--panel); font-size: 28px; color: var(--muted); }
.bm { padding: 10px 12px; }
.bm h3 { margin: 0 0 6px; font-size: 16px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tags span { font-size: 11px; padding: 2px 8px; border-radius: 4px; background: var(--panel); color: var(--accent); }
.syn { margin: 0 0 6px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.stat { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.reader-app[hidden], .shelf[hidden] { display: none; }

/* ---- 评论 ---- */
.comments { margin-top: 3em; border-top: 1px solid var(--hairline); padding-top: 1.5em; }
.comments h2 { font-size: 17px; margin: 0 0 .8em; }
.cmt { padding: 10px 0; border-bottom: 1px solid var(--hairline); }
.cmt-meta { display: flex; gap: 10px; align-items: baseline; font-size: 13px; margin-bottom: 4px; }
.cmt-meta b { color: var(--accent); }
.cmt-meta span { color: var(--muted); font-size: 12px; }
.cmt p { margin: 0; font-size: 15px; line-height: 1.7; text-indent: 0; }
.cmt-empty { color: var(--muted); font-size: 14px; }
.cmt-form { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.cmt-form input, .cmt-form textarea {
  background: var(--bg); color: var(--fg); border: 1px solid var(--hairline);
  border-radius: 8px; padding: 9px 12px; font-size: 15px; font-family: inherit;
}
.cmt-form textarea { min-height: 80px; resize: vertical; }
.cmt-form button { align-self: flex-end; border: none; background: var(--accent); color: #fff;
  padding: 8px 22px; border-radius: 8px; cursor: pointer; font-size: 15px; }

/* ---- 翻页模式（书页式阅读） ---- */
.page-viewport {
  position: fixed; top: 48px; bottom: 56px; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel);
}
.reader-app.paged .reader { display: none; }
.page {
  width: min(92vw, 44rem); height: 100%;
  background: var(--bg); border: 1px solid var(--hairline);
  border-radius: 10px; box-shadow: 0 10px 36px rgba(0,0,0,.16);
  padding: 2.4rem 2.6rem 2.6rem; box-sizing: border-box;
  display: flex; flex-direction: column; overflow: hidden;
}
.page .pt-title { font-size: 1.25em; font-weight: 700; margin: 0 0 .8em; }
.page .pt-body { flex: 1; overflow: hidden; }
.page .pt-body p { margin: 0 0 .9em; text-align: justify; text-indent: 2em; }
.page .pt-body p.quote { text-indent: 0; background: var(--panel); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 4px; font-size: .92em; }
.page .pt-body img { display: block; max-width: 100%; max-height: 100%; margin: 0 auto; object-fit: contain; border-radius: 6px; }
.page-img { display: flex; align-items: center; justify-content: center; }
.measure { position: fixed; top: -9999px; left: 0; visibility: hidden; font-size: var(--fs,18px); line-height: var(--lh,1.9); }
.measure p { margin: 0 0 .9em; text-indent: 2em; }
.measure p.quote { text-indent: 0; padding: 10px 14px; }
.page-img .pt-body { display: flex; align-items: center; justify-content: center; }

/* ---- 页面更满 + 翻页动画 ---- */
.page { width: min(96vw, 60rem); padding: 1.8rem 2.4rem 2.2rem; }
.page .pt-body p { margin: 0 0 .5em; }
.measure p, .measure p.quote { margin: 0 0 .5em; }
.anim-fw { animation: pgfwd .28s ease; }
.anim-bw { animation: pgbwd .28s ease; }
@keyframes pgfwd { from { transform: translateX(48px); opacity: .15; } to { transform: translateX(0); opacity: 1; } }
@keyframes pgbwd { from { transform: translateX(-48px); opacity: .15; } to { transform: translateX(0); opacity: 1; } }

/* ---- 滑动阅读：隐藏滚动条 + 正文加宽 + 图片全宽 ---- */
html, body { scrollbar-width: none; -ms-overflow-style: none; }
::-webkit-scrollbar { display: none; }
.reader { max-width: min(94vw, 54rem); }
.ch-body img.fig, .ch-body img.cover, .ch-body img.scene {
  display: block; width: 100%; max-width: 100%; border-radius: 8px; margin: 1.2em 0;
}
.ch-body img.cover { margin-top: 0; }

/* ---- 全屏滑页阅读 ---- */
.deck { position: fixed; top: 48px; bottom: 56px; left: 0; right: 0; overflow: hidden; background: var(--bg); }
.pages { display: flex; height: 100%; transition: transform .34s ease; will-change: transform; }
.pg { flex: 0 0 100%; width: 100%; height: 100%; box-sizing: border-box; padding: 6vh 7vw 6vh; overflow: hidden; }
.pg .pg-title { font-size: 1.35em; font-weight: 700; margin: 0 0 1em; }
.pg .pg-body { height: calc(100% - 3em); overflow: hidden; }
.pg p { margin: 0 0 .6em; text-indent: 2em; text-align: justify; }
.pg p.quote { text-indent: 0; background: var(--panel); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 4px; font-size: .92em; }
.pg-img .pg-body { display: flex; align-items: center; justify-content: center; }
.pg-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.measure { position: fixed; top: -9999px; visibility: hidden; font-size: var(--fs,18px); line-height: var(--lh,1.9); }
.measure p { margin: 0 0 .6em; text-indent: 2em; }
.measure p.quote { text-indent: 0; }
.pg-img { padding: 0; display: flex; align-items: center; justify-content: center; background: #0a0a0a; }
.pg-img img { width: 100%; height: 100%; object-fit: contain; }
