/* ============================================================
   AI Agent 有声书 · 黑/白极简主题（亮色 + 暗色，右上角手动切换）
   液态玻璃仅用于导航/浮层；内容层保持实体；颜色克制（黑白灰）
   iOS standalone 底部孤儿条带（WebKit 313800）用 --strip 补偿
   ============================================================ */

:root {
  /* ---- 基础色（亮色：白 / 黑 / 浅灰） ---- */
  --bg: #ffffff;
  --bg2: #fafafa;
  --surface: #f5f5f7;            /* 内容层表面 */
  --surface2: #ebebee;           /* 按压/次级表面 */
  --hairline: rgba(0,0,0,.09);   /* 细分隔线 */
  --hairline-soft: rgba(0,0,0,.05);
  --hairline-strong: rgba(0,0,0,.3);

  --text: #111111;
  --text2: rgba(17,17,17,.64);
  --text3: rgba(17,17,17,.40);

  --accent: #111111;             /* 主操作/激活态 = 黑 */
  --accent2: #444444;
  --accent-ring: rgba(17,17,17,.9);
  --on-accent: #ffffff;          /* 强调背景上的文字 */
  --tint: rgba(17,17,17,.05);
  --tint-strong: rgba(17,17,17,.10);
  --danger: #111111;

  --track: rgba(0,0,0,.12);
  --handle: rgba(0,0,0,.16);
  --scrollbar: rgba(0,0,0,.14);
  --ripple-color: rgba(0,0,0,.12);

  /* ---- 玻璃（亮色） ---- */
  --glass-blur: 24px;
  --glass-sat: 150%;
  --glass-bg: linear-gradient(150deg, rgba(255,255,255,.86), rgba(255,255,255,.66) 40%, rgba(255,255,255,.76));
  --glass-border: rgba(255,255,255,.9);
  --glass-hl: inset 0 1px 0 rgba(255,255,255,.98);
  --glass-shadow: 0 16px 48px rgba(0,0,0,.12);
  --glass-gloss: rgba(255,255,255,.5);

  --topbar-bg: rgba(255,255,255,.72);
  --topbar-line: rgba(0,0,0,.08);

  --inset-bg: rgba(0,0,0,.05);
  --inset-border: rgba(0,0,0,.07);
  --inset-hl: inset 0 1px 0 rgba(255,255,255,.6);

  --overlay-bg: rgba(0,0,0,.25);

  --toast-bg: rgba(255,255,255,.92);
  --toast-border: rgba(0,0,0,.08);

  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow-cover: 0 8px 20px rgba(0,0,0,.22);
  --shadow-cover-sm: 0 4px 14px rgba(0,0,0,.18);
  --shadow-cover-lg: 0 18px 44px rgba(0,0,0,.22), 0 4px 12px rgba(0,0,0,.12);
  --shadow-play: rgba(0,0,0,.28);
  --shadow-thumb: 0 2px 8px rgba(0,0,0,.25);
  --shadow-toast: 0 10px 30px rgba(0,0,0,.18);

  /* ---- 圆角 ---- */
  --r-xl: 30px;
  --r-lg: 22px;
  --r-md: 15px;
  --r-sm: 11px;

  /* ---- 安全区 / 底部条带补偿（--strip / --sink-player 由 JS 写入） ---- */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --strip: 0px;
  --sink-player: 0px;
}

/* ---- 暗色主题（与亮色同构，只换变量） ---- */
html[data-theme="dark"] {
  --bg: #101012;
  --bg2: #161619;
  --surface: #1b1b1f;
  --surface2: #232327;
  --hairline: rgba(255,255,255,.12);
  --hairline-soft: rgba(255,255,255,.06);
  --hairline-strong: rgba(255,255,255,.3);

  --text: #f5f5f7;
  --text2: rgba(245,245,247,.66);
  --text3: rgba(245,245,247,.42);

  --accent: #ffffff;
  --accent2: #d1d1d6;
  --accent-ring: rgba(255,255,255,.85);
  --on-accent: #0a0a0c;
  --tint: rgba(255,255,255,.08);
  --tint-strong: rgba(255,255,255,.14);
  --danger: #ffffff;

  --track: rgba(255,255,255,.18);
  --handle: rgba(255,255,255,.28);
  --scrollbar: rgba(255,255,255,.22);
  --ripple-color: rgba(255,255,255,.16);

  --glass-bg: linear-gradient(150deg, rgba(40,40,44,.82), rgba(22,22,26,.66) 40%, rgba(30,30,34,.78));
  --glass-border: rgba(255,255,255,.14);
  --glass-hl: inset 0 1px 0 rgba(255,255,255,.12);
  --glass-shadow: 0 16px 48px rgba(0,0,0,.5);
  --glass-gloss: rgba(255,255,255,.09);

  --topbar-bg: rgba(16,16,18,.72);
  --topbar-line: rgba(255,255,255,.08);

  --inset-bg: rgba(255,255,255,.07);
  --inset-border: rgba(255,255,255,.1);
  --inset-hl: inset 0 1px 0 rgba(255,255,255,.08);

  --overlay-bg: rgba(0,0,0,.55);

  --toast-bg: rgba(28,28,32,.9);
  --toast-border: rgba(255,255,255,.12);

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-cover: 0 8px 20px rgba(0,0,0,.5);
  --shadow-cover-sm: 0 4px 14px rgba(0,0,0,.4);
  --shadow-cover-lg: 0 18px 44px rgba(0,0,0,.55), 0 4px 12px rgba(0,0,0,.3);
  --shadow-play: rgba(0,0,0,.5);
  --shadow-thumb: 0 2px 8px rgba(0,0,0,.5);
  --shadow-toast: 0 10px 30px rgba(0,0,0,.45);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { height: 100%; background: var(--bg); color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  /* min-height 多 1px：保证文档始终可滚动，使布局视口与可见区域行为一致（iOS standalone） */
  min-height: calc(100% + 1px);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(96px + var(--safe-b) + var(--strip));
  overscroll-behavior-y: none;
}

/* iOS standalone：状态栏区域用页面背景色填充，完全沉浸 */
@media screen and (display-mode: standalone) {
  body::before {
    content: ''; position: fixed; top: 0; left: 0; right: 0; z-index: 99;
    height: env(safe-area-inset-top);
    background: var(--bg); pointer-events: none;
  }
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
img { display: block; }
svg { display: block; }

/* ---------- 玻璃材质（仅浮层/导航） ---------- */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-hl), var(--glass-shadow);
  position: relative;
}
.glass::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(115deg, var(--glass-gloss), transparent 42%);
}

/* 浮层内控件：半透明白/灰表面，避免 glass-on-glass */
.inset-btn {
  background: var(--inset-bg);
  border: 1px solid var(--inset-border);
  box-shadow: var(--inset-hl);
}

.press { transition: transform .16s cubic-bezier(.2,.8,.2,1), filter .16s, background-color .16s, color .16s, border-color .16s, box-shadow .16s; }
.press:active { transform: scale(.955); filter: brightness(.97); }

.ripple { position: relative; overflow: hidden; }
.ripple-ink {
  position: absolute; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, var(--ripple-color), transparent 68%);
  transform: scale(0); animation: ripple .58s cubic-bezier(.2,.7,.3,1) forwards;
}
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

/* ---------- 顶栏（玻璃导航层） ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 12px; padding-top: max(12px, var(--safe-t));
  background: var(--topbar-bg);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  backdrop-filter: blur(20px) saturate(150%);
  border-bottom: 1px solid var(--hairline-soft);
}
#topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--topbar-line), transparent);
}
#topbar-title { font-size: 17px; font-weight: 700; letter-spacing: .2px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); transition: transform .16s cubic-bezier(.2,.8,.2,1), background-color .16s;
}
.icon-btn:active { transform: scale(.9); background: var(--tint); }
.icon-btn svg { width: 24px; height: 24px; }
#btn-back { color: var(--text); }

#topbar-right { display: flex; align-items: center; }
#btn-theme svg { width: 22px; height: 22px; }
#btn-theme .ic-sun { display: none; }
html[data-theme="dark"] #btn-theme .ic-sun { display: block; }
html[data-theme="dark"] #btn-theme .ic-moon { display: none; }

#view { padding: 6px 18px 20px; }
.section-title { font-size: 12px; color: var(--text3); margin: 20px 4px 12px; letter-spacing: 2px; font-weight: 600; }

/* ---------- 书架（内容层：浅灰实体卡片） ---------- */
.bookshelf { display: flex; flex-direction: column; gap: 16px; }
.book-card {
  display: flex; gap: 16px; align-items: center;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-lg);
  padding: 16px; text-align: left; width: 100%;
  box-shadow: var(--shadow-sm);
}
.book-card .cover {
  width: 74px; height: 98px; border-radius: 12px; object-fit: cover; flex-shrink: 0;
  box-shadow: var(--shadow-cover);
}
.book-info { flex: 1; min-width: 0; }
.book-title { font-size: 16px; font-weight: 700; margin-bottom: 3px; letter-spacing: .2px; }
.book-sub { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.book-meta { font-size: 11px; color: var(--text3); display: flex; gap: 10px; flex-wrap: wrap; }
.progress-bar {
  height: 5px; background: var(--track); border-radius: 999px; margin-top: 10px; overflow: hidden;
}
.progress-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* ---------- 章节列表 ---------- */
.chapter-list { display: flex; flex-direction: column; gap: 12px; }
.chapter-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-lg);
  padding: 14px 16px; width: 100%; text-align: left;
  box-shadow: var(--shadow-sm);
}
.chapter-no {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--hairline);
  color: var(--text); font-size: 13px; font-weight: 700;
}
.chapter-info { flex: 1; min-width: 0; }
.chapter-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-sub { font-size: 12px; color: var(--text2); margin-top: 3px; }
.chapter-badge { font-size: 11px; color: var(--text3); margin-left: 8px; flex-shrink: 0; }
.chapter-row.played .chapter-title { color: var(--text2); }
.chapter-row.playing {
  border-color: var(--accent);
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--accent-ring);
}
.chapter-row.playing .chapter-no { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.chapter-row.locked { opacity: .45; }
.chapter-row .play-ind { color: var(--accent); flex-shrink: 0; display: inline-flex; }
.chapter-row .play-ind svg { width: 20px; height: 20px; }
.playing .eq-bars { display: inline-flex; gap: 2.5px; align-items: flex-end; height: 16px; }
.playing .eq-bars i { width: 3px; border-radius: 2px; background: var(--accent); animation: eq 1s ease-in-out infinite; }
.playing .eq-bars i:nth-child(1) { height: 60%; animation-delay: 0s; }
.playing .eq-bars i:nth-child(2) { height: 100%; animation-delay: .18s; }
.playing .eq-bars i:nth-child(3) { height: 45%; animation-delay: .36s; }
@keyframes eq { 0%,100% { transform: scaleY(1); } 50% { transform: scaleY(.45); } }

/* ---------- 迷你播放条（玻璃浮层，底部条带补偿） ---------- */
#mini-player {
  position: fixed; left: 14px; right: 14px;
  bottom: calc(12px + var(--safe-b) - var(--strip));
  transform: translateY(var(--sink-player));
  z-index: 40;
  display: flex; align-items: center; gap: 12px;
  border-radius: 26px; padding: 9px 12px;
  transform-origin: center bottom;
  animation: miniIn .45s cubic-bezier(.22,1.2,.36,1);
}
@keyframes miniIn {
  from { transform: translateY(120%) scale(.9); opacity: 0; }
  to { transform: translateY(var(--sink-player)); opacity: 1; }
}
#mini-cover { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; flex-shrink: 0; box-shadow: var(--shadow-cover-sm); }
#mini-meta { flex: 1; min-width: 0; }
#mini-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mini-chapter { font-size: 11px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mini-play { color: var(--text); width: 42px; height: 42px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
#mini-play:active { transform: scale(.9); background: var(--tint); }
#mini-play svg { width: 22px; height: 22px; }

/* ---------- 浮层容器（播放器 / 定时） ---------- */
.sheet {
  position: fixed; inset: auto 0 0 0; z-index: 50;
  bottom: calc(-1 * var(--strip));
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 10px 22px calc(28px + var(--safe-b));
  max-height: 92vh; overflow-y: auto; overscroll-behavior-y: contain;
  transform: translateY(104%);
  visibility: hidden; pointer-events: none;
  transition: transform .5s cubic-bezier(.22,1.18,.32,1), visibility 0s linear .5s;
}
.sheet.open { transform: none; visibility: visible; pointer-events: auto; transition: transform .5s cubic-bezier(.22,1.18,.32,1), visibility 0s; }
#player-sheet { z-index: 50; }
#timer-sheet { z-index: 60; padding-bottom: calc(20px + var(--safe-b)); }
.sheet-handle {
  width: 46px; height: 5px; border-radius: 3px; margin: 6px auto 14px;
  background: var(--handle); touch-action: none;
}
.sheet-dragzone {
  position: absolute; top: 0; left: 0; right: 0; height: 34px;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  touch-action: none; z-index: 1;
}

#player-cover {
  width: min(56vw, 230px); aspect-ratio: 3/4; border-radius: 18px; object-fit: cover;
  margin: 6px auto 20px;
  box-shadow: var(--shadow-cover-lg);
}
#player-book { text-align: center; font-size: 12px; color: var(--text3); letter-spacing: 2px; font-weight: 600; }
#player-chapter { text-align: center; font-size: 18px; font-weight: 700; margin: 6px 0 2px; letter-spacing: .2px; }
#player-section { text-align: center; font-size: 13px; color: var(--text2); margin-bottom: 16px; }

/* 进度条 */
#progress-wrap { margin: 8px 0 2px; }
#seek {
  width: 100%; -webkit-appearance: none; appearance: none; outline: none;
  height: 6px; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 0%), var(--track) var(--fill, 0%));
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-thumb);
}
#seek::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--accent); box-shadow: var(--shadow-thumb);
}
#time-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--text3); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* 知识点 chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; font-size: 12px; color: var(--text2);
  background: var(--inset-bg); border: 1px solid var(--inset-border);
  border-radius: 999px; padding: 7px 13px; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 700; }

/* 播放控制 */
#controls { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; gap: 6px; }
.ctl-btn {
  min-width: 56px; min-height: 46px; padding: 8px 10px; font-size: 13px; color: var(--text2);
  border-radius: 16px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-weight: 500;
}
.ctl-btn svg { width: 22px; height: 22px; }
.ctl-btn.active { color: var(--text); border-color: var(--hairline-strong); background: var(--tint); }
.icon-big { font-size: 22px; }
.icon-play {
  width: 66px; height: 66px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px var(--shadow-play);
  flex-shrink: 0;
}
.icon-play svg { width: 28px; height: 28px; }
.icon-play:active { transform: scale(.92); }

/* 定时弹层 */
#timer-sheet h3 { text-align: center; font-size: 16px; font-weight: 700; margin: 4px 0 18px; }
.timer-group { margin-bottom: 20px; }
.timer-label { font-size: 12px; color: var(--text3); margin-bottom: 10px; letter-spacing: 1px; font-weight: 600; }
.timer-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.timer-options button {
  font-size: 12px; padding: 11px 4px; border-radius: 14px;
  color: var(--text2);
}
.timer-options button.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 700; }
.timer-cancel {
  display: block; width: 100%; padding: 13px; border-radius: 16px;
  background: var(--inset-bg); border: 1px solid var(--inset-border);
  color: var(--text); font-size: 14px; font-weight: 600; margin-bottom: 10px;
}
.timer-close { display: block; width: 100%; padding: 13px; border-radius: 16px; color: var(--text2); font-size: 14px; font-weight: 600; }

/* 遮罩 */
#overlay {
  position: fixed; inset: 0; z-index: 45;
  background: var(--overlay-bg);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .35s ease, visibility 0s linear .35s;
}
#overlay.open { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .35s ease; }

/* Toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(132px + var(--safe-b) - var(--strip)); z-index: 70;
  background: var(--toast-bg);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--toast-border); color: var(--text);
  font-size: 13px; padding: 10px 20px; border-radius: 999px; white-space: nowrap;
  box-shadow: var(--glass-hl), var(--shadow-toast);
  animation: toastIn .35s cubic-bezier(.22,1.2,.36,1);
}
@keyframes toastIn { from { transform: translate(-50%, 16px) scale(.92); opacity: 0; } to { transform: translate(-50%, 0) scale(1); opacity: 1; } }

.badge { display: inline-block; font-size: 10px; padding: 3px 9px; border-radius: 999px; background: var(--inset-bg); border: 1px solid var(--hairline-soft); color: var(--text3); }
.badge.warn { color: var(--text2); }
.empty { text-align: center; color: var(--text3); font-size: 14px; padding: 70px 20px; line-height: 1.9; }

/* ---------- 文稿跟随 ---------- */
#transcript-bar { margin: 14px 0 4px; }
#btn-transcript { width: 100%; min-height: 46px; border-radius: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; }
#btn-transcript svg { width: 20px; height: 20px; }
#transcript {
  display: grid; grid-template-rows: 0fr;
  margin-top: 8px; border: 1px solid var(--hairline-soft); border-radius: var(--r-md);
  background: var(--bg2); overflow: hidden;
  transition: grid-template-rows .42s cubic-bezier(.32,.72,.28,1);
}
#transcript.open { grid-template-rows: 1fr; }
#transcript .ts-inner { min-height: 0; overflow: hidden; }
.ts-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 14px; font-size: 12px; color: var(--text3);
  border-bottom: 1px solid var(--hairline-soft); position: sticky; top: 0; z-index: 1;
}
.ts-follow { font-size: 12px; color: var(--text2); border-radius: 999px; padding: 5px 12px; }
.ts-follow.on { color: var(--text); border-color: var(--hairline-strong); background: var(--tint); font-weight: 600; }
#transcript-body { max-height: 40vh; overflow-y: auto; padding: 6px 14px 16px; -webkit-overflow-scrolling: touch; }
.ts-sec-title { font-size: 12px; color: var(--text); font-weight: 700; margin: 16px 0 6px; letter-spacing: .5px; }
.ts-sec-title:first-child { margin-top: 10px; }
.ts-line {
  font-size: 15px; line-height: 1.8; color: var(--text2); padding: 4px 8px;
  border-left: 2.5px solid transparent; border-radius: 8px; cursor: pointer;
  transition: background-color .2s, color .2s;
}
.ts-line.active { color: var(--text); background: var(--tint); border-left-color: var(--accent); }
.ts-line:hover { background: var(--tint); }

#transcript-body::-webkit-scrollbar { width: 5px; }
#transcript-body::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 999px; }

/* ---------- 无障碍：减少动态 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
