/* ===================== LReading 样式 =====================
 * 五套主题走 CSS 变量（--bg/--fg/--panel/--muted/--accent/--border），
 * 阅读参数（字号/行距/段距/缩进）由 app.js 写到 :root 变量上。
 * 桌面与移动端同一套结构，<640px 断点做适配。
 */

/* ---------- 阅读参数变量 ---------- */
:root {
  --font-size: 19px;
  --line-height: 1.9;
  --para-gap: 0.9em;
  --indent: 2em;
}

/* ---------- 主题 ---------- */
body[data-theme="paper"]     { --bg:#ffffff; --fg:#262626; --panel:#f5f6f8; --muted:#8a8f99; --accent:#4f7cff; --border:#e6e8ec; }
body[data-theme="parchment"] { --bg:#f4ecd8; --fg:#5b4636; --panel:#ede2c8; --muted:#a3937a; --accent:#b07a2e; --border:#e0d4b8; }
body[data-theme="green"]     { --bg:#c7edcc; --fg:#2c4030; --panel:#b7ddba; --muted:#6d8a72; --accent:#2f8f4e; --border:#b2d6b6; }
body[data-theme="night"]     { --bg:#181a1f; --fg:#c6c9cf; --panel:#23262c; --muted:#7c818b; --accent:#7f9dff; --border:#33373f; }
body[data-theme="black"]     { --bg:#000000; --fg:#9a9a9a; --panel:#101010; --muted:#5a5a5a; --accent:#8095d0; --border:#262626; }

/* ---------- 字体族 ---------- */
body[data-font="sans"]  .read-content p { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
body[data-font="serif"] .read-content p { font-family: Georgia, "Times New Roman", "Songti SC", SimSun, "Noto Serif SC", serif; }
body[data-font="kai"]   .read-content p { font-family: KaiTi, STKaiti, "Kaiti SC", "KaiTi GB", "Noto Serif SC", serif; }

/* ---------- 基础 ---------- */
* { box-sizing: border-box; }
/* hidden 属性必须无条件生效：.loading/.reader/.shelf-wrap 都设了 display，
   否则会盖掉 [hidden] 的 display:none（曾导致首屏加载遮罩和阅读器常显） */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  border-radius: 8px;
  font-family: inherit;
}
button:active { opacity: .75; }
input {
  font-family: inherit;
  color: var(--fg);
}

/* ===================== 首页 ===================== */
.view { min-height: 100%; }
.hero { max-width: 720px; margin: 0 auto; padding: 10vh 20px 30px; text-align: center; }
.logo { font-size: 38px; font-weight: 800; letter-spacing: 1px; color: var(--accent); }
.slogan { margin: 10px 0 26px; color: var(--muted); font-size: 15px; }
.paste-box { display: flex; gap: 10px; max-width: 640px; margin: 0 auto; }
#pasteInput {
  flex: 1;
  min-width: 0;
  padding: 13px 16px;
  font-size: 15px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s;
}
#pasteInput:focus { border-color: var(--accent); }
#btnGo { padding: 0 26px; font-size: 15px; background: var(--accent); color: #fff; border: none; white-space: nowrap; }
.tip { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* 书架 */
.shelf-wrap { max-width: 720px; margin: 0 auto; padding: 10px 20px 60px; }
.shelf-title { font-size: 14px; color: var(--muted); margin: 14px 0 10px; }
.shelf-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color .15s;
}
.shelf-item:hover { border-color: var(--accent); }
.si-info { flex: 1; min-width: 0; }
.si-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.si-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.si-open { padding: 8px 14px; background: var(--accent); color: #fff; border: none; font-size: 13px; white-space: nowrap; }
.si-del { padding: 8px 11px; font-size: 12px; color: var(--muted); }

/* ===================== 阅读器 ===================== */
.reader {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* 移动端浏览器工具栏收起时保持正确视口 */
}
.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.top-bar .bar-btn { padding: 8px 12px; font-size: 14px; white-space: nowrap; }
.bar-mid { flex: 1; min-width: 0; text-align: center; }
.bar-book { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.read-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.read-content { max-width: 780px; margin: 0 auto; padding: 26px 22px 60px; }
.read-content p {
  font-size: var(--font-size);
  line-height: var(--line-height);
  margin: 0 0 var(--para-gap);
  text-indent: var(--indent);
  letter-spacing: .2px;
  word-break: break-all;
}

.bottom-bar {
  justify-content: space-between;
  border-bottom: none;
  border-top: 1px solid var(--border);
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.nav-btn { flex: 1; padding: 10px 18px; font-size: 14px; }
.nav-btn:disabled { opacity: .35; cursor: default; }
.pos { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ===================== 抽屉（目录 / 设置） ===================== */
.mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .45);
  opacity: 0; pointer-events: none;
  transition: opacity .18s;
  z-index: 40;
}
.mask.on { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(360px, 86vw);
  background: var(--panel);
  border-left: 1px solid var(--border);
  z-index: 50;
  transform: translateX(105%);
  transition: transform .18s;
  display: flex;
  flex-direction: column;
}
.drawer.on { transform: none; }
.drawer-head {
  padding: 14px 16px;
  font-weight: 700; font-size: 16px;
  border-bottom: 1px solid var(--border);
}
.drawer-sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }

#tocSearch {
  margin: 10px 12px 4px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  outline: none;
  font-size: 14px;
}
.toc-list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 4px 0 30px; }
.toc-list li {
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toc-list li:active { background: var(--bg); }
.toc-list li.cur { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

.set-scroll { flex: 1; overflow-y: auto; padding-bottom: 30px; }
.set-group { padding: 14px 16px 4px; }
.set-label { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row button { padding: 8px 14px; font-size: 13px; }
.btn-row button.cur { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 主题色块按钮 */
.swatch { position: relative; padding-left: 26px !important; }
.swatch::before {
  content: '';
  position: absolute; left: 9px; top: 50%;
  width: 12px; height: 12px;
  margin-top: -6px;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.sw-paper::before     { background: #ffffff; }
.sw-parchment::before { background: #f4ecd8; }
.sw-green::before     { background: #c7edcc; }
.sw-night::before     { background: #181a1f; }
.sw-black::before     { background: #000; }

.val { color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.chk-row { font-size: 14px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.chk-row input { accent-color: var(--accent); }

/* ===================== 加载提示 / 轻提示 ===================== */
.loading {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0, 0, 0, .5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #fff;
  font-size: 14px;
}
.spin {
  width: 30px; height: 30px;
  border: 3px solid rgba(255, 255, 255, .25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: sp .8s linear infinite;
}
@keyframes sp { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%; bottom: 12vh;
  transform: translateX(-50%) translateY(10px);
  background: rgba(20, 22, 26, .92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all .2s;
  z-index: 99;
  max-width: 86vw;
  text-align: center;
}
.toast.on { opacity: 1; transform: translateX(-50%); }

/* ===================== 移动端适配（<640px） ===================== */
@media (max-width: 640px) {
  .hero { padding-top: 7vh; }
  .paste-box { flex-direction: column; }
  #btnGo { padding: 13px; }
  .logo { font-size: 32px; }

  .bar { padding: 6px 8px; }
  .top-bar { padding-top: calc(6px + env(safe-area-inset-top)); } /* 刘海屏不被状态栏遮挡 */
  .drawer-head { padding-top: calc(14px + env(safe-area-inset-top)); }
  .bar-btn { padding: 8px 10px; font-size: 13px; }
  .bar-book { display: none; } /* 小屏省空间，只显示章节标题 */
  .bar-mid { text-align: left; }

  .read-content { padding: 18px 16px 46px; }
  .nav-btn { padding: 12px 18px; font-size: 14px; }

  .drawer { width: 100vw; border-left: none; } /* 移动端目录/设置全屏 */

  .shelf-item { padding: 12px; }
  .si-open { padding: 10px 12px; }
}
