/* ============================================================================
   PMG Flip-Deck - self-contained page-flip viewer (no WordPress, no plugin).
   Replaces the old DearFlip/dFlip 3D FlipBook. Renders pre-rasterized deck
   pages (WebP) with a CSS 3D page-turn. Mobile-friendly: swipe + tap zones.
   Theme-aware via existing tokens (var(--fg), var(--orange), var(--bg-elev)).
   ============================================================================ */

.flipdeck {
  --fd-accent: var(--orange, #F1420B);
  position: relative;
  width: 100%;
  margin-top: 1.4rem;
}

/* Deck picker (tabs) for the multi-deck showcase. Sits above the stage. */
.flipdeck-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.flipdeck-tab {
  font-family: "Oswald", sans-serif;
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-muted, rgba(255,255,255,0.7));
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--grey-30, rgba(255,255,255,0.22));
  border-radius: 100px;
  background: transparent;
  cursor: pointer;
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease;
  white-space: nowrap;
}
.flipdeck-tab:hover { color: var(--fg, #fff); border-color: var(--fd-accent); }
.flipdeck-tab.is-active {
  color: #fff;
  background: var(--fd-accent);
  border-color: var(--fd-accent);
}
.flipdeck-tab:focus-visible { outline: 2px solid var(--fd-accent); outline-offset: 2px; }

/* Stage keeps the book 16:9 and centered. */
.flipdeck-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--hair, rgba(255,255,255,0.12));
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elev, #0d0d0d);
  perspective: 2200px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

/* Each page image fills the stage; only the current page is shown. */
.flipdeck-page {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg-elev, #0d0d0d);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease;
  will-change: opacity;
}
.flipdeck-page.is-current { opacity: 1; visibility: visible; z-index: 2; }

/* The turning overlay: a clone that rotates around the spine for the 3D flip. */
.flipdeck-turn {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg-elev, #0d0d0d);
  z-index: 5;
  transform-origin: left center;
  transform: rotateY(0deg);
  box-shadow: 0 0 0 rgba(0,0,0,0);
  visibility: hidden;
  backface-visibility: hidden;
}
.flipdeck-turn.turn-next {
  transform-origin: left center;
  animation: fdTurnNext 0.55s cubic-bezier(0.4, 0.1, 0.3, 1) forwards;
}
.flipdeck-turn.turn-prev {
  transform-origin: right center;
  animation: fdTurnPrev 0.55s cubic-bezier(0.4, 0.1, 0.3, 1) forwards;
}
@keyframes fdTurnNext {
  0%   { transform: rotateY(0deg);   box-shadow: -8px 0 22px rgba(0,0,0,0.0); }
  50%  { box-shadow: -22px 0 34px rgba(0,0,0,0.35); }
  100% { transform: rotateY(-172deg); box-shadow: -8px 0 22px rgba(0,0,0,0.0); }
}
@keyframes fdTurnPrev {
  0%   { transform: rotateY(0deg);   box-shadow: 8px 0 22px rgba(0,0,0,0.0); }
  50%  { box-shadow: 22px 0 34px rgba(0,0,0,0.35); }
  100% { transform: rotateY(172deg);  box-shadow: 8px 0 22px rgba(0,0,0,0.0); }
}

/* Tap zones (left = prev, right = next) for touch + click. */
.flipdeck-zone {
  position: absolute;
  top: 0;
  height: 100%;
  width: 34%;
  z-index: 8;
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
}
.flipdeck-zone.prev { left: 0; }
.flipdeck-zone.next { right: 0; }
.flipdeck-zone:focus-visible { outline: 2px solid var(--fd-accent); outline-offset: -4px; }

/* Controls bar. */
.flipdeck-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}
.flipdeck-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 100px;
  border: 1px solid var(--grey-30, rgba(255,255,255,0.22));
  background: transparent;
  color: var(--fg, #fff);
  cursor: pointer;
  transition: color 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}
.flipdeck-btn:hover:not(:disabled) { color: #fff; background: var(--fd-accent); border-color: var(--fd-accent); }
.flipdeck-btn:disabled { opacity: 0.35; cursor: default; }
.flipdeck-btn svg { width: 16px; height: 16px; fill: currentColor; }

.flipdeck-counter {
  font-family: "Oswald", sans-serif;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-muted, rgba(255,255,255,0.7));
  min-width: 78px;
  text-align: center;
}

.flipdeck-fs {
  margin-left: 0.4rem;
}

/* Fullscreen viewer. */
.flipdeck.is-fullscreen .flipdeck-stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  z-index: 9999;
  border-radius: 0;
  background: #050505;
  display: flex;
  align-items: center;
  justify-content: center;
}
.flipdeck.is-fullscreen .flipdeck-controls {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  background: rgba(10,10,10,0.7);
  padding: 0.5rem 1rem;
  border-radius: 100px;
  backdrop-filter: blur(6px);
}

/* Loading + reduced motion. */
.flipdeck-page:not([src]) { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  .flipdeck-turn.turn-next, .flipdeck-turn.turn-prev { animation-duration: 0.01s; }
  .flipdeck-page { transition: none; }
}
@media (max-width: 640px) {
  .flipdeck-btn { width: 38px; height: 38px; }
  .flipdeck-counter { font-size: 0.72rem; }
  .flipdeck-tab { font-size: 0.68rem; padding: 0.5rem 0.85rem; letter-spacing: 0.08em; }
  .flipdeck-picker { gap: 0.4rem; }
}
