/* Weaver · 网文阅读 样式 */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --color-primary: #a16b3b;        /* 书卷棕 */
  --color-bg: #faf6ef;
  --color-card: #fffdf8;
  --color-text: #3a342c;
  --color-muted: #8a8174;
  --color-border: #e6ddcd;
  --topbar-h: 52px;
  --bottom-h: 56px;
  --font-size: 18px;
  --line-h: 1.9;
  /* 阅读正文样式（设置面板可调；默认雅黑） */
  --reader-font: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  --reader-weight: 400;
  --reader-decoration: none;
  --reader-letter-spacing: 0px;
}

body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Noto Serif SC", "SimSun", serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 700px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

/* ---- 顶栏 ---- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: #fffdf8;
  border-bottom: 1px solid var(--color-border);
}
.topbar h1 { font-size: 18px; font-weight: 700; color: var(--color-primary); }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.topbar-btn {
  border: 1px solid var(--color-border); background: #fffdf8;
  color: var(--color-primary); border-radius: 8px;
  padding: 6px 12px; font-size: 14px; cursor: pointer;
}
.topbar-btn:active { background: var(--color-bg); }

/* 目录视图切换 */
.toc-switch { display: flex; overflow: hidden; border: 1px solid var(--color-border); border-radius: 8px; }
.switch-btn {
  border: none; background: #fffdf8; color: var(--color-muted);
  padding: 6px 12px; font-size: 14px; line-height: 1; cursor: pointer;
}
.switch-btn + .switch-btn { border-left: 1px solid var(--color-border); }
.switch-btn.active { background: var(--color-primary); color: #fff; }

/* ---- 导入栏 ---- */
.import-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.btn-import {
  border: 1px dashed var(--color-primary); background: #fffdf8;
  color: var(--color-primary); border-radius: 10px;
  padding: 10px 14px; font-size: 14px; cursor: pointer;
}
.btn-import:active { background: #f7efdf; }
.btn-import[disabled] { opacity: .5; cursor: not-allowed; }
.import-msg { font-size: 13px; color: var(--color-muted); flex: 1; }

/* ---- 搜索栏 ---- */
.search-bar {
  width: 100%; padding: 10px 14px; margin-bottom: 14px;
  border: 1px solid var(--color-border); border-radius: 10px;
  background: var(--color-card); color: var(--color-text); font-size: 14px;
  outline: none;
}
.search-bar:focus { border-color: var(--color-primary); }

/* ---- 书架 ---- */
.shelf-view { padding: 16px; }
.shelf-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
}
.book-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--color-card); border: 1px solid var(--color-border);
  border-radius: 12px; padding: 14px 8px; cursor: pointer;
  transition: transform .08s ease;
}
.book-card:active { transform: scale(.97); }
.book-cover {
  width: 84px; height: 112px; border-radius: 6px;
  background: linear-gradient(160deg, #d9a86a, #a16b3b);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 700;
  box-shadow: 0 3px 8px rgba(0,0,0,.15);
  position: relative;
}
/* 选择模式的勾选标（左上角） */
.check-mark {
  position: absolute; top: 4px; left: 4px;
  width: 22px; height: 22px; z-index: 2;
  border: 2px solid #fff; border-radius: 50%;
  background: rgba(0,0,0,.25); color: transparent;
  font-size: 13px; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.check-mark.on { background: #c0392b; border-color: #c0392b; color: #fff; }
/* 已勾选的书卡 */
.book-card.selected {
  border-color: #c0392b;
  box-shadow: 0 0 0 2px rgba(192,57,43,.25) inset;
}
.book-cover.b0 { background: linear-gradient(160deg, #e6b87a, #a16b3b); }
.book-cover.b1 { background: linear-gradient(160deg, #7fb3d5, #3b6f96); }
.book-cover.b2 { background: linear-gradient(160deg, #8fbf8a, #52794f); }
.book-cover.b3 { background: linear-gradient(160deg, #c48fa8, #8d5270); }
.book-cover.b4 { background: linear-gradient(160deg, #8fa8c4, #52708d); }
.book-name {
  font-size: 14px; font-weight: 600; text-align: center;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.book-meta { font-size: 12px; color: var(--color-muted); }
.shelf-empty { text-align: center; color: var(--color-muted); padding: 60px 0; font-size: 14px; }
.shelf-view.has-del-bar, .toc-view.has-del-bar { padding-bottom: calc(var(--bottom-h) + 24px); }

/* ---- 目录页 ---- */
.toc-view { padding: 14px 14px 30px; }
.toc-head { padding: 4px 6px 12px; }
.toc-title { font-size: 17px; font-weight: 700; display: block; }
.toc-author { font-size: 13px; color: var(--color-muted); margin-right: 8px; }
.toc-count { font-size: 12px; color: var(--color-muted); }

/* 上次读到横幅：点击续读 */
.toc-lastread {
  display: flex; align-items: center; gap: 8px;
  width: 100%; margin-bottom: 12px; padding: 10px 12px;
  border: 1px solid var(--color-border); border-left: 3px solid var(--color-primary);
  border-radius: 0 10px 10px 0;
  background: linear-gradient(90deg, rgba(161,107,59,.10), rgba(161,107,59,.02) 70%, transparent);
  cursor: pointer; text-align: left; font-family: inherit;
}
.toc-lastread:active { background: rgba(161,107,59,.16); }
.toc-lastread .lr-tag {
  flex: none; font-size: 12px; color: #fff; background: var(--color-primary);
  border-radius: 6px; padding: 2px 7px; line-height: 1.5;
}
.toc-lastread .lr-name {
  flex: 1; min-width: 0; font-size: 14px; color: var(--color-text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toc-lastread .lr-arrow { flex: none; color: var(--color-primary); font-size: 16px; line-height: 1; }

/* 列表视图 */
.toc-cell { display: flex; align-items: center; min-width: 0; }
.toc-list.list-view { display: flex; flex-direction: column; }
.toc-list.list-view .toc-cell {
  width: 100%; margin-bottom: 2px; border-bottom: 1px solid var(--color-border);
}
.toc-list.list-view .toc-item {
  flex: 1; width: 100%; text-align: left;
  padding: 12px 8px;
  background: none; border: none;
  color: var(--color-text); font-size: 15px; cursor: pointer; line-height: 1.5;
}
.toc-list.list-view .toc-item .no { color: var(--color-muted); margin-right: 10px; min-width: 28px; font-variant-numeric: tabular-nums; }
.toc-list.list-view .toc-item .check-mark {
  position: static; display: inline-flex; margin-right: 8px;
  vertical-align: middle;
}
.toc-list.list-view .toc-item.selected { background: #fbeee6; }

/* 网格视图：一行多章 */
.toc-list.grid-view {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.toc-list.grid-view .toc-item {
  position: relative;
  flex: 1; display: block; text-align: center;
  min-width: 0;
  padding: 14px 6px; border: 1px solid var(--color-border); border-radius: 10px;
  background: var(--color-card); color: var(--color-text); cursor: pointer;
  font-size: 14px; line-height: 1.4; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.toc-list.grid-view .toc-item .no { display: block; color: var(--color-muted); font-size: 12px; margin-bottom: 3px; }
.toc-list.grid-view .toc-item .check-mark {
  position: absolute; top: 4px; left: 4px;
}
.toc-list.grid-view .toc-item.selected { border-color: #c0392b; }
.toc-empty { grid-column: 1 / -1; text-align: center; color: var(--color-muted); padding: 40px 0; font-size: 14px; }

/* 分卷行：卷是结构不是内容, 独占一整行, 与章节明显区分 */
.toc-vol-cell { grid-column: 1 / -1; }
.toc-volume {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 12px 12px;
  margin: 14px 0 6px;
  background: linear-gradient(90deg, rgba(161,107,59,.13), rgba(161,107,59,.04) 65%, rgba(161,107,59,0));
  border: none; border-left: 3px solid var(--color-primary);
  border-radius: 0 8px 8px 0;
  color: var(--color-primary);
  font-family: inherit;
  font-size: 15px; font-weight: 700; letter-spacing: 1px;
  line-height: 1.4; text-align: center;
  cursor: default;
}
.toc-volume .vol-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-volume .check-mark { position: static; margin-right: 8px; flex: none; }
.toc-volume.selected { background: #fbeee6; }
/* 卷行不吃 list-view 的章节下划线, 靠上下留白与左侧色条自成一段 */
.toc-list.list-view .toc-vol-cell { border-bottom: none; }
.toc-list .toc-vol-cell:first-child .toc-volume { margin-top: 4px; }

/* ---- 阅读页 ---- */
.reader-view { padding: 0 18px calc(var(--bottom-h) + 30px); }
.reader-content { padding-top: 6px; font-family: var(--reader-font); }
.chapter-title {
  text-align: center; font-size: 20px; font-weight: 700;
  margin: 18px 0 24px; color: var(--color-text);
}
.chapter-body {
  font-size: var(--font-size);
  line-height: var(--line-h);
  letter-spacing: var(--reader-letter-spacing);
  font-weight: var(--reader-weight);
  text-decoration: var(--reader-decoration);
  text-align: justify;
  word-break: break-word;
}
.chapter-body p { margin-top: .6em; margin-bottom: .9em; text-indent: 2em; }
.chapter-end { text-align: center; color: var(--color-muted); margin-top: 30px; font-size: 13px; }
.chapter-chars {
  position: fixed; right: 14px; bottom: calc(var(--bottom-h) + 12px);
  background: rgba(0,0,0,.06); color: var(--color-muted);
  font-size: 12px; padding: 4px 10px; border-radius: 12px;
  font-variant-numeric: tabular-nums;
}

/* ---- 横向翻页模式（起点式） ----
 * 原理：正文容器定高 + CSS 多栏（每栏宽=可视宽，一栏一页），
 * 超出的栏横向溢出，由 #reader-clip 裁掉；JS 用 translateX 平移换页。 */
body.pagemode { overflow: hidden; }
body.pagemode #app {
  height: 100vh;
  height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
body.pagemode .reader-view {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  padding: 0 18px calc(var(--bottom-h) + 10px);
  /* 横向滑动交 app 处理，避免触屏把横滑当浏览器前进/后退手势 */
  touch-action: pan-y;
}
body.pagemode .reader-clip { flex: 1; min-height: 0; overflow: hidden; }
body.pagemode .reader-content {
  height: 100%;
  column-fill: auto;
  transition: transform .28s ease;
  will-change: transform;
}
body.pagemode .chapter-body p { text-indent: 2em; }

/* ---- 正文插图（md 图片段：整段图 img-p / 行内图 inline-img） ---- */
.chapter-body p.img-p { text-indent: 0; text-align: center; margin: 1.2em 0; }
.chapter-body p.img-p img {
  max-width: 100%; max-height: 72vh;
  border-radius: 6px; box-shadow: 0 1px 6px rgba(0,0,0,.08);
}
.chapter-body .inline-img {
  max-width: 100%; max-height: 2.6em;
  vertical-align: middle; border-radius: 3px;
}

/* ---- PDF 书阅读（kind=pdf：canvas 整页渲染，翻页走 reader 手势） ---- */
body.pdfmode { overflow: hidden; }   /* 整页视图，禁背景滚动（同 pagemode 思路） */
.pdf-clip {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  /* 上下让出顶栏/底导（栏自动隐去时 canvas 居中不受影响） */
  padding: calc(var(--topbar-h) + 8px) 10px calc(var(--bottom-h) + 10px);
  overflow: hidden;
  touch-action: none;   /* 横滑翻页交 app 处理，禁浏览器手势 */
}
.pdf-canvas {
  max-width: 100%; max-height: 100%;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0,0,0,.18);
  border-radius: 3px;
}

/* ---- 书籍详情卡片 ---- */
.book-card-modal {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
}
.book-card-modal.hidden { display: none; }
.bcard-box {
  width: min(440px, 92vw);
  background: #fffdf8; border-radius: 14px; padding: 24px 22px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  position: relative; text-align: center;
  max-height: 86vh; overflow-y: auto;
}
.bcard-close {
  position: absolute; top: 8px; right: 12px;
  border: none; background: none; color: var(--color-muted);
  font-size: 24px; line-height: 1; cursor: pointer;
}
.bcard-close:active { color: var(--color-primary); }
.bcard-cover {
  width: 120px; height: 160px; margin: 6px auto 14px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 34px; font-weight: 700;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
}
.bcard-cover.b0 { background: linear-gradient(160deg, #e6b87a, #a16b3b); }
.bcard-cover.b1 { background: linear-gradient(160deg, #7fb3d5, #3b6f96); }
.bcard-cover.b2 { background: linear-gradient(160deg, #8fbf8a, #52794f); }
.bcard-cover.b3 { background: linear-gradient(160deg, #c48fa8, #8d5270); }
.bcard-cover.b4 { background: linear-gradient(160deg, #8fa8c4, #52708d); }
.bcard-name { font-size: 18px; font-weight: 700; margin-bottom: 14px; }
.bcard-meta { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.bcard-row { display: flex; justify-content: center; gap: 12px; font-size: 14px; }
.bcard-row .lbl { color: var(--color-muted); }
.bcard-row .val { color: var(--color-text); }
/* 上次读到/简介：标签在上，内容下一行换行显示，左对齐便于阅读长文本 */
.bcard-row.bcard-stack { flex-direction: column; gap: 6px; text-align: left; }
.bcard-row.bcard-stack .lbl { text-align: left; }
.bcard-row.bcard-stack .val { line-height: 1.6; white-space: normal; }
/* 上次读到超链接：可点击直达对应章节文本位置 */
.bcard-row.bcard-stack .lr-link {
  color: var(--color-primary);
  font-weight: 600; text-decoration: underline;
  cursor: pointer; word-break: break-all;
}
.bcard-row.bcard-stack .lr-link:hover { color: #8a5a2c; }
.bcard-row.bcard-stack .lr-link:active { color: #6f4522; }
.btn-enter-read {
  width: 100%; border: none; border-radius: 10px; padding: 12px 0;
  background: var(--color-primary); color: #fff; font-size: 16px; cursor: pointer;
}
.btn-enter-read:active { filter: brightness(.92); }

/* ---- 阅读设置浮层（齿轮） ---- */
.settings-panel {
  position: fixed; top: calc(var(--topbar-h) + 10px); right: 14px; z-index: 80;
  display: flex; flex-direction: column; gap: 12px;
  width: min(300px, calc(100vw - 28px));
  background: #fffdf8; border: 1px solid var(--color-border); border-radius: 12px;
  padding: 14px 16px; box-shadow: 0 6px 20px rgba(0,0,0,.08);
}
.set-row { display: flex; align-items: center; gap: 10px; }
.set-lbl { flex: none; font-size: 13px; color: var(--color-muted); }
.set-chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; justify-content: flex-end; }
.set-chip {
  border: 1px solid var(--color-border); background: #fffdf8;
  color: var(--color-muted); border-radius: 14px;
  padding: 6px 11px; font-size: 13px; line-height: 1; cursor: pointer;
}
.set-chip:active { background: var(--color-bg); }
.set-chip.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.font-btn {
  border: 1px solid var(--color-border); background: #fffdf8; color: var(--color-primary);
  border-radius: 8px; padding: 6px 12px; font-size: 14px; cursor: pointer;
}
.font-btn:active { background: var(--color-bg); }
.font-num { min-width: 30px; text-align: center; color: var(--color-text); }

/* ---- 底部导航 ---- */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(700px, 100%); height: var(--bottom-h);
  display: flex; background: #fffdf8;
  border-top: 1px solid var(--color-border);
}
.nav-btn {
  flex: 1; border: none; background: none;
  color: var(--color-primary); font-size: 16px; cursor: pointer;
}
.nav-btn:active { background: var(--color-bg); }
.nav-btn[disabled] { color: var(--color-muted); opacity: .5; }

/* ---- 阅读沉浸：顶栏/底导自动隐去（core/readerbar） ----
 * body.reader-bars-hidden 仅在阅读视图时挂载。
 * 只做视觉平移（translate）隐去、保留两栏的布局空间 → 正文不移动、下方无空隙，上下各留一条空栏位。 */
.topbar { transition: transform .34s ease, opacity .26s ease; }
.bottom-nav { transition: transform .34s ease, opacity .26s ease; }
body.reader-bars-hidden .topbar {
  transform: translateY(-100%);
  opacity: 0; pointer-events: none;
}
body.reader-bars-hidden .bottom-nav {
  transform: translateX(-50%) translateY(100%);
  opacity: 0; pointer-events: none;
}

/* 选词批注：B 方案（移动端）. 平时触屏正文 user-select:none → 无原生选中工具栏；
 * 长按唤出「划词」入口后挂 body.note-select-mode 才临时放开选择（页面小游戏同思路：不喂可选文本即无系统菜单）。
 * 桌面(fine) 保持原生拖选不变。 */
.reader-content, #chapter-body, .pager-wrap { -webkit-tap-highlight-color: transparent; }
@media (pointer: coarse) {
  .reader-content, #chapter-body, .pager-wrap {
    -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  }
  body.note-select-mode .reader-content,
  body.note-select-mode #chapter-body,
  body.note-select-mode .pager-wrap {
    user-select: text; -webkit-user-select: text;
  }
}
@media (pointer: fine) {
  .reader-content, #chapter-body, .pager-wrap { user-select: text; -webkit-user-select: text; }
}

/* ---- 顶栏删除按钮（超管） ---- */
.topbar-btn.del-btn {
  color: #c0392b; border-color: #e3b7ad;
  background: #fff6f3;
  font-weight: 600;
}
.topbar-btn.del-btn:active { background: #fce8e2; }

/* ---- 选择删除操作条 ---- */
.del-bar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(700px, 100%); height: var(--bottom-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  background: #fffdf8; border-top: 1px solid var(--color-border);
  z-index: 60;
}
.del-bar-btn {
  border: 1px solid var(--color-border); background: #fff;
  color: var(--color-primary); border-radius: 8px;
  padding: 8px 14px; font-size: 14px; cursor: pointer;
  white-space: nowrap;
}
.del-bar-btn:active { background: var(--color-bg); }
.del-bar-btn.del-confirm {
  background: #c0392b; border-color: #c0392b; color: #fff;
  font-weight: 600;
}
.del-bar-btn.del-confirm:active { background: #a93226; }
.sel-count {
  flex: 1; text-align: center;
  color: var(--color-muted); font-size: 14px;
}

/* ---- 工具 ---- */
.hidden { display: none !important; }