:root {
  --bg: #f7f5f0;
  --fg: #23201c;
  --muted: #8a827a;
  --card: #ffffff;
  --line: #e4ded4;
  --accent: #a4501f;
  --reader-bg: #faf7f1;
  --reader-fg: #2b2721;
  --font-size: 19px;
  --line-height: 1.85;
}
[data-theme='dark'] {
  --bg: #16181a;
  --fg: #e6e3de;
  --muted: #8d8880;
  --card: #1f2225;
  --line: #2c3033;
  --accent: #d98a52;
  --reader-bg: #14161a;
  --reader-fg: #c9c6c0;
}
[data-theme='sepia'] {
  --bg: #efe6d6;
  --fg: #3a322a;
  --card: #f8f1e4;
  --line: #ded2bd;
  --accent: #8b5a2b;
  --reader-bg: #f3ead9;
  --reader-fg: #3d352c;
}
[data-theme='green'] {
  --bg: #e8f0e8;
  --fg: #22301f;
  --card: #f5faf5;
  --line: #cfe0cf;
  --accent: #2f6b3a;
  --reader-bg: #eef6ee;
  --reader-fg: #263523;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  overscroll-behavior-y: none;
}

a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

header.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 8px; align-items: center;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-top: calc(10px + env(safe-area-inset-top));
}
header.topbar input[type='search'] {
  flex: 1; min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
}
header.topbar button {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--fg); font-size: 15px;
}

main { max-width: 820px; margin: 0 auto; padding: 12px 12px 90px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin-bottom: 10px;
}
.book-row { display: flex; gap: 12px; }
.book-row img.cover {
  width: 66px; height: 88px; object-fit: cover; border-radius: 6px; background: var(--line); flex: 0 0 auto;
}
.book-row .meta { min-width: 0; }
.book-row h3 { margin: 0 0 4px; font-size: 17px; line-height: 1.3; }
.book-row .sub { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.book-row .intro { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.book-row .latest { color: var(--accent); font-size: 13px; margin-top: 6px; }

.btn {
  display: inline-block; padding: 9px 14px; border-radius: 10px; font-size: 15px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:active { opacity: .75; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.toc-list { display: block; }
.toc-list a {
  display: block; padding: 9px 4px; border-bottom: 1px solid var(--line); color: var(--fg); font-size: 15px;
}
.toc-list a .idx { color: var(--muted); font-size: 12px; margin-right: 6px; }
.toc-list a.active { color: var(--accent); font-weight: 600; }

/* 阅读页 */
.reader { max-width: 860px; margin: 0 auto; padding: 0 16px 120px; }
.reader h1.chapter-title {
  font-size: 20px; margin: 18px 0 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line);
  font-weight: 600; line-height: 1.4;
}
.reader .paras p {
  font-size: var(--font-size); line-height: var(--line-height);
  margin: 0 0 0.85em; text-indent: 2em; color: var(--reader-fg);
  font-family: 'Songti SC', 'Noto Serif CJK SC', 'Source Han Serif SC', Georgia, serif;
}
.reader .paras p.blank { text-indent: 0; color: var(--muted); font-size: .9em; }

.reader-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: 6px; justify-content: space-between;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.reader-bar button {
  flex: 0 0 auto; min-height: 44px; min-width: 44px; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); font-size: 14px;
}
.reader-bar .spacer { flex: 1 1 auto; }

.reader-progress {
  position: fixed; top: 0; left: 0; height: 2px; background: var(--accent); z-index: 40; width: 0;
}

.panel {
  position: fixed; inset: auto 0 0 0; z-index: 50; background: var(--card);
  border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px rgba(0,0,0,.18);
  max-height: 70vh; overflow: auto;
}
.panel h4 { margin: 0 0 10px; font-size: 15px; }
.panel .row { gap: 10px; }
.range { width: 100%; }
.tip { color: var(--muted); font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%);
  background: rgba(0,0,0,.82); color: #fff; padding: 8px 14px; border-radius: 20px; font-size: 14px; z-index: 99;
}

.loading { text-align: center; color: var(--muted); padding: 22px 0; font-size: 14px; }
.searching::after { content: ''; animation: dots 1.2s infinite; }
@keyframes dots { 0% { content: ''; } 33% { content: '.'; } 66% { content: '..'; } 100% { content: '...'; } }

@media (min-width: 700px) {
  main { padding-bottom: 40px; }
  .reader-bar { position: sticky; bottom: 0; }
}
