/* ============================================================
   静态小说阅读站 · 样式
   ============================================================ */

/* ---------- 变量：主题由 JS 切换 data-theme ---------- */
:root {
  --bg: #f7f5f0;
  --bg-elev: #ffffff;
  --fg: #2b2b2b;
  --fg-soft: #6b6b6b;
  --fg-faint: #9a9a9a;
  --line: rgba(0, 0, 0, 0.09);
  --accent: #b5453c;
  --accent-soft: rgba(181, 69, 60, 0.10);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.07);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* 阅读器排版变量，由设置面板实时改写 */
  --reader-font: 18px;
  --reader-lh: 1.90;
  --reader-para: 0.90em;
  --reader-pad: 22px;
  --reader-weight: 400;
  --reader-family: var(--font-serif);

  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", Georgia, serif;
  --font-sans: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* 护眼绿 */
[data-theme="green"] {
  --bg: #dce7d4;
  --bg-elev: #e6efdf;
  --fg: #2c3327;
  --fg-soft: #55604d;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #4a7c40;
  --accent-soft: rgba(74, 124, 64, 0.12);
}
/* 米黄 */
[data-theme="sepia"] {
  --bg: #f4ecd8;
  --bg-elev: #faf4e6;
  --fg: #4a3f2f;
  --fg-soft: #75674f;
  --line: rgba(90, 70, 30, 0.12);
  --accent: #9a6b2f;
  --accent-soft: rgba(154, 107, 47, 0.12);
}
/* 夜间 */
[data-theme="dark"] {
  --bg: #1b1c1e;
  --bg-elev: #242629;
  --fg: #c8c9cc;
  --fg-soft: #8e9096;
  --fg-faint: #63656b;
  --line: rgba(255, 255, 255, 0.10);
  --accent: #d08a70;
  --accent-soft: rgba(208, 138, 112, 0.15);
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}
/* 纯黑 */
[data-theme="black"] {
  --bg: #000000;
  --bg-elev: #0e0e0e;
  --fg: #9a9a9a;
  --fg-soft: #6e6e6e;
  --fg-faint: #4a4a4a;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #8a7a6a;
  --accent-soft: rgba(138, 122, 106, 0.16);
  --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body { transition: background-color .25s, color .25s; }

button { font-family: inherit; color: inherit; cursor: pointer; }
input { font-family: inherit; }
ol, ul { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, p { margin: 0; }

svg {
  width: 22px; height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.page {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.page[hidden] { display: none; }

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ---------- 顶栏 ---------- */
.app-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(var(--safe-top) + 8px) 8px 8px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  flex: none;
  position: relative;
  z-index: 5;
}
.app-title {
  font-size: 19px; font-weight: 600;
  padding: 0 8px;
  letter-spacing: .04em;
}
.app-bar-title {
  flex: 1; min-width: 0;
  padding: 0 4px;
}
.app-bar-title h1 {
  font-size: 17px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-bar-sub {
  font-size: 12px; color: var(--fg-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-bar-actions { display: flex; gap: 2px; margin-left: auto; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--fg);
  flex: none;
}
.icon-btn:active { background: var(--accent-soft); }
.icon-btn.active { color: var(--accent); }
.icon-btn.active svg { fill: var(--accent-soft); }

/* ---------- 搜索 ---------- */
.search-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.search-bar[hidden] { display: none; }
.search-bar input {
  flex: 1;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  outline: none;
}
.search-bar input:focus { border-color: var(--accent); }

/* ---------- 标签页 ---------- */
.tabs {
  display: flex; gap: 4px;
  padding: 6px 8px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.tab {
  padding: 7px 15px;
  border: 0; border-radius: 20px;
  background: transparent;
  color: var(--fg-soft);
  font-size: 14px;
}
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tab-count {
  display: inline-block;
  min-width: 17px; padding: 0 4px;
  margin-left: 3px;
  border-radius: 9px;
  background: var(--line);
  font-size: 11px; line-height: 17px;
  text-align: center;
}

/* ---------- 书列表 ---------- */
.book-grid { padding: 10px 10px 24px; }

.book-item {
  display: flex; gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-elev);
  margin-bottom: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform .12s;
}
.book-item:active { transform: scale(.985); }

.book-cover {
  flex: none;
  width: 52px; height: 72px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; font-weight: 600;
  color: #fff;
  font-family: var(--font-serif);
  overflow: hidden;
}
.book-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.book-name {
  font-size: 16px; font-weight: 600; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-meta {
  margin-top: 4px;
  font-size: 12.5px; color: var(--fg-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-prog {
  margin-top: auto; padding-top: 7px;
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--fg-faint);
}
.bar { flex: 1; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.book-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 10.5px; font-weight: 600;
  margin-left: 5px;
  vertical-align: 1px;
}

.empty { padding: 70px 24px; text-align: center; }
.empty-title { font-size: 16px; color: var(--fg-soft); }
.empty-sub { margin-top: 6px; font-size: 13px; color: var(--fg-faint); }

.list-foot {
  padding: 14px; text-align: center;
  font-size: 12px; color: var(--fg-faint);
}

/* ---------- 目录 ---------- */
.toc { padding: 8px 10px 30px; }
.toc-item {
  display: flex; align-items: baseline; gap: 10px;
  padding: 12px 12px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
}
.toc-item:last-child { border-bottom: 0; }
.toc-item:active { background: var(--accent-soft); }
.toc-item.current { color: var(--accent); font-weight: 600; }
.toc-item.read { color: var(--fg-faint); }
.toc-idx {
  flex: none;
  min-width: 26px;
  font-size: 12px; color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
}
.toc-name { flex: 1; }
.toc-chars { flex: none; font-size: 11.5px; color: var(--fg-faint); }

/* ---------- 阅读器 ---------- */
.reader { background: var(--bg); }

.reader-bar {
  position: absolute; left: 0; right: 0;
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-top) + 6px) 8px 6px;
  background: var(--bg);
  z-index: 10;
  transition: transform .22s ease, opacity .22s ease;
}
.reader-bar.top-shadow { box-shadow: 0 1px 0 var(--line); }
.reader-bar.bottom {
  bottom: 0; top: auto;
  padding: 6px 8px calc(var(--safe-bottom) + 6px);
  box-shadow: 0 -1px 0 var(--line);
}
body.hide-bars .reader-bar:not(.pinned) {
  transform: translateY(-140%);
  opacity: 0;
  pointer-events: none;
}
body.hide-bars .reader-bar.bottom:not(.pinned) { transform: translateY(140%); }

.reader-title {
  flex: 1; min-width: 0;
  text-align: center;
  font-size: 14px; color: var(--fg-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.reader-progress {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 2px; background: var(--line);
}
.reader-progress-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width .12s linear;
}

.reader-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 54px) 0 calc(var(--safe-bottom) + 60px);
}

.reader-content {
  padding: 8px var(--reader-pad) 40px;
  font-family: var(--reader-family);
  font-size: var(--reader-font);
  font-weight: var(--reader-weight);
  line-height: var(--reader-lh);
  color: var(--fg);
  max-width: 720px;
  margin: 0 auto;
  text-align: justify;
  word-break: break-word;
}

.chapter-title {
  font-size: calc(var(--reader-font) * 1.18);
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 1.4em;
  padding-bottom: .5em;
  border-bottom: 1px solid var(--line);
}

.chapter-body p {
  margin: 0 0 var(--reader-para);
  text-indent: 2em;
}
.chapter-body p.no-indent { text-indent: 0; }

.chapter-nav {
  display: flex; gap: 10px;
  margin-top: 42px;
  font-family: var(--font-sans);
}
.nav-btn {
  flex: 1;
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-elev);
  color: var(--fg);
  font-size: 14px;
}
.nav-btn:active { background: var(--accent-soft); }
.nav-btn:disabled { opacity: .4; }
.nav-btn.ghost { flex: 0 0 84px; color: var(--fg-soft); }

.reader-loading {
  padding: 60px 20px; text-align: center;
  color: var(--fg-faint); font-size: 14px;
  font-family: var(--font-sans);
}

/* 翻页动画 */
.reader-content.slide-in-left { animation: slideInLeft .26s ease; }
.reader-content.slide-in-right { animation: slideInRight .26s ease; }
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(28px); }
  to { opacity: 1; transform: none; }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(-28px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 抽屉 ---------- */
.drawer-mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .42);
  z-index: 40;
  animation: fadeIn .18s;
}
.drawer-mask[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.drawer {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: min(86vw, 360px);
  background: var(--bg-elev);
  z-index: 50;
  display: flex; flex-direction: column;
  box-shadow: 4px 0 20px rgba(0, 0, 0, .18);
  animation: slideIn .22s ease;
}
.drawer.right { left: auto; right: 0; box-shadow: -4px 0 20px rgba(0, 0, 0, .18); animation: slideInR .22s ease; }
.drawer[hidden] { display: none; }
@keyframes slideIn { from { transform: translateX(-100%) } to { transform: none } }
@keyframes slideInR { from { transform: translateX(100%) } to { transform: none } }

.drawer-head {
  display: flex; align-items: center;
  padding: calc(var(--safe-top) + 10px) 12px 10px 16px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.drawer-head h2 { flex: 1; font-size: 16px; font-weight: 600; }
.drawer-body {
  flex: 1; overflow-y: auto;
  padding: 12px 14px calc(var(--safe-bottom) + 24px);
  -webkit-overflow-scrolling: touch;
}
.drawer-body .toc-item { font-size: 14.5px; }

/* ---------- 设置面板 ---------- */
.set-group { margin-bottom: 22px; }
.set-label {
  font-size: 13px; color: var(--fg-soft);
  margin-bottom: 9px;
  display: flex; justify-content: space-between; align-items: baseline;
}
.set-val {
  font-variant-numeric: tabular-nums;
  color: var(--accent); font-weight: 600;
}
.set-hint {
  font-size: 12px; color: var(--fg-faint);
  margin-bottom: 10px;
}

.theme-row { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-chip {
  width: 54px; height: 54px;
  border-radius: 11px;
  border: 2px solid transparent;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}
.theme-chip > span {
  display: block;
  width: 30px; height: 24px;
  border-radius: 5px;
  border: 1px solid rgba(128, 128, 128, .28);
  margin-bottom: 2px;
}
.theme-chip.active { border-color: var(--accent); }
.theme-chip[data-t="light"]  { background: var(--bg-elev); color: #2b2b2b; }
.theme-chip[data-t="light"]  > span { background: #f7f5f0; }
.theme-chip[data-t="sepia"]  { background: var(--bg-elev); color: #4a3f2f; }
.theme-chip[data-t="sepia"]  > span { background: #f4ecd8; }
.theme-chip[data-t="green"]  { background: var(--bg-elev); color: #2c3327; }
.theme-chip[data-t="green"]  > span { background: #dce7d4; }
.theme-chip[data-t="dark"]   { background: var(--bg-elev); color: #c8c9cc; }
.theme-chip[data-t="dark"]   > span { background: #1b1c1e; }
.theme-chip[data-t="black"]  { background: var(--bg-elev); color: #9a9a9a; }
.theme-chip[data-t="black"]  > span { background: #000; }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper input[type=range] { flex: 1; accent-color: var(--accent); }
.step-btn {
  flex: none;
  min-width: 40px; height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 13px;
}
.step-btn:active { background: var(--accent-soft); }

.seg { display: flex; gap: 6px; }
.seg.col { flex-direction: column; }
.seg-btn {
  flex: 1;
  padding: 9px 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--fg);
  font-size: 13.5px;
}
.seg-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.switch-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.switch-row > span:first-child { flex: 1; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  flex: none;
  width: 44px; height: 26px;
  border-radius: 13px;
  background: var(--line);
  position: relative;
  transition: background .18s;
}
.switch::after {
  content: ""; position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .18s;
}
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }

.btn-block {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
}
.btn-block:active { background: var(--accent-soft); }
.btn-block.danger { color: #c0392b; border-color: rgba(192, 57, 43, .3); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--safe-bottom) + 76px);
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 22px;
  background: rgba(0, 0, 0, .82);
  color: #fff;
  font-size: 13.5px;
  z-index: 90;
  animation: toastIn .2s;
  max-width: 80vw;
  text-align: center;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px) } to { opacity: 1; transform: translate(-50%, 0) } }

/* ---------- 桌面端：居中收窄 ---------- */
@media (min-width: 720px) {
  .page {
    left: 50%;
    transform: translateX(-50%);
    width: 480px;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    box-shadow: 0 0 40px rgba(0, 0, 0, .06);
  }
  .drawer { left: 50%; margin-left: -240px; width: 360px; }
  .drawer.right { left: 50%; right: auto; margin-left: -120px; }
  .toast { bottom: 40px; }
}
