/* ============================================================
   静读 · 样式表
   设计取向：克制留白、温暖中性色、舒适的阅读排版
   仅使用系统字体栈，零外部字体依赖
   ============================================================ */

:root {
  /* 浅色：温暖的米白底，墨黑字，赤陶色强调 */
  --bg:        #faf9f5;
  --surface:   #ffffff;
  --surface-2: #f3f1ea;
  --border:    #e8e4d9;
  --text:      #2b2a27;
  --text-soft: #6b6a64;
  --text-dim:  #97958c;
  --accent:    #c45a36;   /* 赤陶 */
  --accent-soft: #e9d9cf;
  --shadow:    0 1px 3px rgba(40, 38, 33, .06), 0 6px 24px rgba(40, 38, 33, .05);

  --serif: "Noto Serif SC", "Songti SC", "Source Han Serif SC", "Source Han Serif CN", STSong, SimSun, Georgia, serif;
  --sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;

  --reader-width: 38rem;
  --topbar-height: 3.25rem;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #1f1e1c;
    --surface:   #272523;
    --surface-2: #2f2d2a;
    --border:    #3a3733;
    --text:      #ece9e2;
    --text-soft: #aba89f;
    --text-dim:  #7d7a72;
    --accent:    #e08a63;
    --accent-soft: #45342b;
    --shadow:    0 1px 3px rgba(0, 0, 0, .3), 0 6px 24px rgba(0, 0, 0, .25);
  }
}

/* 手动主题覆盖（data-theme 优先于系统偏好） */
:root[data-theme="light"] {
  --bg: #faf9f5; --surface: #ffffff; --surface-2: #f3f1ea; --border: #e8e4d9;
  --text: #2b2a27; --text-soft: #6b6a64; --text-dim: #97958c;
  --accent: #c45a36; --accent-soft: #e9d9cf;
  --shadow: 0 1px 3px rgba(40,38,33,.06), 0 6px 24px rgba(40,38,33,.05);
}
:root[data-theme="dark"] {
  --bg: #1f1e1c; --surface: #272523; --surface-2: #2f2d2a; --border: #3a3733;
  --text: #ece9e2; --text-soft: #aba89f; --text-dim: #7d7a72;
  --accent: #e08a63; --accent-soft: #45342b;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  scroll-behavior: smooth;
  max-width: 100%;
  overflow-x: hidden;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  padding-top: var(--topbar-height);
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  width: 100%;
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem 1.1rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  transform: translate3d(0, 0, 0);
  transition: transform .2s ease, background-color .2s ease, border-color .2s ease;
  will-change: transform;
}
.reader-topbar-hidden .topbar {
  transform: translate3d(0, calc(-100% - 2px), 0);
}
.brand {
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text);
  text-decoration: none;
  font-size: 1.02rem;
}
.topbar-title {
  flex: 1;
  text-align: center;
  font-size: .9rem;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-actions { display: flex; gap: .35rem; margin-left: auto; }

.icon-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  font-size: .85rem;
  padding: .38rem .6rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 书架 ---------- */
.shelf {
  max-width: 46rem;
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
}
.shelf-title {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 600;
  margin: 0 0 .3rem;
  letter-spacing: .01em;
}
.shelf-sub { color: var(--text-soft); margin: 0 0 2.2rem; font-size: .95rem; }

.book-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .9rem; }
.book-list .empty { color: var(--text-dim); padding: 1rem 0; }

.book-card {
  --cover-w: 4.2rem;
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  transition: transform .18s ease, border-color .18s ease;
}
.book-card:hover { transform: translateY(-2px); border-color: var(--accent-soft); }
.book-card.has-cover {
  --cover-w: 6rem;
  padding: 1.05rem 1.15rem;
}
.book-link {
  flex: 1;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  border-radius: 8px;
}
.book-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.book-cover {
  width: var(--cover-w);
  aspect-ratio: 2 / 3;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--surface-2), var(--accent-soft));
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(40, 38, 33, .12);
}
.book-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.book-card.has-cover .book-cover {
  border-radius: 10px;
  box-shadow: 0 5px 18px rgba(40, 38, 33, .18);
}
.book-cover-link {
  color: inherit;
  text-decoration: none;
  transition: transform .18s ease, box-shadow .18s ease;
}
.book-cover-link:hover {
  transform: translateY(-1px) scale(1.015);
}
.book-cover-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}
.book-cover-placeholder {
  display: grid;
  place-items: center;
}
.book-cover-placeholder span {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--accent);
}
.book-main { min-width: 0; }
.book-name { font-family: var(--serif); font-size: 1.2rem; font-weight: 600; margin: 0 0 .2rem; }
.book-author { color: var(--text-soft); font-size: .9rem; }
.book-meta { color: var(--text-dim); font-size: .8rem; white-space: nowrap; }
.book-side { display: flex; flex-direction: column; align-items: flex-end; gap: .55rem; flex-shrink: 0; }
.offline-btn {
  appearance: none; font-family: inherit; font-size: .75rem;
  color: var(--text-soft); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px;
  padding: .26rem .62rem; cursor: pointer; white-space: nowrap;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.offline-btn:hover { border-color: var(--accent-soft); color: var(--text); }
.offline-btn:disabled { cursor: default; opacity: .75; }
.offline-btn[data-state="downloaded"] {
  color: var(--accent); border-color: var(--accent-soft); background: transparent;
}
.offline-btn[data-state="error"] { color: var(--accent); border-color: var(--accent); }

/* ---------- Android App 推荐卡 ---------- */
.app-banner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.15rem;
  margin: 0 0 1.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.app-banner-text { display: flex; flex-direction: column; gap: .2rem; flex: 1; min-width: 0; padding-right: 1.5rem; }
.app-banner-text strong { font-size: .98rem; color: var(--text); }
.app-banner-text span { font-size: .85rem; color: var(--text-soft); }
.app-banner-get {
  flex-shrink: 0;
  background: var(--accent); color: #fff;
  font-size: .9rem; text-decoration: none; white-space: nowrap;
  padding: .5rem 1.1rem; border-radius: 999px;
  transition: filter .15s ease;
}
.app-banner-get:hover { filter: brightness(1.06); }
.app-banner-x {
  position: absolute; top: .5rem; right: .5rem;
  appearance: none; border: 1px solid transparent; background: transparent;
  color: var(--text-soft); font-size: .85rem; line-height: 1;
  padding: .3rem .45rem; border-radius: 8px; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.app-banner-x:hover { background: var(--surface-2); color: var(--text); }
.book-progress {
  margin-top: .55rem; font-size: .78rem; color: var(--accent);
  display: inline-flex; align-items: center; gap: .35rem;
}

/* ---------- 阅读进度条 ---------- */
.progress-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 100%;
  display: flex; align-items: stretch; gap: 1px; z-index: 30;
}
.progress-seg {
  /* 高度交给 align-items: stretch 撑满容器的 3px——
     不用 height:100%，避免 flex 项百分比高度解析失败而塌成 0 高 */
  background: var(--border);              /* 未读 */
  transition: background .15s linear;
}
.progress-seg.read { background: var(--accent); }  /* 已读 */

/* ---------- 阅读区 ---------- */
.reader {
  max-width: var(--reader-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 6rem;
}
.chapter-title {
  font-family: var(--serif);
  font-size: clamp(1.5rem, 3.5vw, 1.9rem);
  font-weight: 600;
  margin: 0 0 1.8rem;
  text-align: center;
  letter-spacing: .01em;
}
.chapter-body {
  font-family: var(--serif);
  font-size: var(--reader-font, 1.12rem);
  line-height: 1.95;
  color: var(--text);
}
.chapter-body p {
  margin: 0 0 1.25em;
  text-indent: 2em;
}
.chapter-body p:first-child { margin-top: 0; }
.chapter-body .empty { text-align: center; color: var(--text-dim); text-indent: 0; }

.pdf-reading .reader {
  position: fixed;
  inset: 0;
  z-index: 10;
  max-width: none;
  padding: 0;
  background: var(--surface-2);
}
.pdf-reading .chapter-title {
  display: none;
}
.pdf-reading .chapter-body {
  width: 100%;
  height: 100%;
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
}
.pdf-reader-shell {
  width: 100%;
  height: 100%;
}
.pdf-toolbar {
  position: fixed;
  bottom: max(.5rem, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 24;
  display: flex;
  align-items: center;
  gap: .45rem;
  max-width: calc(100vw - 1rem);
  padding: .38rem .48rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateX(-50%);
  transition: opacity .16s ease, transform .16s ease;
}
.pdf-page-label {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  color: var(--text-soft);
  font-size: .78rem;
}
.pdf-part-select,
.pdf-page-input {
  width: 3.25rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: .28rem .35rem;
  font: inherit;
  font-size: .78rem;
}
.pdf-part-select {
  width: min(17rem, 42vw);
  min-width: 7rem;
}
.pdf-page-input {
  appearance: textfield;
}
.pdf-part-select:focus,
.pdf-page-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.pdf-page-total {
  color: var(--text-dim);
  white-space: nowrap;
}
.pdf-zoom-value {
  min-width: 2.7rem;
  color: var(--text-dim);
  font-size: .72rem;
  text-align: center;
}
.pdf-open-link {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  color: var(--text);
  border-radius: 6px;
  font-size: 1rem;
  text-decoration: none;
}
.pdf-open-link:hover {
  background: var(--surface-2);
}
.pdf-canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--surface-2);
  padding: 0;
  overflow: auto;
  text-align: center;
  overscroll-behavior: contain;
  overscroll-behavior-x: none;
  touch-action: pan-x pan-y;
  transition: height .16s ease, top .16s ease;
}
.pdf-reading:not(.pdf-controls-hidden) .pdf-canvas-wrap {
  top: var(--topbar-height);
  height: calc(100% - var(--topbar-height) - 3.75rem - env(safe-area-inset-bottom));
}
.pdf-canvas {
  display: block;
  max-width: none;
  margin: auto;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .12);
  transform-origin: center center;
}
.pdf-canvas.is-pinching {
  will-change: transform;
}
.pdf-edge-gesture {
  display: none;
}
.pdf-status {
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 23;
  margin: 0;
  padding: .4rem .6rem;
  transform: translate(-50%, -50%);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: .86rem;
  text-align: center;
}
.pdf-status:empty {
  display: none;
}
.pdf-controls-hidden .pdf-toolbar {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(100% + 1rem + env(safe-area-inset-bottom)));
}
.pdf-reading {
  padding-top: 0;
  overflow: hidden;
}

@media (pointer: coarse) {
  .reader-edge-gesture,
  .pdf-edge-gesture {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 22;
    display: block;
    width: 28px;
    touch-action: none;
  }
  .reader-edge-gesture { z-index: 19; }
  .reader-edge-gesture-left,
  .pdf-edge-gesture-left { left: 0; }
  .reader-edge-gesture-right,
  .pdf-edge-gesture-right { right: 0; }
}

/* 章节内分隔（用于场景切换 * * *） */
.chapter-body hr {
  border: none; text-align: center; margin: 2em 0;
}
.chapter-body hr::before {
  content: "* * *"; color: var(--text-dim); letter-spacing: .5em;
}

/* ---------- 词语标注 ---------- */
/* 5 种类别样式循环使用：浅底色 + 同色系细下划线，悬停可看类别名 */
:root {
  --hl-0-bg: #f5e3da; --hl-0-line: #c45a36;  /* 赤陶 · 人名等首类 */
  --hl-1-bg: #e2eae0; --hl-1-line: #5d7a5a;  /* 苔绿 */
  --hl-2-bg: #e3e7ee; --hl-2-line: #5a6e8c;  /* 黛蓝 */
  --hl-3-bg: #efe6d8; --hl-3-line: #9a7b3f;  /* 赭黄 */
  --hl-4-bg: #ece2ec; --hl-4-line: #84618a;  /* 紫灰 */
}
@media (prefers-color-scheme: dark) {
  :root {
    --hl-0-bg: #43332c; --hl-0-line: #e08a63;
    --hl-1-bg: #313a30; --hl-1-line: #93ad8f;
    --hl-2-bg: #2f3540; --hl-2-line: #8fa3c2;
    --hl-3-bg: #3e372a; --hl-3-line: #c4a468;
    --hl-4-bg: #3a313b; --hl-4-line: #b58fbc;
  }
}
:root[data-theme="light"] {
  --hl-0-bg: #f5e3da; --hl-0-line: #c45a36;
  --hl-1-bg: #e2eae0; --hl-1-line: #5d7a5a;
  --hl-2-bg: #e3e7ee; --hl-2-line: #5a6e8c;
  --hl-3-bg: #efe6d8; --hl-3-line: #9a7b3f;
  --hl-4-bg: #ece2ec; --hl-4-line: #84618a;
}
:root[data-theme="dark"] {
  --hl-0-bg: #43332c; --hl-0-line: #e08a63;
  --hl-1-bg: #313a30; --hl-1-line: #93ad8f;
  --hl-2-bg: #2f3540; --hl-2-line: #8fa3c2;
  --hl-3-bg: #3e372a; --hl-3-line: #c4a468;
  --hl-4-bg: #3a313b; --hl-4-line: #b58fbc;
}

mark.hl {
  color: inherit;
  border-radius: 4px;
  padding: 0 .12em;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .22em;
  cursor: help;
  transition: background .15s ease;
}
mark.hl-0 { background: var(--hl-0-bg); text-decoration-color: var(--hl-0-line); }
mark.hl-1 { background: var(--hl-1-bg); text-decoration-color: var(--hl-1-line); }
mark.hl-2 { background: var(--hl-2-bg); text-decoration-color: var(--hl-2-line); }
mark.hl-3 { background: var(--hl-3-bg); text-decoration-color: var(--hl-3-line); }
mark.hl-4 { background: var(--hl-4-bg); text-decoration-color: var(--hl-4-line); }

/* 顶栏「标注」按钮关闭时整体还原为普通文字 */
body.no-hl mark.hl {
  background: transparent;
  text-decoration: none;
  padding: 0;
  cursor: inherit;
}

/* ---------- 章节导航 ---------- */
.chapter-nav {
  display: flex; justify-content: space-between; gap: 1rem;
  margin-top: 3.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border);
}
.nav-btn {
  appearance: none; font-family: inherit; font-size: .92rem;
  padding: .65rem 1.1rem; border-radius: 10px; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  transition: background .15s ease, border-color .15s ease;
}
.nav-btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--accent-soft); }
.nav-btn:disabled { opacity: .4; cursor: default; }
.nav-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 目录抽屉 ---------- */
.toc {
  position: fixed;
  top: 0;
  right: 0;
  left: auto;
  z-index: 40;
  width: min(22rem, calc(100vw - 1rem));
  max-width: calc(100vw - 1rem);
  height: 100dvh;
  max-height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0,0,0,.12);
  padding: 1.4rem 1.2rem;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  contain: paint;
  transform: translate3d(0, 0, 0);
  transition: transform .22s ease, visibility .22s ease;
}
.toc[hidden] {
  display: block;
  visibility: hidden;
  transform: translate3d(calc(100% + 2px), 0, 0);
  pointer-events: none;
}
.toc-title { font-size: 1rem; margin: .2rem 0 1rem; color: var(--text-soft); font-weight: 600; }
.toc-list { list-style: none; margin: 0; padding: 0; counter-reset: ch; }
.toc-list li { margin: 0; }
.toc-list a {
  display: block; padding: .55rem .7rem; border-radius: 8px;
  color: var(--text-soft); text-decoration: none; font-size: .92rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
  transition: background .12s ease, color .12s ease;
}
.toc-list a:hover { background: var(--surface-2); color: var(--text); }
.toc-list a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toc-list a.current { color: var(--accent); background: var(--accent-soft); }
.toc:focus { outline: none; }

/* ---------- 页脚 ---------- */
.footer {
  max-width: 46rem; margin: 0 auto; padding: 2rem 1.25rem 3rem;
  color: var(--text-dim); font-size: .82rem; border-top: 1px solid var(--border);
}
.footer code {
  background: var(--surface-2); padding: .1em .4em; border-radius: 5px;
  font-size: .9em; color: var(--text-soft);
}
/* ---------- 书签和笔记 ---------- */
.icon-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.chapter-body p.bookmarked {
  border-left: 3px solid var(--accent);
  padding-left: .8em;
  margin-left: -.95em;
  border-radius: 4px;
}

.bookmarks-panel {
  position: fixed;
  top: 0;
  right: 0;
  left: auto;
  z-index: 42;
  width: min(24rem, calc(100vw - 1rem));
  max-width: calc(100vw - 1rem);
  height: 100dvh;
  max-height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0,0,0,.12);
  padding: 1.4rem 1.2rem;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  contain: paint;
  transform: translate3d(0, 0, 0);
  transition: transform .22s ease, visibility .22s ease;
}
.bookmarks-panel[hidden] {
  display: block;
  visibility: hidden;
  transform: translate3d(calc(100% + 2px), 0, 0);
  pointer-events: none;
}
.bookmarks-panel:focus { outline: none; }

.bookmarks-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  margin: .2rem 0 1rem;
}
.bookmarks-title {
  font-size: 1rem;
  margin: 0;
  color: var(--text-soft);
  font-weight: 600;
}
.bookmark-add {
  appearance: none;
  flex-shrink: 0;
  font-family: inherit;
  font-size: .82rem;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: .42rem .72rem;
  cursor: pointer;
}
.bookmark-add:hover { filter: brightness(1.04); }
.bookmark-add:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bookmark-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: .7rem;
}
.bookmark-empty {
  color: var(--text-dim);
  font-size: .9rem;
  line-height: 1.7;
  padding: .8rem .2rem;
}
.bookmark-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem;
  align-items: start;
  padding: .75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.bookmark-jump {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  text-align: left;
  padding: 0;
  cursor: pointer;
  min-width: 0;
}
.bookmark-jump:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.bookmark-title,
.bookmark-meta,
.bookmark-excerpt,
.bookmark-note {
  display: block;
}
.bookmark-title {
  color: var(--text);
  font-size: .92rem;
  font-weight: 600;
  margin-bottom: .15rem;
}
.bookmark-meta {
  color: var(--text-dim);
  font-size: .75rem;
  margin-bottom: .38rem;
}
.bookmark-excerpt {
  color: var(--text-soft);
  font-family: var(--serif);
  font-size: .88rem;
  line-height: 1.65;
}
.bookmark-note {
  color: var(--accent);
  font-size: .82rem;
  line-height: 1.55;
  margin-top: .42rem;
  padding-left: .65rem;
  border-left: 2px solid var(--accent-soft);
}
.bookmark-delete {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-family: inherit;
  font-size: .75rem;
  border-radius: 999px;
  padding: .25rem .55rem;
  cursor: pointer;
}
.bookmark-delete:hover { color: var(--accent); border-color: var(--accent-soft); }
.bookmark-delete:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }


/* ---------- 全书搜索 ---------- */
.search-panel {
  position: fixed;
  top: 0;
  right: 0;
  left: auto;
  z-index: 40;
  width: min(24rem, calc(100vw - 1rem));
  max-width: calc(100vw - 1rem);
  height: 100dvh;
  max-height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0,0,0,.12);
  padding: 1.4rem 1.2rem;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  contain: paint;
  transform: translate3d(0, 0, 0);
  transition: transform .18s ease, visibility .18s ease;
}
.search-panel[hidden] {
  display: block;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(calc(100% + 2px), 0, 0);
}
.search-panel:focus { outline: none; }
.search-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .8rem;
  margin-bottom: 1rem;
}
.search-title {
  font-size: 1rem;
  margin: .2rem 0 0;
  color: var(--text-soft);
  font-weight: 600;
}
.search-shortcut {
  color: var(--text-dim);
  font-size: .72rem;
  white-space: nowrap;
}
.search-form {
  display: flex;
  gap: .5rem;
  margin-bottom: .75rem;
}
.search-input {
  min-width: 0;
  flex: 1;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: .56rem .7rem;
  font: inherit;
  font-size: .9rem;
}
.search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.search-submit {
  appearance: none;
  border: 1px solid var(--accent-soft);
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: .55rem .75rem;
  font: inherit;
  font-size: .86rem;
  cursor: pointer;
  white-space: nowrap;
}
.search-submit:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.search-status {
  margin: 0 0 .9rem;
  color: var(--text-dim);
  font-size: .8rem;
  line-height: 1.55;
}
.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: .75rem;
}
.search-empty {
  color: var(--text-dim);
  font-size: .86rem;
  line-height: 1.7;
  padding: .8rem .2rem;
}
.search-item {
  margin: 0;
  padding: .8rem .75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.search-item-streaming {
  opacity: 0;
  transform: translateY(8px);
  animation: searchResultAppear .42s ease forwards;
}
@keyframes searchResultAppear {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.search-item:hover { background: var(--surface-2); }
.search-result {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  text-align: left;
  padding: 0;
  cursor: pointer;
  width: 100%;
  min-width: 0;
}
.search-result:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.search-result-title,
.search-result-meta,
.search-result-excerpt {
  display: block;
}
.search-result-title {
  color: var(--text);
  font-size: .92rem;
  font-weight: 600;
  margin-bottom: .15rem;
}
.search-result-meta {
  color: var(--text-dim);
  font-size: .75rem;
  margin-bottom: .38rem;
}
.search-result-excerpt {
  color: var(--text-soft);
  font-family: var(--serif);
  font-size: .88rem;
  line-height: 1.65;
}
.search-mark {
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 4px;
  padding: 0 .1em;
}
.chapter-body p.search-target {
  background: var(--accent-soft);
  border-radius: 8px;
  box-shadow: 0 0 0 .45rem var(--accent-soft);
  transition: background .25s ease, box-shadow .25s ease;
}

/* ---------- 阅读进度同步 ---------- */
.sync-panel {
  position: fixed;
  top: 0;
  right: 0;
  left: auto;
  z-index: 41;
  width: min(24rem, calc(100vw - 1rem));
  max-width: calc(100vw - 1rem);
  height: 100dvh;
  max-height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0,0,0,.12);
  padding: 1.4rem 1.2rem;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  contain: paint;
  transform: translate3d(0, 0, 0);
  transition: transform .18s ease, visibility .18s ease;
}
.sync-panel[hidden] {
  display: block;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(calc(100% + 2px), 0, 0);
}
.sync-panel:focus { outline: none; }
.sync-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .8rem;
  margin-bottom: 1rem;
}
.sync-title {
  font-size: 1rem;
  margin: .2rem 0 0;
  color: var(--text-soft);
  font-weight: 600;
}
.sync-form {
  display: grid;
  gap: .75rem;
  margin-bottom: .85rem;
}
.sync-code {
  width: 100%;
  min-width: 0;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: .58rem .72rem;
  font: inherit;
  font-size: .9rem;
}
.sync-code:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.sync-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
}
.sync-action {
  appearance: none;
  border: 1px solid var(--accent-soft);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: .56rem .75rem;
  font: inherit;
  font-size: .86rem;
  cursor: pointer;
}
.sync-action:hover:not(:disabled) {
  background: var(--surface-2);
}
.sync-action:disabled {
  cursor: default;
  opacity: .65;
}
.sync-action:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.sync-action:first-child {
  background: var(--accent);
  color: #fff;
}
.sync-status {
  margin: 0;
  color: var(--text-dim);
  font-size: .82rem;
  line-height: 1.6;
}
.sync-status[data-state="ok"] { color: var(--accent); }
.sync-status[data-state="error"] { color: #b33a2b; }
:root[data-theme="dark"] .sync-status[data-state="error"] { color: #f08b7e; }


@media (max-width: 520px) {
  .book-card {
    --cover-w: 3.6rem;
    align-items: center;
    padding: .9rem;
    gap: .7rem;
  }
  .book-card.has-cover {
    --cover-w: 5.4rem;
    padding: 1rem .9rem;
  }
  .book-cover { border-radius: 7px; }
  .book-card.has-cover .book-cover { border-radius: 9px; }
  .book-name { font-size: 1.08rem; }
  .book-side { gap: .45rem; }
}


@media (max-width: 380px) {
  .book-card.has-cover { --cover-w: 4.9rem; }
}

@media (max-width: 520px) {
  .toc,
  .search-panel,
  .sync-panel,
  .bookmarks-panel {
    width: min(22rem, calc(100vw - .75rem));
    max-width: calc(100vw - .75rem);
    padding: 1.15rem 1rem;
  }
}

@media (max-width: 520px) {
  :root { --topbar-height: 3rem; }
  .topbar { gap: .45rem; padding: .62rem .75rem; }
  .topbar-title { display: none; }
  .topbar-actions { gap: .25rem; overflow-x: auto; scrollbar-width: none; }
  .topbar-actions::-webkit-scrollbar { display: none; }
  .icon-btn { font-size: .78rem; padding: .34rem .46rem; }
}


@media (prefers-reduced-motion: reduce) {
  .topbar {
    transition: none;
  }
  .search-item-streaming {
    opacity: 1;
    transform: none;
    animation: none;
  }
}
