/* ============================================================================
   STORIES — book built in CSS (no photographed book) + real page-turn leaf.
   Loaded after studio-shell.css. Selectors carry an id so they win over the
   accumulated !important rules in studio-shell.css without touching them.
   ========================================================================== */

/* Stage: a quiet surface for the book to lie on. */
body.ph-site.ph-stories .ph-book-stage {
  background: none !important;
  background-image: none !important;
  aspect-ratio: 1700 / 1210 !important;
  perspective: 2400px !important;
  perspective-origin: 50% 42% !important;
  overflow: visible !important;
}

/* The open book: two paper pages on one grid. */
body.ph-site.ph-stories #stories-grid {
  position: absolute !important;
  inset: 5.5% 5% 8.5% !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  gap: 0 !important;
  isolation: isolate !important;
  background-color: #fbfaf7 !important;
  background-image:
    linear-gradient(rgba(251,250,247,.86), rgba(251,250,247,.86)),
    url("assets/textures/paper.jpg") !important;
  background-repeat: repeat, repeat !important;
  background-size: auto, 420px 420px !important;
  transform-style: preserve-3d !important;
  box-shadow:
    1px 1px 0 #ebe8e1, 2px 2px 0 #fbfaf7, 3px 3px 0 #e6e3dc, 4px 4px 0 #fbfaf7, 5px 5px 0 #e1ded6,
    6px 6px 0 #fbfaf7, 7px 7px 0 #dcd9d1,
    0 34px 54px -22px rgba(30,27,22,.42),
    0 10px 22px -10px rgba(30,27,22,.18) !important;
}
/* Left-hand page-edge stack. */
body.ph-site.ph-stories #stories-grid::after {
  content: "" !important;
  display: block !important;
  position: absolute !important;
  inset: 0 !important;
  z-index: -1 !important;
  pointer-events: none !important;
  background: none !important;
  box-shadow:
    -1px 1px 0 #ebe8e1, -2px 2px 0 #fbfaf7, -3px 3px 0 #e6e3dc, -4px 4px 0 #fbfaf7, -5px 5px 0 #e1ded6,
    -6px 6px 0 #fbfaf7, -7px 7px 0 #dcd9d1 !important;
}
/* Gutter: the pages dip into the binding. Sits above the pages, below the leaf. */
body.ph-site.ph-stories #stories-grid::before {
  content: "" !important;
  display: block !important;
  position: absolute !important;
  inset: 0 !important;
  z-index: 10 !important;
  pointer-events: none !important;
  background:
    linear-gradient(90deg,
      transparent 41%,
      rgba(30,27,22,.035) 46.5%,
      rgba(30,27,22,.11) 49.4%,
      rgba(30,27,22,.16) 50%,
      rgba(30,27,22,.11) 50.6%,
      rgba(30,27,22,.035) 53.5%,
      transparent 59%) !important;
}

/* Pages themselves stay transparent over the paper grid. */
body.ph-site.ph-stories #stories-grid .ph-book-page {
  position: relative !important;
  width: 100% !important;
  height: 100% !important;
  background: transparent !important;
  background-image: none !important;
  box-shadow: none !important;
  transform: none !important;
  backface-visibility: visible !important;
}

/* ---------------------------------------------------------------- leaf --- */
/* Corner peel: the turning sheet is one flat layer clipped along a moving crease;
   the folded-over flap is the reverse side, mirrored about the spine and reflected
   across the crease (turn.js-style). Two layers, no strips, no polygons. */
body.ph-site.ph-stories #stories-grid .ph-leaf {
  position: absolute !important;
  inset: 0 !important;
  z-index: 30 !important;
  margin: 0 !important;
  padding: 0 !important;
  /* Clip (not scroll): the flap may poke a little past the book, but the huge
     rotated crease strips must never enlarge the page and summon a scrollbar. */
  overflow: clip !important;
  overflow-clip-margin: 48px;
  pointer-events: none !important;
  background: none !important;
  box-shadow: none !important;
  transform: none !important;
}
body.ph-site.ph-stories .ph-book-stage,
body.ph-site.ph-stories #stories-magazine { overflow-x: clip !important; }
body.ph-site.ph-stories #stories-grid .ph-leaf-layer {
  position: absolute !important;
  inset: 0 !important;
  display: block !important;
  overflow: visible !important;
  transform-origin: 0 0 !important;
  will-change: transform, clip-path;
}
body.ph-site.ph-stories #stories-grid .ph-leaf-back { opacity: 0; }
body.ph-site.ph-stories #stories-grid .ph-leaf-page {
  position: absolute !important;
  top: 0 !important;
  height: 100% !important;
  display: block !important;
  overflow: hidden !important;
  background-color: #fbfaf7 !important;
  background-image:
    linear-gradient(rgba(251,250,247,.86), rgba(251,250,247,.86)),
    url("assets/textures/paper.jpg") !important;
  background-repeat: repeat, repeat !important;
  background-size: auto, 420px 420px !important;
}
/* Crease shading: a long strip whose centre line is the crease. */
body.ph-site.ph-stories #stories-grid .ph-leaf-crease {
  position: absolute !important;
  left: -150% !important;
  top: -110px !important;
  width: 300% !important;
  height: 220px !important;
  pointer-events: none !important;
  opacity: 0;
  will-change: transform, opacity;
  background: linear-gradient(180deg,
    rgba(26,23,18,0) 0%,
    rgba(26,23,18,.05) 36%,
    rgba(26,23,18,.20) 49%,
    rgba(26,23,18,.26) 50%,
    rgba(26,23,18,.14) 54%,
    rgba(26,23,18,0) 72%) !important;
}
body.ph-site.ph-stories #stories-grid .ph-leaf-crease--back {
  background: linear-gradient(180deg,
    rgba(26,23,18,0) 24%,
    rgba(26,23,18,.10) 44%,
    rgba(26,23,18,.30) 50%,
    rgba(255,255,255,.18) 53%,
    rgba(26,23,18,0) 66%) !important;
}

/* Nothing else from the previous turn systems may draw. */
body.ph-site.ph-stories #stories-grid .ph-book-turn-page,
body.ph-site.ph-stories #stories-grid .ph-book-turn-curl,
body.ph-site.ph-stories #stories-grid .ph-book-mesh-strip,
body.ph-site.ph-stories .ph-book-edge-stack { display: none !important; }

/* ------------------------------------------------------------- mobile --- */
@media (max-width: 767px) {
  body.ph-site.ph-stories .ph-book-stage { aspect-ratio: 850 / 1210 !important; }
  body.ph-site.ph-stories #stories-grid,
  body.ph-site.ph-stories #stories-grid.is-single-page,
  body.ph-site.ph-stories #stories-grid.is-right-page {
    inset: 4% 5% 7% !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }
  body.ph-site.ph-stories #stories-grid::before { display: none !important; }

}


/* ------------------------------------------------------- inline player --- */
/* Play like a picture in a book: no YouTube chrome. The player is oversized so
   its title bar and badges fall outside the frame, and a shield blocks hover
   so no overlay ever wakes up. Click the shield to pause/resume. */
body.ph-site.ph-stories .ph-book-page-visual.is-playing { overflow: hidden !important; }
body.ph-site.ph-stories .ph-book-page-visual > .ph-book-inline-video {
  top: -15% !important;
  height: 130% !important;
  left: -3% !important;
  width: 106% !important;
  pointer-events: none !important;
}
body.ph-site.ph-stories .ph-book-video-shield {
  position: absolute !important;
  inset: 0 !important;
  z-index: 3 !important;
  cursor: pointer !important;
  background: transparent !important;
}
body.ph-site.ph-stories .ph-book-video-shield.is-paused::after {
  content: "" !important;
  position: absolute !important;
  left: 50% !important;
  top: 50% !important;
  width: 0 !important;
  height: 0 !important;
  border-style: solid !important;
  border-width: 14px 0 14px 22px !important;
  border-color: transparent transparent transparent rgba(255,255,255,.85) !important;
  transform: translate(-40%, -50%) !important;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,.4)) !important;
}
body.ph-site.ph-stories .ph-book-video-close { z-index: 4 !important; }


/* ------------------------------------------------------- page furniture --- */
/* Folio: centred at the foot of each page. */
body.ph-site.ph-stories #stories-grid .ph-book-page::after {
  content: attr(data-page) !important;
  position: absolute !important;
  left: 50% !important;
  right: auto !important;
  bottom: 3.6% !important;
  transform: translateX(-50%) !important;
  margin: 0 !important;
  color: rgba(70,66,59,.62) !important;
  font-family: "Cormorant Garamond", Georgia, serif !important;
  font-size: clamp(9px, .72vw, 12px) !important;
  letter-spacing: .04em !important;
  line-height: 1 !important;
}
body.ph-site.ph-stories .ph-book-page-action { display: none !important; }


/* ------------------------------------------------- controls below the book --- */
body.ph-site.ph-stories #stories-magazine > .container { display: flex !important; flex-direction: column !important; }
body.ph-site.ph-stories .ph-book-stage { order: 1 !important; }
body.ph-site.ph-stories .ph-book-controls {
  order: 2 !important;
  margin: clamp(18px, 2.4vw, 34px) auto 0 !important;
  padding: 0 !important;
  width: min(100%, 1500px) !important;
}
body.ph-site.ph-stories .ph-stories-toolbar {
  order: 3 !important;
  display: flex !important;
  justify-content: center !important;
  margin: clamp(10px, 1.4vw, 18px) auto 0 !important;
  padding: 0 !important;
  border: 0 !important;
  width: min(100%, 1500px) !important;
}
body.ph-site.ph-stories .ph-stories-toolbar label,
body.ph-site.ph-stories #story-archive-count { display: none !important; }
body.ph-site.ph-stories .ph-stories-toolbar select {
  width: min(100%, 560px) !important;
  text-align: center !important;
  text-align-last: center !important;
}

/* ---------------------------------------------------- breathing room --- */
/* The book sits in a full-height room: generous air above and below, so the
   footer starts just past the first screen and needs a small scroll. */
body.ph-site.ph-stories #stories-magazine {
  box-sizing: border-box !important;
  min-height: 100vh !important;
  padding-top: clamp(56px, 8vh, 120px) !important;
  padding-bottom: clamp(96px, 14vh, 200px) !important;
}
body.ph-site.ph-stories .ph-book-controls { margin-top: clamp(28px, 4vh, 56px) !important; }
@media (max-width: 767px) {
  body.ph-site.ph-stories #stories-magazine {
    padding-top: clamp(28px, 5vh, 56px) !important;
    padding-bottom: clamp(72px, 12vh, 140px) !important;
  }
}
