:root {
  --ink: #24160d;
  --ink-soft: #4a3424;
  --vermilion: #9e1d2a;
  --gold: #d4b15a;
  --gold-bright: #f0d78c;
  --paper: #f3e2c2;
  --paper-dark: #e4cc9a;
  --desk: #140c08;
  --shadow: rgba(20, 8, 4, 0.55);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--desk);
  color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif;
}

body {
  background:
    radial-gradient(1200px 700px at 50% 40%, #3a2214 0%, #140c08 55%, #090604 100%);
}

#embers {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(ellipse at center, transparent 42%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.25), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.4));
}

.stage {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 16px 24px 20px;
  gap: 10px;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--gold-bright);
  text-shadow: 0 0 12px rgba(212, 177, 90, 0.35);
  font-size: 14px;
  letter-spacing: 0.18em;
}

.hud a.home {
  color: inherit;
  text-decoration: none;
  letter-spacing: 0.2em;
  font-size: 12px;
  border: 1px solid rgba(212, 177, 90, 0.35);
  padding: 8px 12px;
  border-radius: 999px;
}
.hud button {
  appearance: none;
  border: 1px solid rgba(212, 177, 90, 0.45);
  background: linear-gradient(180deg, rgba(80, 48, 22, 0.7), rgba(30, 16, 8, 0.85));
  color: var(--gold-bright);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.12em;
  font-family: inherit;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.hud button:hover {
  transform: translateY(-1px);
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(212, 177, 90, 0.28);
}

.hud .title {
  font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
  font-size: 22px;
  letter-spacing: 0.4em;
}

.book-wrap {
  --book-w: min(980px, 92vw);
  --book-h: min(640px, calc(100vh - 150px));
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 2400px;
  min-height: 0;
}

.nav-hit {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(240, 215, 140, 0.4);
  background: rgba(20, 10, 6, 0.45);
  color: var(--gold-bright);
  font-size: 28px;
  cursor: pointer;
  z-index: 5;
  backdrop-filter: blur(6px);
  transition: transform 0.2s, background 0.2s;
}

.nav-hit:hover {
  transform: translateY(-50%) scale(1.08);
  background: rgba(90, 50, 20, 0.55);
}

.nav-hit.prev { left: max(8px, calc(50% - var(--book-w) / 2 - 76px)); }
.nav-hit.next { right: max(8px, calc(50% - var(--book-w) / 2 - 76px)); }

.book {
  width: var(--book-w);
  height: var(--book-h);
  position: relative;
  transform-style: preserve-3d;
  filter: drop-shadow(0 28px 40px var(--shadow));
  touch-action: none;
  user-select: none;
}

.book.shake {
  animation: shake 0.42s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px) rotateZ(-0.4deg); }
  75% { transform: translateX(6px) rotateZ(0.4deg); }
}

.book::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 10px;
  bottom: 10px;
  width: 18px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #3a1c12, #6b3a22 40%, #2a140d);
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.5);
  z-index: 4;
  border-radius: 2px;
  pointer-events: none;
}

.sheet {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  transform-style: preserve-3d;
}

.page {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(90, 50, 20, 0.08), transparent 8%),
    repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(90, 60, 20, 0.035) 28px),
    radial-gradient(circle at 20% 10%, rgba(255, 250, 230, 0.45), transparent 40%),
    linear-gradient(180deg, var(--paper), var(--paper-dark));
  color: var(--ink);
  box-shadow: inset 0 0 80px rgba(90, 50, 10, 0.12);
}

.page.left {
  border-radius: 8px 0 0 8px;
  transform-origin: right center;
  box-shadow: inset -18px 0 30px rgba(80, 40, 10, 0.08);
}

.page.right {
  border-radius: 0 8px 8px 0;
  transform-origin: left center;
  box-shadow: inset 18px 0 30px rgba(80, 40, 10, 0.08);
}

.page-inner {
  height: 100%;
  padding: 36px 40px 48px;
  overflow: hidden;
  position: relative;
}

.page-inner::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(158, 29, 42, 0.18);
  pointer-events: none;
}

.flipper {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  pointer-events: none;
  z-index: 6;
  will-change: transform;
}

.flipper.forward {
  right: 0;
  transform-origin: left center;
}

.flipper.back {
  left: 0;
  transform-origin: right center;
}

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  overflow: hidden;
  background:
    linear-gradient(180deg, var(--paper), var(--paper-dark));
}

.flipper.forward .flip-face.front {
  border-radius: 0 8px 8px 0;
}

.flipper.forward .flip-face.back {
  transform: rotateY(180deg);
  border-radius: 8px 0 0 8px;
}

.flipper.back .flip-face.front {
  border-radius: 8px 0 0 8px;
}

.flipper.back .flip-face.back {
  transform: rotateY(-180deg);
  border-radius: 0 8px 8px 0;
}

.flipper.full {
  width: 100%;
  left: 0;
  right: 0;
  transform-origin: left center;
}

.flipper .shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,.28), transparent 18%, transparent 82%, rgba(0,0,0,.12));
  mix-blend-mode: multiply;
  z-index: 3;
}

.fold {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 7;
  mix-blend-mode: multiply;
}

.book.cover-spread .sheet {
  grid-template-columns: 1fr;
}
.book.cover-spread .page.left { display: none; }
.book.cover-spread .page.right { border-radius: 8px; }
.book.cover-spread::before { display: none; }

.cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(240, 215, 140, 0.18), transparent 45%),
    linear-gradient(180deg, #4a1d16, #2a0f0c 40%, #1a0a08);
  color: var(--gold-bright);
  border-radius: 8px;
}

.cover .seal {
  width: 72px;
  height: 72px;
  border: 3px solid #c44536;
  color: #e25a48;
  display: grid;
  place-items: center;
  font-family: "Ma Shan Zheng", serif;
  font-size: 28px;
  margin-bottom: 18px;
  transform: rotate(-8deg);
  box-shadow: 0 0 0 4px rgba(196, 69, 54, 0.15);
}

.cover h1 {
  font-family: "Ma Shan Zheng", serif;
  font-size: clamp(56px, 8vw, 92px);
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 18px rgba(240, 215, 140, 0.25);
}

.cover .sub {
  margin-top: 12px;
  letter-spacing: 0.5em;
  opacity: 0.85;
}

.cover .hint {
  margin-top: 48px;
  font-size: 13px;
  letter-spacing: 0.28em;
  animation: pulse 2.4s ease-in-out infinite;
}

.cover.end h1 {
  font-size: clamp(40px, 6vw, 72px);
}

.blank {
  display: grid;
  place-items: center;
  color: rgba(74, 52, 36, 0.35);
  letter-spacing: 0.4em;
}

.verse .ci {
  margin-top: 18px;
  font-size: 18px;
  letter-spacing: 0.3em;
  color: var(--vermilion);
}

@keyframes pulse {
  0%, 100% { opacity: 0.45; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-4px); }
}

.verse {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-family: "Ma Shan Zheng", serif;
  font-size: clamp(22px, 2.4vw, 32px);
  line-height: 1.7;
}

.toc h2, .chapter-head {
  font-family: "ZCOOL XiaoWei", "Noto Serif SC", serif;
  color: var(--vermilion);
  text-align: center;
  letter-spacing: 0.2em;
  margin-bottom: 18px;
  font-weight: 400;
}

.toc-list {
  display: grid;
  gap: 8px;
}

.toc-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(90, 50, 20, 0.18);
  font-size: 14px;
}

.toc-item:hover {
  color: var(--vermilion);
}

.chapter-head {
  font-size: 20px;
  line-height: 1.5;
}

.prose p {
  text-align: justify;
  text-indent: 2em;
  line-height: 1.95;
  font-size: 16px;
  margin-bottom: 0.35em;
}

.folio {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16px;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
  z-index: 2;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: rgba(240, 215, 140, 0.8);
  font-size: 13px;
  letter-spacing: 0.16em;
}

.progress {
  width: min(420px, 50vw);
  height: 4px;
  background: rgba(240, 215, 140, 0.15);
  border-radius: 99px;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8a1c24, var(--gold));
  box-shadow: 0 0 12px rgba(240, 215, 140, 0.6);
  transition: width 0.35s ease;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(360px, 92vw);
  height: 100%;
  background: linear-gradient(180deg, #2a160e, #140b07);
  color: var(--gold-bright);
  z-index: 20;
  transform: translateX(110%);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: -20px 0 40px rgba(0, 0, 0, 0.4);
  padding: 24px 18px;
  overflow: auto;
}

.drawer.open { transform: translateX(0); }

.drawer h3 {
  font-family: "Ma Shan Zheng", serif;
  font-size: 28px;
  letter-spacing: 0.3em;
  margin-bottom: 16px;
}

.drawer button.ch {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  padding: 8px 6px;
  cursor: pointer;
  border-bottom: 1px solid rgba(240, 215, 140, 0.12);
}

.drawer button.ch:hover { color: #fff3c4; }

.loader {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: #120a07;
  color: var(--gold-bright);
  text-align: center;
}

.loader h2 {
  font-family: "Ma Shan Zheng", serif;
  font-size: 48px;
  letter-spacing: 0.4em;
  margin-bottom: 12px;
}

.loader .bar {
  width: 220px;
  height: 3px;
  margin: 20px auto 0;
  background: rgba(240, 215, 140, 0.2);
  overflow: hidden;
}

.loader .bar span {
  display: block;
  height: 100%;
  width: 40%;
  background: var(--gold);
  animation: load 1.1s ease-in-out infinite;
}

.loader.hide {
  opacity: 0;
  transition: opacity 0.55s ease;
}

@keyframes load {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(350%); }
}

.splash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
}

.measure {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  left: -9999px;
  top: 0;
}

@media (max-width: 860px) {
  .book-wrap {
    --book-w: min(520px, 94vw);
    --book-h: min(720px, calc(100vh - 140px));
  }
  .book.single .page.left {
    display: none;
  }
  .book.single::before {
    display: none;
  }
  .sheet {
    grid-template-columns: 1fr;
  }
  .page.right {
    border-radius: 8px;
  }
  .book::before { display: none; }
  .nav-hit.prev { left: 6px; }
  .nav-hit.next { right: 6px; }
  .page-inner { padding: 28px 22px 44px; }
  .prose p { font-size: 15px; line-height: 1.85; }
  .hud .title { font-size: 18px; letter-spacing: 0.24em; }
}
