/* 革命理想高于天 —— 竖版渲染器样式（内容层与表现层分离） */
:root {
  --ratio: 0.5679;
  --page-w: min(100vw, calc(100vh * var(--ratio)));
  --page-h: min(calc(100vw / var(--ratio)), 100vh);
  --letterbox: #0f0a08;
  /* 以下由 app.js 依据 theme.json 注入 */
  --font-title: serif; --font-heading: serif; --font-body: sans-serif; --font-caption: sans-serif;
  --title-color: #98210e; --heading-color: #98210e; --ink: #1a1512; --caption-color: #1a1512;
  --shadow: none; --paper: #f7ecc9; --text-halo: 0 0 0 transparent;
  --kicker-scale: .0362; --title-scale: .0362; --heading-scale: .0281;
  --body-scale: .0312; --caption-scale: .0133;
  --pad-x: .078; --pad-top: .049;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: var(--letterbox); }
body { font-family: var(--font-body); color: var(--ink); }

/* 舞台：黑边留白区 */
.stage {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #3a120a 0%, var(--letterbox) 78%);
}

/* 页面：固定纵横比，居中；黑边由 stage 填充 */
.page {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: var(--page-w); height: var(--page-h);
  overflow: hidden; background: #c9b28a;
  box-shadow: 0 0 0 1px rgba(253,248,194,.18), 0 16px 60px rgba(0,0,0,.7);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .35s ease, visibility .35s;
}
.page.active { opacity: 1; visibility: visible; pointer-events: auto; }

/* 底图：整铺背景（页比例与底图一致，故严丝合缝） */
.bg { position: absolute; inset: 0; z-index: 0; }
.bg img { width: 100%; height: 100%; object-fit: cover; object-position: center; display: block; }

/* 原图页（封面/前言/结语） */
.full-img { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: cover; display: block; }

/* 内容：叠加于底图之上；flex 列布局让文字页可整体下移/补图贴底 */
.content {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column;
  padding: calc(var(--page-h) * var(--pad-top)) calc(var(--page-w) * var(--pad-x)) calc(var(--page-h) * .06);
  overflow: hidden;
}

/* 文字块主体：可整体下移（--t-y，占页高比例）；两段间距（--t-gap） */
.body {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  margin-top: calc(var(--page-h) * var(--t-y, 0));
}
.body .para { margin-bottom: .25em; }
.body .para + .para { margin-top: var(--t-gap, 0em); }

/* 短文字页（无图且文字不足 72% 页高）：正文块垂直居中、两段间距拉大（--t-y 可再整体下移） */
.page.spacious .body { justify-content: center; margin-top: calc(var(--page-h) * var(--t-y, 0)); }
.page.spacious .body .para { margin-bottom: 1.15em; }
.page.spacious .body .para + .para { margin-top: .35em; }

/* 标题（红字，居中，可多行） */
.page-title { margin-bottom: .5em; line-height: 1.28; letter-spacing: .06em; text-align: center; }
.page-title .kicker {
  display: block; font-family: var(--font-heading); font-weight: 900;
  font-size: calc(var(--page-w) * var(--kicker-scale)); color: var(--title-color);
  text-shadow: var(--shadow);
}
.page-title .main {
  display: block; font-family: var(--font-title); font-weight: 900;
  font-size: calc(var(--page-w) * var(--title-scale)); color: var(--title-color);
  text-shadow: var(--shadow);
}

/* 小节标题 */
.heading {
  font-family: var(--font-heading); font-weight: 900;
  font-size: calc(var(--page-w) * var(--heading-scale)); color: var(--heading-color);
  margin: .9em 0 .3em; letter-spacing: .05em;
  text-shadow: var(--shadow);
  position: relative; padding-left: .45em;
}
.heading::before {
  content: ""; position: absolute; left: 0; top: .12em; bottom: .12em;
  width: .16em; background: var(--heading-color); border-radius: 2px;
}

/* 段落（正文不加粗，标题加粗由 heading 承担） */
.para {
  font-size: calc(var(--page-w) * var(--body-scale)); line-height: 1.2;
  font-weight: 400;
  text-align: justify; text-indent: 2em; letter-spacing: 0; margin-bottom: .2em;
  text-shadow: var(--shadow);
}

/* 引言 / 诗词 */
.quote {
  margin: 1em 0; padding: .7em .9em;
  border-left: .18em solid var(--title-color);
  font-family: var(--font-title); font-size: calc(var(--page-w) * var(--body-scale));
  line-height: 1.8; letter-spacing: .03em; white-space: pre-line;
}
.quote .author { display: block; text-align: right; font-size: .8em; margin-top: .5em; color: var(--title-color); }

/* 馆藏文献图页（按图片编号分组；自动按张数与横竖排版，点开单张放大） */
/* 图库为页内最后一个块时：占满标题下剩余高度，图片+图注整体垂直居中 → 单图页/双图页不再下半截空 */
.gallery { margin-top: calc(.8em + var(--page-h) * var(--g-top, 0)); display: flex; flex-direction: column; }
.content > .gallery:last-child { flex: 1; min-height: 0; }
.content > .gallery:last-child .g-block { margin: auto 0; }
.gallery .g-block { display: flex; flex-direction: column; }
.gallery .imgs {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: center;
  gap: calc(var(--page-w) * .035);
}
.gallery .im { display: flex; flex-direction: column; align-items: center; flex: none; }
.gallery .im img {
  cursor: zoom-in; height: auto; display: block; width: auto; max-width: 100%;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,.35));
}
/* 单图：居中放大，占屏比例更高（可经 --g-scale 再放大，--g-fit 为安全带收缩） */
.gallery.g-one .im { max-width: calc(96% * var(--g-scale, 1) * var(--g-fit, 1)); }
.gallery.g-one .im img { max-height: calc(var(--page-h) * .6 * var(--g-scale, 1) * var(--g-fit, 1)); }
/* 两张竖版：并排、对齐、等高（高度由 JS 按两图比例算出 --ph） */
.gallery.g-two-v .imgs { align-items: center; }
.gallery.g-two-v .im img { height: calc(var(--ph, auto) * var(--g-fit, 1)); max-height: calc(var(--page-h) * .6 * var(--g-scale, 1) * var(--g-fit, 1)); }
/* 两张横版 / 一横一竖：上下堆叠、居中对齐 */
.gallery.g-two-h .imgs { flex-direction: column; align-items: center; }
.gallery.g-two-h .im { max-width: calc(88% * var(--g-scale, 1) * var(--g-fit, 1)); }
.gallery.g-two-h .im img { max-height: calc(var(--page-h) * .3 * var(--g-scale, 1) * var(--g-fit, 1)); }
.gallery.g-two-h .im.tall img { max-height: calc(var(--page-h) * .36 * var(--g-scale, 1) * var(--g-fit, 1)); }
/* 三张及以上：整齐两列网格（不交错位移） */
.gallery.g-many .im { max-width: calc(47% * var(--g-scale, 1) * var(--g-fit, 1)); }
.gallery.g-many .im img { max-height: calc(var(--page-h) * .42 * var(--g-scale, 1) * var(--g-fit, 1)); }
/* 文字页补图（X.Y.0）：贴页底（不参与垂直居中伸展） */
.gallery.g-zero { flex: none; margin-top: auto; padding-top: calc(var(--page-h) * .05); }
.gallery.g-zero .g-block { margin: 0; }
.gallery.g-zero .im img { max-height: calc(var(--page-h) * .4 * var(--g-fit, 1)); }

/* 图注：标题与第二行（出版信息等）同字号；多图各自图注用 .im-cap */
.gallery .cap-title, .gallery .cap-desc, .gallery .im-cap {
  font-family: var(--font-caption); font-weight: 700;
  font-size: calc(var(--page-w) * var(--caption-title-scale) * var(--cap-scale, 1));
  line-height: 1.4; color: var(--caption-color); text-align: center;
  text-shadow: var(--shadow);
}
.gallery .cap-title { margin-top: .4em; }
.gallery .cap-desc { opacity: .8; margin-top: .1em; }
.gallery .im-cap { margin-top: .35em; max-width: 100%; }

/* 文字白描边/光晕（theme.json parts.*.halo 启用，压深色底图时保证可读；默认透明） */
.content :is(.kicker, .main, .heading, .para, .quote, .quote .author, .cap-title, .cap-desc, .im-cap) {
  text-shadow: var(--shadow), var(--text-halo);
}

/* 内容占位（待补充的页面） */
.placeholder {
  position: absolute; left: 0; right: 0; top: 62%; text-align: center;
  font-size: calc(var(--page-w) * .022); color: rgba(0,0,0,.35); letter-spacing: .2em;
}

/* 浮动目录按钮（无标题栏，仅一个角落小按钮） */
#btn-toc {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 14px; z-index: 30;
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 0; cursor: pointer; font-size: 18px;
  background: rgba(0,0,0,.25); color: #fdf8c2;
  border: 1px solid rgba(253,248,194,.18);
}

/* 底部翻页 */
.nav {
  position: fixed; left: 0; right: 0; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 30;
  display: flex; justify-content: space-between; padding: 0 14px; pointer-events: none;
}
.nav button {
  pointer-events: auto; border: 0; border-radius: 999px; cursor: pointer;
  padding: 9px 18px; font-size: 14px; background: rgba(0,0,0,.28); color: #fdf8c2;
  border: 1px solid rgba(253,248,194,.2);
}
.nav button[disabled] { opacity: .3; }

/* 目录抽屉 */
#index-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; max-height: 72%;
  padding: 18px 20px calc(22px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(58,18,10,.97), rgba(20,16,14,.98));
  border-top: 1px solid rgba(253,248,194,.25); border-radius: 16px 16px 0 0;
  transform: translateY(105%); transition: transform .4s cubic-bezier(.22,.9,.3,1);
  overflow-y: auto;
}
#index-sheet.open { transform: translateY(0); }
#index-sheet h3 { color: #fdf8c2; letter-spacing: 4px; font-size: 16px; margin-bottom: 10px; }
#index-sheet button {
  display: block; width: 100%; text-align: left; margin-bottom: 6px;
  padding: 9px 14px; background: rgba(253,248,194,.06);
  border: 1px solid rgba(253,248,194,.22); border-radius: 8px;
  color: #f2e8c8; font-size: 14px; cursor: pointer;
}
#index-sheet button.nav-index, #index-sheet button.nav-part { font-weight: 700; }
#index-sheet button.nav-unit { padding-left: 22px; font-weight: 400; }
#index-sheet button.nav-unit .u-no { font-size: 11px; color: #b3a686; letter-spacing: 2px; }
#index-sheet button.nav-unit .u-title { font-size: 14px; }

/* 前言三块（第一部分/第二部分/第三部分） */
#part-blocks {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 38;
  padding: 0 16px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
  transform: translateY(105%); transition: transform .4s cubic-bezier(.22,.9,.3,1);
  pointer-events: none;
}
#part-blocks.open { transform: translateY(0); pointer-events: auto; }
#part-blocks button {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 15px 18px; border-radius: 12px; cursor: pointer; text-align: left;
  background: linear-gradient(180deg, rgba(58,18,10,.96), rgba(40,14,9,.96));
  border: 1px solid rgba(253,248,194,.28);
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
#part-blocks button b {
  flex: none; font-family: var(--font-title); font-size: 22px; color: #fdf8c2;
  letter-spacing: 2px;
}
#part-blocks button span { font-size: 14px; color: #e8dcc0; letter-spacing: 1px; }

/* 放大细读 lightbox */
#lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.94);
  display: none; align-items: center; justify-content: center; flex-direction: column;
}
#lightbox.open { display: flex; }
#lightbox .lb-img {
  max-width: 96vw; max-height: 74vh; object-fit: contain;
  background: #fff; box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
#lightbox .lb-cap { color: #eee; font-size: 14px; margin-top: 14px; max-width: 88vw; text-align: center; line-height: 1.6; }
#lightbox .lb-close {
  position: absolute; top: 12px; right: 16px; font-size: 30px; line-height: 1;
  color: #fff; background: none; border: 0; cursor: pointer;
}
#lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 34px; color: #fff; background: none; border: 0; cursor: pointer; padding: 14px; }
#lightbox .lb-nav.prev { left: 4px; }
#lightbox .lb-nav.next { right: 4px; }
#lightbox .lb-count { position: absolute; top: 14px; left: 16px; color: #bbb; font-size: 13px; }

/* ==================== PC 三栏 ==================== */
#pc-layout { display: block; }
#left-nav, #right-panel { display: none; }

body.pc #pc-layout { display: flex; height: 100vh; overflow: hidden; }
body.pc .stage { position: relative; flex: 1; min-width: 0; height: 100vh; }

/* 左栏：目录（封面/前言/结语 + 各部分一行 + 各单元两行缩进） */
body.pc #left-nav {
  display: flex; flex-direction: column; flex: none;
  width: var(--side-w); overflow-y: auto;
  background: rgba(18,14,12,.96); border-right: 1px solid rgba(253,248,194,.14);
  padding: 14px 0 20px;
  scrollbar-width: thin; scrollbar-color: rgba(253,248,194,.22) transparent;
}
#left-nav::-webkit-scrollbar { width: 6px; }
#left-nav::-webkit-scrollbar-thumb { background: rgba(253,248,194,.2); border-radius: 3px; }
#left-nav button {
  display: block; width: calc(100% - 16px); text-align: left;
  margin: 0 8px 2px; padding: 7px 12px; border: 0; border-radius: 5px;
  background: transparent; color: #e8dcc0; font-size: 14px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#left-nav button:hover { background: rgba(253,248,194,.08); }
#left-nav button.active { background: rgba(139,37,19,.55); color: #fdf8c2; border-left: 2px solid #fdf8c2; }
/* 封面/前言/结语/部分：加粗 */
#left-nav button.nav-index, #left-nav button.nav-part { font-weight: 700; color: #f2e8c8; }
#left-nav button.nav-part { margin-top: 8px; font-size: 15px; }
/* 单元：两行、缩进、不加粗 */
#left-nav button.nav-unit { padding: 5px 12px 6px 26px; font-weight: 400; }
#left-nav button.nav-unit .u-no { font-size: 11px; color: #b3a686; letter-spacing: 2px; }
#left-nav button.nav-unit .u-title { font-size: 14px; color: #ddd2ba; }

/* 右栏：当前页图片放大面板（无图时留空深色底） */
body.pc #right-panel {
  display: flex; flex-direction: column; flex: none;
  width: var(--side-w); overflow-y: auto;
  background: rgba(18,14,12,.96); border-left: 1px solid rgba(253,248,194,.14);
  padding: 22px 22px; gap: 14px;
  scrollbar-width: thin; scrollbar-color: rgba(253,248,194,.22) transparent;
}
#right-panel::-webkit-scrollbar { width: 6px; }
#right-panel::-webkit-scrollbar-thumb { background: rgba(253,248,194,.2); border-radius: 3px; }
#right-panel .rp-title { font-family: var(--font-caption); font-weight: 700; font-size: 18px; color: #f2e8c8; text-align: center; letter-spacing: 1px; }
#right-panel .rp-desc { font-size: 13px; color: #b3a686; text-align: center; }
#right-panel .rp-imgs { display: flex; flex-direction: column; gap: 18px; align-items: center; }
#right-panel .rp-imgs img { max-width: 100%; height: auto; box-shadow: 0 8px 26px rgba(0,0,0,.55); }

/* PC 隐藏移动端 chrome */
body.pc #btn-toc, body.pc .nav { display: none; }

/* PC 页面尺寸：左右栏等宽 → 中栏居中；页宽自适应中栏 */
body.pc {
  --side-w: clamp(340px, 24vw, 480px);
  --mid-w: calc(100vw - 2 * var(--side-w));
  --page-w: min(var(--mid-w), calc(100vh * var(--ratio)));
  --page-h: min(calc(var(--mid-w) / var(--ratio)), 100vh);
}
body.pc #part-blocks { display: none; }

/* ==================== 背景音乐开关（仅 PC 左下角，高透明） ==================== */
#bgm-toggle {
  position: fixed; left: 12px; bottom: 12px; z-index: 30;
  width: 38px; height: 38px; border-radius: 50%;
  display: none; align-items: center; justify-content: center;
  background: none; border: 1px solid rgba(253,248,194,.22);
  color: #fdf8c2; cursor: pointer; opacity: .26;
  transition: opacity .3s;
}
#bgm-toggle:hover { opacity: .92; }
#bgm-toggle svg { width: 18px; height: 18px; }
#bgm-toggle.playing { opacity: .5; }
#bgm-toggle.playing svg { animation: note-pulse 1.6s ease-in-out infinite; }
@keyframes note-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
body.pc #bgm-toggle { display: flex; }
