/* Scroll-scrubbed 3D booklet. Timing lives in js/book-flip.js */

html:has([data-book-flip]) {
  scroll-behavior: auto;
}

.book-flip-flow {
  position: relative;
  width: 100%;
  min-height: 100svh;
  margin: 8px 0 56px;
  background: var(--ww-bg, #fff);
}

.book-flip {
  --book-ink: #17110a;
  --book-page-w: 1399;
  --book-page-h: 2722;
  position: relative;
  z-index: 1;
  isolation: isolate;
  width: 100%;
  margin: 0;
  overflow: visible;
  background: var(--ww-bg, #fff);
}

.book-flip__stage {
  position: relative;
  height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  box-sizing: border-box;
  perspective: 1800px;
  perspective-origin: 50% 50%;
  overflow: visible;
  touch-action: pan-y;
  background: var(--ww-bg, #fff);
}

.book-flip__backdrop {
  position: absolute;
  top: 8px;
  right: 0;
  bottom: 8px;
  left: 0;
  z-index: 0;
  overflow: hidden;
  border-radius: var(--ww-radius, 5px);
  pointer-events: none;
}

.book-flip__backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.book-flip__scene {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  transform-style: preserve-3d;
}

.book-flip__slot {
  --page-h: min(72svh, calc(100svh - 16px), 860px);
  --page-w: calc(var(--page-h) * var(--book-page-w) / var(--book-page-h));
  position: relative;
  z-index: 1;
  width: min(var(--page-w), calc(50% - 10px), 420px);
  aspect-ratio: 1399 / 2722;
  height: auto;
  transform-style: preserve-3d;
}

.book-flip__book {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: left center;
}

/* Flat back cover in the same slot as the front. Shown only after close. */
.book-flip__closed {
  position: absolute;
  inset: 0;
  z-index: 6;
  overflow: hidden;
  isolation: isolate;
  opacity: 0;
  pointer-events: none;
  background-color: var(--book-ink);
  transform: none;
  transform-style: flat;
}

.book-flip.is-closed-flat .book-flip__book {
  visibility: hidden;
}

.book-flip.is-closed-flat .book-flip__closed {
  opacity: 1;
}

.book-flip__closed::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("../assets/rood/paper-uncoated.png");
  background-size: 220px 220px;
  mix-blend-mode: soft-light;
  opacity: 0.55;
}

.book-flip__closed img {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% + 3px);
  height: calc(100% + 3px);
  max-width: none;
  object-fit: cover;
  object-position: 0 0;
  display: block;
  background-color: var(--book-ink);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: contrast(0.9) saturate(0.84);
}

.book-flip__leaf {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  background-color: var(--book-ink);
}

.book-flip__leaf.is-idle {
  visibility: hidden;
  pointer-events: none;
}

.book-flip__sheet {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: left center;
  background-color: var(--book-ink);
}

.book-flip__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  background-color: var(--book-ink);
  box-sizing: border-box;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.book-flip__face--front {
  background-color: var(--book-ink);
}

.book-flip__face--back {
  transform: rotateY(180deg);
  background-color: var(--book-ink);
}

.book-flip__face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("../assets/rood/paper-uncoated.png");
  background-size: 220px 220px;
  mix-blend-mode: soft-light;
  opacity: 0.55;
}

.book-flip__face img {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% + 3px);
  height: calc(100% + 3px);
  max-width: none;
  object-fit: cover;
  object-position: 0 0;
  display: block;
  background-color: var(--book-ink);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  /* Uncoated: ink sits in the sheet — slightly softer contrast, less gloss. */
  filter: contrast(0.9) saturate(0.84);
}

/* ——— Reduced motion ——— */

.book-flip--reduced {
  margin-bottom: 48px;
}

.book-flip--reduced .book-flip__backdrop {
  display: none;
}

.book-flip--reduced .book-flip__stage {
  display: none;
}

.book-flip__reduced {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.book-flip__reduced-page {
  margin: 0;
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity 0.7s cubic-bezier(0.25, 0.1, 0.25, 1),
    transform 0.7s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.book-flip__reduced-page.is-in {
  opacity: 1;
  transform: none;
}

.book-flip__reduced-frame {
  position: relative;
  width: min(420px, 100%);
  aspect-ratio: 1399 / 2722;
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
  background: var(--book-ink);
}

.book-flip__reduced-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("../assets/rood/paper-uncoated.png");
  background-size: 220px 220px;
  mix-blend-mode: soft-light;
  opacity: 0.55;
}

.book-flip__reduced-frame img {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% + 3px);
  height: calc(100% + 3px);
  max-width: none;
  object-fit: cover;
  object-position: 0 0;
  display: block;
  filter: contrast(0.9) saturate(0.84);
}

.book-flip__reduced-page figcaption {
  margin-top: 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ww-muted);
}

@media (max-width: 809px) {
  .book-flip__slot {
    --page-h: min(68svh, calc(100svh - 16px));
    width: min(var(--page-w), calc(50% - 6px), 280px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .book-flip__reduced-page {
    opacity: 1;
    transform: none;
    transition: none;
  }
}
