/* audiobook-shell.css — 播放器书皮样式（页面布局/设计令牌/组件外观）。
 * 由 novel1/audiobook/index.html 的内联 <style> 抽出：三本书镜像共用同一份
 * （交叉缓存只下载一次）；改书皮观感改这里，勿再内联回页面。
 * 书特定只读变量见下方 :root / [data-theme] 设计令牌区。 */

:root {
  color-scheme: light;
  --bg: #f7f1e8;
  --surface: #fffaf4;
  --surface-light: #efe4d5;
  --text: #2f2923;
  --text-dim: #6f6255;
  --accent: #b66b3f;
  --accent-deep: #8f4f2c;
  --accent-glow: rgba(182,107,63,0.12);
  --highlight: rgba(182,107,63,0.10);
  --gold: #c7954f;
  --border: #e5d8c9;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #211b18;
  --surface: #312721;
  --surface-light: #30241e;
  --text: #f3e9dd;
  --text-dim: #b4a294;
  --accent: #dc9968;
  --accent-deep: #f0b184;
  --accent-glow: rgba(220,153,104,0.16);
  --highlight: rgba(220,153,104,0.12);
  --gold: #d8ad68;
  --border: #55443a;
}
* { margin:0; padding:0; box-sizing:border-box; }
html { scroll-behavior: smooth; }
body {
  background:
    radial-gradient(circle at 10% 0%, rgba(199,149,79,.15), transparent 34rem),
    radial-gradient(circle at 100% 20%, rgba(182,107,63,.11), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: "Noto Serif SC","Source Han Serif SC","Songti SC","SimSun",serif;
  /* 定高 + 隐藏溢出：构成 app-shell 布局，正文在 .reader 内部滚动、播放栏常驻底部 */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
  -webkit-tap-highlight-color: transparent;
  contain: layout style;
}
header {
  text-align: center;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  max-width: 100%;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 14px;
  display: grid; place-items: center;
  color: #fff8ef; background: linear-gradient(145deg, var(--accent), var(--gold));
  box-shadow: 0 8px 18px rgba(182,107,63,.24);
  font-family: "Noto Serif SC","Source Han Serif SC",serif; font-size: 19px;
  transition: transform .25s cubic-bezier(.22,.61,.36,1);
}
.brand:hover .brand-mark { transform: scale(1.06) rotate(-3deg); }
.brand-body { display: flex; flex-direction: column; line-height: 1.1; text-align: left; min-width: 0; }
.brand-title { font-size: 1.5rem; font-weight: 400; letter-spacing: 0.4em; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 0.7rem; color: var(--text-dim); letter-spacing: 0.18em; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-btns {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 8px;
}
.icon-btn {
  background: var(--surface-light);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  touch-action: manipulation;
}
.icon-btn:hover { background: var(--accent-glow); border-color: var(--accent); }
.menu-btn {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
}

/* 侧边目录 */
.sidebar {
  position: fixed;
  left: -320px;
  top: 0;
  width: 300px;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: left 0.3s ease;
  z-index: 200;
  padding: 20px 0;
  contain: layout style;
}
.sidebar.open { left: 0; }
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  display: none;
}
.sidebar-overlay.show { display: block; }
.sidebar h3 {
  font-size: 0.9rem;
  color: var(--accent);
  letter-spacing: 0.2em;
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.sidebar a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 18px 9px 16px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  /* 不做 padding-left 位移过渡：目录整列重排的布局抖动代价高于 3px 位移的观感收益，
     hover 反馈由背景色 + 左侧 ::before 指示条承担 */
  transition: background 0.22s ease, color 0.22s ease, border-left-color 0.22s ease;
  border-left: 3px solid transparent;
  border-radius: 0 14px 14px 0;
  margin: 1px 0;
  position: relative;
  animation: ab-toc-in 0.5s ease both;
}
.sidebar a::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  transform: scaleY(0);
  transform-origin: center;
  transition: transform 0.25s cubic-bezier(0.22, 0.61, 0.36, 1);
  pointer-events: none;
}
.sidebar a:hover {
  color: var(--text);
  background: var(--accent-glow);
}
.sidebar a:hover::before {
  transform: scaleY(0.65);
}
.sidebar a.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-left-color: var(--accent);
  font-weight: 600;
}
.sidebar a.active::before {
  transform: scaleY(1);
  box-shadow: 0 0 12px var(--accent);
}
.sidebar a .ch-dur {
  font-size: 0.7rem;
  color: var(--text-dim);
  opacity: 0.65;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  transition: opacity 0.22s ease, color 0.22s ease;
}
.sidebar a:hover .ch-dur {
  opacity: 1;
  color: var(--accent);
}
@keyframes ab-toc-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* 主内容区 */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.reader {
  flex: 1;
  overflow-y: auto;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 40px;
  -webkit-overflow-scrolling: touch;
}
.chapter-title {
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--accent);
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.05em;
}
.chapter-content {
  font-size: 1.05rem;
  line-height: 2;
  letter-spacing: 0.02em;
}
.seg {
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
  padding: 1px 3px;
}
.seg:hover { background: var(--surface-light); color: var(--text); transform: translateY(-1px); }
.seg.active {
  background: var(--highlight);
  color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
  transition: background .15s ease, box-shadow .25s ease, color .15s ease;
}
.seg.flash {
  animation: ab-seg-flash .7s ease;
}
/* 首段章名旁白：大标题已展示，正文隐藏避免重复（仍可点击定位到 0:00） */
.seg.seg--dup { display: none; }
@keyframes ab-seg-flash {
  0%   { background: var(--accent); color: #fff; box-shadow: 0 0 0 4px var(--accent); transform: scale(1.04); }
  100% { background: var(--highlight); color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); transform: scale(1); }
}

/* 底部播放栏 */
.player-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.play-btn {
  background: var(--accent);
  border: none;
  color: var(--bg);
  width: 44px; height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  touch-action: manipulation;
}
.play-btn:hover { opacity: 0.85; }
.play-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.player-info {
  flex: 1;
  min-width: 0;
}
.player-title {
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.time-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: monospace;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
}
.progress-track {
  flex: 1;
  height: 6px;
  background: var(--surface-light);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  /* 不设 overflow:hidden：会裁掉悬停气泡（-22px）与 thumb 圆点 */
  transition: height .22s ease;
}
.progress-track:hover { height: 9px; }
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, transparent));
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s linear;
  position: relative;
}
.progress-track:hover .progress-fill { opacity: 0.95; }
.progress-tooltip {
  position: absolute;
  top: -22px;
  left: 0;
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.65rem;
  font-family: monospace;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.progress-tooltip.show { opacity: 1; }
.speed-btn, .font-size-btn {
  background: var(--surface-light);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  flex-shrink: 0;
  transition: all 0.2s;
  touch-action: manipulation;
}
.speed-btn:hover, .font-size-btn:hover { border-color: var(--accent); color: var(--accent); }
.font-size-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-glow); }

/* 导航按钮 */
.nav-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.nav-btn {
  background: var(--surface-light);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  touch-action: manipulation;
}
.nav-btn:hover { background: var(--accent-glow); border-color: var(--accent); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* 加载态 */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.loading .spinner {
  display: inline-block;
  width: 32px; height: 32px;
  border: 3px solid var(--surface-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 顶部进度条 */
.top-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  background: var(--accent);
  z-index: 300;
  transition: width .55s cubic-bezier(.22,.61,.36,1);
}

/* 章节搜索 */
.sidebar-search {
  padding: 12px 20px 8px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.sidebar-search input {
  width: 100%;
  background: var(--surface-light);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px 8px 32px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.sidebar-search input:focus { border-color: var(--accent); }
.sidebar-search::before {
  content: "⌕";
  position: absolute;
  left: 32px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 0.95rem;
  pointer-events: none;
}

/* 阅读字号变量 */
.reader { font-size: calc(1rem * var(--reading-size, 1)); }
.reader .chapter-content { font-size: calc(1.05rem * var(--reading-size, 1)); }

/* 主题图标动效 */
#themeBtn { transition: transform .35s cubic-bezier(.22,.61,.36,1); }
#themeBtn.spinning { transform: rotate(180deg); }

/* 入场动画 */
@keyframes ab-fade-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
header, .reader, .player-bar { animation: ab-fade-up .55s ease both; }
header { animation-delay: .05s; }
.reader { animation-delay: .15s; }
.player-bar { animation-delay: .25s; }

/* 章节标题：带渐显 + 下划线扫过 */
.chapter-title {
  position: relative;
  animation: ab-title-in .55s cubic-bezier(.22,.61,.36,1) both;
}
.chapter-title::after {
  content: "";
  position: absolute;
  left: 0; bottom: -1px;
  width: 0; height: 1px;
  background: linear-gradient(90deg, var(--accent), transparent);
  animation: ab-underline .9s .25s cubic-bezier(.22,.61,.36,1) forwards;
}
@keyframes ab-title-in {
  from { opacity: 0; transform: translateY(8px); letter-spacing: .12em; }
  to { opacity: 1; transform: translateY(0); letter-spacing: .05em; }
}
@keyframes ab-underline { to { width: 56px; } }

/* 侧边栏切换图标动效 */
.menu-btn { transition: transform .35s cubic-bezier(.22,.61,.36,1), background .22s ease, border-color .22s ease; }
.menu-btn:hover { transform: rotate(90deg) translateY(0); }

/* icon-btn：统一提升 */
.icon-btn { transition: background .22s ease, border-color .22s ease, color .22s ease, transform .22s cubic-bezier(.22,.61,.36,1); }
.icon-btn:active { transform: scale(.9); }

/* 主题按钮：日/月图标随 data-theme 切换（纯 CSS，无 JS 文本替换） */
#themeBtn .icon-sun { display: block; }
#themeBtn .icon-moon { display: none; }
[data-theme="dark"] #themeBtn .icon-sun { display: none; }
[data-theme="dark"] #themeBtn .icon-moon { display: block; }

/* 缓存按钮：下载/旋转图标随预取状态切换 */
.cache-icon .icon-dl { display: block; }
.cache-icon .icon-sync { display: none; }
.cache-icon.prefetching .icon-dl { display: none; }
.cache-icon.prefetching .icon-sync { display: block; animation: spin 1.2s linear infinite; }

/* 播放按钮：状态切换（去掉无限脉冲，保留按压缩放） */
.play-btn { position: relative; transition: transform .2s cubic-bezier(.22,.61,.36,1), background .2s ease, box-shadow .2s ease; }
.play-btn .icon-play, .play-btn .icon-pause {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  transition: opacity .22s ease, transform .28s cubic-bezier(.22,.61,.36,1);
}
.play-btn .icon-pause { opacity: 0; transform: translate(-50%,-50%) scale(.5); }
.play-btn.playing .icon-play { opacity: 0; transform: translate(-50%,-50%) scale(.5); }
.play-btn.playing .icon-pause { opacity: 1; transform: translate(-50%,-50%) scale(1); }
.play-btn:hover:not(:disabled) { transform: scale(1.05); box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 30%, transparent); }
.play-btn:active:not(:disabled) { transform: scale(.96); }

/* 播放按钮：音频加载/重试中的转圈状态 */
.play-btn.audio-loading .icon-play, .play-btn.audio-loading .icon-pause { opacity: 0; transform: translate(-50%,-50%) scale(.5); }
.play-btn.audio-loading::after {
  content: '';
  position: absolute; top: 50%; left: 50%;
  width: 18px; height: 18px; margin: -9px 0 0 -9px;
  border: 2px solid color-mix(in srgb, var(--bg) 40%, transparent);
  border-top-color: var(--bg);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .play-btn.audio-loading::after { animation-duration: 2.5s; }
}

/* speed-btn / font-size-btn：按下反馈 */
.speed-btn, .font-size-btn { transition: background .18s ease, border-color .18s ease, color .18s ease, transform .18s cubic-bezier(.22,.61,.36,1); }
.speed-btn:active, .font-size-btn:active { transform: scale(.92); }

/* nav-btn：章节翻页按钮 */
.nav-btn { transition: background .18s ease, border-color .18s ease, color .18s ease, transform .2s cubic-bezier(.22,.61,.36,1); }
.nav-btn:hover:not(:disabled) { transform: translateY(-1px); }
.nav-btn:active:not(:disabled) { transform: scale(.9); }
.nav-btn:disabled { opacity: .25; }

@media (max-width: 768px) {
  header { padding: 14px 16px 12px; }
  /* 四字长书名在窄屏收缩省略，不与左右两侧悬浮按钮重叠：
     预留左菜单(36+16) + 右按钮 3×36+2×8+16 + 间隙 */
  .brand { max-width: calc(100% - 224px); }
  .brand-title { font-size: 1.3rem; }
  .brand-mark { width: 34px; height: 34px; font-size: 17px; }
  .menu-btn { left: 12px; }
  .header-btns { right: 12px; }
  .reader { padding: 20px 16px 30px; }
  .chapter-title { font-size: 1.2rem; }
  .chapter-content { font-size: 0.95rem; line-height: 1.9; }
  .player-bar { padding: 8px 12px; gap: 8px; }
  .play-btn { width: 44px; height: 44px; font-size: 1rem; }
  .speed-btn, .font-size-btn { padding: 4px 8px; font-size: 0.72rem; }
  .nav-btn { width: 38px; height: 38px; font-size: 0.8rem; }
  .player-title { font-size: 0.75rem; }
  .sidebar { width: 85vw; max-width: 320px; left: -85vw; }
  .sidebar.open { left: 0; }
  .sidebar a { padding: 12px 20px; font-size: 0.9rem; }
  .sidebar h3 { font-size: 1rem; }
}
@media (max-width: 480px) {
  /* 预留左菜单(40+12) + 右按钮 3×40+2×8+12（含安装按钮）+ 间隙；字距收紧让四字标题尽量完整显示 */
  .brand { max-width: calc(100% - 208px); }
  .brand-title { font-size: 1.05rem; letter-spacing: 0.18em; }
  .brand-sub { font-size: 0.65rem; }
  .brand-mark { width: 32px; height: 32px; font-size: 16px; }
  .icon-btn { width: 34px; height: 34px; font-size: 0.9rem; }
  .reader { padding: 16px 14px 24px; }
  .chapter-content { font-size: 0.9rem; }
  /* 播放栏两行收束：行1 = 播放键 + 标题/进度（info flex:1 吃满自然换行），
     行2 = 全部控件居中；nav-btns 不再独占一行（原三行布局浪费纵向空间）。
     行距由下方触控目标断点的 row-gap: 2px 统一控制 */
  .player-bar { padding: 6px 10px; gap: 6px; flex-wrap: wrap; justify-content: center; }
  .player-bar .nav-btns { order: 10; }
  .player-bar .speed-btn, .player-bar .font-size-btn { font-size: 0.68rem; }
  .time-label { font-size: 0.65rem; min-width: 32px; }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
  .icon-btn:hover, .nav-btn:hover, .speed-btn:hover, .font-size-btn:hover {
    background: var(--surface-light); border-color: var(--border); color: var(--text);
  }
  .icon-btn:active, .nav-btn:active { transform: scale(0.92); }
  .sidebar a:hover { background: transparent; border-left-color: transparent; }
  .sidebar a:hover::before { transform: scaleY(0); }
  .sidebar a:active { background: var(--surface-light); }
  /* 触屏段落热区加高：inline 垂直 padding 不参与行盒计算，零回流；
     相邻段落点击区几乎相接，长文本手机上更好点中 */
  .seg { padding-top: 5px; padding-bottom: 5px; }

  /* 触屏禁用菜单按钮 90° 旋转 + 标题下划线扫过，节电 */
  .menu-btn:hover { transform: none; }
  .chapter-title::after { animation: none; width: 56px; }
  .progress-track:hover { height: 6px; }
}

/* 离线缓存浮动面板（持续自动缓存） */
.cache-panel {
  position: fixed; z-index: 25; right: 16px; bottom: 100px;
}
.cache-toggle {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-light);
  color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center; font-size: 18px; position: relative;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  transition: all .2s;
}
.cache-toggle:hover { border-color: var(--accent); color: var(--accent); }
.cache-toggle.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.cache-badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px;
  border-radius: 9px; background: var(--accent); color: var(--bg);
  font-size: 10px; font-weight: 700;
  display: grid; place-items: center; padding: 0 4px;
}
/* display:grid 会压过 hidden 属性的 UA 样式，必须显式关闭，否则徽标「0」常驻盖住正文 */
.cache-badge[hidden] { display: none; }
.cache-popup {
  display: none; position: absolute; right: 0; bottom: 52px;
  width: 280px; padding: 16px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--surface);
  box-shadow: 0 12px 40px rgba(0,0,0,0.28);
}
.cache-popup.open { display: block; }
.cache-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.cache-title { font-size: 14px; font-weight: 700; color: var(--accent); }
.cache-status { font-size: 11px; color: var(--text-dim); }
.cache-status.online { color: #2f7d4a; }
.cache-status.offline { color: var(--accent); }
.cache-progress-wrap { margin-bottom: 8px; }
.cache-progress { height: 6px; border-radius: 99px; background: var(--surface-light); overflow: hidden; }
.cache-progress > span {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: var(--accent); transition: width .3s;
}
.cache-count { display: block; margin-top: 5px; font-size: 11px; color: var(--text-dim); text-align: right; }
.cache-hint { margin: 0 0 12px; font-size: 11px; color: var(--text-dim); line-height: 1.5; }
.cache-actions { display: flex; gap: 8px; }
.cache-btn {
  flex: 1; padding: 8px 0; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-light); color: var(--text); cursor: pointer;
  font-size: 12px; font-family: inherit;
  transition: all .15s;
}
.cache-btn:hover { border-color: var(--accent); color: var(--accent); }
.cache-btn.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.cache-btn.primary:hover { opacity: 0.85; }
.cache-btn:disabled { opacity: .45; cursor: not-allowed; }
/* 移动端：避让底部播放器（两行布局后的栏高 + 间隙），移到导航条上方 */
@media (max-width: 480px) {
  .cache-panel { right: 12px; bottom: 112px; }
  .cache-toggle { width: 40px; height: 40px; }
  .cache-popup { width: calc(100vw - 24px); max-width: 320px; }
}

/* 安全区域适配（刘海屏/底部横条） */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  header { padding-top: calc(16px + env(safe-area-inset-top)); }
  .player-bar { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  /* 抽屉目录同样避开顶部刘海（独立于 header 的定位层） */
  .sidebar { padding-top: calc(20px + env(safe-area-inset-top)); }
}

/* 高对比度模式 */
@media (prefers-contrast: more) {
  .seg.active { box-shadow: 0 0 0 2px var(--accent); }
  .icon-btn, .nav-btn, .speed-btn, .font-size-btn { border-width: 2px; }
}

/* ===== 交互动效升级 ===== */
/* 章节内容入场（节点随章节切换重建，动画自动重放） */
.chapter-content { animation: ab-content-in .5s cubic-bezier(.22,.61,.36,1) both; }
@keyframes ab-content-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* 骨架屏加载（替代 spinner） */
.skeleton-wrap { padding: 4px 0; }
.skeleton { position: relative; overflow: hidden; background: var(--surface-light); border-radius: 10px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 9%, transparent), transparent);
  transform: translateX(-100%);
  animation: ab-sk 1.4s ease-in-out infinite;
}
@keyframes ab-sk { 60% { transform: translateX(100%); } 100% { transform: translateX(100%); } }
.sk-title { width: 44%; height: 26px; margin-bottom: 30px; }
.sk-line { height: 15px; margin-bottom: 20px; }

/* 侧栏遮罩淡入淡出 */
.sidebar-overlay { display: block; opacity: 0; visibility: hidden; transition: opacity .3s ease, visibility 0s linear .32s; }
.sidebar-overlay.show { opacity: 1; visibility: visible; transition: opacity .3s ease; }

/* 侧栏滑动缓动升级 */
.sidebar { transition: left .38s cubic-bezier(.22,.61,.36,1); }

/* 目录条目：打开侧栏时才播 stagger（配合 JS 逐项 delay） */
.sidebar a { animation: none; }
.sidebar.open a { animation: ab-toc-in .45s cubic-bezier(.22,.61,.36,1) both; }
/* 虚拟滚动项随滚动持续重建，入场动画会造成淡入闪烁，豁免 */
.sidebar .ab-virtual-content a { animation: none; }

/* 进度条拇指：悬停/拖拽时浮现 */
.progress-thumb {
  position: absolute; top: 50%; left: 0; z-index: 2;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); border: 2.5px solid var(--surface);
  box-shadow: 0 1px 5px rgba(0,0,0,.35);
  transform: translate(-50%,-50%) scale(0);
  transition: transform .18s cubic-bezier(.22,.61,.36,1);
  pointer-events: none;
}
.progress-track:hover .progress-thumb,
.progress-track.is-dragging .progress-thumb { transform: translate(-50%,-50%) scale(1); }

/* 播放键状态切换弹跳 */
.play-btn.is-pop { animation: ab-pop .3s cubic-bezier(.22,.61,.36,1); }
@keyframes ab-pop { 0% { transform: scale(.84); } 60% { transform: scale(1.07); } 100% { transform: scale(1); } }

/* 缓存弹层：弹入 */
.cache-popup {
  display: block; opacity: 0; visibility: hidden;
  transform: translateY(10px) scale(.97); transform-origin: bottom right;
  transition: opacity .24s ease, transform .3s cubic-bezier(.22,.61,.36,1), visibility 0s linear .3s;
}
.cache-popup.open { opacity: 1; visibility: visible; transform: none; transition: opacity .24s ease, transform .3s cubic-bezier(.22,.61,.36,1); }

/* 减少动态偏好：新增动画直出 */
@media (prefers-reduced-motion: reduce) {
  .chapter-content, .sidebar.open a, .skeleton::after { animation: none !important; }
  .play-btn .icon-play, .play-btn .icon-pause { transition: none !important; }
}

/* 宽屏常驻目录：≥1024px 时目录固定在左侧（吸收 nanian 版经验），不再用抽屉 */
@media (min-width: 1024px) {
  body {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
  }
  header { grid-column: 1 / -1; grid-row: 1; }
  .menu-btn { display: none; }
  .sidebar-overlay { display: none !important; }
  .sidebar {
    grid-column: 1; grid-row: 2;
    position: static;
    left: auto; top: auto;
    width: auto; height: auto;
    min-height: 0;
    padding: 12px 0 20px;
    border-top: none;
    transition: none;
    z-index: auto;
  }
  /* 打开/关闭类不再影响布局（无遮罩、无动画） */
  .sidebar.open a { animation: none; }
  .main-wrap { grid-column: 2; grid-row: 2; min-height: 0; }
  .reader { padding: 36px 40px 48px; }
}

/* 进度跳转按钮（桌面显示；移动端靠进度条拖拽与长按） */
.skip-btn {
  background: var(--surface-light);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .18s ease, border-color .18s ease, transform .18s cubic-bezier(.22,.61,.36,1);
  touch-action: manipulation;
}
.skip-btn:hover { background: var(--accent-glow); border-color: var(--accent); }
.skip-btn:active { transform: scale(.9); }
@media (max-width: 767px) { .skip-btn { display: none; } }

/* 图标按钮：SVG 图标统一尺寸 */
.icon-btn svg, .nav-btn svg, .skip-btn svg { display: block; }

/* 内联错误条（播放器上方） */
.player-bar { position: relative; }

/* ===== 移动端体验补强（触控目标 / 进度条命中区 / 横屏 / 输入缩放） ===== */
/* iOS Safari：输入框字号 ≥16px，聚焦时不触发页面自动缩放 */
@media (max-width: 768px) {
  .sidebar-search input { font-size: 16px; }
}
/* 触屏：进度条命中区加高到 24px（视觉细条不变，整条可点可拖） */
@media (hover: none) and (pointer: coarse) {
  .progress-track,
  .progress-track:hover { height: 24px; background: transparent; }
  .progress-track::before {
    content: "";
    position: absolute;
    left: 0; right: 0; top: 9px;
    height: 6px;
    border-radius: 3px;
    background: var(--surface-light);
  }
  .progress-fill { height: 6px; margin-top: 9px; }
  .ab-buffer { top: 9px; height: 6px; }
  .progress-thumb { top: 12px; }
}
/* 小屏：控件触控目标提升到 ≥40px */
@media (max-width: 480px) {
  .icon-btn { width: 40px; height: 40px; }
  .player-bar { row-gap: 2px; }
  .speed-btn, .font-size-btn { padding: 9px 12px; font-size: 0.75rem; }
  .nav-btn { width: 42px; height: 42px; }
}
/* 手机横屏：压缩头部与留白，把高度留给正文 */
@media (orientation: landscape) and (max-height: 500px) {
  header { padding: 8px 16px 7px; padding-top: 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand-mark { width: 28px; height: 28px; font-size: 14px; border-radius: 10px; }
  .brand-title { font-size: 1rem; }
  .brand-sub { display: none; }
  .icon-btn { width: 30px; height: 30px; }
  .menu-btn { left: 10px; }
  .header-btns { right: 10px; gap: 6px; }
  .reader { padding: 14px 20px 22px; }
  .chapter-title { font-size: 1.05rem; margin-bottom: 12px; padding-bottom: 8px; }
  .chapter-content { line-height: 1.8; }
  .player-bar { padding-top: 6px; }
  .cache-panel { bottom: 64px; }
}
