/* =============================================================
   BOOK DRAFT
   Scroll-driven page-flip view of the portfolio PDF.
   The book is sticky in the viewport while a tall scroll
   container drives leaf rotation.
   ============================================================= */

.book-page {
  background:
    radial-gradient(ellipse at top, #f1e6d1 0%, #ece1ca 45%, #e4d6b8 100%);
  color: #2b2417;
  min-height: 100vh;
}

.topbar--book {
  background: rgba(244, 236, 223, 0.85);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid rgba(43, 36, 23, 0.08);
  position: sticky;
  top: 0;
  z-index: 50;
}

/* ------- INTRO ------- */
.book-intro {
  max-width: 960px;
  margin: 0 auto;
  padding: 6rem 2rem 4rem;
  text-align: center;
}
.book-intro .meta-label {
  display: inline-block;
  margin-bottom: 1.25rem;
}
.book-title {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 300;
  font-size: clamp(2.5rem, 6vw, 5rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin: 0 0 1.25rem;
  font-style: italic;
}
.book-sub {
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 1.05rem;
  color: #4a3f2c;
  max-width: 36rem;
  margin: 0 auto 2rem;
  line-height: 1.55;
}
.book-sub kbd {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85em;
  background: rgba(43, 36, 23, 0.08);
  border: 1px solid rgba(43, 36, 23, 0.2);
  border-radius: 4px;
  padding: 0.05em 0.45em;
  margin: 0 0.1em;
}
.book-cta {
  display: inline-block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #a84e24;
  text-decoration: none;
  border-bottom: 1px solid #a84e24;
  padding-bottom: 0.3rem;
  transition: color 0.2s, border-color 0.2s;
}
.book-cta:hover { color: #2b2417; border-color: #2b2417; }

.book-alt {
  margin: 2rem auto 0;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 0.85rem;
  color: #6b5f48;
}
.book-alt a {
  color: #4a3f2c;
  border-bottom: 1px solid currentColor;
  text-decoration: none;
  margin-left: 0.25rem;
}
.book-alt a:hover { color: #a84e24; }

/* Mobile fallback list — hidden on desktop */
.book-mobile { display: none; }


/* ------- BOOK STAGE ------- */
/* Tall scroll container; book inside is sticky.
   Total height grows by (leaves + 1) * 100vh, set in JS to match leaf count. */
.book-stage {
  position: relative;
  /* fallback height; JS overrides with --leaf-count */
  height: calc(100vh * 13);
}

.book-sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-items: center;
  justify-items: center;
  padding: 3vh 2vw 2vh;
  box-sizing: border-box;
}

/* The book itself */
.book {
  position: relative;
  width: min(95vw, calc((100vh - 12rem) * 2.83));
  /* aspect-ratio matches the source PDF spread (2381 x 841 pts) */
  aspect-ratio: 2381 / 841;
  perspective: 2400px;
  perspective-origin: 50% 50%;
  filter: drop-shadow(0 30px 50px rgba(43, 36, 23, 0.35))
          drop-shadow(0 6px 12px rgba(43, 36, 23, 0.15));
}

/* Static base — first verso (left) and last recto (right) are always there.
   They get covered by leaves as those flip. */
.book-base {
  position: absolute;
  inset: 0;
  display: flex;
  background: #faf4e6;
  z-index: 0;
}
.book-base-page {
  width: 50%;
  height: 100%;
  background-size: 200% 100%;
  background-repeat: no-repeat;
  background-color: #faf4e6;
}
.book-base-page--left  { background-position: left center; }
.book-base-page--right { background-position: right center; }

/* Center spine — subtle gutter shading */
.book-spine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 28px;
  margin-left: -14px;
  z-index: 30;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(0,0,0,0) 0%,
    rgba(0,0,0,0.18) 35%,
    rgba(0,0,0,0.30) 50%,
    rgba(0,0,0,0.18) 65%,
    rgba(0,0,0,0) 100%);
}

/* Outer page edges — soft shadows around the book */
.book-shadow {
  position: absolute;
  top: 2%;
  bottom: 2%;
  width: 14px;
  z-index: 1;
  pointer-events: none;
}
.book-shadow--left {
  left: -4px;
  background: linear-gradient(90deg, rgba(0,0,0,0.18), transparent);
  border-radius: 2px 0 0 2px;
}
.book-shadow--right {
  right: -4px;
  background: linear-gradient(270deg, rgba(0,0,0,0.18), transparent);
  border-radius: 0 2px 2px 0;
}

/* Leaves container occupies the right half of the book */
.book-leaves {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* A single leaf: positioned on the right side of the book,
   rotates around its left edge (the spine). */
.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  will-change: transform;
}

/* Each face of the leaf shows half of its source spread */
.leaf-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background-color: #faf4e6;
  background-size: 200% 100%;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 30px rgba(43, 36, 23, 0.05);
}

/* Front face = recto of "current" spread.
   Image is 2x wide, so we show the right half. */
.leaf-front {
  background-position: right center;
}

/* Back face = verso of "next" spread.
   Rotated 180° on Y so it appears on the left side after flipping.
   Image is 2x wide, show the left half. */
.leaf-back {
  background-position: left center;
  transform: rotateY(180deg);
}

/* Subtle gradient on the leaf to give it physicality during the flip */
.leaf-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(0,0,0,0.18) 0%,
    rgba(0,0,0,0) 12%,
    rgba(0,0,0,0) 88%,
    rgba(0,0,0,0.10) 100%);
  opacity: 0.85;
}
.leaf-back::after {
  /* Mirror the gradient so the inner edge is on the right (the spine when flipped) */
  transform: scaleX(-1);
}

/* HUD: spread counter + nav */
.book-hud {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-top: 1.5rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #4a3f2c;
}
.book-btn {
  appearance: none;
  background: transparent;
  border: 1px solid rgba(43, 36, 23, 0.35);
  border-radius: 999px;
  width: 2.4rem;
  height: 2.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: #2b2417;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.book-btn:hover {
  background: rgba(168, 78, 36, 0.08);
  border-color: #a84e24;
  color: #a84e24;
}
.book-btn:active { transform: scale(0.95); }
.book-counter-sep { opacity: 0.4; margin: 0 0.25em; }

/* Progress rail */
.book-progress {
  width: min(420px, 60vw);
  height: 2px;
  background: rgba(43, 36, 23, 0.12);
  border-radius: 2px;
  margin-top: 0.75rem;
  overflow: hidden;
}
.book-progress-fill {
  height: 100%;
  width: 0%;
  background: #a84e24;
  transition: width 0.15s ease-out;
}

/* ------- OUTRO ------- */
.book-outro {
  max-width: 760px;
  margin: 0 auto;
  padding: 6rem 2rem 4rem;
  text-align: center;
}
.book-outro h2 {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 300;
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  line-height: 1.15;
  margin: 1rem 0 1.25rem;
}
.book-outro p {
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.65;
  color: #4a3f2c;
  margin-bottom: 2rem;
}
.book-outro-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

/* ------- MOBILE ------- */
@media (max-width: 720px) {
  .book-intro { padding: 4rem 1.5rem 2rem; }

  /* Hide the flip-book stage on small screens — the spread aspect ratio
     becomes unreadably short. Show the linear list instead. */
  .book-stage { display: none; }

  .book-mobile {
    display: block;
    max-width: 100%;
    padding: 1rem 1rem 4rem;
  }
  .book-mobile-note {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.7rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #6b5f48;
    text-align: center;
    margin: 0 auto 1.5rem;
    max-width: 28rem;
    line-height: 1.6;
  }
  .book-mobile-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  .book-mobile-list li {
    background: #faf4e6;
    box-shadow:
      0 8px 18px rgba(43, 36, 23, 0.18),
      0 2px 4px rgba(43, 36, 23, 0.08);
    border-radius: 2px;
    overflow: hidden;
  }
  .book-mobile-list img {
    display: block;
    width: 100%;
    height: auto;
  }
}

/* Reduced motion — disable transitions but still allow scroll-driven flip */
@media (prefers-reduced-motion: reduce) {
  .book-progress-fill { transition: none; }
}
