/* ==========================================================================
   小说阅读 — 书架与阅读器样式
   复用 style.css 的设计令牌；阅读区单独三套背景（纸黄 / 白 / 夜间）。
   ========================================================================== */

/* ---------- 工具 ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.btn-sm {
  padding: 0.42rem 0.85rem;
  font-size: 0.86rem;
  border-radius: var(--radius-sm);
}

[hidden] { display: none !important; }

/* ---------- 书架 ---------- */
.reader-main { flex: 1; }

.reader-shelf .lead { max-width: 62ch; }

.shelf-toolbar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}

.shelf-drop {
  padding: 0.75rem;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.18s ease, background 0.18s ease;
}

.shelf-drop.is-drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.shelf-empty {
  margin: 0;
  padding: 2.2rem 1rem;
  text-align: center;
  color: var(--muted);
}

.book-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 0.85rem;
  padding: 0.35rem;
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 1rem 1.05rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.book-title {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.book-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.55rem;
}

.shelf-note {
  margin-top: 1rem;
  font-size: 0.86rem;
  line-height: 1.7;
}

/* ---------- 阅读器外壳 ---------- */
body.reader-open { overflow: hidden; }

.reader-view {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;

  --rd-bg: #f4ecd8;
  --rd-text: #3a3125;
  --rd-muted: #8a7f6a;
  --rd-line-height: 1.9;
  --rd-line-color: rgba(58, 49, 37, 0.14);
  --rd-soft: rgba(58, 49, 37, 0.06);
  --rd-bar: rgba(244, 236, 216, 0.94);

  --rd-size: 18px;
  --rd-width: 720px;
  --rd-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", serif;

  background: var(--rd-bg);
  color: var(--rd-text);
}

.reader-view[data-reader-theme="white"] {
  --rd-bg: #ffffff;
  --rd-text: #1f2328;
  --rd-muted: #777d84;
  --rd-line-color: rgba(31, 35, 40, 0.12);
  --rd-soft: rgba(31, 35, 40, 0.05);
  --rd-bar: rgba(255, 255, 255, 0.94);
}

.reader-view[data-reader-theme="night"] {
  --rd-bg: #14161a;
  --rd-text: #ccd1d8;
  --rd-muted: #7f8792;
  --rd-line-color: rgba(204, 209, 216, 0.16);
  --rd-soft: rgba(204, 209, 216, 0.08);
  --rd-bar: rgba(20, 22, 26, 0.94);
}

/* ---------- 顶栏 / 底栏 ---------- */
.reader-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 0 0 auto;
  padding: 0.55rem 0.9rem;
  background: var(--rd-bar);
  backdrop-filter: blur(8px);
  border-color: var(--rd-line-color);
  z-index: 5;
}

.reader-bar-top { border-bottom: 1px solid var(--rd-line-color); }
.reader-bar-bottom { border-top: 1px solid var(--rd-line-color); }

.rd-btn,
.rd-nav {
  appearance: none;
  border: 1px solid var(--rd-line-color);
  background: transparent;
  color: var(--rd-text);
  border-radius: 999px;
  padding: 0.36rem 0.8rem;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
}

.rd-btn:hover,
.rd-nav:hover { background: var(--rd-soft); }

.rd-btn:disabled,
.rd-nav:disabled { opacity: 0.38; cursor: default; }

.rd-nav { padding: 0.34rem 0.7rem; }

.reader-head {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--rd-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rd-actions { display: flex; gap: 0.4rem; }

/* ---------- 正文 ---------- */
.reader-body-wrap {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2.2rem 1.2rem 3.4rem;
  -webkit-overflow-scrolling: touch;
}

.reader-body {
  max-width: var(--rd-width);
  margin: 0 auto;
  font-family: var(--rd-serif);
  font-size: var(--rd-size);
  line-height: var(--rd-line-height);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  text-align: justify;
  letter-spacing: 0.01em;
}

.reader-body:focus { outline: none; }

/* ---------- 左右翻页（分栏排版） ---------- */
.reader-view.is-paged .reader-body-wrap {
  overflow: hidden;
  padding-block: 2rem 1.6rem;
  padding-inline: max(1.2rem, calc((100% - var(--rd-width)) / 2));
}

.reader-view.is-paged .reader-body {
  width: 100%;
  max-width: none;
  margin: 0;
  column-gap: 56px;
  column-fill: auto;
  transform: translateX(0);
  transition: transform 0.24s ease-out;
  will-change: transform;
}

.rd-page-turn {
  position: absolute;
  bottom: 5.4rem;
  z-index: 6;
  display: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--rd-line-color);
  border-radius: 50%;
  background: var(--rd-bar);
  color: var(--rd-text);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.55;
  backdrop-filter: blur(6px);
  transition: opacity 0.15s ease;
}

.rd-page-turn:hover { opacity: 1; }
.rd-page-turn[disabled] { opacity: 0.18; cursor: default; }
.rd-page-prev { right: 5.4rem; }
.rd-page-next { right: 1rem; }

.reader-view.is-paged .rd-page-turn { display: block; }

@media (prefers-reduced-motion: reduce) {
  .reader-view.is-paged .reader-body { transition: none; }
}

/* ---------- 进度 ---------- */
.reader-progress {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  align-items: center;
}

.reader-progress-label {
  margin: 0;
  font-size: 0.76rem;
  color: var(--rd-muted);
  white-space: nowrap;
}

.reader-progress-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--rd-soft);
  overflow: hidden;
}

.reader-progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: currentColor;
  transition: width 0.18s ease;
}

/* ---------- 目录抽屉 ---------- */
.reader-backdrop {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: rgba(0, 0, 0, 0.38);
}

.reader-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  width: min(360px, 86vw);
  display: flex;
  flex-direction: column;
  background: var(--rd-bg);
  border-left: 1px solid var(--rd-line-color);
  box-shadow: -18px 0 40px -24px rgba(0, 0, 0, 0.5);
}

.reader-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--rd-line-color);
  flex: 0 0 auto;
}

.reader-drawer-head h2 {
  margin: 0;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 1rem;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0.45rem 0;
  overflow-y: auto;
}

.toc-list li { margin: 0; }

.toc-list button {
  display: block;
  width: 100%;
  padding: 0.62rem 1rem;
  border: 0;
  background: none;
  color: var(--rd-text);
  font: inherit;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toc-list button:hover { background: var(--rd-soft); }

.toc-list button[aria-current="true"] {
  color: var(--rd-text);
  font-weight: 700;
  background: var(--rd-soft);
  box-shadow: inset 3px 0 0 currentColor;
}

/* ---------- 设置面板 ---------- */
.reader-sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 9;
  width: min(560px, 94vw);
  transform: translateX(-50%);
  background: var(--rd-bg);
  border: 1px solid var(--rd-line-color);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -18px 40px -24px rgba(0, 0, 0, 0.5);
  padding-bottom: 0.9rem;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1.1rem;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.9rem;
}

.setting-row label { flex: 0 0 auto; }

.setting-row input[type="range"] {
  flex: 1 1 auto;
  max-width: 260px;
  accent-color: var(--rd-text);
}

.setting-label { flex: 0 0 auto; }

.setting-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--rd-text);
}

.setting-hint {
  margin: 0.4rem 1.1rem 0;
  font-size: 0.78rem;
  line-height: 1.6;
}

.theme-swatches { display: flex; gap: 0.55rem; }

.swatch {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--rd-line-color);
  cursor: pointer;
}

.swatch[data-theme="paper"] { background: #f4ecd8; }
.swatch[data-theme="white"] { background: #ffffff; }
.swatch[data-theme="night"] { background: #14161a; }

.swatch[aria-pressed="true"] {
  border-color: currentColor;
  box-shadow: 0 0 0 2px var(--rd-bg), 0 0 0 3px currentColor;
}

/* ---------- 沉浸模式 ---------- */
.reader-view.is-immersive .reader-bar { display: none; }

.reader-view.is-immersive .reader-body-wrap { padding-top: 2.8rem; }

/* ---------- 提示 ---------- */
.reader-toast {
  position: fixed;
  left: 50%;
  bottom: 1.4rem;
  z-index: 120;
  transform: translateX(-50%);
  max-width: min(86vw, 480px);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: rgba(20, 22, 18, 0.92);
  color: #fff;
  font-size: 0.84rem;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
}

/* ---------- 小屏 ---------- */
@media (max-width: 620px) {
  .reader-bar { padding: 0.45rem 0.55rem; gap: 0.4rem; }
  .rd-btn { padding: 0.32rem 0.58rem; font-size: 0.8rem; }
  .reader-head { font-size: 0.82rem; }
  .rd-nav { padding: 0.3rem 0.5rem; font-size: 0.8rem; }
  .reader-body-wrap { padding: 1.4rem 1rem 2.6rem; }
  .reader-view.is-paged .reader-body-wrap { padding-block: 1.4rem 1.1rem; padding-inline: 0.8rem; }
  .reader-view.is-paged .reader-body { column-gap: 36px; }
  .rd-page-turn { width: 30px; height: 30px; font-size: 0.95rem; bottom: 4.9rem; }
  .rd-page-prev { right: 4.6rem; }
  .rd-page-prev { left: 0.2rem; }
  .rd-page-next { right: 0.2rem; }
  .setting-row { flex-wrap: wrap; }
  .setting-row input[type="range"] { max-width: none; width: 100%; }
}
