:root {
  --fs: 18px;
  --bg: #f7f5f0;
  --paper: #f7f5f0;
  --card: #ffffff;
  --text: #2c2a26;
  --muted: #8b8578;
  --border: #e5dfd2;
  --accent: #8c6239;
  --accent-soft: #f0e7da;
  --shadow: 0 2px 10px rgba(60, 48, 30, .08);
}

html[data-theme="dark"] {
  --bg: #14161a;
  --paper: #14161a;
  --card: #1b1e23;
  --text: #c8c4bb;
  --muted: #7e7a72;
  --border: #2b2f36;
  --accent: #c9a86a;
  --accent-soft: #262a31;
  --shadow: 0 2px 10px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding-left: 18px;
  padding-right: 18px;
}

/* ---------- 书架首页 ---------- */
.site-head {
  padding: 32px 0 18px;
  border-bottom: 1px solid var(--border);
}
.site-title {
  margin: 0;
  font-size: 22px;
  letter-spacing: .04em;
}
.site-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.booklist { padding-top: 18px; padding-bottom: 40px; }

.books {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px 16px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-height: 78px;
  transition: transform .12s ease, border-color .12s ease;
}
.book-card:active { transform: scale(.985); border-color: var(--accent); }

.book-name {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
  word-break: break-all;
}
.book-meta { font-size: 12px; color: var(--muted); }

.empty {
  margin: 40px auto;
  padding: 24px;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: 12px;
  font-size: 14px;
  color: var(--muted);
}
.empty-title { font-size: 16px; color: var(--text); font-weight: 600; margin-top: 0; }
.empty code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
.empty-tip { margin-bottom: 0; }

.site-foot {
  padding: 20px 18px 40px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- 阅读页顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  height: 50px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}
.tb-title {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  font-size: 15px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tb-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.tb-btn {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: inherit;
}
.tb-btn:active { background: var(--accent-soft); }
.tb-back { padding: 0 12px; }

/* ---------- 正文 ---------- */
.reader {
  padding-top: 22px;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.chapter-title {
  margin: 8px 0 22px;
  font-size: calc(var(--fs) * 1.15);
  line-height: 1.5;
  font-weight: 700;
  letter-spacing: .01em;
}

.content { font-size: var(--fs); }
.content p {
  margin: 0 0 .95em;
  line-height: 1.95;
  text-indent: 2em;
  letter-spacing: .01em;
  word-break: break-word;
  text-align: justify;
}
.content p.muted { color: var(--muted); text-indent: 0; }

/* ---------- 编码切换菜单（乱码时用） ---------- */
.enc-menu {
  display: none;
  position: fixed;
  top: calc(52px + env(safe-area-inset-top));
  right: 12px;
  z-index: 45;
  min-width: 190px;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.enc-menu.show { display: block; }
.enc-menu-title { font-size: 12px; color: var(--muted); padding: 4px 8px 6px; }
.enc-item { display: block; padding: 9px 10px; font-size: 14px; border-radius: 8px; }
.enc-item:active { background: var(--accent-soft); }
.enc-item.on { color: var(--accent); font-weight: 600; background: var(--accent-soft); }
.enc-tip {
  margin-top: 6px;
  padding: 8px 8px 2px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- 底部翻页 ---------- */
.botbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.botbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn {
  flex: 0 0 auto;
  min-width: 92px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
}
.nav-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
html[data-theme="dark"] .nav-btn.primary { color: #171a1f; }
.nav-btn.disabled {
  opacity: .42;
  background: transparent;
}
.nav-pos {
  flex: 1 1 auto;
  height: 42px;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

/* ---------- 目录抽屉 ---------- */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .38);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 40;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 88vw);
  background: var(--card);
  border-left: 1px solid var(--border);
  z-index: 50;
  transform: translateX(102%);
  transition: transform .22s ease;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.drawer.show { transform: translateX(0); }

.drawer-head {
  height: 50px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--muted);
}
.drawer-search {
  flex: 0 0 auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.drawer-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.drawer-search input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.dir-list {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  list-style: none;
  margin: 0;
  padding: 6px 0 24px;
}
.dir-list li { margin: 0; }
.dir-list li a {
  display: block;
  padding: 11px 14px;
  font-size: 14px;
  line-height: 1.45;
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}
.dir-list li.current a { color: var(--accent); font-weight: 600; background: var(--accent-soft); }
.dir-list li.hide { display: none; }

/* ---------- 桌面端微调 ---------- */
@media (min-width: 768px) {
  :root { --fs: 19px; }
  .site-head { padding-top: 44px; }
  .topbar-inner { height: 56px; padding: 0 18px; }
  .tb-btn { height: 34px; }
  .reader { padding-top: 32px; }
  .content p { line-height: 2; }
  .nav-btn:hover { border-color: var(--accent); }
  .book-card:hover { border-color: var(--accent); }
  .drawer { width: 420px; }
}

/* iPhone 等窄屏 */
@media (max-width: 380px) {
  .wrap { padding-left: 14px; padding-right: 14px; }
  .nav-btn { min-width: 78px; font-size: 14px; }
  .tb-btn { padding: 0 8px; }
}
