/* ===== TOKENS ===== */
:root {
  --bg: #f5efe2;
  --bg-deep: #ece4d4;
  --surface: #fcfaf5;
  --surface2: #ece4d4;
  --surface3: #dfd5c2;
  --ink1: #1a1510;
  --ink2: #4a3f30;
  --ink3: #6e6248;
  --ink4: #a89878;
  --accent: #a85a1a;
  --accent-soft: rgba(168,90,26,0.10);
  --accent-deep: #7a3d10;
  --jade: #4a6e4a;
  --jade-soft: rgba(74,110,74,0.12);
  --vermillion: #8b2c1f;
  --border: rgba(26,21,16,0.14);
  --border-soft: rgba(26,21,16,0.08);
  --border-strong: rgba(26,21,16,0.30);
  --rule: rgba(26,21,16,0.55);
  --font-display: 'Cormorant Garamond', 'Georgia', serif;
  --font-mono: 'DM Mono', 'Courier New', monospace;
  --radius: 4px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --hl-yinyin: rgba(74,110,74,0.18);
  --hl-yinyin-strong: rgba(74,110,74,0.28);
  --hl-kieran: rgba(168,90,26,0.16);
  --hl-kieran-strong: rgba(168,90,26,0.26);
  --reader-font-size: 19px;
}

.night-mode {
  --bg: #1c1916;
  --bg-deep: #161310;
  --surface: #262220;
  --surface2: #302b28;
  --surface3: #3c3632;
  --ink1: #e8dcc4;
  --ink2: #b5a688;
  --ink3: #8f8268;
  --ink4: #564c3a;
  --accent: #c8864a;
  --accent-soft: rgba(200,134,74,0.12);
  --accent-deep: #a86e30;
  --jade: #7ca06a;
  --jade-soft: rgba(124,160,106,0.14);
  --vermillion: #b04a3a;
  --border: rgba(156,138,108,0.35);
  --border-soft: rgba(156,138,108,0.20);
  --border-strong: rgba(156,138,108,0.50);
  --rule: rgba(156,138,108,0.45);
  --hl-yinyin: rgba(124,160,106,0.20);
  --hl-yinyin-strong: rgba(124,160,106,0.32);
  --hl-kieran: rgba(200,134,74,0.18);
  --hl-kieran-strong: rgba(200,134,74,0.30);
}

/* ===== RESET ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* 横向锁死：iOS WebView 里页面不准左右晃（音音 07-03）。三次踩坑的最终形态：
   1. overflow-x:hidden —— 锁住了，但 body 上的 hidden 创建裁剪容器，sticky 顶栏
      参照系被偷换成 body，滚动时顶栏跟内容跑（音音实测）
   2. overflow-x:clip —— sticky 好了，但 WebKit 视口语义里 clip 挡不住 iOS 横向
      橡皮筋手势，又能左右拉了（音音实测 ×2）
   3. clip（裁视觉溢出）+ touch-action: pan-y（手势层禁横向 pan）—— 各管各的。
   长按选字/拖选区把手是系统手势，不走 touch-action，划线不受影响。 */
html, body { overflow-x: clip; }
body { touch-action: pan-y; }

body {
  background: var(--bg);
  color: var(--ink1);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.35s var(--ease), color 0.35s var(--ease);
}

/* ===== LAYOUT ===== */
.folio {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

/* ===== BACK LINK ===== */
.back-link {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 16px;
  z-index: 1000;
  text-decoration: none;
  color: var(--ink3);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  opacity: 0.5;
  transition: opacity 0.25s var(--ease);
}
.back-link:hover { opacity: 1; }

/* ===== HEADER ===== */
.page-header {
  padding: calc(20px + env(safe-area-inset-top, 0px)) 0 20px;
}

.header-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.nav-back {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink2);
  text-decoration: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.05em;
  border: none;
  background: none;
  transition: color 0.25s var(--ease);
}
.nav-back:hover { color: var(--accent); }
.nav-back svg { width: 10px; height: 10px; }

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.05em;
  border: none;
  background: none;
  transition: opacity 0.25s var(--ease);
  padding: 4px 0;
}
.nav-btn:hover { opacity: 0.7; }
/* 书架 add a book：标题块下的全宽虚线按钮——drop zone 的手机形态（音音 07-03 定位置/配色）。
   墨棕虚线不抢书的风头；桌面 >600px 藏按钮、显拖拽大框，同一个位置两种范式。 */
.nav-btn.btn-upload {
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 13px;
  margin: 16px 0 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: none;
  color: var(--ink3);
  font-size: 13px;
  letter-spacing: 0.08em;
}
.nav-btn.btn-upload:hover { opacity: 1; color: var(--accent); border-color: var(--accent); }
.nav-btn.btn-upload svg { width: 13px; height: 13px; }
@media (min-width: 601px) {
  .nav-btn.btn-upload { display: none; }
}
.nav-btn svg { width: 11px; height: 11px; }
.nav-btn.subtle { color: var(--ink3); }

.page-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 42px;
  color: var(--ink1);
  line-height: 1.1;
  margin-bottom: 4px;
}

.page-subtitle {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink3);
}
.page-subtitle .dash { color: var(--ink3); opacity: 0.5; }

.header-rule {
  height: 1px;
  background: var(--rule);
  margin-top: 16px;
}

/* ===== SHELF CARDS ===== */
.shelf-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 16px;
}

.book-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: background 0.25s var(--ease), border-color 0.25s var(--ease);
}
.book-card:hover { border-color: var(--border-strong); }
.book-card:active { background: var(--surface2); }

.book-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 6px;
}

.book-card-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  color: var(--ink1);
  line-height: 1.2;
  flex: 1;
  margin-right: 8px;
}

.book-card-chevron {
  color: var(--ink4);
  font-size: 9px;
  margin-top: 6px;
  flex-shrink: 0;
}

.book-card-meta {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  color: var(--ink3);
  margin-bottom: 10px;
  letter-spacing: 0.05em;
}

.book-card-bar {
  height: 4px;
  background: var(--surface3);
  border-radius: 2px;
  overflow: hidden;
}
.book-card-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.35s var(--ease);
}

/* file input 的隐藏姿势：iOS 对 display:none 的 <input type=file> 有历史怪癖——
   label 点击不弹 picker（渲染树里不存在就不唤起）。1px + opacity:0 保持"活着但看不见"。 */
.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

/* ===== UPLOAD ZONE ===== */
.upload-zone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 16px;
  transition: border-color 0.25s var(--ease), background 0.25s var(--ease);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
/* 手机上藏大 drop zone（桌面拖拽范式，窄屏纯占地）——右上角 Upload label 是唯一入口（音音 07-03） */
@media (max-width: 600px) {
  .upload-zone { display: none; }
}
.upload-glyph {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 300;
  color: var(--ink3);
  margin-bottom: 8px;
}
.upload-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink3);
}

/* ===== BOOK DETAIL ===== */
.detail-hero {
  padding: 0 0 20px;
}

.detail-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 32px;
  color: var(--ink1);
  line-height: 1.15;
  margin-bottom: 8px;
}

.detail-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 1px;
  color: var(--ink3);
}

/* detail 页第一动作，字号/高度都要压过下面的卡片（音音 07-04：主次别反） */
.continue-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 20px 22px;
  background: var(--ink1);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 16px;
  transition: opacity 0.25s var(--ease);
}
.continue-btn:hover { opacity: 0.85; }
.continue-btn svg { width: 17px; height: 17px; }

/* ===== PROGRESS CARD ===== */
.progress-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.progress-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.progress-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  color: var(--ink1);
}

.progress-pages {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 1.5px;
  color: var(--ink3);
  text-transform: uppercase;
}

.progress-row {
  margin-bottom: 12px;
}
.progress-row:last-child { margin-bottom: 0; }

.progress-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.progress-label {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink1);
}

.progress-pct {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 300;
}
.progress-pct.amber { color: var(--accent); }
.progress-pct.jade { color: var(--jade); }

.bar-gauge {
  height: 7px;
  background: var(--surface3);
  border-radius: 3.5px;
  overflow: hidden;
}
.bar-gauge-fill {
  height: 100%;
  border-radius: 2.5px;
  transition: width 0.35s var(--ease);
}
.bar-gauge-fill.amber { background: var(--accent); }
.bar-gauge-fill.jade { background: var(--jade); }

/* ===== ANNOTATIONS CARD (detail) ===== */
.annot-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

.annot-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px;
}

.annot-card-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  color: var(--ink1);
}

.annot-card-count {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 300;
  color: var(--ink3);
}

.annot-group {
  border-top: 0.5px solid var(--border);
}

.annot-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  color: var(--ink2);
}
.annot-group-toggle:hover { background: var(--accent-soft); }

.annot-group-pid {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 400;
  color: var(--ink3);
  letter-spacing: 0.5px;
}

.annot-group-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.annot-group-n {
  font-size: 11px;
  font-weight: 300;
  color: var(--ink3);
}

.annot-group-chevron {
  font-size: 8px;
  color: var(--ink3);
  transition: transform 0.35s var(--ease);
}
.annot-group-chevron.open { transform: rotate(180deg); }

.annot-group-body {
  padding: 0 16px 14px;
}

.annot-row {
  margin-bottom: 10px;
}
.annot-row:last-child { margin-bottom: 0; }

.annot-row-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.annot-row-author {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
}
.annot-row-author.yinyin { color: var(--jade); }
.annot-row-author.kieran { color: var(--accent); }

.annot-row-date {
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 300;
  color: var(--ink3);
}

.annot-row-highlight {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--ink2);
  line-height: 1.6;
  padding: 2px 6px;
  border-radius: 3px;
  display: inline;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  background: var(--hl-yinyin-strong);
}
.annot-row-highlight.hl-kieran { background: var(--hl-kieran-strong); }

.annot-row-note {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink1);
  line-height: 1.6;
}

/* ===== DELETE BOOK ===== */
.delete-book-btn {
  display: block;
  width: 100%;
  padding: 16px;
  margin-top: 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--vermillion);
  opacity: 0.5;
  transition: opacity 0.25s var(--ease);
  text-align: center;
}
.delete-book-btn:hover { opacity: 1; }

/* ===== READING VIEW ===== */
.reader-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: env(safe-area-inset-top, 0px) 20px 0;
  display: flex;
  align-items: center;
  min-height: 44px;
  transition: background 0.35s var(--ease);
}

.reader-topbar-title {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-style: italic;
  font-size: calc(var(--reader-font-size) + 2px);
  font-weight: 600;
  color: var(--ink1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 40px;
}

.reader-topbar-left,
.reader-topbar-right {
  flex-shrink: 0;
}

.reader-topbar .nav-back,
.reader-topbar .nav-btn {
  padding: 8px 0;
}

.page-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 1px;
  color: var(--ink3);
  padding: 14px 0 18px;
}
.page-label .s { color: var(--accent); }
.page-label .cur { color: var(--ink1); }

/* ===== PARAGRAPHS (v2: no tap-to-expand, text always selectable) ===== */
.paragraph {
  padding: 10px 20px;
  position: relative;
  transition: background 0.2s var(--ease);
  -webkit-user-select: text;
  user-select: text;
}

.paragraph.bookmarked {
  border-left: 2px solid var(--accent);
  padding-left: 18px;
}

.para-text {
  font-family: var(--font-display);
  font-size: var(--reader-font-size);
  line-height: 1.8;
  color: var(--ink2);
}

.para-id {
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 300;
  color: var(--ink4);
  display: block;
  margin-bottom: 2px;
  user-select: none;
  pointer-events: none;
  opacity: 0.6;
  letter-spacing: 0.05em;
}


/* ===== ANNOTATION COLOR BAR (left border) ===== */
.paragraph.has-yinyin {
  border-left: 2px solid var(--jade);
  padding-left: 18px;
}
.paragraph.has-kieran {
  border-left: 2px solid var(--accent);
  padding-left: 18px;
}
.paragraph.has-both {
  border-left: 2px solid;
  border-image: linear-gradient(to bottom, var(--jade) 50%, var(--accent) 50%) 1;
  padding-left: 18px;
}
/* bookmarked + annotation: annotation bar wins */
.paragraph.bookmarked.has-yinyin {
  border-left: 2px solid var(--jade);
}
.paragraph.bookmarked.has-kieran {
  border-left: 2px solid var(--accent);
}
.paragraph.bookmarked.has-both {
  border-left: 2px solid;
  border-image: linear-gradient(to bottom, var(--jade) 50%, var(--accent) 50%) 1;
}

/* ===== HIGHLIGHT MARKS ===== */
mark.hl {
  border-radius: 2px;
  padding: 1px 0;
  cursor: pointer;
  transition: background 0.15s var(--ease);
  position: relative;
}

mark.hl-yinyin {
  background: var(--hl-yinyin);
}
mark.hl-yinyin:hover {
  background: var(--hl-yinyin-strong);
}

mark.hl-kieran {
  background: var(--hl-kieran);
}
mark.hl-kieran:hover {
  background: var(--hl-kieran-strong);
}

mark.hl-both {
  background: linear-gradient(180deg, var(--hl-yinyin) 50%, var(--hl-kieran) 50%);
}
mark.hl-both:hover {
  background: linear-gradient(180deg, var(--hl-yinyin-strong) 50%, var(--hl-kieran-strong) 50%);
}

/* ===== SELECTION ACTION BAR =====
   固定屏幕底部滑出（音音 07-03 v2）：跟着选区飘的浮条跟 iOS 原生 edit 菜单
   抢地皮——上方撞（原生默认位）、下方也撞（选区靠上时原生翻下来）。
   底部固定条跟"跟着选区跳"的原生菜单彻底解耦，且离拇指最近。 */
.sel-toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  background: var(--surface);
  border-top: 0.5px solid var(--border-strong);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.10);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 4px;
  opacity: 0;
  transform: translateY(100%);
  transition: opacity 0.2s var(--ease), transform 0.25s var(--ease);
  pointer-events: none;
}
.sel-toolbar.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.sel-toolbar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  min-height: 52px;
  border: none;
  background: none;
  border-radius: 2px;
  cursor: pointer;
  color: var(--ink2);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.sel-toolbar-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.sel-toolbar-btn svg {
  width: 16px;
  height: 16px;
}

.sel-toolbar-btn.hl-btn {
  width: auto;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 0.5px;
  gap: 5px;
}

/* ===== ANNOTATION PANEL (bottom sheet) ===== */
.annot-panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.25);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s var(--ease);
  pointer-events: none;
}
.annot-panel-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.annot-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 91;
  background: var(--surface);
  border-top: 0.5px solid var(--border);
  border-radius: 12px 12px 0 0;
  max-height: 70vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.35s var(--ease);
  padding: 0;
}
.annot-panel.open {
  transform: translateY(0);
}

.annot-panel-handle {
  width: 32px;
  height: 4px;
  background: var(--surface3);
  border-radius: 2px;
  margin: 10px auto 0;
}

.annot-panel-header {
  padding: 12px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.annot-panel-title {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink3);
}

.annot-panel-close {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink3);
  padding: 4px;
  transition: color 0.2s var(--ease);
}
.annot-panel-close:hover { color: var(--ink1); }
.annot-panel-close svg { width: 14px; height: 14px; }

.annot-panel-quote {
  padding: 0 20px 12px;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink2);
  border-bottom: 0.5px solid var(--border-soft);
  margin-bottom: 4px;
}

.annot-panel-quote::before {
  content: '\201C';
  color: var(--ink4);
  font-size: 20px;
  margin-right: 2px;
}

.annot-panel-list {
  padding: 8px 20px;
}

.annot-panel-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
}

.annot-panel-bar {
  width: 2px;
  min-height: 20px;
  border-radius: 1px;
  flex-shrink: 0;
  align-self: stretch;
}
.annot-panel-bar.jade { background: var(--jade); opacity: 0.6; }
.annot-panel-bar.amber { background: var(--accent); opacity: 0.6; }

.annot-panel-item-body {
  flex: 1;
  min-width: 0;
}

.annot-panel-item-author {
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.annot-panel-item-author.jade { color: var(--jade); }
.annot-panel-item-author.amber { color: var(--accent); }

.annot-panel-item-text {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink2);
  line-height: 1.6;
}

.annot-panel-item-hl {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--ink2);
  line-height: 1.6;
  padding: 2px 4px;
  border-radius: 3px;
  display: inline;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.annot-panel-item.hl-jade .annot-panel-item-hl { background: var(--hl-yinyin-strong); }
.annot-panel-item.hl-amber .annot-panel-item-hl { background: var(--hl-kieran-strong); }

.annot-panel-item-date {
  font-family: var(--font-mono);
  font-size: 7px;
  font-weight: 300;
  color: var(--ink4);
  margin-top: 2px;
}

.annot-panel-input-row {
  display: flex;
  gap: 4px;
  padding: 8px 20px 12px;
  border-top: 0.5px solid var(--border-soft);
  margin-top: 4px;
}

.annot-panel-input {
  flex: 1;
  border: 0.5px solid var(--border);
  border-radius: 2px;
  padding: 8px 10px;
  font-family: var(--font-display);
  font-size: 14px;
  background: var(--bg);
  color: var(--ink1);
  outline: none;
  transition: border-color 0.2s var(--ease);
}
.annot-panel-input:focus { border-color: var(--accent); }
.annot-panel-input::placeholder { color: var(--ink4); }

.annot-panel-send {
  border: 0.5px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink2);
  padding: 8px 14px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 0.5px;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
  white-space: nowrap;
}
.annot-panel-send:hover { background: var(--accent); color: var(--bg); }

.annot-panel-actions {
  padding: 0 20px 16px;
  display: flex;
  gap: 8px;
}

.annot-panel-action-btn {
  border: 0.5px solid var(--border);
  border-radius: 2px;
  background: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 0.5px;
  color: var(--ink3);
  padding: 6px 12px;
  transition: all 0.2s var(--ease);
}
.annot-panel-action-btn:hover { border-color: var(--border-strong); color: var(--ink2); }
.annot-panel-action-btn.danger { color: var(--vermillion); }
.annot-panel-action-btn.danger:hover { border-color: var(--vermillion); background: rgba(139,44,31,0.06); }


.annot-panel-item { position: relative; }
.annot-panel-item-del { position: absolute; top: 8px; right: 8px; background: none; border: none; color: var(--ink4); font-size: 16px; cursor: pointer; padding: 0 4px; line-height: 1; opacity: 0.5; transition: opacity 0.2s, color 0.2s; }
.annot-panel-item-del:hover { opacity: 1; color: var(--vermillion); }
.annot-panel-item-bell { position: absolute; top: 8px; right: 30px; background: none; border: none; color: var(--ink4); cursor: pointer; padding: 0 3px; line-height: 1; opacity: 0.5; transition: opacity 0.2s, color 0.2s; }
.annot-panel-item-bell svg { width: 13px; height: 13px; display: block; }
.annot-panel-item-bell:hover { opacity: 1; color: var(--accent); }
.annot-panel-item-bell.rung { opacity: 1; color: var(--accent); animation: bell-swing 0.5s ease; }
@keyframes bell-swing { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(14deg); } 55% { transform: rotate(-10deg); } 80% { transform: rotate(5deg); } }
.annot-panel-empty {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  color: var(--ink4);
  padding: 8px 0;
}

/* ===== PAGE NAV (bottom) ===== */
.page-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-top: 0.5px solid var(--border);
  margin-top: 20px;
}

.page-nav-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.5px;
  color: var(--ink2);
  padding: 8px 0;
  transition: color 0.2s var(--ease);
}
.page-nav-btn:hover { color: var(--accent); }
.page-nav-btn:disabled { color: var(--ink4); cursor: default; }
.page-nav-btn svg { width: 10px; height: 10px; }

.page-nav-center {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 1px;
  color: var(--ink3);
}

/* ===== PROGRESS BAR (reader) ===== */
.reader-progress {
  height: 3px;
  background: var(--surface3);
  margin: 0;
}
.reader-progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.35s var(--ease);
}

/* ===== ANNOTATIONS OVERVIEW ===== */
.overview-filter {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  flex-wrap: wrap;
}

.filter-chip {
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink3);
  padding: 4px 8px;
  border-radius: 2px;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.filter-chip:hover { background: var(--accent-soft); }
.filter-chip.active {
  background: var(--ink1);
  color: var(--bg);
}

.overview-item {
  border-bottom: 0.5px solid var(--border);
  padding: 12px 0;
}

.overview-para {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--ink3);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

.overview-annot {
  padding: 4px 0 4px 10px;
  border-left: 2px solid transparent;
}
.overview-annot.user { border-left-color: var(--jade); }
.overview-annot.kieran { border-left-color: var(--accent); }

.overview-annot-author {
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.overview-annot-text {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink2);
  line-height: 1.5;
}

/* ===== VOCAB PAGE ===== */
.vocab-entry {
  border-bottom: 0.5px solid var(--border);
  padding: 12px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.vocab-entry-body { flex: 1; min-width: 0; }

.vocab-word {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  color: var(--ink1);
  margin-bottom: 2px;
}

.vocab-note {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink3);
}

.vocab-source {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  color: var(--ink4);
  cursor: pointer;
  margin-top: 2px;
}
.vocab-source:hover { color: var(--accent); }

.vocab-edit {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink4);
  font-size: 9px;
  padding: 4px;
  transition: color 0.2s var(--ease);
  flex-shrink: 0;
}
.vocab-edit:hover { color: var(--accent); }
.vocab-edit svg { width: 14px; height: 14px; }

.vocab-delete {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink4);
  font-size: 9px;
  padding: 4px;
  transition: color 0.2s var(--ease);
  flex-shrink: 0;
}
.vocab-delete:hover { color: var(--vermillion); }

.vocab-underline {
  text-decoration: underline;
  text-decoration-style: solid;
  text-decoration-color: rgba(139, 44, 31, 0.85);
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.night-mode .vocab-underline {
  text-decoration-color: rgba(176, 74, 58, 0.85);
  text-decoration-thickness: 2px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 16px;
}

.empty-glyph {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 300;
  color: var(--ink3);
  margin-bottom: 12px;
}

.empty-text {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 1.5px;
  color: var(--ink3);
  text-transform: uppercase;
}

/* ===== LOADING ===== */
.loading {
  text-align: center;
  padding: 48px 16px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink3);
}

/* ===== DIALOG OVERLAY ===== */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.dialog-box {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  width: 320px;
  max-width: 90vw;
  padding: 20px;
}

.dialog-text {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--ink1);
  margin-bottom: 16px;
  line-height: 1.5;
}

.dialog-input {
  width: 100%;
  border: 0.5px solid var(--border);
  border-radius: 2px;
  padding: 8px 10px;
  font-family: var(--font-display);
  font-size: 15px;
  background: var(--bg);
  color: var(--ink1);
  margin-bottom: 16px;
  outline: none;
}
.dialog-input:focus { border-color: var(--accent); }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-btn {
  border: 0.5px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink2);
  padding: 6px 16px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 1px;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.dialog-btn:hover { background: var(--surface2); }
.dialog-btn.primary {
  background: var(--ink1);
  color: var(--bg);
  border-color: var(--ink1);
}
.dialog-btn.primary:hover { opacity: 0.85; }
.dialog-btn.danger {
  background: var(--vermillion);
  color: var(--bg);
  border-color: var(--vermillion);
}
.dialog-btn.danger:hover { opacity: 0.85; }

/* ===== READER BOTTOM TOOLBAR ===== */
.reader-bottombar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: rgba(252,250,245,0.85);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 0.5px solid var(--border-soft);
  padding: 0 0 env(safe-area-inset-bottom, 0);
  transition: background 0.35s var(--ease);
}
.night-mode .reader-bottombar {
  background: rgba(38,34,32,0.85);
}

.reader-bottombar-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 20px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.5px;
  color: var(--ink4);
}


.page-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--surface3);
  border-radius: 2px;
  outline: none;
  margin: 6px 0 2px;
}
.page-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.page-slider-label {
  display: block;
  text-align: center;
  margin-bottom: 2px;
}


.search-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  z-index: 90;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  display: none;
}
.search-panel.visible { display: block; }
.search-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-panel-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--ink1);
  outline: none;
}
.search-panel-input:focus { border-color: var(--accent); }
.search-panel-input::placeholder { color: var(--ink4); }
.search-panel-close {
  background: none;
  border: none;
  color: var(--ink3);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  font-family: var(--font-mono);
}
.search-panel-info {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--ink4);
  padding: 4px 0 0;
}
.search-results {
  max-height: 60vh;
  overflow-y: auto;
  margin-top: 8px;
}
.search-result-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.15s;
}
.search-result-item:hover { background: var(--accent-soft); }
.search-result-pid {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--ink4);
  margin-bottom: 2px;
}
.search-result-text {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink2);
  line-height: 1.5;
}
.search-result-text mark {
  background: var(--hl-yinyin-strong);
  color: var(--ink1);
  border-radius: 2px;
  padding: 0 1px;
}

.toc-panel {
  position: fixed;
  bottom: 80px;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  z-index: 80;
  transform: translateY(100%);
  transition: transform 0.3s var(--ease);
  padding: env(safe-area-inset-bottom, 0);
}
.toc-panel.visible { transform: translateY(0); }
.toc-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 10px;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.toc-panel-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 18px;
  color: var(--ink1);
}
.toc-panel-close {
  background: none;
  border: none;
  color: var(--ink3);
  font-size: 18px;
  cursor: pointer;
}
.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 20px;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--ink2);
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border-soft);
}
.toc-item:hover { background: var(--accent-soft); }
.toc-item.active { color: var(--accent); font-weight: 500; }
.toc-item.level-1 { padding-left: 36px; font-size: 14px; color: var(--ink3); }
.toc-item.level-2 { padding-left: 52px; font-size: 13px; color: var(--ink3); }
.toc-empty {
  padding: 30px 20px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink4);
}
.reader-bottombar-icons {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 6px 20px 10px;
  max-width: 360px;
  margin: 0 auto;
}

.bottombar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink3);
  padding: 6px 12px;
  transition: color 0.2s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.bottombar-btn:hover,
.bottombar-btn:active { color: var(--accent); }
.bottombar-btn.active { color: var(--accent); }
.bottombar-btn svg { width: 20px; height: 20px; }
.bottombar-btn-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.5px;
}

/* ===== FONT SIZE PANEL ===== */
.fontsize-panel {
  position: fixed;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  z-index: 41;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  padding: 14px 20px;
  width: 260px;
  max-width: 90vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.fontsize-panel.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.fontsize-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.fontsize-panel-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink3);
}

.fontsize-panel-value {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
  color: var(--ink2);
}

.fontsize-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--surface3);
  border-radius: 2px;
  outline: none;
}
.fontsize-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}
.fontsize-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.fontsize-panel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.fontsize-panel-row .small-a {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--ink4);
}
.fontsize-panel-row .large-a {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--ink4);
}
.fontsize-panel-row .night-label {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 300;
  color: var(--ink3);
  margin-left: auto;
  cursor: pointer;
}
.fontsize-panel-row .night-label:hover { color: var(--accent); }

/* ===== BOOKMARK RIBBON ===== */
.bookmark-ribbon {
  position: fixed;
  top: calc(44px + env(safe-area-inset-top, 0px));
  right: 0;
  z-index: 15;
  width: 24px;
  height: 36px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.bookmark-ribbon.visible {
  opacity: 1;
  transform: translateY(0);
}
.bookmark-ribbon svg {
  width: 24px;
  height: 36px;
}

/* ===== SELECTION TOOLBAR SEPARATOR ===== */
.sel-toolbar-btn-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.5px;
}

.sel-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  align-self: center;
  margin: 0 2px;
}

/* ===== NIGHT TOGGLE ===== */
.night-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 50;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0.5px solid var(--border);
  background: var(--surface);
  color: var(--ink3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.25s var(--ease), border-color 0.25s var(--ease), opacity 0.25s var(--ease);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.night-toggle:hover { border-color: var(--accent); }
.night-toggle.hidden-in-reader {
  opacity: 0;
  pointer-events: none;
}

/* ===== CONTEXT MENU ===== */
.ctx-menu {
  position: absolute;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 50;
  min-width: 140px;
  padding: 4px 0;
}

.ctx-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 300;
  color: var(--ink2);
  text-align: left;
  transition: background 0.15s var(--ease);
}
.ctx-item:hover { background: var(--accent-soft); }
.ctx-item.danger { color: var(--vermillion); }

/* ===== MOBILE ===== */
@media (max-width: 480px) {
  .folio { padding: 0 16px 80px; }
  .folio.reader-folio { padding-bottom: 100px; }
  .page-title { font-size: 34px; }
  .detail-title { font-size: 26px; }
  .paragraph { padding: 8px 16px; }
  .annot-panel { max-height: 80vh; }
  .fontsize-panel { bottom: 72px; }
}

/* Reader-specific folio padding */
.folio.reader-folio {
  padding-bottom: 100px;
}

/* ===== TRANSITIONS ===== */
.fade-in {
  animation: fadeIn 0.35s var(--ease);
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== SELECTION STYLING ===== */
::selection {
  background: rgba(168,90,26,0.20);
}
.night-mode ::selection {
  background: rgba(200,134,74,0.25);
}

/* ===== FIDELITY MODE (PDF 原版) ===== */
/* 三层：canvas 位图(z0) → 高亮 overlay(z1，不吃指针) → TextLayer(z2，透明可选中)。
   overlay 点击走 JS hit-test，不靠 DOM 事件。 */
.fid-folio { max-width: none; }
/* 放大后横向在 stage 里滚（body 仍锁横滑，同宽表格模式）。
   不用 flex 居中——flex center + overflow 会裁掉左缘不可达（经典坑），
   block + wrap margin auto：zoom=1 正好占满、放大后从左滚起。
   touch-action pan-x pan-y：允许单指拖动，两指捏合归 JS（fidInitPinch）。 */
.pdf-stage {
  position: relative;
  width: 100%;
  min-height: 200px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}
.pdf-page-wrap {
  position: relative;
  margin: 0 auto;
  box-shadow: 0 1px 6px rgba(43,36,26,0.12), 0 6px 24px rgba(43,36,26,0.08);
  background: #fff;
}

/* 缩放浮钮：右缘竖排，避开底栏和划线操作条；跟手势两条路并存（腱鞘炎友好） */
.fid-zoom {
  position: fixed;
  right: 10px;
  bottom: calc(170px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(43,36,26,0.14);
  overflow: hidden;
  opacity: 0.92;
}
.fid-zoom-btn {
  width: 44px;
  height: 40px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--ink2);
  font-family: var(--font-mono);
}
.fid-zoom-btn:active { background: var(--surface2); }
.fid-zoom-label {
  width: 44px;
  padding: 6px 0;
  border: none;
  border-top: 0.5px solid var(--border-soft);
  border-bottom: 0.5px solid var(--border-soft);
  background: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink3);
}
.pdf-page-wrap canvas {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 0;
}
.night-mode .pdf-page-wrap { background: #1a1712; }
.night-mode .pdf-page-wrap canvas {
  filter: invert(0.88) hue-rotate(180deg) contrast(0.92);
}

/* 高亮 overlay：双色沿用 reflow 的 token；night mode 不 invert（token 自带夜色值） */
.fid-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.fid-hl {
  position: absolute;
  border-radius: 1px;
}
.fid-hl.yinyin { background: var(--hl-yinyin-strong); }
.fid-hl.kieran { background: var(--hl-kieran-strong); }
.fid-hl.underline {
  background: transparent;
  border-bottom: 1.5px dashed var(--accent);
  opacity: 0.75;
}
.fid-hl.underline.yinyin { border-bottom-color: var(--jade); }

/* TextLayer（照抄 pdf.js v6 官方 pdf_viewer.css 的定位/缩放公式——
   span 字号 = --font-height × --total-scale-factor，少一条选区坐标就会膨胀） */
.textLayer {
  color-scheme: only light;
  position: absolute;
  text-align: initial;
  inset: 0;
  overflow: clip;
  opacity: 1;
  line-height: 1;
  letter-spacing: normal;
  word-spacing: normal;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: CanvasText;
  z-index: 2;
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
}
.textLayer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  -webkit-user-select: text;
  user-select: text;
}
.textLayer > :not(.markedContent),
.textLayer .markedContent span:not(.markedContent) {
  z-index: 1;
  --font-height: 0;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  --scale-x: 1;
  --rotate: 0deg;
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.textLayer .markedContent {
  display: contents;
}
.textLayer span[role="img"] {
  -webkit-user-select: none;
  user-select: none;
  cursor: default;
}
.textLayer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: 0;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
}
.textLayer.selecting .endOfContent {
  top: 0;
}
.textLayer ::selection {
  background: rgba(168,90,26,0.28);
  color: transparent;
}
.night-mode .textLayer ::selection {
  background: rgba(200,134,74,0.35);
  color: transparent;
}

.fid-loading {
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.fid-loading.visible { opacity: 1; }

/* 上传时的 reflow / fidelity 二选一 */
.mode-pick {
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.mode-pick:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.mode-pick-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink1);
}
.mode-pick-desc {
  font-size: 11px;
  color: var(--ink3);
  margin-top: 2px;
}
