/* ============ 古典小说文库 · 样式 ============ */
:root {
  --bg: #f5efe0;
  --surface: #faf6ea;
  --surface2: #efe7d3;
  --ink: #2c2416;
  --ink2: #5a4e3a;
  --muted: #8a7d65;
  --accent: #8b2f1e;
  --accent-soft: #f0ddd4;
  --border: #d9cdb4;
  --shadow: 0 4px 20px rgba(60,40,20,.12);
  --reader-bg: #f7f1e1;
  --font-serif: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
}
[data-theme="night"] {
  --bg: #1a1a1e; --surface: #242428; --surface2: #2e2e33;
  --ink: #e0dcd4; --ink2: #a8a49c; --muted: #6e6a62;
  --accent: #d4856a; --accent-soft: #3a2a24; --border: #3a3a40;
  --shadow: 0 4px 20px rgba(0,0,0,.4); --reader-bg: #1e1e22;
}
[data-theme="green"] {
  --bg: #e8efe4; --surface: #f0f5ec; --surface2: #dde7d6;
  --ink: #2a3326; --ink2: #4d5a45; --muted: #7a8a70;
  --accent: #3d6b35; --accent-soft: #d4e5cf; --border: #c5d4bc;
  --shadow: 0 4px 20px rgba(40,60,30,.12); --reader-bg: #eef4ea;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.8;
  transition: background .3s, color .3s;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ---- 顶栏 ---- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: .05em; }
.logo-seal {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 6px;
  background: var(--accent); color: #fff; font-size: 18px;
}
.searchbox {
  flex: 1; max-width: 480px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 24px;
  background: var(--surface); border: 1px solid var(--border);
}
.searchbox svg { fill: var(--muted); flex-shrink: 0; }
.searchbox input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 14px; color: var(--ink); font-family: inherit;
}
.top-actions { display: flex; gap: 8px; }
.top-actions button {
  padding: 7px 14px; border-radius: 20px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); color: var(--ink2);
}
.top-actions button:hover { background: var(--surface2); }

/* ---- 搜索下拉 ---- */
.search-drop {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%);
  width: min(480px, 90vw); max-height: 420px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); z-index: 60;
}
.sd-group { padding: 8px 6px 4px; font-size: 12px; color: var(--muted); letter-spacing: .1em; padding-left: 14px; }
.sd-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 14px; font-size: 14px; color: var(--ink2);
  border-bottom: 1px solid var(--border);
}
.sd-item:hover { background: var(--surface2); }
.sd-item .sd-name { color: var(--ink); font-weight: 600; }
.sd-item .sd-sub { font-size: 12px; color: var(--muted); margin-left: 8px; }
.sd-item .sd-chapter { font-size: 12px; color: var(--muted); display: block; margin-top: 2px; }
.sd-empty { padding: 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---- 首页 ---- */
.hero { text-align: center; padding: 48px 20px 24px; }
.hero h1 { font-size: 38px; letter-spacing: .15em; margin-bottom: 8px; }
.hero p { color: var(--muted); font-size: 15px; letter-spacing: .1em; }
.stats {
  display: flex; justify-content: center; gap: 0;
  max-width: 720px; margin: 28px auto;
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  background: var(--surface);
}
.stat { flex: 1; padding: 18px 12px; text-align: center; border-right: 1px solid var(--border); }
.stat:last-child { border-right: none; }
.stat-num { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--muted); letter-spacing: .1em; margin-top: 2px; }
.cat-chips {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  max-width: 800px; margin: 0 auto 28px; padding: 0 20px;
}
.cat-chip {
  padding: 7px 16px; border-radius: 20px; font-size: 13px;
  background: var(--surface); border: 1px solid var(--border); color: var(--ink2);
}
.cat-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.continue-card {
  max-width: 720px; margin: 0 auto 24px; padding: 14px 20px;
  background: var(--accent-soft); border-radius: 10px;
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.continue-card .cc-label { font-size: 12px; color: var(--muted); letter-spacing: .1em; }
.continue-card .cc-title { font-weight: 600; color: var(--accent); }
.book-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px; max-width: 1100px; margin: 0 auto; padding: 0 20px 40px;
}
.book-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.book-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.book-card .bc-cat {
  display: inline-block; font-size: 11px; padding: 2px 8px;
  background: var(--accent-soft); color: var(--accent); border-radius: 4px; margin-bottom: 8px;
}
.book-card h3 { font-size: 17px; margin-bottom: 6px; }
.book-card .bc-author { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.book-card .bc-meta { font-size: 12px; color: var(--ink2); }
.section-title {
  max-width: 1100px; margin: 0 auto 16px; padding: 0 20px;
  font-size: 18px; letter-spacing: .1em; display: flex; justify-content: space-between; align-items: baseline;
}
.section-title .st-count { font-size: 13px; color: var(--muted); }

/* ---- 阅读页 ---- */
.reader-top {
  position: sticky; top: 55px; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  background: color-mix(in srgb, var(--reader-bg) 90%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.rt-back { display: flex; align-items: center; gap: 4px; font-size: 14px; color: var(--ink2); }
.rt-title { flex: 1; text-align: center; }
.rt-title .rt-book { font-size: 15px; font-weight: 600; }
.rt-title .rt-chapter { font-size: 12px; color: var(--muted); }
.rt-btn {
  width: 36px; height: 36px; border-radius: 8px;
  display: grid; place-items: center; font-size: 16px;
  background: var(--surface); border: 1px solid var(--border);
}
.reader-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 80; background: transparent; pointer-events: none; }
.reader-progress i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 0 2px 2px 0; transition: width .08s linear; }
.reader {
  max-width: 720px; margin: 0 auto; padding: 32px 24px 60px;
  background: var(--reader-bg); min-height: calc(100vh - 100px);
}
.reader .r-cat { text-align: center; font-size: 12px; color: var(--muted); letter-spacing: .15em; margin-bottom: 8px; }
.reader h2 {
  text-align: center; font-size: 24px; margin-bottom: 24px;
  padding-bottom: 14px; border-bottom: 2px solid var(--accent);
  display: inline-block; width: 100%;
}
.reader h2::after { content: ''; display: block; width: 60px; height: 2px; background: var(--accent); margin: 12px auto 0; }
.reader .rd-body p {
  text-indent: 2em; margin-bottom: 16px; font-size: 17px;
  line-height: var(--reader-lh, 1.95); letter-spacing: var(--reader-ls, .05em);
  color: var(--ink);
}
/* 竖排模式 */
.reader.vertical .rd-body {
  writing-mode: vertical-rl;
  height: calc(100vh - 200px);
  overflow-x: auto;
  text-indent: 0;
  column-gap: 2em;
}
.reader.vertical .rd-body p {
  text-indent: 0;
  margin: 0 0 0 1.5em;
  display: inline-block;
}
.chapter-nav {
  display: flex; justify-content: space-between; gap: 16px;
  max-width: 720px; margin: 24px auto 0; padding: 0 24px;
}
.nav-btn {
  flex: 1; padding: 14px 16px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  text-align: left;
}
.nav-btn.next { text-align: right; }
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }
.nav-btn .nb-label { font-size: 12px; color: var(--muted); letter-spacing: .12em; }
.nav-btn .nb-title { font-size: 14.5px; color: var(--ink); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bottom-nav {
  display: none; position: sticky; bottom: 0; z-index: 30;
  background: var(--reader-bg); border-top: 1px solid var(--border);
  padding: 8px 12px; gap: 8px; justify-content: space-between;
}
.bottom-nav button {
  flex: 1; padding: 11px 8px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; color: var(--ink2);
}
.bottom-nav button:disabled { opacity: .35; cursor: not-allowed; }

/* ---- 抽屉 ---- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(20,15,8,.4);
  z-index: 90; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.drawer-mask.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; bottom: 0; width: min(340px, 88vw);
  background: var(--surface); z-index: 100;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  transition: transform .24s ease;
}
.drawer.left { left: 0; transform: translateX(-102%); }
.drawer.right { right: 0; transform: translateX(102%); }
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.drawer-head h3 { font-size: 17px; letter-spacing: .08em; }
.drawer-close {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center; font-size: 20px; color: var(--muted);
}
.drawer-close:hover { background: var(--surface2); color: var(--ink); }
.toc-list { flex: 1; overflow-y: auto; padding: 10px; }
.toc-item {
  display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left;
  padding: 9px 12px; border-radius: 9px; font-size: 14px; color: var(--ink2); line-height: 1.5;
}
.toc-item:hover { background: var(--surface2); color: var(--ink); }
.toc-item .toc-n { font-size: 12px; color: var(--muted); flex-shrink: 0; min-width: 2.4em; }
.toc-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---- 设置面板 ---- */
.settings-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.setting-row { margin-bottom: 20px; }
.setting-row label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; letter-spacing: .08em; }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; padding: 8px 4px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 13px; color: var(--ink2);
}
.seg button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.font-row { display: flex; align-items: center; gap: 10px; }
.font-row button {
  width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 16px; color: var(--ink2);
}
.font-row .fval { flex: 1; text-align: center; font-size: 15px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.6; margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--border); }

/* ---- 词典弹窗 ---- */
.dict-mask {
  position: fixed; inset: 0; background: rgba(20,15,8,.35);
  z-index: 200; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.dict-mask.open { opacity: 1; pointer-events: auto; }
.dict-card {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(.95);
  width: min(480px, 92vw); max-height: 70vh;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: 0 8px 40px rgba(0,0,0,.25);
  z-index: 201; display: flex; flex-direction: column;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.dict-card.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.dict-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.dict-word { font-size: 28px; font-weight: 700; color: var(--accent); }
.dict-pinyin { font-size: 16px; color: var(--ink2); }
.dict-close {
  margin-left: auto; width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center; font-size: 20px; color: var(--muted);
}
.dict-close:hover { background: var(--surface2); }
.dict-meta {
  padding: 8px 20px; font-size: 12px; color: var(--muted);
  display: flex; gap: 14px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.dict-body { flex: 1; overflow-y: auto; padding: 14px 20px; }
.dict-pron-group { margin-bottom: 16px; }
.dict-pron { font-size: 15px; color: var(--accent); font-weight: 600; margin-bottom: 6px; }
.dict-def { font-size: 14.5px; color: var(--ink); line-height: 1.8; margin-bottom: 6px; }
.dict-def .sense-num { color: var(--accent); font-weight: 600; margin-right: 4px; }
.dict-empty { text-align: center; color: var(--muted); padding: 30px 0; font-size: 14px; }
.dict-foot {
  padding: 8px 20px; font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--border); text-align: center;
}

/* 选中文字后的"释"按钮 */
.dict-popup-btn {
  position: absolute; z-index: 150;
  padding: 5px 12px; border-radius: 6px;
  background: var(--accent); color: #fff;
  font-size: 13px; font-family: inherit;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  cursor: pointer;
}
.dict-popup-btn:hover { background: color-mix(in srgb, var(--accent) 85%, black); }

/* ---- 响应式 ---- */
@media (max-width: 640px) {
  .hero h1 { font-size: 28px; }
  .stats { flex-wrap: wrap; }
  .stat { min-width: 50%; border-bottom: 1px solid var(--border); }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 0 12px 30px; }
  .reader { padding: 20px 16px 40px; }
  .reader .rd-body p { font-size: 16px; }
  .chapter-nav { display: none; }
  .bottom-nav { display: flex; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .logo-text { display: none; }
  .searchbox { max-width: none; }
}
