/* ═══════════════════════════════════════
   READER.CSS - 阅读界面、选词 dock、进度条
   ═══════════════════════════════════════ */

/* 阅读器覆盖层 */
#reader-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 2000;
  display: none;
  flex-direction: column;
  padding-bottom: 0;
}

#reader-overlay.active {
  display: flex;
}

/* 顶部 Header - 48px */
#reader-header {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: relative;
  flex-shrink: 0;
}

/* 返回箭头 - 细 SVG */
#reader-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--ink);
  cursor: pointer;
  margin-left: -6px;
  flex-shrink: 0;
  transition: opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

#reader-back:hover {
  opacity: 0.6;
}

/* 书名 - 绝对居中，不受两侧按钮宽度影响 */
#reader-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 160px); /* 两侧各留 80px 给按钮 */
  font-family: var(--font-title);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

/* 右侧操作按钮组 */
#reader-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

.reader-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  font-size: 0.9rem;
  color: var(--ink-mid);
  cursor: pointer;
  border: none;
  background: none;
  transition: color 0.2s;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  border-radius: 6px;
}

.reader-action-btn:hover {
  color: var(--ink);
}

/* 进度条 - header 底部 1px */
#reader-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--rule);
}

#reader-progress-bar {
  height: 100%;
  background: var(--ink-faint);
  width: 0%;
  transition: width 0.3s ease;
}

/* 正文区 - 全部走 --read-* 变量 */
#reader-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--read-px);
  font-family: var(--font-body);
  font-size: var(--read-size);
  line-height: var(--read-line);
  letter-spacing: var(--read-tracking);
  background: var(--read-bg, var(--bg));
  color: var(--read-ink, var(--ink));
}

#reader-content p {
  margin-bottom: var(--read-para);
}

/* TXT 模式：首行缩进 2em */
#reader-content.txt-content p {
  text-indent: 2em;
}

/* 对话段落不缩进（以引号开头） */
#reader-content.txt-content p.dialogue {
  text-indent: 0;
}

/* 强制首行缩进模式（「字」面板开关控制） */
/* 覆盖 EPUB 原有样式，强制所有段落首行缩进 2em */
#reader-content.force-indent p {
  text-indent: 2em !important;
}
/* 标题、对话段落、blockquote 不缩进 */
#reader-content.force-indent h1,
#reader-content.force-indent h2,
#reader-content.force-indent h3,
#reader-content.force-indent h4,
#reader-content.force-indent blockquote,
#reader-content.force-indent li {
  text-indent: 0 !important;
}

/* 章节标题样式增强 */
#reader-content h1,
#reader-content h2,
#reader-content h3 {
  font-family: var(--font-title);
  font-weight: 600;
  text-indent: 0;
  break-after: avoid;
}

#reader-content h1 {
  font-size: 1.4em;
  margin-top: 2.5em;
  margin-bottom: 1em;
  text-align: center;
}

#reader-content h2 {
  font-size: 1.2em;
  margin-top: 2.2em;
  margin-bottom: 0.8em;
}

/* TXT 识别出的章节标题：居中、上方加分隔 */
#reader-content h2.chapter-title {
  text-align: center;
  padding-top: 1.5em;
  border-top: 1px solid var(--rule);
  margin-top: 2.5em;
}

#reader-content h3 {
  font-size: 1.08em;
  margin-top: 1.8em;
  margin-bottom: 0.6em;
}

/* EPUB 章节分隔线 */
#reader-content hr.chapter-break {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2.5em 0;
}

/* 排版避断：标题/段首不出现在页底 */
#reader-content h1,
#reader-content h2,
#reader-content h3 {
  break-after: avoid;
  page-break-after: avoid;
}

#reader-content p {
  orphans: 2;
  widows: 2;
}

/* EPUB 保留的强调样式 */
#reader-content em,
#reader-content i {
  font-style: italic;
}

#reader-content strong,
#reader-content b {
  font-weight: 600;
}

#reader-content blockquote {
  margin: 1em 0;
  padding-left: 1em;
  border-left: 2px solid var(--rule);
  color: var(--ink-mid);
}

/* 选词高亮 - 底线风格 */
.text-selected {
  background: transparent;
  border-bottom: 1.5px solid var(--ink-faint);
  cursor: pointer;
}

/* ─── 选词 Dock ─── */
/* 48px，border-top，纯文字无背景 */
#selection-dock {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: var(--bg);
  border-top: 1px solid var(--rule);
  display: none;
  align-items: center;
  justify-content: space-around;
  z-index: 2100;
  padding-bottom: env(safe-area-inset-bottom);
}

#selection-dock.active {
  display: flex;
  animation: dockIn 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes dockIn {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.dock-action {
  font-size: 0.78rem;
  font-weight: 300;
  color: var(--ink-mid);
  cursor: pointer;
  letter-spacing: 0.06em;
  border: none;
  background: none;
  font-family: var(--font-ui);
  transition: color 0.2s;
  padding: 0 12px;
  height: 100%;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  /* 防止点击按钮时浏览器清空选区 */
  user-select: none;
  -webkit-user-select: none;
}

.dock-action:hover {
  color: var(--ink);
}

/* ─── 标注按钮包裹层（用于定位二级菜单） ─── */
.dock-annot-wrap {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
}

/* 标注按钮激活态 */
.dock-action--annot.open {
  color: var(--ink);
}

/* ─── 标注二级菜单 ─── */
#annot-submenu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 2200;
  min-width: 128px;
  /* 防止菜单内点击丢失选区 */
  user-select: none;
  -webkit-user-select: none;
}

#annot-submenu.open {
  display: flex;
  animation: annotMenuIn 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes annotMenuIn {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* 色块行 */
.annot-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* 分隔线 */
.annot-divider {
  height: 1px;
  background: var(--rule);
  margin: 0 -2px;
}

/* 高亮色块（实心圆） */
.annot-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  background: var(--bg);
}

.annot-swatch:hover,
.annot-swatch:active {
  transform: scale(1.18);
  border-color: var(--ink-faint);
}

/* 淡灰 */
.annot-swatch--gray   { background: #d4d0c8 !important; }
/* 鹅黄 */
.annot-swatch--yellow { background: #f5e87a !important; }
/* 反色：ink 背景 + bg 文字（用渐变模拟双色圆）*/
.annot-swatch--invert {
  background: linear-gradient(135deg, var(--ink) 50%, var(--bg) 50%) !important;
  border: 2px solid var(--rule) !important;
}

/* 划线色块（空心圆 + 底部条带） */
.annot-swatch--line {
  position: relative;
  background: var(--bg) !important;
  border: 2px solid var(--rule);
  overflow: hidden;
}

.annot-swatch--line::after {
  content: '';
  position: absolute;
  bottom: 3px;
  left: 2px;
  right: 2px;
  height: 3px;
  border-radius: 2px;
  background: var(--line-color, #6b6960);
}

/* ─── 标注样式：高亮 ─── */
mark.annot-highlight {
  background: var(--annot-color, #d4d0c8);
  border-radius: 2px;
  padding: 0 1px;
  cursor: pointer;
  border-bottom: none;
  color: inherit;
}

/* 反色高亮 */
mark.annot-highlight.annot-invert {
  background: var(--ink);
  color: var(--bg);
  border-radius: 2px;
  padding: 0 1px;
  cursor: pointer;
}

/* ─── 标注样式：划线 ─── */
mark.annot-underline {
  background: transparent;
  border-bottom: 2px solid var(--annot-color, #6b6960);
  padding: 0;
  cursor: pointer;
}

/* ─── 标注上下文菜单 ─── */
#annot-ctx-menu {
  position: fixed;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.14);
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 2300;
  min-width: 148px;
  user-select: none;
  -webkit-user-select: none;
}

#annot-ctx-menu.open {
  display: flex;
  animation: annotMenuIn 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.annot-ctx-divider {
  height: 1px;
  background: var(--rule);
  margin: 0 -2px;
}

.annot-ctx-actions {
  display: flex;
  gap: 6px;
  justify-content: space-between;
}

.annot-ctx-btn {
  flex: 1;
  font-size: 0.75rem;
  font-weight: 300;
  color: var(--ink-mid);
  letter-spacing: 0.04em;
  font-family: var(--font-ui);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 5px 0;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.annot-ctx-btn:hover {
  color: var(--ink);
  background: var(--rule);
}

.annot-ctx-btn--del {
  color: #e55;
  border-color: rgba(238,85,85,0.3);
}

.annot-ctx-btn--del:hover {
  background: rgba(238,85,85,0.08);
  color: #c00;
}

/* 保留旧的 text-selected 兼容性 */
mark.text-selected {
  background: transparent;
  border-bottom: 1.5px solid var(--ink-faint);
  cursor: pointer;
}

/* ─── 底栏（常驻，目录 / 页码 / 字面板） ─── */
#reader-bottom-bar {
  height: calc(48px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--rule);
  flex-shrink: 0;
  z-index: 2050;
}

.bottom-bar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  font-size: 1rem;
  color: var(--ink-mid);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.bottom-bar-btn:hover {
  color: var(--ink);
}

/* 页码区（分页模式下显示，滚动模式下隐藏） */
#page-indicator-inner {
  display: none;
  align-items: center;
  gap: 12px;
}

#page-indicator-inner.active {
  display: flex;
}

/* ─── 目录面板（左侧拉出） ─── */
#toc-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 2190;
  display: none;
  opacity: 0;
  transition: opacity 0.25s;
}

#toc-backdrop.active {
  display: block;
  opacity: 1;
}

#toc-panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(80vw, 320px);
  background: var(--bg);
  z-index: 2200;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

#toc-panel.active {
  transform: translateX(0);
}

#toc-header {
  height: 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}

#toc-title {
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}

#toc-close {
  font-size: 0.75rem;
  font-weight: 300;
  color: var(--ink-faint);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: color 0.2s;
}

#toc-close:hover {
  color: var(--ink);
}

#toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.toc-item {
  padding: 12px 20px;
  font-size: 0.85rem;
  font-weight: 300;
  color: var(--ink-mid);
  cursor: pointer;
  border-bottom: 1px solid var(--rule);
  transition: color 0.2s;
  letter-spacing: 0.02em;
}

.toc-item:hover {
  color: var(--ink);
}

.toc-empty {
  padding: 40px 24px;
  font-size: 0.82rem;
  font-weight: 300;
  color: var(--ink-faint);
  text-align: center;
  line-height: 1.7;
  letter-spacing: 0.02em;
}

/* ─── 排版快捷面板（「字」触发，可滚动） ─── */
#typography-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2150;
  display: none;
}

#typography-backdrop.active {
  display: block;
}

#typography-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--rule);
  z-index: 2160;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

#typography-panel.active {
  transform: translateY(0);
}

#typography-handle {
  width: 32px;
  height: 3px;
  background: var(--ink-ghost);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

/* 可滚动内容区 */
#typography-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 24px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.typo-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0;
  margin-bottom: 6px;
}

.typo-label {
  font-size: 0.72rem;
  font-weight: 300;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
  width: 48px;
  flex-shrink: 0;
}

.typo-options {
  display: flex;
  gap: 0;
  flex: 1;
  align-items: center;
}

.typo-btn {
  flex: 1;
  font-size: 0.78rem;
  font-weight: 300;
  font-family: var(--font-ui);
  color: var(--ink-faint);
  background: none;
  border: none;
  padding: 6px 0;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: color 0.15s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.typo-btn.active {
  color: var(--ink);
  font-weight: 400;
}

/* 滑块行 */
.typo-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  padding-left: 48px;
}

/* 内嵌折叠滑块行（在 typo-group 内部，占满整行） */
.typo-inline-slider {
  display: none;
  flex-basis: 100%;
  padding-left: 48px;
  padding-top: 6px;
  padding-bottom: 2px;
  margin-bottom: 0;
}

.typo-inline-slider.expanded {
  display: flex;
}

/* 自定义按钮 */
.typo-custom-btn {
  flex: none !important;
  padding: 6px 10px !important;
  color: var(--ink-ghost) !important;
  font-size: 0.72rem !important;
}

.typo-custom-btn.active {
  color: var(--ink) !important;
  font-weight: 400 !important;
}

.typo-slider {
  flex: 1;
  height: 2px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--rule);
  outline: none;
  cursor: pointer;
}

.typo-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink);
  border: none;
}

.typo-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ink);
  border: none;
}

.typo-slider-val {
  font-size: 0.65rem;
  font-weight: 300;
  color: var(--ink-ghost);
  letter-spacing: 0.04em;
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* 分区标签 */
.typo-section-label {
  font-size: 0.55rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--ink-ghost);
  text-transform: uppercase;
  padding-top: 16px;
  padding-bottom: 8px;
  border-top: 1px solid var(--rule);
  margin-top: 12px;
}

/* 字体/配色 chip 行（「字」面板内） */
.typo-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0 4px;
}

.typo-font-chip {
  font-size: 0.72rem;
  font-weight: 300;
  font-family: var(--font-ui);
  color: var(--ink-faint);
  border: 1px solid var(--rule);
  padding: 3px 10px;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
}

.typo-font-chip.active {
  color: var(--ink);
  border-color: var(--ink-mid);
}

.typo-empty-tip {
  font-size: 0.68rem;
  font-weight: 200;
  color: var(--ink-ghost);
  letter-spacing: 0.03em;
}

/* 阅读配色 chip */
.typo-color-chip {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--rule);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, border-color 0.15s;
}

.typo-color-chip.active {
  border-color: var(--ink);
  transform: scale(1.15);
}

/* ─── 本书大脑面板（记忆按钮触发，底部上滑） ─── */
#memory-panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2150;
  display: none;
}

#memory-panel-backdrop.active {
  display: block;
}

#memory-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--rule);
  z-index: 2160;
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

#memory-panel.active {
  transform: translateY(0);
}

#memory-handle {
  width: 32px;
  height: 3px;
  background: var(--ink-ghost);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

#memory-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 24px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.memory-section-label {
  font-size: 0.55rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--ink-ghost);
  text-transform: uppercase;
  padding-bottom: 8px;
}

#memory-context {
  width: 100%;
  box-sizing: border-box;
  min-height: 80px;
  max-height: 160px;
  resize: vertical;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 300;
  line-height: 1.6;
  padding: 10px 12px;
  outline: none;
  letter-spacing: 0.02em;
  transition: border-color 0.2s;
}

#memory-context:focus {
  border-color: var(--ink-faint);
}

.memory-action-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px 0;
  font-size: 0.78rem;
  font-weight: 300;
  font-family: var(--font-ui);
  color: var(--ink-mid);
  background: none;
  border: 1px solid var(--rule);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: color 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.memory-action-btn:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
}

.memory-action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 记忆卡片 */
.memory-card {
  position: relative;
  border: 1px solid var(--rule);
  padding: 10px 32px 10px 12px;
  margin-bottom: 8px;
  font-size: 0.82rem;
  font-weight: 300;
  color: var(--ink);
  line-height: 1.6;
  letter-spacing: 0.02em;
  min-height: 24px;
}

.memory-card:focus {
  outline: none;
  border-color: var(--ink-faint);
}

.memory-card-del {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.7rem;
  font-weight: 300;
  color: var(--ink-ghost);
  cursor: pointer;
  transition: color 0.2s;
  padding: 2px 4px;
  -webkit-tap-highlight-color: transparent;
}

.memory-card-del:hover {
  color: var(--ink);
}

/* ═══════════════════════════════════════
   分页模式
   ═══════════════════════════════════════ */

/* 分页容器：保留 padding 作为视觉边距，overflow hidden 裁切列滑动 */
#reader-content.paginated {
  overflow: hidden;
  position: relative;
}

/* 内层多栏容器 */
#reader-content.paginated .page-columns {
  column-fill: auto;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
  box-sizing: border-box;
  /* column-width, column-gap, height, padding 由 JS recalcPages() 动态设置 */
}

/* 双页模式下的间隔线（通过 column-rule 实现） */
#reader-content.paginated.dual-page .page-columns {
  column-rule: 1px solid var(--rule);
}

/* ── 分页模式：正文两端对齐 ── */
/* 仅对段落文字生效，标题保持居中/左对齐 */
#reader-content.paginated .page-columns p {
  text-align: justify;
  text-align-last: left;       /* 最后一行左对齐，避免孤行撑满 */
  word-break: break-word;      /* 超长单词允许断行 */
  overflow-wrap: break-word;
  hyphens: auto;               /* 自动连字符断词（中文无效，英文有效） */
}

/* ── 分页模式：EPUB 章节分隔线处强制换页 ── */
/* parser.js 在每个 spine 章节文件之间插入 <hr class="chapter-break">，
   分页模式下在此处强制换列（换页），实现章节级分页。
   hr 本身隐藏，不占用新页空间。 */
#reader-content.paginated .page-columns hr.chapter-break {
  break-after: column;
  -webkit-column-break-after: always; /* Safari 兼容 */
  visibility: hidden;   /* 隐藏分割线本身，仅保留换页语义 */
  margin: 0;
  height: 0;
  border: none;
}

/* ── 分页模式：标题不在列末孤立 ── */
#reader-content.paginated .page-columns h1,
#reader-content.paginated .page-columns h2,
#reader-content.paginated .page-columns h3 {
  break-after: avoid;
  -webkit-column-break-after: avoid;
}

.page-nav-btn {
  font-size: 0.75rem;
  font-weight: 300;
  color: var(--ink-faint);
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font-ui);
  padding: 4px 8px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.page-nav-btn:hover {
  color: var(--ink);
}

.page-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

#page-num {
  font-size: 0.72rem;
  font-weight: 300;
  color: var(--ink-mid);
  letter-spacing: 0.06em;
  min-width: 60px;
  text-align: center;
}

/* 翻页触摸区域（#reader-content 是 flex 子项，bottom:0 即内容区底部） */
.page-tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 2040;
  cursor: pointer;
}

.page-tap-left {
  left: 0;
  width: 30%;
}

.page-tap-right {
  right: 0;
  width: 30%;
}

/* ═══ PDF Canvas 分页模式 ═══ */

/* PDF 模式下的正文容器：垂直滚动，页面上下排列 */
#reader-content.pdf-content {
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #e8e5de;
  /* 覆盖文本排版变量，PDF 不需要 */
  font-size: initial;
  line-height: initial;
  letter-spacing: initial;
}

[data-theme="dark"] #reader-content.pdf-content {
  background: #1a1918;
}

/* 每页容器 */
.pdf-page {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 8px 0;
}

.pdf-page:first-child {
  padding-top: 0;
}

/* img + text layer 的共同包装层，position:relative 确保 text layer 相对于 img 定位 */
.pdf-page-inner {
  position: relative;
  display: inline-block; /* 宽度收缩到 img 实际宽度，而非撑满父容器 */
  line-height: 0; /* 消除 img 底部的 inline 间隙 */
}

/* 页面图片：自适应宽度，保持原始比例 */
.pdf-page img {
  width: 100%;
  max-width: 800px;
  height: auto;
  display: block;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  background: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

[data-theme="dark"] .pdf-page img {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* PDF 反色模式（暗色阅读） */
#reader-content.pdf-inverted .pdf-page img {
  filter: invert(1) hue-rotate(180deg);
}

/* PDF text layer — 透明但可选中（支持划词） */
.pdf-text-layer {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  line-height: 1;
  color: transparent;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
  pointer-events: auto;
}

.pdf-text-layer span {
  position: absolute;
  white-space: pre;
  transform-origin: 0% 0%;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

/* 选中高亮 */
.pdf-text-layer ::selection {
  background: rgba(211, 84, 0, 0.3);
}

/* PDF 分页模式：隐藏滚动，单页居中 */
#reader-content.pdf-paginated {
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#reader-content.pdf-paginated .pdf-page {
  padding: 0;
  width: 100%;
  height: 100%;
  align-items: center;
}

/* 分页模式下 pdf-page-inner 保持 inline-block，由父级 flex 居中 */
#reader-content.pdf-paginated .pdf-page-inner {
  display: inline-block;
}

#reader-content.pdf-paginated .pdf-page img {
  max-height: 100%;
  object-fit: contain;
}

/* PDF 双页并列模式 */
#reader-content.pdf-paginated.pdf-dual-page {
  flex-direction: row;
  gap: 2px;
}

#reader-content.pdf-paginated.pdf-dual-page .pdf-page {
  width: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#reader-content.pdf-paginated.pdf-dual-page .pdf-page img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ─── EPUB 插图 ─── */
#reader-content.epub-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.8em auto;
}

/* 行内数学公式图片（hangz-illustrations 类）：保持行内，限制高度 */
#reader-content.epub-content img.hangz-illustrations {
  display: inline-block;
  height: 1.4em;          /* 与正文行高匹配 */
  width: auto;
  max-width: none;
  vertical-align: middle;
  margin: 0 0.1em;
}

/* 分页模式：限制普通插图高度，避免单张图片撑满整页 */
#reader-content.epub-content.paginated img:not(.hangz-illustrations) {
  max-height: 60vh;
  object-fit: contain;
}

/* ─── EPUB 文内锚点链接 ─── */
#reader-content a[data-anchor] {
  color: var(--ink-faint);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, opacity 0.15s;
}

#reader-content a[data-anchor]:hover,
#reader-content a[data-anchor]:active {
  color: var(--ink);
  opacity: 0.7;
}

/* ─── 阅读器笔记面板（右侧拉出） ─── */
#reader-notes-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 2190;
  display: none;
  opacity: 0;
  transition: opacity 0.25s;
}

#reader-notes-backdrop.active {
  display: block;
  opacity: 1;
}

#reader-notes-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(82vw, 340px);
  background: var(--bg);
  z-index: 2200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

#reader-notes-panel.active {
  transform: translateX(0);
}

#reader-notes-header {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}

#reader-notes-title {
  flex: 1;
  font-family: var(--font-title);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-notes-new-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--ink-mid);
  background: var(--rule);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 0.02em;
}

.reader-notes-new-btn:hover {
  background: var(--ink-faint);
  color: var(--ink);
}

#reader-notes-close {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 300;
  color: var(--ink-faint);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: color 0.2s;
  white-space: nowrap;
}

#reader-notes-close:hover {
  color: var(--ink);
}

#reader-notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.reader-notes-loading,
.reader-notes-empty {
  padding: 32px 20px;
  font-size: 0.8rem;
  font-weight: 300;
  color: var(--ink-faint);
  text-align: center;
  line-height: 1.8;
}

/* 笔记面板内的笔记卡片继承 notes.css 的 .note-item 样式，
   此处仅覆盖面板内需要调整的部分 */
#reader-notes-list .note-item {
  margin: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--rule);
  border-left: none;
  border-right: none;
  border-top: none;
}

#reader-notes-list .note-item:last-child {
  border-bottom: none;
}
