:root {
  --ink: #17130f;
  --parchment: #f2eadc;
  --scar: #8d3030;
  --gold: #b9a46d;
  --gold-soft: #d5c48e;
  --mist: #bbb6ae;
  --left-stack: 2px;
  --right-stack: 18px;
  --turn-progress: 0;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  overflow-x: hidden;
  color: var(--parchment);
  font-family: Georgia, "Times New Roman", serif;
  background:
    linear-gradient(rgba(7,7,8,.84), rgba(8,8,9,.95)),
    url("../images/background1.png") center / cover fixed no-repeat;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 43%, rgba(185,164,109,.13), transparent 31%),
    radial-gradient(circle at 50% 55%, transparent 28%, rgba(0,0,0,.45) 80%);
}

a { color: inherit; }
button { font: inherit; }

.archive-bar {
  width: min(1180px, calc(100% - 32px));
  min-height: 68px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid rgba(185,164,109,.18);
}
.archive-bar a {
  text-decoration: none;
  color: var(--gold-soft);
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: .7rem;
}
.archive-status {
  color: #8f8a82;
  font-size: .66rem;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.page-wrapper {
  min-height: calc(100vh - 68px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 38px 18px 54px;
}

.book-header {
  width: min(850px, 100%);
  text-align: center;
  margin-bottom: 22px;
  position: relative;
  z-index: 60;
}
.book-header .eyebrow {
  margin: 0 0 8px;
  color: var(--scar);
  font-size: .69rem;
  letter-spacing: .27em;
  text-transform: uppercase;
}
.book-header h1 {
  margin: 0;
  color: var(--parchment);
  font-size: clamp(2.2rem, 5.4vw, 4.2rem);
  line-height: 1;
  letter-spacing: .08em;
  font-weight: 500;
}
.book-header h2 {
  margin: 11px 0 0;
  color: var(--mist);
  font-weight: 400;
  font-size: 1rem;
  letter-spacing: .04em;
}

.reading-stage {
  width: min(1220px, 100%);
  min-height: 750px;
  position: relative;
  display: grid;
  place-items: center;
  padding: 28px 18px 34px;
  border-top: 1px solid rgba(185,164,109,.16);
  border-bottom: 1px solid rgba(185,164,109,.16);
  background:
    linear-gradient(90deg, rgba(0,0,0,.34), transparent 25%, transparent 75%, rgba(0,0,0,.34)),
    radial-gradient(ellipse at center, rgba(185,164,109,.04), transparent 58%),
    rgba(7,7,8,.34);
}
.reading-stage::before,
.reading-stage::after {
  content: "";
  position: absolute;
  top: 50%;
  width: min(210px, 17vw);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(185,164,109,.3));
}
.reading-stage::before { left: 0; }
.reading-stage::after { right: 0; transform: rotate(180deg); }

.stage-note {
  position: absolute;
  top: 50%;
  width: 168px;
  transform: translateY(-50%);
  color: #77736d;
  font-size: .65rem;
  line-height: 1.75;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.stage-note.left { left: 22px; text-align: right; }
.stage-note.right { right: 22px; }
.stage-note strong {
  display: block;
  margin-bottom: 8px;
  color: #aaa392;
  font-weight: 400;
}

.book-rig {
  position: relative;
  width: min(930px, calc(100vw - 56px));
  min-height: 660px;
  display: flex;
  align-items: center;
  justify-content: center;
  isolation: isolate;
}

.book-shadow {
  position: absolute;
  z-index: -8;
  left: 50%;
  bottom: 24px;
  width: min(760px, 78%);
  height: 58px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(0,0,0,.68);
  filter: blur(24px);
  opacity: .88;
  transition: width .45s ease, opacity .25s ease, filter .25s ease;
}
.reading-stage.is-flipping .book-shadow {
  width: min(820px, 84%);
  opacity: 1;
  filter: blur(30px);
}

.paper-stack {
  position: absolute;
  top: 50%;
  width: clamp(260px, 34vw, 430px);
  aspect-ratio: 420 / 620;
  transform: translateY(-50%);
  border-radius: 2px 6px 6px 2px;
  pointer-events: none;
  z-index: -4;
  opacity: .8;
}
.paper-stack::before,
.paper-stack::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #cbbd9e;
  border: 1px solid rgba(54,38,23,.18);
}
.paper-stack::after {
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255,255,255,.28) 0,
      rgba(255,255,255,.28) 1px,
      rgba(71,49,27,.12) 1px,
      rgba(71,49,27,.12) 2px,
      transparent 2px,
      transparent 4px
    ),
    #d5c8aa;
}
.paper-stack-left {
  right: 50%;
  margin-right: -1px;
  transform: translateY(-50%) translateX(calc(var(--left-stack) * -0.6));
  box-shadow:
    calc(var(--left-stack) * -1) 0 0 #b7a887,
    calc(var(--left-stack) * -1.6) 3px 10px rgba(0,0,0,.32);
  clip-path: inset(0 0 0 calc(100% - max(var(--left-stack), 2px)));
}
.paper-stack-right {
  left: 50%;
  margin-left: -1px;
  transform: translateY(-50%) translateX(calc(var(--right-stack) * .6));
  box-shadow:
    var(--right-stack) 0 0 #b7a887,
    calc(var(--right-stack) * 1.6) 3px 10px rgba(0,0,0,.32);
  clip-path: inset(0 calc(100% - max(var(--right-stack), 2px)) 0 0);
}

.spine-shadow {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: min(620px, 82vw);
  max-height: 620px;
  transform: translate(-50%, -50%);
  z-index: 30;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.45), rgba(0,0,0,.14) 35%, transparent 72%);
  filter: blur(3px);
  transition: opacity .45s ease;
}
.book-rig.is-open .spine-shadow { opacity: .8; }

.flipbook {
  position: relative;
  z-index: 5;
  width: 100%;
  height: 640px;
  filter: drop-shadow(0 26px 32px rgba(0,0,0,.28));
  transition: filter .25s ease, transform .25s ease;
}
.flipbook:not(.is-ready) .book-page:not(:first-child) { display: none; }
.reading-stage.is-flipping .flipbook { filter: drop-shadow(0 35px 38px rgba(0,0,0,.42)); }

/* StPageFlip creates these elements at runtime. */
.stf__parent { margin: 0 auto; }
.stf__block { perspective: 2600px !important; }
.stf__item { overflow: hidden; }
.stf__outerShadow,
.stf__innerShadow,
.stf__hardShadow,
.stf__hardInnerShadow { mix-blend-mode: multiply; }

.book-page {
  position: relative;
  overflow: hidden;
  background: #d7c7a8;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(69,49,28,.14);
  user-select: none;
  -webkit-user-select: none;
}

.parchment-page {
  background:
    linear-gradient(90deg, rgba(57,39,23,.14), transparent 7%, transparent 92%, rgba(57,39,23,.08)),
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(71,47,25,.04)),
    url("../images/page.png") center / cover no-repeat;
}
.parchment-page::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 13% 20%, rgba(104,70,35,.06), transparent 16%),
    radial-gradient(circle at 80% 72%, rgba(104,70,35,.05), transparent 19%),
    linear-gradient(90deg, rgba(49,33,19,.12), transparent 4%, transparent 95%, rgba(49,33,19,.07));
  mix-blend-mode: multiply;
}
.parchment-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border: 1px solid rgba(82,55,30,.16);
  box-shadow:
    inset 14px 0 20px rgba(62,42,25,.07),
    inset -8px 0 14px rgba(62,42,25,.04),
    inset 0 0 22px rgba(88,59,30,.045);
}

.cover-page {
  color: var(--parchment);
  border-radius: 2px 8px 8px 2px;
  box-shadow:
    inset -8px 0 18px rgba(0,0,0,.32),
    inset 2px 0 0 rgba(255,255,255,.05),
    0 0 0 1px rgba(204,174,104,.2);
}
.front-cover {
  background:
    linear-gradient(90deg, rgba(0,0,0,.34), transparent 8%, transparent 91%, rgba(0,0,0,.22)),
    url("../images/front-cover.png") center / cover no-repeat;
}
.front-cover::after {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(215,190,125,.18);
  box-shadow: inset 0 0 18px rgba(0,0,0,.24);
  pointer-events: none;
}
.cover-edge {
  position: absolute;
  right: 0;
  top: 1.5%;
  bottom: 1.5%;
  width: 7px;
  border-radius: 0 5px 5px 0;
  background: linear-gradient(90deg, rgba(91,58,28,.15), rgba(231,213,167,.38), rgba(58,35,18,.32));
  box-shadow: 2px 0 3px rgba(0,0,0,.28);
}
.back-cover {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 42%, rgba(153,118,55,.14), transparent 32%),
    linear-gradient(90deg, rgba(0,0,0,.2), transparent 9%, transparent 91%, rgba(0,0,0,.3)),
    #201816;
  border: 1px solid rgba(185,164,109,.24);
}
.back-cover::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(185,164,109,.12);
}
.back-cover-mark {
  color: rgba(213,196,142,.35);
  font-size: .66rem;
  letter-spacing: .28em;
  text-transform: uppercase;
}

.page-content {
  position: relative;
  z-index: 2;
  height: 100%;
  padding: clamp(2.4rem, 6.5vw, 3.7rem) clamp(2rem, 5.4vw, 3.1rem) 3.3rem;
  overflow: hidden;
}
.page-content h3 {
  margin: 0;
  text-align: center;
  color: #49371f;
  text-transform: uppercase;
  letter-spacing: .11em;
  font-size: clamp(.88rem, 2vw, 1.08rem);
  line-height: 1.5;
}
.divider {
  width: 58px;
  height: 1px;
  margin: 18px auto 30px;
  background: var(--scar);
}
.page-content p {
  margin: 0;
  color: var(--ink);
  font-size: clamp(.86rem, 1.8vw, 1rem);
  line-height: 1.7;
}
.page-content p + p { margin-top: 1em; }
.page-content blockquote {
  margin: 2.6rem 0 0;
  padding: 1.2rem 0 0;
  border-top: 1px solid rgba(141,48,48,.3);
  color: #523d2a;
  font-size: .86rem;
  line-height: 1.55;
  font-style: italic;
  text-align: center;
}
.folio {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 20px;
  color: rgba(77,56,35,.55) !important;
  text-align: center;
  font-size: .65rem !important;
  letter-spacing: .15em;
}
.end-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.seal-mark {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  margin-bottom: 26px;
  border: 1px solid rgba(110,39,39,.36);
  border-radius: 50%;
  color: rgba(110,39,39,.55);
  font-size: 2rem;
  font-style: italic;
  box-shadow: inset 0 0 0 5px rgba(110,39,39,.035);
}
.archive-sigil {
  color: rgba(91,66,36,.45);
  font-size: 2.1rem;
  margin-bottom: 20px;
}
.archive-copy {
  color: rgba(63,47,31,.62) !important;
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: .68rem !important;
  line-height: 1.8 !important;
}
.page-action {
  appearance: none;
  margin-top: 30px;
  border: 1px solid rgba(86,64,31,.55);
  background: rgba(255,255,255,.13);
  color: #513e24;
  min-height: 42px;
  padding: 0 18px;
  text-transform: uppercase;
  letter-spacing: .13em;
  font-size: .65rem;
  cursor: pointer;
}
.page-action:hover { background: rgba(99,72,37,.08); }

.book-loading,
.book-error {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 80;
  color: #8e887e;
  text-transform: uppercase;
  letter-spacing: .15em;
  font-size: .62rem;
  pointer-events: none;
}
.book-error {
  width: min(420px, 80%);
  padding: 18px;
  border: 1px solid rgba(141,48,48,.38);
  background: rgba(9,9,10,.9);
  color: #c1aaa5;
  text-align: center;
  line-height: 1.6;
}

.book-controls {
  width: min(760px, 100%);
  margin: 24px auto 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
}
.control-btn {
  appearance: none;
  border: 1px solid rgba(185,164,109,.44);
  background: rgba(8,8,9,.64);
  color: var(--gold-soft);
  min-height: 42px;
  padding: 0 18px;
  font-size: .65rem;
  letter-spacing: .15em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, opacity .2s ease, transform .2s ease;
}
.control-btn:hover:not(:disabled) {
  border-color: var(--gold-soft);
  background: rgba(185,164,109,.08);
  transform: translateY(-1px);
}
.control-btn:disabled { opacity: .28; cursor: default; }
.control-btn.next { justify-self: end; }
.control-btn.prev { justify-self: start; }
.progress-wrap { min-width: 210px; text-align: center; }
.progress-text {
  display: block;
  margin-bottom: 8px;
  color: #9d978d;
  font-size: .63rem;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.progress-track {
  height: 1px;
  background: rgba(185,164,109,.18);
  overflow: hidden;
}
.progress-bar {
  display: block;
  width: 0;
  height: 100%;
  background: var(--gold);
  transition: width .35s ease;
}

.reading-tools {
  width: min(760px, 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-top: 18px;
}
.hint {
  margin: 0;
  color: #78736b;
  font-size: .61rem;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.sound-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: #807b72;
  padding: 5px 0;
  font-size: .6rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
}
.sound-toggle:hover { color: var(--gold-soft); }
.sound-toggle[aria-pressed="true"] .sound-icon { opacity: .35; text-decoration: line-through; }

.exit-link {
  margin-top: 27px;
  color: var(--gold-soft);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: .16em;
  font-size: .66rem;
}
.exit-link:hover { text-decoration: underline; }
.noscript-note {
  margin: 1rem auto 2rem;
  color: #c2b9aa;
  text-align: center;
}


/* Built-in safety mode: keeps the Codex visible and turnable if the external
   page-curl engine is blocked or slow to load. */
.flipbook.fallback-mode {
  width: clamp(280px, 38vw, 420px);
  height: 620px;
  max-width: calc(100vw - 40px);
  perspective: 2600px;
  transform-style: preserve-3d;
}
.flipbook.fallback-mode .book-page {
  display: block !important;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transform: rotateY(0deg);
  backface-visibility: hidden;
  transition: transform .85s cubic-bezier(.2,.7,.2,1), filter .35s ease;
}
.flipbook.fallback-mode .book-page.fallback-turned {
  transform: rotateY(-178deg);
  pointer-events: none;
}
.flipbook.fallback-mode .book-page:not(.fallback-turned) {
  pointer-events: auto;
}

/* A tiny after-turn movement prevents the book feeling mechanically rigid. */
.book-rig.is-settling .flipbook {
  animation: page-settle .26s cubic-bezier(.2,.8,.25,1);
}
@keyframes page-settle {
  0% { transform: translateY(0); }
  42% { transform: translateY(1.5px); }
  72% { transform: translateY(-.7px); }
  100% { transform: translateY(0); }
}

@media (max-width: 980px) {
  .stage-note { display: none; }
  .reading-stage { min-height: 720px; }
  .book-rig { width: min(920px, calc(100vw - 34px)); }
}

@media (max-width: 700px) {
  .archive-bar { min-height: 58px; }
  .archive-status { display: none; }
  .page-wrapper { padding: 28px 10px 40px; }
  .reading-stage { min-height: 610px; padding: 22px 4px 25px; }
  .book-rig { width: calc(100vw - 20px); min-height: 560px; }
  .flipbook { height: 560px; }
  .flipbook.fallback-mode { height: 560px; width: min(82vw, 360px); }
  .paper-stack { width: min(82vw, 360px); }
  .spine-shadow { display: none; }
  .book-controls { grid-template-columns: 1fr 1fr; gap: 10px; }
  .progress-wrap { grid-column: 1 / -1; grid-row: 1; min-width: 0; }
  .control-btn.prev { grid-column: 1; grid-row: 2; width: 100%; }
  .control-btn.next { grid-column: 2; grid-row: 2; width: 100%; }
  .reading-tools { justify-content: center; flex-wrap: wrap; text-align: center; }
  .hint { flex-basis: 100%; line-height: 1.5; }
  .page-content { padding: 2.2rem 2rem 2.75rem; }
  .page-content p { font-size: clamp(.82rem, 3.3vw, .94rem); line-height: 1.6; }
}

@media (max-width: 420px) {
  .reading-stage { min-height: 565px; }
  .book-rig { min-height: 520px; }
  .flipbook { height: 515px; }
  .flipbook.fallback-mode { height: 515px; width: min(84vw, 340px); }
  .page-content { padding: 1.85rem 1.55rem 2.55rem; }
  .divider { margin-bottom: 20px; }
}

@media (hover: none) {
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
