/* ========================================================
   Анимированная книга — 3D-открытие и пролистывание
   ======================================================== */

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

.reader { padding: clamp(36px, 5vw, 72px) 0 clamp(60px, 8vw, 120px); }

.reader__head { text-align: center; margin-bottom: clamp(20px, 3vw, 40px); }
.reader__crumb {
  display: inline-flex; align-items: center; gap: 14px;
  font-family: var(--display);
  font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--rust);
  margin-bottom: 18px;
}
.reader__crumb .rule { width: 36px; height: 1px; background: var(--rust); }
.reader__title {
  font-family: var(--serif);
  font-weight: 500; font-style: italic;
  font-size: clamp(48px, 7vw, 96px);
  line-height: 0.95; margin: 0 0 16px;
  color: var(--ink);
}
.reader__title em { font-style: italic; font-weight: 400; }
.reader__sub {
  font-family: var(--serif);
  font-size: clamp(17px, 1vw + 10px, 22px);
  line-height: 1.5;
  color: var(--on-paper-mute);
  max-width: 52ch;
  margin: 0 auto;
}

.reader__keys {
  margin-top: clamp(24px, 3vw, 36px);
  text-align: center;
  font-family: var(--display);
  font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--on-paper-mute);
  display: flex; justify-content: center; align-items: center;
  gap: 16px; flex-wrap: wrap;
}
.reader__keys a { color: var(--rust); }
.reader__keys a:hover { color: var(--rust-2); }

/* ===================== Book stage ===================== */
.book-stage {
  position: relative;
  margin: clamp(20px, 3vw, 40px) auto 0;
  width: 100%;
  max-width: min(1080px, calc(78vh * 1.42));
  perspective: 2800px;
  perspective-origin: 50% 80%;
  padding: clamp(24px, 3vw, 48px) clamp(8px, 2vw, 32px);
}

.book {
  position: relative;
  width: 100%;
  aspect-ratio: 1.42 / 1;
  transform-style: preserve-3d;
  transition: transform 1s cubic-bezier(.2,.7,.2,1);
  margin: 0 auto;
}
.book[data-state="closed"] { transform: rotateX(6deg); }
.book[data-state="opening"] { transform: rotateX(2deg); }
.book[data-state="open"] { transform: rotateX(0deg); }

/* drop shadow under the book */
.book::before {
  content: "";
  position: absolute;
  left: 6%; right: 6%;
  bottom: -36px;
  height: 80px;
  background: radial-gradient(50% 100% at 50% 0%, rgba(15,13,10,0.55), transparent 70%);
  filter: blur(10px);
  z-index: -1;
  transition: left .9s ease, right .9s ease, opacity .9s ease;
  opacity: 0.85;
}
.book[data-state="closed"]::before { left: 28%; right: 28%; opacity: 0.7; }

/* center spine line — visible only when open */
.book::after {
  content: "";
  position: absolute;
  left: 50%; top: 0; bottom: 0;
  width: 5px;
  background: linear-gradient(180deg,
    rgba(15,13,10,0) 0%,
    rgba(15,13,10,0.55) 8%,
    rgba(15,13,10,0.65) 92%,
    rgba(15,13,10,0) 100%);
  transform: translateX(-50%);
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity .6s ease .35s;
}
.book[data-state="open"]::after { opacity: 1; }

/* paper background pages on left/right */
.book__back {
  position: absolute;
  top: 0; bottom: 0;
  width: 50%;
  background:
    radial-gradient(120% 80% at 0% 50%, rgba(15,13,10,0.10) 0%, transparent 30%),
    var(--cream);
  border: 1px solid rgba(15,13,10,0.08);
  display: grid; place-items: center;
  font-family: var(--serif);
  color: var(--on-paper-mute);
  font-style: italic;
  overflow: hidden;
  transition: opacity .55s ease;
}
.book__back--left {
  left: 0;
  box-shadow: inset -16px 0 36px -16px rgba(15,13,10,0.25);
}
.book__back--right {
  right: 0;
  box-shadow: inset 16px 0 36px -16px rgba(15,13,10,0.25);
  background:
    radial-gradient(120% 80% at 100% 50%, rgba(15,13,10,0.10) 0%, transparent 30%),
    var(--cream);
}
.book[data-state="closed"] .book__back { opacity: 0; }

.book__back-inner {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center;
  color: rgba(15,13,10,0.45);
  padding: 24px;
}
.book__back-inner .ornament {
  font-family: var(--serif); font-size: 28px; font-style: italic;
}
.book__back-inner .mark {
  width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid rgba(15,13,10,0.25);
  display: grid; place-items: center;
  font-family: var(--serif); font-style: italic; font-size: 24px;
}
.book__back-inner small {
  font-family: var(--display); font-size: 10px; letter-spacing: 0.28em; text-transform: uppercase;
  color: rgba(15,13,10,0.4);
}

/* ===================== Leaves ===================== */
/* a leaf = one physical sheet — front (recto) + back (verso) */
.leaf {
  position: absolute;
  top: 0; left: 50%;
  width: 50%; height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 1.1s cubic-bezier(.45,.05,.2,1);
  will-change: transform;
}
.leaf.flipped { transform: rotateY(-180deg); }

/* COVER leaf in closed state: translated to look centered (book appears closed) */
.book[data-state="closed"] .leaf--cover {
  transform: translateX(-50%);
  box-shadow: 0 36px 90px -18px rgba(15,13,10,0.55);
}
/* OPENING: cover slides into spine position before flipping */
.book[data-state="opening"] .leaf--cover {
  transform: translateX(0);
}
/* hide all non-cover leaves until book is opening */
.book[data-state="closed"] .leaf:not(.leaf--cover) {
  visibility: hidden;
}

.leaf__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  background: var(--cream);
  border: 1px solid rgba(15,13,10,0.08);
}
.leaf__face--back { transform: rotateY(180deg); }

.leaf__face img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}

/* inner-edge shadow toward the spine */
.leaf__face::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 16%;
  pointer-events: none;
}
.leaf__face--front::after {
  left: 0;
  background: linear-gradient(90deg, rgba(15,13,10,0.42), transparent 70%);
}
.leaf__face--back::after {
  right: 0;
  background: linear-gradient(270deg, rgba(15,13,10,0.42), transparent 70%);
}

/* COVER face — heavy, dark, stamped */
.leaf__face--cover {
  background: var(--ink);
  box-shadow:
    inset 0 0 0 1px rgba(255, 232, 200, 0.07),
    inset 0 0 80px rgba(0,0,0,0.55);
}
.leaf__face--cover::after {
  background: linear-gradient(90deg, rgba(0,0,0,0.55), transparent 60%);
}
.leaf__face--cover .leaf__corner {
  position: absolute; top: 14px; right: 18px;
  font-family: var(--serif); font-style: italic;
  font-size: 18px; color: var(--gold);
  z-index: 2;
}
.leaf__face--cover .leaf__hint {
  position: absolute; bottom: 18px; left: 0; right: 0;
  text-align: center;
  font-family: var(--display);
  font-size: 10px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--gold);
  opacity: 0;
  transition: opacity .6s ease .4s;
  z-index: 2;
}
.book[data-state="closed"] .leaf__face--cover .leaf__hint {
  opacity: 0.75;
  animation: hintPulse 2.4s ease-in-out infinite;
}
@keyframes hintPulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 0.95; }
}

/* page numbers */
.leaf__face .pgnum {
  position: absolute;
  bottom: 16px;
  font-family: var(--serif); font-style: italic; font-size: 14px;
  color: rgba(15,13,10,0.55);
  letter-spacing: 0.04em;
  z-index: 2;
}
.leaf__face--front .pgnum { right: 22px; }
.leaf__face--back  .pgnum { left: 22px; }

/* locked finale page */
.leaf__face--locked {
  background: var(--ink);
  color: var(--on-ink);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center;
  padding: clamp(20px, 3vw, 40px);
  gap: 14px;
}
.leaf__face--locked .seal {
  width: 84px; height: 84px; border-radius: 50%;
  border: 1px solid var(--gold);
  display: grid; place-items: center;
  color: var(--gold);
  font-family: var(--serif); font-style: italic; font-size: 32px;
  margin-bottom: 8px;
}
.leaf__face--locked h4 {
  font-family: var(--serif); font-style: italic;
  font-size: clamp(20px, 2vw, 30px); line-height: 1.15; margin: 0;
  max-width: 18ch;
  color: var(--on-ink);
}
.leaf__face--locked p {
  color: var(--on-ink-mute);
  font-size: 13px; line-height: 1.55; max-width: 28ch; margin: 0;
}
.leaf__face--locked small {
  font-family: var(--display); font-size: 10px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--gold);
  margin-top: 6px;
}

/* colophon (back of locked) */
.leaf__face--colophon {
  background: var(--cream);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center;
  padding: 40px;
  gap: 12px;
  color: var(--on-paper-mute);
}
.leaf__face--colophon .title {
  font-family: var(--serif); font-size: clamp(40px, 5vw, 72px); color: var(--ink);
  margin: 0; line-height: 1;
}
.leaf__face--colophon .title em { font-style: italic; font-weight: 500; }
.leaf__face--colophon .sub {
  font-family: var(--display); font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase;
  margin: 0;
}
.leaf__face--colophon .rule { width: 36px; height: 1px; background: var(--on-paper-line); margin: 4px 0; }
.leaf__face--colophon small { font-size: 12px; max-width: 28ch; line-height: 1.5; letter-spacing: 0.04em; }

/* ===================== Hit zones ===================== */
.book__zone {
  position: absolute;
  top: 0; bottom: 0;
  width: 40%;
  z-index: 25;
  cursor: pointer;
  background: transparent;
  display: flex; align-items: center;
  opacity: 0;
  transition: opacity .25s ease;
  border: 0; outline: 0;
  padding: 0 18px;
}
.book__zone--prev { left: 0; justify-content: flex-start; }
.book__zone--next { right: 0; justify-content: flex-end; }
.book__zone:hover,
.book__zone:focus-visible { opacity: 1; }
.book__zone[disabled] { cursor: not-allowed; opacity: 0 !important; }

.book__zone .hint {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase;
  padding: 10px 18px;
  border-radius: 999px;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 12px 24px -8px rgba(15,13,10,0.5);
}

/* Closed: hide prev zone, expand next zone full-width, restyle its hint */
.book[data-state="closed"] .book__zone--prev { display: none; }
.book[data-state="closed"] .book__zone--next {
  left: 0; right: 0; width: 100%;
  justify-content: center; padding: 0;
  opacity: 1;
}
.book[data-state="closed"] .book__zone--next .hint {
  background: var(--rust);
  color: var(--cream);
  font-size: 12px;
  padding: 14px 26px;
  box-shadow: 0 18px 36px -12px rgba(141,35,42,0.55);
}

/* ===================== Controls ===================== */
.book-controls {
  margin: clamp(28px, 4vw, 48px) auto 0;
  display: flex; align-items: center; justify-content: center;
  gap: 18px;
  max-width: 1080px;
}
.book-controls__btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 1px solid var(--ink);
  color: var(--ink);
  font-family: var(--serif); font-size: 24px; line-height: 1;
  transition: background .2s ease, color .2s ease, opacity .2s ease, transform .2s ease;
  background: transparent;
}
.book-controls__btn:hover { background: var(--ink); color: var(--paper); transform: translateY(-1px); }
.book-controls__btn[disabled] { opacity: 0.25; cursor: not-allowed; }
.book-controls__counter {
  font-family: var(--display);
  font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--on-paper-mute);
  min-width: 110px; text-align: center;
}
.book-controls__counter strong {
  color: var(--ink);
  font-family: var(--serif); font-style: italic; font-size: 20px;
  letter-spacing: 0; font-weight: 500;
  margin-right: 6px;
}

/* status row above the book */
.book-status {
  display: flex; justify-content: space-between; align-items: center;
  gap: 18px; flex-wrap: wrap;
  margin: clamp(36px, 5vw, 56px) auto 0;
  padding: 16px var(--gutter);
  border-top: 1px solid var(--on-paper-line-2);
  border-bottom: 1px solid var(--on-paper-line-2);
  font-family: var(--display);
  font-size: 10px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--on-paper-mute);
}
.book-status .item { display: flex; align-items: baseline; gap: 10px; }
.book-status .item strong { color: var(--ink); font-family: var(--serif); font-style: italic; font-size: 16px; letter-spacing: 0; font-weight: 500; }

@media (max-width: 720px) {
  .book-stage { perspective: 1600px; padding: 12px 4px; }
  .book__zone .hint { font-size: 10px; padding: 8px 12px; }
  .book-status { font-size: 9px; }
  .reader__title { font-size: clamp(36px, 12vw, 56px); }
  .leaf__face--locked h4 { font-size: 18px; }
  .leaf__face--locked p { font-size: 11px; }
  .leaf__face--locked .seal { width: 56px; height: 56px; font-size: 22px; }
  .leaf__face--colophon { padding: 16px; }
  .leaf__face--colophon .title { font-size: clamp(28px, 9vw, 48px); }
}
