/**
 * pdf-flipbook reader.
 *
 * Brand-agnostic. Inside a WordPress block theme the palette resolves from
 * theme.json via the --wp--preset--* variables; the literals at the end of each
 * chain are neutral defaults for anywhere else.
 *
 * To brand it outside WordPress, set the --pdfflip-brand-* variables on any
 * ancestor (:root works). Do NOT set --pdfflip-accent itself on an ancestor:
 * the declarations below are on the element, and an element's own declaration
 * beats an inherited one, so the override would be silently ignored.
 */

.pdfflip {
  --pdfflip-paper: var(--pdfflip-brand-paper, var(--wp--preset--color--base, #fafafa));
  --pdfflip-ink: var(--pdfflip-brand-ink, var(--wp--preset--color--contrast, #16181a));
  --pdfflip-muted: var(--pdfflip-brand-muted, var(--wp--preset--color--muted, #767a7e));
  --pdfflip-line: var(--pdfflip-brand-line, var(--wp--preset--color--line, #e3e3e1));
  --pdfflip-accent: var(--pdfflip-brand-accent, var(--wp--preset--color--accent, #2b6cb0));
  --pdfflip-display: var(--pdfflip-brand-display, var(--wp--preset--font-family--display, system-ui, "Segoe UI", Helvetica, Arial, sans-serif));
  --pdfflip-aspect: 1.414;

  /* Height available to the book once the toolbar and stage padding are taken
   * out. A spread is wide, so without a height cap an A3 issue overflows the
   * viewport on any laptop and the reader turns into a scrolling chore. */
  --pdfflip-maxh: calc(100svh - 190px);

  position: relative;
  margin-inline: auto;
  background: #1a1d1f;
  color: #fff;
}

/* ---------------------------------------------------------------------------
 * Stage
 * ------------------------------------------------------------------------ */
.pdfflip__stage {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: clamp(4px, 1.5vw, 20px);
  padding: clamp(12px, 3vw, 34px) clamp(6px, 2vw, 26px);
  /* A subtle vignette reads as "lightbox" and stops the page images from
   * bleeding into the surrounding editorial layout. */
  background:
    radial-gradient(ellipse at 50% 42%, #303537 0%, #1a1d1f 72%);
}

.pdfflip__book-wrap {
  min-width: 0;
  display: flex;
  justify-content: center;
}

.pdfflip__book {
  /* Reserve the spread's footprint up front: two pages wide in landscape, one
   * in portrait. Without this the toolbar jumps once the first image lands. */
  width: 100%;
  max-width: min(100%, calc(var(--pdfflip-maxh) / var(--pdfflip-aspect) * 2));
  aspect-ratio: 2 / var(--pdfflip-aspect);
  margin-inline: auto;
}

.pdfflip.is-portrait .pdfflip__book {
  aspect-ratio: 1 / var(--pdfflip-aspect);
  max-width: min(100%, calc(var(--pdfflip-maxh) / var(--pdfflip-aspect)));
}

/* StPageFlip positions these itself; we only style the surface. */
.pdfflip__page {
  background: #fff;
  overflow: hidden;
  /* Paper edge. Cheap, and it does most of the work of selling the flip. */
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.pdfflip__page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.35s ease;
  user-select: none;
  -webkit-user-drag: none;
}

.pdfflip__page.is-ready img { opacity: 1; }

/* Skeleton shimmer while a page decodes. */
.pdfflip__page:not(.is-ready)::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, #f4f3f0 30%, #e8e7e3 50%, #f4f3f0 70%);
  background-size: 220% 100%;
  animation: pdfflip-shimmer 1.4s ease-in-out infinite;
}

@keyframes pdfflip-shimmer {
  from { background-position: 180% 0; }
  to   { background-position: -60% 0; }
}

/* ---------------------------------------------------------------------------
 * Side navigation
 * ------------------------------------------------------------------------ */
.pdfflip__nav {
  flex: none;
  display: grid;
  place-items: center;
  width: clamp(34px, 5vw, 52px);
  height: clamp(34px, 5vw, 52px);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.pdfflip__nav svg { width: 46%; height: 46%; }

.pdfflip__nav:hover {
  background: var(--pdfflip-accent);
  border-color: var(--pdfflip-accent);
  transform: scale(1.06);
}

.pdfflip__nav:focus-visible {
  outline: 2px solid var(--pdfflip-accent);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------------------
 * Toolbar
 * ------------------------------------------------------------------------ */
.pdfflip__bar {
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 20px);
  padding: 10px clamp(10px, 2.5vw, 22px);
  background: #101315;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
}

.pdfflip__btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 2px;
  background: transparent;
  color: #fff;
  font-family: var(--pdfflip-display);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.pdfflip__btn svg { width: 15px; height: 15px; flex: none; }
.pdfflip__btn:hover { background: rgba(255, 255, 255, 0.1); }

.pdfflip__btn--accent {
  background: var(--pdfflip-accent);
  border-color: var(--pdfflip-accent);
}
.pdfflip__btn--accent:hover { filter: brightness(1.12); }

.pdfflip__btn:focus-visible {
  outline: 2px solid var(--pdfflip-accent);
  outline-offset: 2px;
}

.pdfflip__track {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pdfflip__count {
  font-family: var(--pdfflip-display);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
}
.pdfflip__count b { color: #fff; }

.pdfflip__slider {
  flex: 1 1 auto;
  min-width: 0;
  height: 3px;
  appearance: none;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 2px;
  cursor: pointer;
}

.pdfflip__slider::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--pdfflip-accent);
  border: 2px solid #101315;
}

.pdfflip__slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #101315;
  border-radius: 50%;
  background: var(--pdfflip-accent);
}

.pdfflip__tools { display: flex; gap: 8px; flex: none; }

/* ---------------------------------------------------------------------------
 * Contents sheet
 * ------------------------------------------------------------------------ */
/* `display: flex` beats the `hidden` attribute's UA `display: none`, which would
 * leave the closed sheet stacked over the book swallowing every click. Restate
 * it explicitly rather than relying on the attribute alone. */
.pdfflip__sheet[hidden] { display: none; }

.pdfflip__sheet {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: rgba(12, 15, 16, 0.97);
  backdrop-filter: blur(6px);
  animation: pdfflip-fade 0.2s ease;
}

@keyframes pdfflip-fade { from { opacity: 0; } to { opacity: 1; } }

.pdfflip__sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(14px, 3vw, 26px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  font-family: var(--pdfflip-display);
  font-size: 0.95rem;
  letter-spacing: 0.01em;
}

.pdfflip__thumbs {
  flex: 1 1 auto;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: clamp(10px, 1.6vw, 20px);
  padding: clamp(14px, 3vw, 26px);
}

.pdfflip__thumb {
  padding: 0;
  border: 0;
  background: none;
  color: rgba(255, 255, 255, 0.55);
  font-family: var(--pdfflip-display);
  font-size: 0.72rem;
  cursor: pointer;
}

.pdfflip__thumb img {
  display: block;
  width: 100%;
  height: auto;
  margin-bottom: 6px;
  background: #fff;
  border: 1px solid transparent;
  outline: 1px solid rgba(255, 255, 255, 0.1);
  transition: outline-color 0.16s ease, transform 0.16s ease;
}

.pdfflip__thumb:hover img { transform: translateY(-2px); outline-color: rgba(255, 255, 255, 0.5); }
.pdfflip__thumb.is-current img { outline: 2px solid var(--pdfflip-accent); }
.pdfflip__thumb.is-current { color: #fff; }

/* ---------------------------------------------------------------------------
 * Zoom + fullscreen
 * ------------------------------------------------------------------------ */
.pdfflip.is-zoomed .pdfflip__stage {
  overflow: auto;
  padding: 0;
}

.pdfflip.is-zoomed .pdfflip__book {
  max-width: none;
  width: 165%;
}

.pdfflip.is-zoomed .pdfflip__nav { display: none; }

.pdfflip.is-fullscreen {
  /* No surrounding page chrome in fullscreen, so the book gets the height back. */
  --pdfflip-maxh: calc(100svh - 96px);

  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #101315;
}

.pdfflip.is-fullscreen .pdfflip__stage { flex: 1 1 auto; min-height: 0; }
.pdfflip.is-fullscreen .pdfflip__book { max-height: 100%; }

/* ---------------------------------------------------------------------------
 * SEO text layer — present for crawlers and screen readers, never painted.
 * ------------------------------------------------------------------------ */
.pdfflip__seo {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.pdfflip__error {
  margin: 0;
  padding: 3rem 1.5rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
}

/* ---------------------------------------------------------------------------
 * Small screens: the side arrows cost width the spread needs, so the toolbar
 * takes over navigation and swipe does the rest.
 * ------------------------------------------------------------------------ */
@media (max-width: 640px) {
  .pdfflip__stage { grid-template-columns: minmax(0, 1fr); }
  .pdfflip__nav { display: none; }
  .pdfflip__btn span { display: none; }
  .pdfflip__btn { padding: 8px 10px; }
  .pdfflip__thumbs { grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .pdfflip__page:not(.is-ready)::after { animation: none; }
  .pdfflip__page img { transition: none; }
  .pdfflip__nav { transition: none; }
}
