:root {
  --fs: 19px;
  --lh: 1.9;
  --bg: #f3ead8;
  --paper: #fbf6ea;
  --ink: #2e2a24;
  --muted: #7d7362;
  --line: rgba(90, 76, 55, .18);
  --accent: #8a5a2b;
  --accent-ink: #fff8ee;
  --shadow: 0 10px 30px rgba(60, 45, 25, .10);
}

[data-theme="light"] {
  --bg: #eef0f2;
  --paper: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: rgba(30, 40, 60, .12);
  --accent: #2b5f8a;
  --accent-ink: #ffffff;
}

[data-theme="dark"] {
  --bg: #14161a;
  --paper: #1c1f24;
  --ink: #c8ccd2;
  --muted: #8b9199;
  --line: rgba(200, 210, 225, .14);
  --accent: #c89b63;
  --accent-ink: #1a1a1a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "STSong", "SimSun", serif;
  font-size: var(--fs);
  line-height: var(--lh);
  transition: background .25s, color .25s;
}

button, input, a { font-family: inherit; font-size: .82em; }

a { color: var(--accent); text-decoration: none; }

/* ---------- 书架 ---------- */

.topbar {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 28px clamp(16px, 5vw, 48px) 8px;
  max-width: 1120px;
  margin: 0 auto;
}

.topbar h1 { margin: 0; font-size: 1.45em; letter-spacing: .06em; }

.hint { color: var(--muted); font-size: .72em; }

.shelf {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px clamp(16px, 5vw, 48px) 48px;
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.card {
  display: flex;
  gap: 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.cover {
  width: 96px;
  height: 136px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
}

[data-theme="dark"] .cover { filter: brightness(.82); }

.cover-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: .7em;
}

.card-body { min-width: 0; display: flex; flex-direction: column; }

.card h2 {
  margin: 0 0 4px;
  font-size: 1.06em;
  letter-spacing: .04em;
  line-height: 1.4;
}

.author { margin: 0 0 6px; color: var(--muted); font-size: .72em; }

.intro {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: .72em;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.stats { margin: auto 0 10px; color: var(--muted); font-size: .7em; }

.progress { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }

.progress .bar { height: 100%; background: var(--accent); }

.progress-text { margin: 6px 0 10px; color: var(--muted); font-size: .68em; }

.primary, .secondary {
  display: inline-block;
  margin-top: 4px;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: .74em;
  text-align: center;
}

.primary { background: var(--accent); color: var(--accent-ink); }

.secondary { border: 1px solid var(--line); color: var(--muted); margin-left: 6px; }

.empty { color: var(--muted); font-size: .85em; }

.site-foot { text-align: center; color: var(--muted); font-size: .68em; padding: 0 16px 32px; }

/* ---------- 阅读器 ---------- */

body[data-page="reader"] { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

.reader-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px max(12px, calc((100vw - 52rem) / 2));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.chapter-head { flex: 1; min-width: 0; text-align: center; line-height: 1.3; }

.book-name { font-size: .72em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chapter-title { font-size: .84em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.reading {
  max-width: 46rem;
  margin: 0 auto;
  padding: 26px max(20px, 6vw) 40px;
}

.chapter p {
  margin: 0 0 .55em;
  text-indent: 2em;
  word-break: break-word;
}

.chapter p:first-child { margin-top: .4em; }

.chapter-end { margin-top: 2.4em; text-align: center; color: var(--muted); font-size: .72em; }

.end-nav { display: flex; gap: 12px; justify-content: center; margin-top: 14px; }

.loading { text-align: center; color: var(--muted); font-size: .8em; padding: 60px 0; line-height: 2; }

.reader-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  gap: 8px;
  padding: 8px max(12px, calc((100vw - 52rem) / 2)) calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

.nav-btn {
  flex: 1;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.nav-btn:disabled { opacity: .4; cursor: default; }

/* ---------- 目录抽屉 ---------- */

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

.drawer.open { transform: none; }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 8px;
  border-bottom: 1px solid var(--line);
}

.drawer-tools { display: flex; gap: 8px; padding: 10px 12px; }

.drawer-tools input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  outline: none;
}

.settings { border-bottom: 1px solid var(--line); padding: 4px 16px 12px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .76em;
  padding: 6px 0;
  color: var(--muted);
}

.setting-row button {
  margin-left: 6px;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}

.toc {
  list-style: none;
  margin: 0;
  padding: 6px 0 40px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: .8em;
}

.toc li a {
  display: block;
  padding: 9px 18px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc li.active a { color: var(--accent); font-weight: 600; background: var(--bg); }
.toc li[hidden] { display: none; }

.mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .32);
}

@media (max-width: 560px) {
  .shelf { grid-template-columns: 1fr; }
  .card { padding: 14px; gap: 14px; }
  .cover { width: 84px; height: 118px; }
  .reading { padding: 20px 18px 32px; }
}
