/* ==========================================================================
   Brochure flipbook (includes/layout/brochure-flipbook.php, js/flipbook.js).
   Loaded only on a project page that has a brochure. The book sits on a
   warm, paper-neutral ground so the brochure's own colours carry the page;
   the controls are small white pills underneath.
   js/flipbook.js sizes .fb-viewport and .fb-frame and sets the state
   classes: is-ready, is-failed, is-spread-mode, is-zoomed, is-fullscreen on
   .fb; is-cover / is-back on .fb-book.
   ========================================================================== */

.pp-brochure {
  --fb-ground: #f3efe8;
  --fb-ground-deep: #e9e3d9;
  --fb-shadow: 0 28px 50px -18px rgba(40, 32, 20, 0.42), 0 10px 22px rgba(40, 32, 20, 0.12);
  padding: clamp(40px, 5vw, 72px) 0 clamp(40px, 5vw, 64px);
  background: radial-gradient(ellipse 90% 70% at 50% 55%, var(--fb-ground) 0%, var(--fb-ground-deep) 100%);
}

.fb-lede {
  margin: 0;
  color: var(--pp-text);
  font-size: var(--fs-md);
}

.fb {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
}

/* --- The book ----------------------------------------------------------- */
.fb-stage {
  position: relative;
  border-radius: var(--radius-md);
  outline: none;
}

.fb-stage:focus-visible {
  outline: 3px solid var(--pp-green);
  outline-offset: 8px;
}

/* Sized by script; this is only the height before it runs. */
.fb-viewport {
  display: flex;
  height: clamp(320px, 60vw, 720px);
  overflow: hidden;
}

/* margin:auto (not justify-content) keeps a zoomed book scrollable to its
   left and top edges. */
.fb-frame {
  position: relative;
  flex: none;
  margin: auto;
}

.fb .fb-book {
  transform: translateX(0);
  transition: transform 0.6s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* The cover and the back cover are alone on their side: centre them. */
.fb .fb-book.is-cover {
  transform: translateX(-25%);
}

.fb .fb-book.is-back {
  transform: translateX(25%);
}

/* The book's shadow on the table, only under the pages that are there. */
.fb .fb-book::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  border-radius: 2px;
  box-shadow: var(--fb-shadow);
  transition: left 0.6s cubic-bezier(0.25, 0.8, 0.25, 1), right 0.6s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.fb .fb-book.is-cover::before {
  left: 50%;
}

.fb .fb-book.is-back::before {
  right: 50%;
}

.fb-page {
  background: #fff;
  overflow: hidden;
}

.fb-sheet {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.fb-sheet canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* A page still being drawn: a soft shimmer instead of a blank sheet. */
.fb-page:not(.is-rendered) .fb-sheet {
  background: linear-gradient(100deg, #fff 30%, #f4f1ec 50%, #fff 70%) 0 0 / 300% 100%;
  animation: fb-shimmer 1.4s linear infinite;
}

.fb-page.is-broken .fb-sheet::after {
  content: 'This page could not be shown. Download the PDF to read it.';
  max-width: 70%;
  color: var(--clr-gray-600);
  font-size: var(--fs-sm);
  text-align: center;
}

/* The curve of the paper into the spine, on facing pages. */
.fb.is-spread-mode .fb-page--left .fb-sheet::before,
.fb.is-spread-mode .fb-page--right .fb-sheet::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  width: 7%;
  pointer-events: none;
}

.fb.is-spread-mode .fb-page--left .fb-sheet::before {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.13), rgba(0, 0, 0, 0.03) 40%, transparent);
}

.fb.is-spread-mode .fb-page--right .fb-sheet::before {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.11), rgba(0, 0, 0, 0.025) 40%, transparent);
}

/* Zoomed: the book scrolls in its box, and dragging pans it. */
.fb-pan {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  cursor: grab;
  touch-action: pan-x pan-y;
}

.fb-pan.is-dragging {
  cursor: grabbing;
}

.fb.is-zoomed .fb-pan {
  display: block;
}

.fb.is-zoomed .fb-viewport {
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: var(--radius-md);
  background: rgba(40, 32, 20, 0.05);
}

/* --- Loading and error ---------------------------------------------------- */
.fb-status {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}

.fb.is-ready .fb-status {
  display: none;
}

/* The empty book while the PDF arrives: one blank page where the cover goes. */
.fb:not(.is-ready) .fb-frame::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 2px;
  background: linear-gradient(100deg, #fff 30%, #f7f4ef 50%, #fff 70%) 0 0 / 300% 100%;
  box-shadow: var(--fb-shadow);
  animation: fb-shimmer 1.4s linear infinite;
}

.fb.is-spread-mode:not(.is-ready) .fb-frame::before {
  left: 25%;
  right: 25%;
}

.fb.is-failed .fb-frame::before {
  animation: none;
  opacity: 0.6;
}

.fb-status-loading,
.fb-status-error {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--clr-gray-600);
  font-size: var(--fs-sm);
}

.fb-status-loading[hidden],
.fb-status-error[hidden] {
  display: none;
}

.fb-status-error {
  max-width: 320px;
  pointer-events: auto;
}

.fb-status-error p {
  margin: 0;
  color: var(--pp-ink);
  line-height: 1.6;
}

.fb-status-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.fb-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--pp-green-soft);
  border-top-color: var(--pp-green);
  border-radius: 50%;
  animation: fb-spin 0.8s linear infinite;
}

.fb-retry {
  padding: 10px 18px;
  border: 1px solid var(--clr-gray-300);
  border-radius: var(--radius-full);
  background: #fff;
  color: var(--pp-ink);
  font: 600 var(--fs-sm) / 1 var(--ff-heading);
  cursor: pointer;
}

.fb-retry:hover {
  border-color: var(--pp-green);
  color: var(--pp-green);
}

/* --- Controls ------------------------------------------------------------------ */
.fb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 14px;
  margin-top: clamp(22px, 3vw, 34px);
}

.fb-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border: 1px solid rgba(40, 32, 20, 0.08);
  border-radius: var(--radius-full);
  background: #fff;
  box-shadow: var(--shadow-md);
}

.fb-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--clr-gray-700);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.fb-btn:hover:not(:disabled) {
  background: var(--pp-green-soft);
  color: var(--pp-green);
}

.fb-btn:focus-visible,
.fb-download:focus-visible,
.fb-retry:focus-visible {
  outline: 2px solid var(--pp-green);
  outline-offset: 2px;
}

.fb-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.fb-icon-exit,
.fb.is-fullscreen .fb-icon-enter {
  display: none;
}

.fb.is-fullscreen .fb-icon-exit {
  display: block;
}

.fb-count {
  min-width: 72px;
  color: var(--pp-ink);
  font-family: var(--ff-heading);
  font-size: var(--fs-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.fb-zoom {
  min-width: 46px;
  color: var(--clr-gray-600);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.fb-download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius-full);
  background: var(--pp-green);
  box-shadow: 0 10px 22px -8px rgba(14, 97, 29, 0.55);
  color: #fff;
  font-family: var(--ff-heading);
  font-size: var(--fs-sm);
  font-weight: 700;
  text-decoration: none;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.fb-download:hover {
  background: var(--pp-green-dark);
  color: #fff;
  transform: translateY(-1px);
}

.fb-download-size {
  font-weight: 500;
  opacity: 0.8;
}

/* --- Full screen ------------------------------------------------------------------ */
.fb.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: flex;
  flex-direction: column;
  max-width: none;
  margin: 0;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 45%, #44463f 0%, #22231f 100%);
}

.fb.is-fullscreen .fb-stage {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}

.fb.is-fullscreen .fb-toolbar {
  margin-top: 14px;
}

.fb.is-fullscreen .fb-group {
  border-color: transparent;
}

.fb.is-fullscreen .fb-stage:focus-visible {
  outline-offset: 2px;
}

.fb::backdrop {
  background: #22231f;
}

html.fb-locked,
html.fb-locked body {
  overflow: hidden;
}

/* --- Small screens ----------------------------------------------------------------- */
@media (max-width: 599px) {
  .fb-toolbar {
    gap: 10px;
  }

  .fb-download {
    padding: 11px 18px;
  }
}

@media (pointer: coarse) {
  .fb-btn {
    width: 44px;
    height: 44px;
  }
}

@keyframes fb-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fb-shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fb .fb-book,
  .fb .fb-book::before {
    transition: none;
  }

  .fb-page:not(.is-rendered) .fb-sheet,
  .fb:not(.is-ready) .fb-frame::before {
    animation: none;
  }

  .fb-spinner {
    animation-duration: 2s;
  }
}
