/* ============ 阅读器样式（移动优先） ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg); color: var(--fg);
  transition: background .2s, color .2s;
}

/* 主题 */
:root, html[data-theme="day"] {
  --bg: #ffffff; --fg: #2b2b2b; --muted: #8a8a8a; --accent: #b3541e;
  --card: #f7f5f2; --border: #e8e4de; --paper: #ffffff; --btn: #f0ede8;
}
html[data-theme="sepia"] {
  --bg: #f3ecdc; --fg: #5b4a38; --muted: #9a8a70; --accent: #a05a1e;
  --card: #ece2cb; --border: #ddd0b4; --paper: #f3ecdc; --btn: #e9dec6;
}
html[data-theme="green"] {
  --bg: #e9f2e4; --fg: #3d4a3a; --muted: #7d8f7a; --accent: #4a7c3a;
  --card: #dcebd4; --border: #c4d8ba; --paper: #e9f2e4; --btn: #d8e8cf;
}
html[data-theme="night"] {
  --bg: #141414; --fg: #c4c4c4; --muted: #777; --accent: #d08a4a;
  --card: #1e1e1e; --border: #2c2c2c; --paper: #141414; --btn: #242424;
}

/* 通用顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; }
.icon-link, .icon-btn {
  border: 1px solid var(--border); background: var(--btn); color: var(--fg);
  border-radius: 8px; padding: 6px 12px; font-size: 14px;
  text-decoration: none; cursor: pointer; line-height: 1.4;
}
.icon-btn { min-width: 40px; text-align: center; }
.icon-link:active, .icon-btn:active { opacity: .7; }

/* 书架 */
.shelf-tools { padding: 12px 16px 4px; max-width: 1100px; margin: 0 auto; }
.shelf-tools input, .drawer-head input {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--paper); color: var(--fg);
}
.shelf {
  display: grid; gap: 14px; padding: 12px 16px 40px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  max-width: 1100px; margin: 0 auto;
}
.book-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
}
.book-card:active { transform: scale(.98); }
.cover {
  aspect-ratio: 3 / 4; display: flex; align-items: center; justify-content: center;
  font-size: 44px; color: rgba(255,255,255,.92); font-weight: 700;
  text-shadow: 0 1px 6px rgba(0,0,0,.25); padding: 12px; text-align: center;
  line-height: 1.3; word-break: break-all;
}
.book-meta { padding: 10px 12px 12px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.book-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-author { font-size: 13px; color: var(--muted); }
.book-stat { font-size: 12px; color: var(--muted); }
.progress-track { height: 4px; background: var(--border); border-radius: 2px; margin-top: 6px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.continue-hint { font-size: 12px; color: var(--accent); margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* 阅读器 */
.reader-bar .reader-titles { flex: 1; min-width: 0; }
.book-title { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content {
  max-width: 46rem; margin: 0 auto; padding: 24px 20px 40px;
  font-size: 18px; line-height: 1.9; word-break: break-word;
}
.content p { margin: 0 0 var(--pgap, .8em); text-indent: 2em; text-align: justify; }
.reader-nav {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border);
  max-width: 46rem; margin: 0 auto;
}
.reader-nav button {
  flex: 1; padding: 12px 0; font-size: 15px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--btn); color: var(--fg); cursor: pointer;
}
.reader-nav button:disabled { opacity: .35; }

/* 抽屉 / 遮罩 */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(86vw, 380px); background: var(--bg); color: var(--fg);
  display: flex; flex-direction: column; border-left: 1px solid var(--border);
  animation: slide-in .22s ease;
}
@keyframes slide-in { from { transform: translateX(30%); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.drawer-head strong { font-size: 16px; white-space: nowrap; }
.drawer-head input { flex: 1; }
.toc-list { overflow-y: auto; flex: 1; }
.toc-item {
  display: block; width: 100%; text-align: left; padding: 12px 16px; font-size: 14px;
  border: none; border-bottom: 1px solid var(--border); background: none; color: var(--fg); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toc-item.current { color: var(--accent); font-weight: 600; background: var(--card); }

/* 排版面板 */
.set-drawer { left: 0; right: 0; top: auto; width: 100%; border-left: none; border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0; animation: sheet-up .22s ease; max-height: 70vh; }
@keyframes sheet-up { from { transform: translateY(30%); opacity: .5; } to { transform: none; opacity: 1; } }
.set-body { padding: 8px 20px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); font-size: 15px; }
.set-row b { color: var(--accent); font-weight: 600; margin-left: 6px; }
.set-row input[type="range"] { flex: 1; max-width: 55%; accent-color: var(--accent); }
.themes { display: flex; gap: 10px; }
.theme-dot { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; }
.theme-dot.on { border-color: var(--accent); }
.t-day { background: #ffffff; } .t-sepia { background: #f3ecdc; }
.t-green { background: #e9f2e4; } .t-night { background: #141414; }

/* 阅读模式切换 */
.seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg-btn { border: none; background: var(--btn); color: var(--fg); padding: 8px 20px; font-size: 14px; cursor: pointer; }
.seg-btn.on { background: var(--accent); color: #fff; }

/* 连续滚动：章节块 */
.ch-block { border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 12px; }
.ch-block:last-child { border-bottom: none; margin-bottom: 0; }
.ch-block-title { font-size: 1.18em; text-align: center; margin: 1em 0; color: var(--fg); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); z-index: 99;
  background: rgba(0,0,0,.8); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 20px; white-space: nowrap;
}

@media (min-width: 768px) {
  .content { padding: 36px 32px 60px; }
  .set-drawer { left: auto; right: 24px; bottom: 24px; top: auto; width: 340px; border: 1px solid var(--border); border-radius: 16px; }
}
