/* ============================================================
   工程手记 · 翻书站样式
   ============================================================ */

:root {
  --page-w: min(37vw, 450px);
  --page-h: calc(var(--page-w) * 1.16);
  --paper: #f7f2e7;
  --paper-deep: #efe7d5;
  --ink: #2c2a26;
  --ink-soft: #6b6459;
  --cover: #102a2f;
  --accent: #c9a86a;
  --flip-ease: cubic-bezier(0.4, 0.1, 0.2, 1);
}

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

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(1200px 700px at 50% 28%, #3d3731, #211d19 72%);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
}

/* ---------- 舞台与书本 ---------- */

.book-viewport {
  position: relative;
  width: calc(var(--page-w) * 2);
  height: var(--page-h);
  perspective: 2400px;
}

#book { position: absolute; inset: 0; transform-style: preserve-3d; }

.book-shadow {
  position: absolute;
  left: 3%; right: 3%; bottom: -22px; height: 34px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.5), transparent 68%);
  filter: blur(9px);
}

/* ---------- 书页（张） ---------- */

.sheet {
  position: absolute;
  left: 50%; top: 0;
  width: var(--page-w);
  height: var(--page-h);
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.9s var(--flip-ease);
}

.sheet.flipped { transform: rotateY(-180deg); }

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background:
    linear-gradient(to right, rgba(0, 0, 0, 0.08), transparent 6%),
    var(--paper);
  border-radius: 3px 8px 8px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7% 8%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.face.back {
  transform: rotateY(180deg);
  border-radius: 8px 3px 3px 8px;
  background:
    linear-gradient(to left, rgba(0, 0, 0, 0.08), transparent 6%),
    var(--paper-deep);
}

/* ---------- 内容页 ---------- */

.face img {
  flex: 1;
  min-height: 0;
  max-width: 100%;
  object-fit: contain;
}

.caption { text-align: center; padding-top: 4%; }

.cap-title {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: calc(var(--page-w) * 0.052);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.12em;
}

.cap-note {
  margin-top: 0.5em;
  font-size: calc(var(--page-w) * 0.032);
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}

/* ---------- 封面 / 扉页 / 封底 ---------- */

.sheet.cover .face.front { background: var(--cover); }

.cover-inner { width: 100%; height: 100%; padding: 5%; }

.cover-frame {
  width: 100%; height: 100%;
  border: 1px solid rgba(201, 168, 106, 0.55);
  outline: 1px solid rgba(201, 168, 106, 0.2);
  outline-offset: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--page-h) * 0.045);
}

.cover-mark { color: var(--accent); font-size: calc(var(--page-w) * 0.075); }

.cover-title {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: calc(var(--page-w) * 0.135);
  font-weight: 700;
  color: var(--paper);
  letter-spacing: 0.22em;
  text-indent: 0.22em; /* 视觉居中补偿 */
}

.cover-sub {
  font-size: calc(var(--page-w) * 0.04);
  color: rgba(247, 242, 231, 0.75);
  letter-spacing: 0.3em;
}

.cover-years {
  font-family: Georgia, serif;
  font-size: calc(var(--page-w) * 0.036);
  color: var(--accent);
  letter-spacing: 0.24em;
}

.titlepage { text-align: center; }

.tp-title {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: calc(var(--page-w) * 0.088);
  color: var(--ink);
  letter-spacing: 0.18em;
}

.tp-sub {
  margin-top: 1em;
  font-size: calc(var(--page-w) * 0.036);
  color: var(--ink-soft);
  letter-spacing: 0.22em;
}

.tp-colophon {
  margin-top: 3.2em;
  font-size: calc(var(--page-w) * 0.032);
  color: var(--ink-soft);
  letter-spacing: 0.12em;
}

.endpage { text-align: center; }

.end-mark { color: var(--accent); font-size: calc(var(--page-w) * 0.06); }

.end-note {
  margin-top: 1.4em;
  font-family: "Songti SC", "STSong", serif;
  font-size: calc(var(--page-w) * 0.045);
  color: var(--ink-soft);
  letter-spacing: 0.3em;
}

/* ---------- 书脊 / 书口 ---------- */

.spine {
  position: absolute;
  left: 50%; top: 1.5%;
  transform: translateX(-50%);
  width: 26px; height: 97%;
  background: linear-gradient(to right, rgba(0,0,0,0.28), rgba(0,0,0,0.05) 45%, rgba(0,0,0,0.05) 55%, rgba(0,0,0,0.28));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  pointer-events: none;
  z-index: 60;
}

.spine .stitch {
  width: 3px; height: 13px;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0.85;
}

.fore-edge {
  position: absolute;
  top: 2%; height: 96%;
  width: 7px;
  background: repeating-linear-gradient(to right, #e8e0cf 0 1px, #cfc5ac 1px 2px);
  border-radius: 2px;
  pointer-events: none;
  z-index: 1;
}

.fore-edge-left { left: calc(50% - 8px); transform: scaleX(-1); }
.fore-edge-right { left: calc(50% + 1px); }

/* ---------- 点击交互 / 提示 / 页码 ---------- */

.open-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(247, 242, 231, 0.85);
  font-size: 15px;
  letter-spacing: 0.18em;
  transition: opacity 0.4s;
}

.open-hint.hidden { opacity: 0; pointer-events: none; }

.hint-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.5); opacity: 1; }
}

.page-indicator {
  min-height: 1.4em;
  font-family: Georgia, serif;
  font-size: 13px;
  color: rgba(201, 168, 106, 0.8);
  letter-spacing: 0.2em;
}

/* ---------- 返回按钮 ---------- */

.back-btn {
  position: fixed;
  top: 22px; left: 22px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(247, 242, 231, 0.3);
  background: rgba(33, 29, 25, 0.6);
  color: rgba(247, 242, 231, 0.9);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s, background 0.2s;
  z-index: 100;
}

.back-btn.visible { opacity: 1; pointer-events: auto; }
.back-btn:hover { background: rgba(60, 52, 44, 0.85); }

/* ---------- 系列标签 / 页脚 / 阅读提示 ---------- */

.series-tag {
  position: absolute;
  top: 5.5%;
  left: 50%;
  transform: translateX(-50%);
  font-size: calc(var(--page-w) * 0.026);
  letter-spacing: 0.26em;
  text-indent: 0.26em;
  color: #f7f2e7;
  padding: 0.4em 1.2em;
  border-radius: 999px;
  white-space: nowrap;
}

.s-eng { background: #4a6b6d; }
.s-taste { background: #a08144; }
.s-med { background: #7d5a68; }
.s-risk { background: #5a6e4f; }

.page-foot {
  margin-top: 0.9em;
  font-size: calc(var(--page-w) * 0.03);
  color: #9a7b3f;
  letter-spacing: 0.22em;
}

.page-foot:hover { text-decoration: underline; text-underline-offset: 4px; }

.card-page .page-foot { margin-top: 0; } /* 间距交给 flex gap */

/* ---------- 样式卡封面页（无图文章） ---------- */

.card-page {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--page-h) * 0.035);
  padding: 0 5%;
}

.card-orn { color: var(--accent); font-size: calc(var(--page-w) * 0.05); }

.card-rule {
  width: 32%;
  height: 1px;
  background: rgba(201, 168, 106, 0.6);
}

.card-title {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: calc(var(--page-w) * 0.058);
  font-weight: 700;
  line-height: 1.6;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-align: center;
}

.card-note {
  font-size: calc(var(--page-w) * 0.031);
  line-height: 1.9;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- 阅读全文操作条 ---------- */

.action-bar {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.read-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 28px;
  border-radius: 999px;
  border: 1px solid rgba(201, 168, 106, 0.5);
  background: rgba(201, 168, 106, 0.14);
  color: #e8d9b0;
  font-size: 14px;
  letter-spacing: 0.2em;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.35s, transform 0.35s, background 0.2s;
}

.read-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.read-btn:hover { background: rgba(201, 168, 106, 0.3); }

/* ---------- 站内阅读器 ---------- */

.reader {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--paper);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.reader.open { opacity: 1; visibility: visible; }

.reader-close {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(44, 42, 38, 0.25);
  background: rgba(247, 242, 231, 0.9);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  z-index: 210;
  transition: background 0.2s;
}

.reader-close:hover { background: var(--paper-deep); }

.reader-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 64px 20px 100px;
}

.reader-body {
  max-width: 720px;
  margin: 0 auto;
  color: #33312c;
  font-size: 16.5px;
  line-height: 1.9;
  -webkit-user-select: text;
  user-select: text;
}

.reader-body h1 {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: 30px;
  line-height: 1.45;
  letter-spacing: 0.04em;
  margin: 0.2em 0 0.9em;
}

.reader-body h2 {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: 23px;
  margin: 1.7em 0 0.6em;
  border-left: 4px solid var(--accent);
  padding-left: 0.55em;
}

.reader-body h3 { font-size: 19px; margin: 1.4em 0 0.5em; }

.reader-body p { margin: 0.9em 0; }

.reader-body a {
  color: #8a6d3b;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.reader-body img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5em auto;
  border-radius: 6px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.12);
}

.reader-body blockquote {
  margin: 1.2em 0;
  padding: 0.6em 1.2em;
  border-left: 3px solid var(--accent);
  background: var(--paper-deep);
  color: var(--ink-soft);
}

.reader-body code {
  background: #ece5d2;
  padding: 0.15em 0.45em;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

.reader-body pre {
  background: #2c2a26;
  color: #e8e2d2;
  padding: 1.1em 1.3em;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.3em 0;
}

.reader-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 0.85em;
}

.reader-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.3em 0;
  font-size: 0.92em;
}

.reader-body th,
.reader-body td {
  border: 1px solid #d8cfb8;
  padding: 0.5em 0.8em;
  text-align: left;
}

.reader-body th { background: var(--paper-deep); }

.reader-body hr {
  border: none;
  border-top: 1px solid #d8cfb8;
  width: 60%;
  margin: 2.2em auto;
}

.reader-body ul,
.reader-body ol { padding-left: 1.5em; margin: 0.8em 0; }
.reader-body li { margin: 0.35em 0; }

.reader-body .mermaid {
  margin: 1.6em auto;
  padding: 0.8em;
  text-align: center;
  overflow-x: auto;
}

.reader-loading,
.reader-error {
  text-align: center;
  margin-top: 18vh;
  color: var(--ink-soft);
  letter-spacing: 0.18em;
}

/* ---------- 小屏适配 ---------- */

@media (max-width: 700px) {
  :root { --page-w: 42vw; }
  .spine { width: 14px; }
  .spine .stitch { height: 9px; }
}
