/* PDF flipbook viewer — Heyzine-class modal overlay */

.pdf-viewer-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.65rem;
  padding: 0.55rem 1.05rem;
  border: 1px solid rgba(233, 142, 84, 0.45);
  border-radius: 999px;
  background: rgba(233, 142, 84, 0.1);
  font-family: 'Poppins', sans-serif;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255, 198, 142, 1);
  cursor: pointer;
  transition: background 0.22s ease, border-color 0.22s ease, transform 0.22s ease, color 0.22s ease;
  text-decoration: none;
  width: max-content;
}

.pdf-viewer-trigger::before {
  content: '';
  width: 0.85rem;
  height: 0.85rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffc68e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z'/%3E%3Cpath d='M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
}

.pdf-viewer-trigger:hover {
  background: rgba(233, 142, 84, 0.22);
  border-color: rgba(255, 198, 142, 0.85);
  color: rgba(255, 252, 245, 1);
  transform: translateY(-1px);
}

.pdf-viewer-trigger[disabled],
.pdf-viewer-trigger[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Modal overlay ----------------------------------------------------- */

.pdf-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  background: rgba(8, 14, 24, 0.92);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 4rem);
  opacity: 0;
  transition: opacity 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.pdf-modal.is-open {
  display: flex;
  opacity: 1;
}

.pdf-modal-backdrop {
  position: absolute;
  inset: 0;
  cursor: zoom-out;
}

.pdf-modal-stage {
  position: relative;
  width: 100%;
  max-width: 1280px;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0.9rem;
  z-index: 1;
}

.pdf-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: rgba(255, 240, 222, 0.95);
}

.pdf-modal-title {
  font-family: 'Poppins', sans-serif;
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin: 0;
}

.pdf-modal-meta {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 198, 142, 0.85);
}

.pdf-modal-close,
.pdf-modal-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 198, 142, 0.32);
  background: rgba(255, 198, 142, 0.08);
  color: rgba(255, 240, 222, 0.95);
  cursor: pointer;
  transition: background 0.22s ease, border-color 0.22s ease, color 0.22s ease, transform 0.22s ease;
  text-decoration: none;
}

.pdf-modal-close:hover,
.pdf-modal-download:hover {
  background: rgba(255, 198, 142, 0.2);
  border-color: rgba(255, 198, 142, 0.7);
  color: rgba(255, 252, 245, 1);
  transform: translateY(-1px);
}

.pdf-modal-close svg,
.pdf-modal-download svg {
  width: 1rem;
  height: 1rem;
}

.pdf-modal-actions {
  display: flex;
  gap: 0.5rem;
}

/* ---- Flipbook stage ---------------------------------------------------- */

.pdf-flipbook-wrap {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 0.5rem;
  background:
    radial-gradient(ellipse 40% 60% at 50% 100%, rgba(0, 0, 0, 0.38), transparent 70%),
    linear-gradient(180deg, rgba(20, 14, 8, 0.5) 0%, rgba(8, 5, 3, 0.7) 100%);
}

/* Container for StPageFlip. The library positions its own .stf__block
   absolutely from this element's origin, so it must NOT be a grid/flex
   parent — otherwise the absolute coordinates get offset and pages
   render half off-screen. The JS sets explicit width/height so the
   container matches the spread; .pdf-flipbook-wrap centers it.

   The transform is animated so that when on the front cover or back
   cover (which display alone, half-width inside the spread), the JS
   can shift the flipbook by ±25% to center the visible page — giving
   a single-page preview that opens into a full spread on flip. */
.pdf-flipbook {
  position: relative;
  display: block;
  transition: transform 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}

/* Cover alone on the right → shift left so it sits in the center. */
.pdf-modal.is-cover .pdf-flipbook {
  transform: translateX(-25%);
}

/* Back cover alone on the left → shift right so it sits in the center. */
.pdf-modal.is-back-cover .pdf-flipbook {
  transform: translateX(25%);
}

/* StPageFlip injects its own root; ensure pages render with subtle drop shadow */
.pdf-flipbook .stf__parent {
  filter: drop-shadow(0 18px 40px rgba(0, 0, 0, 0.4));
  transition: filter 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Closed-book preview: when only the front or back cover is visible,
   stack drop-shadows to fake the silhouette of layered pages tucked
   behind the cover, plus a stronger cast shadow for weight. The
   silhouette offsets sit on the fore-edge (right side for the front
   cover, left side for the back cover) so the cover reads like a
   real book seen from a slight angle. */
.pdf-modal.is-cover .pdf-flipbook .stf__parent {
  filter:
    drop-shadow(2px 0 0 rgba(238, 228, 210, 0.92))
    drop-shadow(4px 0 0 rgba(214, 202, 182, 0.86))
    drop-shadow(6px 0 0 rgba(186, 172, 150, 0.8))
    drop-shadow(8px 1px 0 rgba(160, 144, 122, 0.7))
    drop-shadow(0 32px 56px rgba(0, 0, 0, 0.55))
    drop-shadow(0 10px 18px rgba(0, 0, 0, 0.32));
}

.pdf-modal.is-back-cover .pdf-flipbook .stf__parent {
  filter:
    drop-shadow(-2px 0 0 rgba(238, 228, 210, 0.92))
    drop-shadow(-4px 0 0 rgba(214, 202, 182, 0.86))
    drop-shadow(-6px 0 0 rgba(186, 172, 150, 0.8))
    drop-shadow(-8px 1px 0 rgba(160, 144, 122, 0.7))
    drop-shadow(0 32px 56px rgba(0, 0, 0, 0.55))
    drop-shadow(0 10px 18px rgba(0, 0, 0, 0.32));
}

/* Spine crease overlay — a soft inner shadow along the bound edge,
   layered above the canvas via a pseudo-element so it isn't masked
   by the rendered PDF pixels. Multiply blends with the page so dark
   ink stays dark and only the cream margins darken at the binding. */
.pdf-modal.is-cover .pdf-flipbook .stf__item.--right::after,
.pdf-modal.is-back-cover .pdf-flipbook .stf__item.--left::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
  z-index: 2;
}
.pdf-modal.is-cover .pdf-flipbook .stf__item.--right::after {
  background: linear-gradient(
    to right,
    rgba(0, 0, 0, 0.28) 0,
    rgba(0, 0, 0, 0.08) 18px,
    transparent 36px
  );
}
.pdf-modal.is-back-cover .pdf-flipbook .stf__item.--left::after {
  background: linear-gradient(
    to left,
    rgba(0, 0, 0, 0.28) 0,
    rgba(0, 0, 0, 0.08) 18px,
    transparent 36px
  );
}

/* Block stays transparent so the empty companion-page area on the
   cover/back-cover views doesn't paint as a cream rectangle. Only the
   actual pages get the paper background. */
.pdf-flipbook .stf__block {
  background: transparent !important;
}

.pdf-flipbook .stf__item {
  background: rgba(255, 248, 238, 1) !important;
}

.pdf-page {
  width: 100%;
  height: 100%;
  background: #fff;
  display: block;
}

.pdf-page canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* ---- Footer controls --------------------------------------------------- */

.pdf-modal-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.4rem 0;
  color: rgba(255, 240, 222, 0.85);
  font-family: 'Poppins', sans-serif;
}

.pdf-page-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 198, 142, 0.32);
  background: rgba(255, 198, 142, 0.08);
  color: rgba(255, 240, 222, 0.95);
  cursor: pointer;
  transition: background 0.22s ease, border-color 0.22s ease, transform 0.22s ease;
}

.pdf-page-nav:hover {
  background: rgba(255, 198, 142, 0.2);
  border-color: rgba(255, 198, 142, 0.7);
  transform: translateY(-1px);
}

.pdf-page-nav[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.pdf-page-nav svg {
  width: 1rem;
  height: 1rem;
}

.pdf-page-counter {
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  min-width: 5.5rem;
  text-align: center;
  color: rgba(255, 198, 142, 0.95);
}

/* ---- Loading & empty states ------------------------------------------- */

/* The HTML `hidden` attribute sets display:none via the UA stylesheet,
   but our author rule `display: grid` would otherwise win. Restore the
   intended behaviour explicitly. */
.pdf-modal [hidden] {
  display: none !important;
}

.pdf-state {
  display: grid;
  place-items: center;
  gap: 0.85rem;
  padding: 4rem 2rem;
  text-align: center;
  color: rgba(255, 240, 222, 0.78);
  font-family: 'Poppins', sans-serif;
}

.pdf-state-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(255, 252, 245, 1);
}

.pdf-state-desc {
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.6;
  max-width: 28rem;
  color: rgba(255, 240, 222, 0.7);
}

.pdf-native-viewer {
  width: min(100%, 1040px);
  height: min(72vh, 820px);
  border-radius: 0.5rem;
  overflow: hidden;
  background: rgba(255, 248, 238, 0.96);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.pdf-native-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.pdf-native-fallback-note {
  margin-top: 0.85rem;
  max-width: 44rem;
}

.pdf-state-spinner {
  width: 2.4rem;
  height: 2.4rem;
  border: 2px solid rgba(255, 198, 142, 0.18);
  border-top-color: rgba(255, 198, 142, 0.95);
  border-radius: 50%;
  animation: pdf-spin 0.85s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .pdf-state-spinner { animation: none; }
  .pdf-modal { transition: none; }
}

/* ---- Mobile adjustments ------------------------------------------------ */

@media (max-width: 720px) {
  .pdf-modal {
    padding: 0.5rem;
  }
  .pdf-modal-stage {
    gap: 0.5rem;
  }
  .pdf-modal-title {
    font-size: 0.74rem;
  }
  .pdf-modal-meta {
    display: none;
  }
  .pdf-modal-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .pdf-modal-close,
  .pdf-modal-download {
    width: 2rem;
    height: 2rem;
  }
  .pdf-modal-close svg,
  .pdf-modal-download svg {
    width: 0.875rem;
    height: 0.875rem;
  }
  .pdf-page-nav {
    width: 2rem;
    height: 2rem;
  }
  .pdf-page-nav svg {
    width: 0.875rem;
    height: 0.875rem;
  }
  .pdf-page-counter {
    font-size: 0.7rem;
    min-width: 4.5rem;
  }
}

/* Very small screens - Enhanced mobile responsiveness */
@media (max-width: 480px) {
  .pdf-modal {
    padding: 0.25rem;
  }

  .pdf-modal-stage {
    gap: 0.35rem;
    grid-template-rows: auto 1fr auto;
  }

  .pdf-modal-header {
    padding: 0.25rem;
    gap: 0.35rem;
  }

  .pdf-modal-title {
    font-size: 0.65rem;
    line-height: 1.3;
    max-width: calc(100% - 100px);
  }

  .pdf-modal-close,
  .pdf-modal-download {
    width: 1.75rem;
    height: 1.75rem;
  }

  .pdf-modal-close svg,
  .pdf-modal-download svg {
    width: 0.75rem;
    height: 0.75rem;
  }

  .pdf-flipbook-wrap {
    border-radius: 0.25rem;
  }

  .pdf-modal-footer {
    padding: 0.25rem 0;
    gap: 0.5rem;
  }

  .pdf-page-nav {
    width: 1.75rem;
    height: 1.75rem;
  }

  .pdf-page-nav svg {
    width: 0.75rem;
    height: 0.75rem;
  }

  .pdf-page-counter {
    font-size: 0.65rem;
    min-width: 4rem;
  }

  .pdf-state {
    padding: 2rem 1rem;
    gap: 0.6rem;
  }

  .pdf-state-title {
    font-size: 0.875rem;
  }

  .pdf-state-desc {
    font-size: 0.75rem;
  }

  .pdf-native-viewer {
    height: min(65vh, 600px);
  }
}

/* Extra small screens (≤380px) */
@media (max-width: 380px) {
  .pdf-modal {
    padding: 0.15rem;
  }

  .pdf-modal-stage {
    gap: 0.25rem;
  }

  .pdf-modal-header {
    padding: 0.2rem;
  }

  .pdf-modal-title {
    font-size: 0.6rem;
    max-width: calc(100% - 90px);
  }

  .pdf-modal-close,
  .pdf-modal-download {
    width: 1.5rem;
    height: 1.5rem;
  }

  .pdf-modal-close svg,
  .pdf-modal-download svg {
    width: 0.7rem;
    height: 0.7rem;
  }

  .pdf-page-nav {
    width: 1.5rem;
    height: 1.5rem;
  }

  .pdf-page-nav svg {
    width: 0.7rem;
    height: 0.7rem;
  }

  .pdf-page-counter {
    font-size: 0.6rem;
    min-width: 3.5rem;
    letter-spacing: 0.1em;
  }

  .pdf-state {
    padding: 1.5rem 0.75rem;
  }

  .pdf-state-title {
    font-size: 0.8rem;
  }

  .pdf-state-desc {
    font-size: 0.7rem;
  }
}

/* PDF Viewer Trigger Button - Mobile Responsive */
@media (max-width: 600px) {
  .pdf-viewer-trigger {
    font-size: 0.6rem;
    padding: 0.5rem 0.9rem;
    gap: 0.35rem;
  }

  .pdf-viewer-trigger::before {
    width: 0.75rem;
    height: 0.75rem;
  }
}

@media (max-width: 480px) {
  .pdf-viewer-trigger {
    font-size: 0.55rem;
    padding: 0.45rem 0.8rem;
  }

  .pdf-viewer-trigger::before {
    width: 0.7rem;
    height: 0.7rem;
  }
}
