/* ===== 基础与配色 ===== */
:root {
  --paper: #f6f1e6;
  --paper-deep: #efe6d3;
  --ink: #2b2620;
  --ink-soft: #5c5347;
  --cinnabar: #9e2b25;
  --cinnabar-deep: #7c1f1a;
  --gold: #b08a4f;
  --gold-soft: #d3b98a;
  --hairline: rgba(94, 72, 45, 0.22);
  --radius: 10px;
  --shadow: 0 10px 30px rgba(73, 48, 24, 0.12);
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Songti SC", "STSong", "Noto Serif SC", "Noto Serif CJK SC", "SimSun", serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -8%, rgba(158, 43, 37, 0.07), transparent 60%),
    radial-gradient(900px 500px at 85% 110%, rgba(176, 138, 79, 0.10), transparent 55%),
    repeating-linear-gradient(0deg, transparent 0 26px, rgba(94, 72, 45, 0.025) 26px 27px),
    var(--paper);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* 一屏内显示，页面本身不滚动 */
}

/* ===== 左上角品牌 Logo ===== */
.site-logo {
  position: fixed;
  top: 16px;
  left: 26px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  box-shadow: 0 3px 10px rgba(158, 43, 37, 0.3);
}
.logo-text {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.35em;
  color: var(--cinnabar);
}

/* ===== 主体：铺满全宽、撑满剩余高度 ===== */
.page {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 22px 40px 26px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
}

.seal {
  width: 56px;
  height: 56px;
  flex: none;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--cinnabar), var(--cinnabar-deep));
  color: #fdf8ee;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  writing-mode: vertical-rl;
  border-radius: 6px;
  box-shadow: var(--shadow), inset 0 0 0 3px rgba(253, 248, 238, 0.35);
  transform: rotate(-3deg);
  user-select: none;
}
/* 3 字及以上：改长条形印章，避免文字挤出 */
.seal[data-chars="3"] {
  height: 84px;
  font-size: 1.05rem;
  letter-spacing: 0.05em;
}
.seal[data-chars="4"],
.seal[data-chars="5"] {
  height: 96px;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

.sutra-title {
  font-size: clamp(1.7rem, 3.2vw, 2.5rem);
  letter-spacing: 0.28em;
  font-weight: 700;
  white-space: nowrap;
}
.subtitle {
  margin-top: 6px;
  text-align: center;
  color: var(--ink-soft);
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  font-size: 0.9rem;
}

/* ===== 卡片面板 ===== */
.panel {
  background: rgba(255, 252, 245, 0.78);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ===== 播放控制栏（一行放下全部控件） ===== */
.player-card { flex: none; padding: 14px 22px 12px; }
.player-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.btn-play {
  width: 52px;
  height: 52px;
  flex: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: #fdf8ee;
  background: linear-gradient(145deg, var(--cinnabar), var(--cinnabar-deep));
  box-shadow: 0 6px 16px rgba(158, 43, 37, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-play:hover { transform: scale(1.05); box-shadow: 0 8px 20px rgba(158, 43, 37, 0.45); }
.btn-play:active { transform: scale(0.97); }
.btn-play:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.btn-play .icon { width: 24px; height: 24px; fill: currentColor; }
.btn-play .icon-stop { display: none; }
.btn-play.playing .icon-play { display: none; }
.btn-play.playing .icon-stop { display: block; }

.player-meta { display: flex; align-items: center; gap: 12px; }
.voice-label { font-size: 0.85rem; color: var(--ink-soft); letter-spacing: 0.2em; white-space: nowrap; }

#voice-select {
  appearance: none;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background:
    linear-gradient(45deg, transparent 50%, var(--gold) 50%) right 14px center / 7px 7px no-repeat,
    linear-gradient(135deg, var(--gold) 50%, transparent 50%) right 9px center / 7px 7px no-repeat,
    rgba(255, 255, 255, 0.7);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 8px 34px 8px 12px;
  cursor: pointer;
  min-width: 220px;
}
#voice-select:focus-visible { outline: 3px solid var(--gold-soft); outline-offset: 1px; }

/* ===== 字号 / 排版工具（并入控制栏） ===== */
.tool-group { display: flex; align-items: center; gap: 8px; }
.tool-name { font-size: 0.8rem; color: var(--ink-soft); letter-spacing: 0.2em; }

.size-btn, .layout-btn, .sutra-btn, .pager-btn {
  font-family: inherit;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.size-btn { width: 36px; height: 32px; font-size: 0.88rem; }
.layout-btn, .sutra-btn, .pager-btn { padding: 6px 14px; font-size: 0.86rem; letter-spacing: 0.1em; }
.size-btn:hover, .layout-btn:hover, .sutra-btn:hover, .pager-btn:hover { border-color: var(--gold); color: var(--ink); }
.size-btn.active, .layout-btn.active, .sutra-btn.active {
  background: var(--cinnabar);
  border-color: var(--cinnabar);
  color: #fdf8ee;
}
.size-btn:focus-visible, .layout-btn:focus-visible, .sutra-btn:focus-visible, .pager-btn:focus-visible {
  outline: 3px solid var(--gold-soft);
  outline-offset: 1px;
}
.pager-btn:disabled { opacity: 0.4; cursor: default; }
.pager-btn:disabled:hover { border-color: var(--hairline); color: var(--ink-soft); }

.status {
  flex: 1;
  min-width: 180px;
  text-align: right;
  font-size: 0.84rem;
  color: var(--ink-soft);
  letter-spacing: 0.05em;
}
.status.error { color: var(--cinnabar); }

/* 移动端强制换行占位 / 折叠按钮 / 文字标签（桌面端隐藏） */
.flex-break { display: none; }
.expand-btn { display: none; }
.play-label, .expand-label { display: none; }

.progress {
  display: flex;
  gap: 5px;
  margin-top: 12px;
}
.progress .dot {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(94, 72, 45, 0.15);
  transition: background 0.3s ease;
}
.progress .dot.done { background: var(--gold); }
.progress .dot.now { background: var(--cinnabar); }

/* ===== 经文纸面：撑满剩余高度 ===== */
.sutra-paper {
  flex: 1;
  min-height: 0;
  background:
    radial-gradient(800px 400px at 50% 0%, rgba(176, 138, 79, 0.06), transparent 60%),
    #fdfaf2;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(20px, 3vh, 44px) clamp(28px, 4vw, 72px);
  position: relative;
  display: flex;
  justify-content: center;
}
.sutra-paper::before,
.sutra-paper::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(176, 138, 79, 0.28);
  border-radius: 6px;
  pointer-events: none;
}
.sutra-paper::after { inset: 14px; border-color: rgba(176, 138, 79, 0.14); }

/* 横排：多栏铺满整宽，整体垂直居中 */
.sutra {
  flex: 1;
  min-width: 0;
  align-self: center;
  max-height: 100%;
  overflow: auto;
  text-align: justify;
  letter-spacing: 0.12em;
  column-width: 22em;
  column-gap: 3.5em;
  column-fill: balance;
  column-rule: 1px solid rgba(176, 138, 79, 0.18);
  scrollbar-width: thin;
}
.sutra.size-sm { font-size: 1.05rem; line-height: 2; }
.sutra.size-md { font-size: 1.3rem; line-height: 2.05; }
.sutra.size-lg { font-size: 1.55rem; line-height: 2.1; }

/* 品名标题：横排为居中标题块 */
.chap {
  text-align: center;
  font-size: 0.92em;
  font-weight: 700;
  letter-spacing: 0.35em;
  color: var(--cinnabar);
  padding: 0.4em 0 0.35em;
  break-after: avoid; /* 标题不与正文分列 */
}
.chap-gloss {
  display: inline-block;
  margin-inline-start: 0.8em;
  font-weight: 400;
  font-size: 0.78em;
  letter-spacing: 0.15em;
  color: var(--gold);
}

.seg {
  display: block;
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  margin-bottom: 0.45em;
  transition: background 0.25s ease, color 0.25s ease;
}
.seg:hover { background: rgba(176, 138, 79, 0.14); }
.seg.playing {
  background: rgba(158, 43, 37, 0.10);
  color: var(--cinnabar-deep);
  box-shadow: inset 0 -2px 0 var(--cinnabar);
}
.seg.done { color: var(--ink-soft); }

/* 竖排：从右往左逐列铺满整宽 */
.sutra.vertical {
  writing-mode: vertical-rl;
  flex: 0 0 auto;
  width: auto;
  align-self: stretch;
  height: 100%;
  text-align: left;
  column-width: auto;
  column-rule: none;
  overflow-x: auto;
  overflow-y: hidden;
  letter-spacing: 0.22em;
}
.sutra.vertical .seg.playing { box-shadow: inset 2px 0 0 var(--cinnabar); }

/* 竖排：品名与正文恢复内联流式排布 */
.sutra.vertical .chap {
  display: inline;
  padding: 0;
}
.sutra.vertical .chap-name::after { content: "　"; }
.sutra.vertical .chap-gloss { display: none; }
.sutra.vertical .seg { display: inline; margin: 0; padding: 0 1px; }

/* ===== 分页条 ===== */
.pager {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.pager[hidden] { display: none; }
.page-info {
  font-size: 0.85rem;
  color: var(--ink-soft);
  letter-spacing: 0.15em;
  min-width: 96px;
  text-align: center;
}

/* ===== 页脚 ===== */
.site-footer {
  flex: none;
  border-top: 1px solid var(--hairline);
  padding: 10px 32px 12px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.site-footer a { color: var(--cinnabar); text-decoration: none; border-bottom: 1px solid var(--gold-soft); }
.site-footer a:hover { color: var(--cinnabar-deep); }

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .page { padding: 16px 20px 20px; }
  .status { text-align: left; }
}
@media (max-width: 640px) {
  /* Logo 与印章重叠，小屏隐藏 */
  .site-logo { display: none; }

  .page { padding: 12px 12px 14px; gap: 10px; }
  .hero { gap: 12px; }
  .seal { width: 44px; height: 44px; font-size: 1rem; }
  .seal[data-chars="3"] { height: 62px; font-size: 0.9rem; }
  .seal[data-chars="4"], .seal[data-chars="5"] { height: 74px; font-size: 0.8rem; }
  .sutra-title { font-size: 1.35rem; letter-spacing: 0.12em; }
  .subtitle { font-size: 0.78rem; letter-spacing: 0.3em; text-indent: 0.3em; margin-top: 4px; }

  /* 控制栏：折叠为一行文字按钮（▶ 播放 长条 + 设置），点"设置"展开全部控件 */
  .player-card { padding: 8px 10px; }
  .player-row { gap: 8px; }
  .btn-play {
    order: 1;
    flex: 1;
    width: auto;
    height: 38px;
    border-radius: 19px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-size: 0.88rem;
    letter-spacing: 0.15em;
  }
  .btn-play .icon { width: 15px; height: 15px; }
  .btn-play .play-label { display: inline; }
  .player-meta { flex: 1; min-width: 0; order: 2; }
  .flex-break { display: block; order: 3; flex-basis: 100%; height: 0; }
  .tool-group { gap: 6px; }
  .tool-group[aria-label="经典"] { order: 4; }
  .tool-group[aria-label="字号"] { order: 5; }
  .tool-group[aria-label="排版"] { order: 6; display: none; } /* 手机端不提供竖排 */
  .status { display: none; } /* 手机端去掉状态文字，只留经书内容 */

  /* 设置：与播放按钮同行的文字按钮 */
  .expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    order: 8;
    flex: none;
    height: 38px;
    padding: 0 16px;
    font-family: inherit;
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    color: var(--ink-soft);
    background: transparent;
    border: 1px solid var(--hairline);
    border-radius: 19px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
  }
  .expand-btn svg { display: none; }
  .expand-btn .expand-label { display: inline; }
  .expand-btn:hover { border-color: var(--gold); color: var(--ink); }
  .expand-btn:focus-visible { outline: 3px solid var(--gold-soft); outline-offset: 1px; }
  .expand-btn.open { color: var(--cinnabar); border-color: var(--cinnabar); }

  /* 折叠态：隐藏音色/经典/字号/排版控件与进度条，只留居中的播放按钮 */
  .player-card:not(.expanded) .player-meta,
  .player-card:not(.expanded) .tool-group,
  .player-card:not(.expanded) .progress,
  .player-card:not(.expanded) .flex-break { display: none; }
  .player-card:not(.expanded) .player-row { justify-content: center; }
  .player-card.expanded { padding-bottom: 12px; }

  .voice-label, .tool-name { display: none; }
  #voice-select { min-width: 0; width: 100%; }

  /* 触屏目标 ≥36px，紧凑以容纳一行 */
  .size-btn { width: 36px; height: 36px; font-size: 0.85rem; }
  .layout-btn, .sutra-btn, .pager-btn { padding: 8px 10px; font-size: 0.82rem; min-height: 36px; }

  .sutra-paper { padding: 18px 16px; }
  .sutra-paper::before { inset: 6px; }
  .sutra-paper::after { inset: 9px; }
  .sutra { column-width: auto; }
  .sutra.size-sm { font-size: 0.95rem; line-height: 1.9; }
  .sutra.size-md { font-size: 1.12rem; line-height: 1.95; }
  .sutra.size-lg { font-size: 1.32rem; line-height: 2; }

  .pager { gap: 12px; }
  .page-info { min-width: 0; font-size: 0.8rem; }
  .site-footer { padding: 8px 14px; font-size: 0.7rem; }
}
