/* ── 书斋 · 样式 ─────────────────────────────────────────── */
:root {
  --serif: "Source Han Serif SC", "Noto Serif CJK SC", "Songti SC", "STSong",
           "SimSun", "Georgia", serif;
  --sans: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --bg: #f6f2e9;
  --bg-soft: #fbf8f1;
  --ink: #2a2620;
  --ink-2: #5d564a;
  --ink-3: #8c8474;
  --line: #e2dbcb;
  --accent: #9c3d2e;
  --card: #fffdf8;
  --shadow: 0 10px 26px -12px rgba(70, 50, 20, .35);
  --rail: rgba(226, 219, 203, .8);
  --fs: 18px;
  --lh: 2;
  --measure: 40rem;
}

[data-theme="white"] {
  --bg: #fcfcfa; --bg-soft: #fff; --ink: #23262b; --ink-2: #4d5259;
  --ink-3: #8a9099; --line: #e6e7ea; --card: #fff; --accent: #8c3a2f;
  --rail: rgba(230, 231, 234, .85);
}
[data-theme="sepia"] {
  --bg: #efe3c8; --bg-soft: #f5ecd8; --ink: #4a3f2f; --ink-2: #6b5e49;
  --ink-3: #98896f; --line: #ddcfb0; --card: #f7eed9; --accent: #8a4b23;
  --rail: rgba(221, 207, 176, .85);
}
[data-theme="night"] {
  --bg: #171a1f; --bg-soft: #1d2127; --ink: #b9b3a6; --ink-2: #8e887c;
  --ink-3: #6b665d; --line: #2b3038; --card: #1d2127; --accent: #c0715c;
  --rail: rgba(43, 48, 56, .9);
  --shadow: 0 10px 26px -12px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--serif); line-height: 1.7;
  transition: background .3s ease, color .3s ease;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dim { color: var(--ink-3); }
code { font-family: ui-monospace, Consolas, monospace; background: var(--bg-soft);
  padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.link { background: none; border: 0; color: var(--accent); font-size: 14px;
  text-decoration: underline; text-underline-offset: 3px; }

/* ── 顶栏 ── */
.site-head {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.head-inner {
  max-width: 1240px; margin: 0 auto; padding: 16px 32px 12px;
  display: flex; align-items: center; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.seal {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: var(--accent); color: #fbf7ef; border-radius: 5px;
  font-size: 20px; font-weight: 600; letter-spacing: 0;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18);
}
.brand-text { font-size: 19px; letter-spacing: .14em; font-weight: 600; }

.search-box {
  position: relative; flex: 1; max-width: 460px; display: flex; align-items: center;
}
.search-box .ico { position: absolute; left: 12px; color: var(--ink-3); width: 17px; height: 17px; }
.search-box input {
  width: 100%; padding: 9px 46px 9px 38px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--bg-soft); color: var(--ink);
  font-family: var(--serif); font-size: 14.5px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(156,61,46,.1); }
.search-box input::placeholder { color: var(--ink-3); }
.search-box kbd {
  position: absolute; right: 12px; font-family: var(--sans); font-size: 11px;
  color: var(--ink-3); border: 1px solid var(--line); border-radius: 4px;
  padding: 0 5px; line-height: 17px; background: var(--bg);
}
.head-stat { margin-left: auto; font-size: 13px; color: var(--ink-3);
  letter-spacing: .04em; white-space: nowrap; }

.cats {
  max-width: 1240px; margin: 0 auto; padding: 0 32px 12px;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
}
.cats::-webkit-scrollbar { display: none; }
.cat {
  flex: none; border: 1px solid transparent; background: none; color: var(--ink-2);
  font-size: 14px; padding: 5px 13px; border-radius: 999px; letter-spacing: .05em;
  transition: all .18s;
}
.cat:hover { background: var(--bg-soft); }
.cat.on { background: var(--accent); color: #fbf7ef; font-weight: 500; }

/* ── 书架 ── */
.shelf {
  max-width: 1240px; margin: 0 auto; padding: 32px 32px 90px;
  display: grid; gap: 30px 26px;
  grid-template-columns: repeat(auto-fill, minmax(154px, 1fr));
}
.book { text-align: left; background: none; border: 0; padding: 0; }
.cover {
  aspect-ratio: 5 / 7; border-radius: 3px 6px 6px 3px; position: relative;
  display: grid; place-items: center; overflow: hidden;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.35);
  transition: transform .25s cubic-bezier(.2,.7,.3,1), box-shadow .25s;
  background: linear-gradient(150deg, #f3ecdc, #e8dfc9);
}
.book:hover .cover { transform: translateY(-6px) rotate(-.4deg);
  box-shadow: 0 22px 36px -16px rgba(70,50,20,.45), inset 0 0 0 1px rgba(255,255,255,.4); }
.cover::after {   /* 书脊 */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 9px;
  background: linear-gradient(90deg, rgba(90,70,40,.22), rgba(90,70,40,.02));
}
.cover-in {
  position: absolute; inset: 13px 11px 13px 17px;
  border: 1px solid rgba(120,95,55,.26); border-radius: 2px;
  display: flex; align-items: center; justify-content: center;
  padding: 16px 6px;
}
.cv-title {
  writing-mode: vertical-rl; text-orientation: upright;
  font-size: clamp(15px, 1.45vw, 19px); font-weight: 600; letter-spacing: .14em;
  line-height: 1.12; max-height: 100%; color: #3b3225;
  text-shadow: 0 1px 0 rgba(255,255,255,.55);
}
.cv-author {
  writing-mode: vertical-rl; font-size: 10.5px; letter-spacing: .16em;
  color: #6d5f47; position: absolute; left: 9px; bottom: 11px; opacity: .85;
}
.cv-seal {
  position: absolute; right: 9px; bottom: 9px; width: 22px; height: 22px;
  display: grid; place-items: center; font-size: 12px; color: #fff7f2;
  background: var(--accent); border-radius: 2px; opacity: .85;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
/* 分类配色 */
.cover[data-cat="章回小说"] { background: linear-gradient(150deg, #f0e7d4, #e3d7bd); }
.cover[data-cat="笔记小说"] { background: linear-gradient(150deg, #eef0e4, #dde2ce); }
.cover[data-cat="史书"]     { background: linear-gradient(150deg, #e9e9ee, #d7d8e2); }
.cover[data-cat="诸子"]     { background: linear-gradient(150deg, #edeee6, #d9ddcd); }
.cover[data-cat="诗词"]     { background: linear-gradient(150deg, #f6e9e4, #ecd7cf); }
.cover[data-cat="文集"]     { background: linear-gradient(150deg, #f2ece0, #e4dac6); }

.bk-title { margin-top: 12px; font-size: 15.5px; font-weight: 600; letter-spacing: .04em; }
.bk-meta { font-size: 12px; color: var(--ink-3); margin-top: 3px; display: flex; gap: 6px; }
.bk-prog { margin-top: 8px; height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bk-prog i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

.shelf-empty { max-width: 40rem; margin: 120px auto; text-align: center; line-height: 2.2; }

/* ── 搜索结果 ── */
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.search-head {
  max-width: 860px; margin: 0 auto; padding: 30px 32px 6px;
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 14px; color: var(--ink-3);
}
.hits { max-width: 860px; margin: 0 auto; padding: 12px 32px 90px; }
.hit {
  display: block; width: 100%; text-align: left; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 15px 18px;
  margin-bottom: 12px; transition: border-color .2s, transform .2s;
}
.hit:hover { border-color: var(--accent); transform: translateX(3px); }
.hit-top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.hit-book { font-weight: 600; font-size: 15px; }
.hit-ch { font-size: 13px; color: var(--ink-3); }
.hit-snip { font-size: 14.5px; color: var(--ink-2); line-height: 1.9; }
.hit-snip mark { background: rgba(156,61,46,.16); color: var(--accent); padding: 0 2px; border-radius: 2px; }

/* ── 阅读器 ── */
.reader-wrap { min-height: 100vh; }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px; padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px); border-bottom: 1px solid transparent;
  transition: transform .28s ease, border-color .28s, opacity .2s;
}
.topbar.solid { border-bottom-color: var(--line); }
.topbar.hide { transform: translateY(-102%); }
.tb-btn {
  border: 0; background: none; padding: 7px 11px; border-radius: 7px;
  font-size: 14px; color: var(--ink-2); display: flex; align-items: center; gap: 4px;
  letter-spacing: .04em; transition: background .18s, color .18s;
}
.tb-btn:hover { background: var(--bg-soft); color: var(--ink); }
.tb-btn.on { color: var(--accent); background: var(--bg-soft); }
.tb-title {
  flex: 1; text-align: center; font-size: 14px; color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: .08em;
}
.tb-tools { display: flex; gap: 4px; }

.progress-rail {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 41;
  background: transparent;
}
.progress-bar { height: 100%; width: 0; background: var(--accent); opacity: .55;
  transition: width .15s linear; }

/* ── 翻页阅读器 ───────────────────────────── */
.reader-stage {
  height: 100vh; height: 100dvh; padding: 0 24px;
  display: flex; align-items: stretch; justify-content: center;
}
.book-frame {
  width: 100%; max-width: var(--measure); height: 100%;
  display: flex; flex-direction: column; padding: 44px 26px 14px;
}
.page-area {
  position: relative; flex: 1; overflow: hidden;
  margin: 6px auto 8px; width: 100%; padding: 0;
}
.page-area > .ptrack, .page-area > .pflow { padding: 0; }
/* 版框：古籍的细双线 */
.page-area::before, .page-area::after {
  content: ""; position: absolute; left: 0; right: 0; height: 1px;
  background: var(--line);
}
.page-area::before { top: 0; }
.page-area::after { bottom: 0; }

.ptrack { will-change: transform; }
.pflow {
  column-fill: auto; font-size: var(--fs); line-height: var(--lh);
  color: var(--ink); word-break: break-word;
}
.pflow.vertical {
  writing-mode: vertical-rl; text-orientation: upright;
  letter-spacing: .04em; line-height: 1.9;
}
.pflow .ch-title {
  font-size: 1.28em; font-weight: 600; text-align: center; letter-spacing: .14em;
  margin: 0 0 1.2em; padding-bottom: .8em; border-bottom: 1px solid var(--line);
  line-height: 1.6; break-inside: avoid; break-after: avoid;
}
.pflow.vertical .ch-title { border-bottom: 0; border-left: 1px solid var(--line);
  padding: 0 0 0 0.8em; margin: 0 0 0 1.2em; }
.pflow p { text-indent: 2em; margin: 0 0 .7em; }
.pflow.vertical p { text-indent: 1em; margin: 0 0 0 .7em; }
.pflow h1, .pflow h2, .pflow h3 {
  font-size: 1.05em; font-weight: 600; text-align: center; letter-spacing: .1em;
  margin: 1.2em 0 .9em; break-after: avoid;
}
.pflow blockquote { margin: .8em 0; padding: 0 1em; border-left: 2px solid var(--line); }
.pflow blockquote p { text-indent: 0; }
.pflow img { max-width: 100%; height: auto; display: block; margin: .8em auto; }
.pflow hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }


/* 揭页动画纸片 */
.flip-sheet {
  position: absolute; top: 0; left: 0; overflow: hidden;
  background: var(--bg); backface-visibility: hidden;
  box-shadow: 0 0 30px rgba(70, 50, 20, .16);
}
.flip-sheet > * { pointer-events: none; }

/* 翻页光晕 */
.flip-veil { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.flip-veil.v-next { animation: veilNext .44s ease-out; }
.flip-veil.v-prev { animation: veilPrev .44s ease-out; }
@keyframes veilNext {
  0% { opacity: .55; background: linear-gradient(90deg, transparent 40%, rgba(90,70,40,.14)); }
  100% { opacity: 0; background: linear-gradient(90deg, transparent 70%, transparent); }
}
@keyframes veilPrev {
  0% { opacity: .55; background: linear-gradient(270deg, transparent 40%, rgba(90,70,40,.14)); }
  100% { opacity: 0; background: linear-gradient(270deg, transparent 70%, transparent); }
}

/* 页脚 */
.page-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 2px 0; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink-3);
}
.pf-btn {
  border: 0; background: none; padding: 5px 10px; border-radius: 6px;
  font-size: 12.5px; color: var(--ink-2); letter-spacing: .05em;
  transition: background .16s, color .16s;
}
.pf-btn:hover:not(:disabled) { background: var(--bg-soft); color: var(--accent); }
.pf-btn:disabled { opacity: .3; cursor: default; }
.pf-info {
  flex: 1; display: flex; align-items: baseline; justify-content: center;
  gap: 14px; overflow: hidden; white-space: nowrap;
}
.pf-num { font-variant-numeric: tabular-nums; letter-spacing: .1em; }
.pf-ch { color: var(--ink-3); opacity: .8; overflow: hidden; text-overflow: ellipsis; }
#chLabel { color: var(--ink-3); font-size: 12.5px; }

.corner-hint {
  position: fixed; left: 50%; bottom: 62px; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--bg); font-size: 12.5px; padding: 7px 16px;
  border-radius: 999px; opacity: 0; pointer-events: none; transition: all .28s;
  letter-spacing: .06em; z-index: 44;
}
.corner-hint.show { opacity: .9; transform: translateX(-50%) translateY(0); }

/* ── 抽屉 ── */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 86vw); z-index: 60;
  background: var(--bg-soft); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  animation: slideIn .26s cubic-bezier(.2,.8,.3,1);
  box-shadow: -18px 0 40px -20px rgba(60,40,10,.3);
}
@keyframes slideIn { from { transform: translateX(30px); opacity: .5; } }
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 20px 18px 14px; border-bottom: 1px solid var(--line);
}
.drawer-book { font-size: 16px; font-weight: 600; letter-spacing: .06em; }
.drawer-sub { font-size: 12px; color: var(--ink-3); margin-top: 4px; letter-spacing: .05em; }
.icon-btn { border: 0; background: none; color: var(--ink-3); font-size: 16px; padding: 2px 6px; }
.drawer-list { overflow-y: auto; padding: 8px 0 30px; flex: 1; }
.toc-item {
  display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: none;
  padding: 9px 20px; font-size: 14px; color: var(--ink-2); line-height: 1.5;
  border-left: 2px solid transparent; transition: background .15s, color .15s;
}
.toc-item:hover { background: var(--bg); }
.toc-item.on { color: var(--accent); border-left-color: var(--accent); background: var(--bg); font-weight: 500; }
.toc-item .num { color: var(--ink-3); font-size: 12px; min-width: 2.2em; flex: none; padding-top: 2px; }
.scrim { position: fixed; inset: 0; background: rgba(40,30,15,.28); z-index: 50;
  animation: fade .2s ease; }

/* ── 排版面板 ── */
.panel {
  position: fixed; top: 56px; right: 18px; z-index: 45; width: 290px;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px 18px; box-shadow: 0 20px 44px -18px rgba(50,35,10,.4);
  animation: fade .18s ease;
}
.panel-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.panel-row:last-child { margin-bottom: 0; }
.panel-label { font-size: 12.5px; color: var(--ink-3); width: 2.6em; flex: none; letter-spacing: .08em; }
.seg { display: flex; flex: 1; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button {
  flex: 1; border: 0; background: none; font-size: 12.5px; padding: 7px 0;
  color: var(--ink-2); transition: background .15s, color .15s;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fbf7ef; }
.themes { display: flex; gap: 9px; }
.themes button {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line);
  background: none; padding: 0; display: grid; place-items: center;
}
.themes button i { width: 20px; height: 20px; border-radius: 50%; display: block;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.themes button.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(156,61,46,.12); }

/* ── 响应式 ── */
@media (max-width: 720px) {
  .head-inner { padding: 12px 16px 8px; gap: 12px; flex-wrap: wrap; }
  .head-stat { display: none; }
  .search-box { max-width: none; order: 3; flex-basis: 100%; }
  .search-box kbd { display: none; }
  .cats { padding: 0 16px 10px; }
  .shelf { padding: 20px 16px 80px; gap: 22px 16px;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
  .reader-stage { padding: 0 14px; }
  .book-frame { padding-top: 40px; }
  .page-area { padding-top: 18px; }
  .pflow .ch-title { font-size: 1.15em; }
  .panel { right: 8px; left: 8px; width: auto; top: 52px; }
  .corner-hint { bottom: 14px; }
}

/* 阅读器加载态 */
.reader-loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--ink-3); letter-spacing: .2em; font-size: 14px;
}
