/* 书籍「听书」：
   1) books.html 侧的入口样式（阅读器 4 键、详情页按钮态、详情页大板块）
   2) 独立听书页 books-listen.html 的整页样式
   听书页是真页面（不是浮层），通过 sessionStorage 交接书籍正文。 */

/* 阅读器工具栏回落为 4 个按钮（目录 / 听书 / 夜间 / 设置）：倍速已从阅读器移除，改到听书页里。 */
.books-reader-toolbar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.books-reader-toolbar .reader-listen-button.is-playing {
  background: var(--reader-soft);
  color: var(--reader-active);
}

.books-detail-actions .books-detail-listen.is-playing {
  background: rgba(var(--accent-rgb), 0.16);
  color: var(--cinnabar, #b94132);
}

/* 从详情页点听书时保留阅读器背景与加载提示，避免正文请求期间出现白屏。 */
body.books-listen-opening #books-reader-panel {
  visibility: visible !important;
}

body.books-listen-opening #books-reader-panel .books-reader-content {
  opacity: 0.72;
}

/* ==========================================================================
   书籍详情页大板块
   基准值取自移动端 .study-card-wrapper（daoxue.css）——也就是书库页外面那块大板：
     1px rgba(32,35,33,.08) 描边 + 18px 圆角 + 0 10px 28px rgba(33,36,31,.08) 阴影
   顶部返回按钮与「书籍详情」标题留在板外，与排盘页 / 个人中心等页面的 topbar 一致；
   内容区和底部操作栏共享同一块板，操作文字嵌在板块底部。
   ========================================================================== */
body[data-page='books']:has(#books-detail-view:not([hidden])) .main-content {
  padding-top: 10px;
  padding-bottom: 12px;
}

#books-detail-view .books-detail-content {
  padding-bottom: 0;
  border: 1px solid rgba(32, 35, 33, 0.08);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  background: var(--app-panel-surface, #faf7ee);
  box-shadow: 0 10px 28px rgba(33, 36, 31, 0.08);
  /* The board itself is the scroll container. Keep the action capsule below it
     in the detail view flex column, just like the VIP plan footer. */
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* 详情操作区是大板块的底部，不再是悬浮在板外的窄胶囊。四个按钮等分整块宽度，
   这样滚动上方简介时，操作文字始终固定在板底并与会员中心的底部区域一致。 */
#books-detail-view .books-detail-actions {
  position: relative;
  flex: 0 0 auto;
  z-index: 2;
  width: min(820px, 100%);
  min-height: 58px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0 auto;
  right: auto;
  left: auto;
  transform: none;
  padding: 7px;
  border: 1px solid rgba(32, 35, 33, 0.08);
  border-top: 1px solid var(--line);
  border-radius: 0 0 18px 18px;
  background: var(--app-panel-surface, #faf7ee);
  box-shadow: 0 10px 28px rgba(33, 36, 31, 0.08);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#books-detail-view .books-detail-actions button {
  min-width: 0;
  min-height: 42px;
  padding: 0 10px;
  border-radius: 7px;
  white-space: nowrap;
}

/* ==========================================================================
   独立听书页（books-listen.html）
   板外：顶部返回按钮 + 书名（与全站 topbar 一致）
   板内：封面 → 普通上下滚动正文 → 进度条 → 倍速 → 底部五个键
   ========================================================================== */
body[data-page='books-listen'] {
  /* 听书页是「一屏播放器」：整页不许滚动，滚动只发生在板内的歌词区。
     否则长书会把板撑到上万像素，封面上提和底部控制条都失去意义。 */
  height: 100dvh;
  overflow: hidden;
  background: var(--app-bg, #f4f1e9);
}

body[data-page='books-listen'] .main-content {
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  box-sizing: border-box;
  overflow: hidden;
}

/* 桌面端：这一页没有侧栏，别让 280px 的网格把板挤成一条 —— 单列 + 居中收窄 */
@media (min-width: 761px) {
  body[data-page='books-listen'] .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-page='books-listen'] .main-content {
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
  }
}

/* ---- 板外顶栏 ---- */
.books-listen-topbar {
  min-height: 52px;
  display: grid;
  /* ⚠️ 两列就够：返回键 + 书名。书名紧挨返回键靠左，不要居中（居中的话标题会飘到屏幕中间） */
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 2px;
}

.books-listen-topbar .topbar-back {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  justify-self: start;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink, #23261f);
  cursor: pointer;
}

.books-listen-topbar .topbar-back svg,
.books-listen-topbar .topbar-back [data-lucide] {
  width: 23px;
  height: 23px;
}

.books-listen-topbar-title {
  min-width: 0;
}

.books-listen-topbar-title h1 {
  margin: 0;
  overflow: hidden;
  color: var(--ink, #23261f);
  font-size: 16px;
  font-weight: 800;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- 大板块 ---- */
.books-listen-board {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(32, 35, 33, 0.08);
  border-radius: 18px;
  background: var(--app-panel-surface, #faf7ee);
  box-shadow: 0 10px 28px rgba(33, 36, 31, 0.08);
  overflow: hidden;
}

.books-listen-empty {
  padding: 40px 24px;
  color: var(--muted, #8a8f86);
  font-size: 14px;
  text-align: center;
}

/* ---- 封面（靠上，已按用户要求再缩小一档） ---- */
.books-listen-cover {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 12px 0 2px;
}

.books-listen-cover .books-card-cover {
  width: 96px;
  height: 128px;
  padding: 9px;
  border-radius: 7px;
  box-shadow: 0 12px 22px rgba(33, 36, 31, 0.18);
}

.books-listen-cover .books-spine {
  top: 12px;
  right: 8px;
  bottom: 12px;
  min-width: 22px;
  max-width: 42px;
  font-size: 10px;
}

/* ---- 章节名（封面下方，随朗读推进切换） ---- */
.books-listen-chapter {
  flex: 0 0 auto;
  margin: 12px 0 0;
  padding: 0 22px;
  overflow: hidden;
  color: var(--ink, #23261f);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.books-listen-chapter[hidden] {
  display: none !important;
}

/* ---- 与阅读器一致的普通滚动正文 ---- */
.books-listen-lyrics {
  flex: 1 1 auto;
  min-height: 90px;
  position: relative;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 22px 24px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* 给正文首尾留出少量空白，保持阅读器的自然上下滚动。 */
.books-listen-lyrics::before,
.books-listen-lyrics::after {
  content: '';
  display: block;
  height: var(--listen-edge-space, 24px);
  pointer-events: none;
}

.books-listen-paragraph {
  margin: 0 0 18px;
  color: var(--reader-ink, var(--ink, #23261f));
  font-size: 16px;
  line-height: 1.95;
  text-align: justify;
  text-indent: 2em;
  word-break: break-word;
  letter-spacing: 0;
  orphans: 3;
  widows: 3;
}

.books-listen-line {
  margin: 0;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-align: inherit;
  text-indent: 0;
  word-break: break-word;
  letter-spacing: inherit;
  transition: color 0.25s ease, opacity 0.25s ease;
  cursor: pointer;
}

.books-listen-line.is-read {
  color: inherit;
}

/* 标题单独占一行，外观与阅读器 h4 一致，不参与正文首行缩进。 */
.books-listen-line.is-chapter-heading {
  display: block;
  margin-top: 32px;
  margin-bottom: 18px;
  color: var(--reader-ink, var(--ink, #23261f));
  font-size: 1.06em;
  font-weight: 800;
  line-height: 1.55;
  text-align: center;
  text-indent: 0;
}

/* 正在朗读的这一段：保留红色高亮，正文仍按阅读器的段落流排版。 */
.books-listen-line.is-current {
  color: rgb(var(--accent-rgb, 185, 65, 50));
  font-weight: 800;
}

.books-listen-line.is-current.is-chapter-heading {
  color: rgb(var(--accent-rgb, 185, 65, 50));
}

.books-listen-lyrics-empty {
  margin: 0;
  padding: 30px 20px;
  color: var(--muted, #8a8f86);
  font-size: 14px;
  text-align: center;
}

/* ---- 进度条 ---- */
/* 进度条：±15 秒已挪到下面控制条里，这里只剩时间 + 轨道 */
.books-listen-progress {
  flex: 0 0 auto;
  width: calc(100% - 28px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
}

/* ±15 秒（在控制条里：后退15 在上一节左边，前进15 在下一节左边） */
.books-listen-seek {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted, #8a8f86);
  cursor: pointer;
}

.books-listen-seek svg {
  width: 24px;
  height: 24px;
}

.books-listen-seek span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 8px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.books-listen-track-wrap {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.books-listen-time {
  margin: 0;
  color: var(--muted, #8a8f86);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.books-listen-track {
  position: relative;
  height: 10px;
  border: 0;
  padding: 2px 0;
  border-radius: 999px;
  background: rgba(35, 38, 31, 0.1);
  cursor: pointer;
  touch-action: none;
  user-select: none;
}

.books-listen-track-fill {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  width: 0;
  border-radius: 999px;
  background: var(--cinnabar, #b94132);
}

/* ---- 倍速（放在进度条下方） ---- */
.books-listen-rate-row {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 10px 0 2px;
}

.books-listen-rate {
  padding: 4px 14px;
  border: 1px solid rgba(32, 35, 33, 0.12);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--cinnabar, #b94132);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

/* ---- 底部五个键（在板内，跟板同色，不再是一条白底）
        [后退15] [上一节] [播放] [下一节] [前进15]
        「朗读声音」已于 2026-09-28 按用户要求删除（只剩一种声音，不再给入口） ---- */
.books-listen-controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 6px 10px max(14px, env(safe-area-inset-bottom));
}

.books-listen-controls button {
  border: 0;
  background: transparent;
  color: var(--ink, #23261f);
  font: inherit;
  cursor: pointer;
}

/* 只要图标，不要「选择章节」四个字 */
.books-listen-toc-button {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--muted, #8a8f86);
}

.books-listen-toc-button svg,
.books-listen-toc-button [data-lucide] {
  width: 20px;
  height: 20px;
}

.books-listen-step {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--ink, #23261f);
}

.books-listen-step svg {
  width: 24px;
  height: 24px;
}

.books-listen-toggle {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50% !important;
  background: var(--cinnabar, #b94132) !important;
  color: #fffdf7 !important;
  box-shadow: 0 14px 26px rgba(var(--accent-rgb), 0.28);
}

.books-listen-toggle svg {
  width: 24px;
  height: 24px;
}

.books-listen-icon-play {
  display: grid;
}

.books-listen-icon-pause {
  display: none;
}

.books-listen-toggle[aria-pressed='true'] .books-listen-icon-play {
  display: none;
}

.books-listen-toggle[aria-pressed='true'] .books-listen-icon-pause {
  display: grid;
}

/* ---- 章节列表 sheet ---- */
.books-listen-toc {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.books-listen-toc[hidden] {
  display: none !important;
}

.books-listen-toc-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(20, 22, 19, 0.32);
}

.books-listen-toc-panel {
  position: relative;
  max-height: 74%;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  border-radius: 16px 16px 0 0;
  background: var(--app-panel-surface, #faf7ee);
  box-shadow: 0 -16px 36px rgba(20, 22, 19, 0.18);
}

.books-listen-toc-handle {
  width: 42px;
  height: 4px;
  margin: 8px auto 0;
  border-radius: 999px;
  background: rgba(35, 38, 31, 0.16);
}

.books-listen-toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px 6px;
}

.books-listen-toc-header h2 {
  margin: 0;
  color: var(--ink, #23261f);
  font-size: 15px;
}

.books-listen-toc-header button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(32, 35, 33, 0.06);
  color: inherit;
  cursor: pointer;
}

.books-listen-toc-header button svg,
.books-listen-toc-header button [data-lucide] {
  width: 18px;
  height: 18px;
}

.books-listen-toc-list {
  overflow-y: auto;
  display: grid;
  gap: 2px;
  padding: 4px 8px 14px;
  -webkit-overflow-scrolling: touch;
}

.books-listen-toc-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink, #23261f);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.books-listen-toc-item span:first-child {
  color: var(--muted, #8a8f86);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.books-listen-toc-item[aria-current='true'] {
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--cinnabar, #b94132);
}

/* ---- 弹窗（章节 / 倍速）的选项行：「朗读声音」已于 2026-09-28 删除 ---- */
.books-listen-sheet-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20px;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink, #23261f);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.books-listen-sheet-item + .books-listen-sheet-item {
  margin-top: 2px;
}

.books-listen-sheet-item-label {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.books-listen-sheet-item-hint {
  color: var(--muted, #8a8f86);
  font-size: 12px;
  font-weight: 500;
}

/* 打勾：只有选中那一项才显示 */
.books-listen-sheet-item-check {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  color: rgb(var(--accent-rgb, 185, 65, 50));
  opacity: 0;
}

.books-listen-sheet-item-check svg {
  width: 18px;
  height: 18px;
}

.books-listen-sheet-item[aria-current='true'] {
  background: rgba(var(--accent-rgb), 0.12);
  font-weight: 800;
}

.books-listen-sheet-item[aria-current='true'] .books-listen-sheet-item-check {
  opacity: 1;
}

/* 分组标题（现已不再分组，留着给倍速弹窗之类的复用） */
.books-listen-sheet-group {
  padding: 12px 14px 4px;
  color: var(--muted, #8a8f86);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.books-listen-sheet-note {
  margin: 4px 14px 8px;
  color: var(--muted, #8a8f86);
  font-size: 12px;
  line-height: 1.7;
}

@media (max-height: 720px) {
  .books-listen-cover .books-card-cover {
    width: 82px;
    height: 110px;
    padding: 8px;
  }

  .books-listen-cover {
    padding-top: 8px;
  }

  .books-listen-chapter {
    margin-top: 8px;
    font-size: 13px;
  }

  .books-listen-toggle {
    width: 56px;
    height: 56px;
  }

  .books-listen-line {
    font-size: 15px;
  }

  .books-listen-paragraph {
    margin-bottom: 18px;
    font-size: 15px;
  }

  .books-listen-line.is-chapter-heading {
    font-size: 17px;
  }
}

/* ==========================================================================
   阅读器里的「正在朗读」高亮（听书页点「原文」进入后定位到当前朗读处）
   • 段落级：软底色 + 圆角 + 一点阴影，标出「读到哪一段」
   • 句子级：CSS Custom Highlight API（::highlight），标出「正在念的这一句」
   用负边距 + 内边距做底色，不改文字排版位置（避免进页面时正文整体跳一下）。
   ========================================================================== */
#reader-content .books-article-body .is-listening-now,
#reader-content .is-listening-now {
  margin-right: -10px;
  margin-left: -10px;
  padding: 3px 10px;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.12), rgba(var(--accent-rgb), 0.04));
  box-shadow: 0 2px 12px rgba(var(--accent-rgb), 0.12);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

::highlight(xwg-listen-now) {
  background-color: rgba(var(--accent-rgb), 0.28);
}

/* 夜间模式下底色要更实一点才看得出来 */
body[data-reader-theme='night'] #reader-content .is-listening-now {
  background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.24), rgba(var(--accent-rgb), 0.08));
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.34);
}

body[data-reader-theme='night'] ::highlight(xwg-listen-now) {
  background-color: rgba(var(--accent-rgb), 0.46);
}

/* ==========================================================================
   后台「听书功能」开关（books_listen）关闭后：
   1) app.js 会给听书按钮挂 [hidden]，但详情页/阅读器工具栏的按钮都有
      display:inline-flex / flex 的类规则，会把 UA 样式表里的 [hidden]{display:none}
      压掉——按钮照常显示。这里按项目惯例补一条 !important 的硬隐藏。
   2) 按钮布局跟着变：详情页 4 键（书架/目录/听书/阅读）→ 听书关掉后剩 3 键，
      阅读器 4 键（目录/听书/夜间/设置）同理，都要恢复平均分。
   ========================================================================== */
.books-detail-actions button[hidden],
.books-reader-toolbar button[hidden] {
  display: none !important;
}

.books-detail-actions:has(.books-detail-listen[hidden]) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.books-reader-toolbar:has(.reader-listen-button[hidden]) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
