/* ==========================================================================
   Flipbook 3D — styles
   Personnalisez l'apparence en changeant les variables ci-dessous,
   ou via les réglages de chaque flipbook dans WordPress.
   ========================================================================== */
.fb3d {
  --fb3d-bg: radial-gradient(ellipse at 50% 40%, #3a4656 0%, #232b36 70%, #1c232c 100%);
  --fb3d-accent: #f2b84b;
  --fb3d-bar-bg: rgba(20, 25, 32, 0.72);
  --fb3d-bar-fg: #eef1f5;
  --fb3d-height: 620px;
  --fb3d-radius: 10px;
  --fb3d-paper: #ffffff;
  --fb3d-spine-shadow: 0.22;       /* ombre au creux de la reliure (0 à 1) */

  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: min(var(--fb3d-height), 88vh);
  background: var(--fb3d-bg);
  border-radius: var(--fb3d-radius);
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--fb3d-bar-fg);
  outline: none;
  -webkit-user-select: none;
  user-select: none;
  box-sizing: border-box;
}
.fb3d-embed:not(.fb3d) { display: block; width: 100%; height: min(var(--fb3d-height, 620px), 88vh); }
.fb3d *, .fb3d *::before, .fb3d *::after { box-sizing: border-box; }
.fb3d:focus-visible { box-shadow: inset 0 0 0 2px var(--fb3d-accent); }

.fb3d.fb3d-is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 999999;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border-radius: 0;
}

/* ---------- Scène ---------- */
.fb3d-stage { position: relative; flex: 1 1 auto; min-height: 0; }
.fb3d-scroller {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.fb3d-stage.fb3d-zoomed .fb3d-scroller { overflow: auto; cursor: grab; }
.fb3d-zoomwrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 2400px;
  padding-bottom: 64px; /* place pour la barre d'outils */
}
.fb3d-book {
  position: relative;
  flex: 0 0 auto;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.45, 0, 0.2, 1);
  touch-action: pan-y;
  cursor: pointer;
}
.fb3d-book.fb3d-no-anim, .fb3d-book.fb3d-no-anim * { transition: none !important; }
.fb3d-zoomed .fb3d-book { cursor: default; }

/* ---------- Feuilles ---------- */
.fb3d-leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: var(--pw);
  height: var(--ph);
  transform-origin: 0 50%;
  transform-style: preserve-3d;
}
.fb3d-face {
  position: absolute;
  inset: 0;
  background: var(--fb3d-paper);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15), 0 10px 30px -8px rgba(0, 0, 0, 0.45);
}
.fb3d-back { transform: rotateY(180deg); }
.fb3d-face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}
/* Creux de la reliure */
.fb3d-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.fb3d-front::after {
  background: linear-gradient(to right,
    rgba(0, 0, 0, calc(var(--fb3d-spine-shadow) * 1.2)) 0%,
    rgba(0, 0, 0, calc(var(--fb3d-spine-shadow) * 0.35)) 3%,
    rgba(0, 0, 0, 0) 9%,
    rgba(255, 255, 255, 0.05) 96%,
    rgba(0, 0, 0, 0.06) 100%);
}
.fb3d-back::after {
  background: linear-gradient(to left,
    rgba(0, 0, 0, calc(var(--fb3d-spine-shadow) * 1.2)) 0%,
    rgba(0, 0, 0, calc(var(--fb3d-spine-shadow) * 0.35)) 3%,
    rgba(0, 0, 0, 0) 9%,
    rgba(0, 0, 0, 0.06) 100%);
}
.fb3d-face.fb3d-cover::after { background: linear-gradient(to right, rgba(255,255,255,0.12), rgba(0,0,0,0) 4%); }
.fb3d-back.fb3d-cover::after { background: linear-gradient(to left, rgba(255,255,255,0.12), rgba(0,0,0,0) 4%); }

/* Tranches (épaisseur du livre) */
.fb3d-edge {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 0;
  background: repeating-linear-gradient(to right, #e9e6df 0 1px, #cfcac0 1px 2px);
  transition: width 0.4s ease;
  box-shadow: 0 8px 22px -6px rgba(0, 0, 0, 0.5);
}
.fb3d-edge-l { right: 100%; }
.fb3d-edge-r { left: 100%; }

/* ---------- Page qui tourne ---------- */
.fb3d-flipper {
  display: none;
  position: absolute;
  top: 0;
  left: 50%;
  width: var(--pw);
  height: var(--ph);
  transform-style: preserve-3d;
  pointer-events: none;
}
.fb3d-strip {
  position: absolute;
  top: 0;
  height: var(--ph);
  transform-origin: 0 50%;
  transform-style: preserve-3d;
}
.fb3d-sface {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% + 2px); /* chevauchement : évite les fines lignes entre les bandes */
  height: 100%;
  background-color: var(--fb3d-paper);
  background-repeat: no-repeat;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.fb3d-sback { transform: rotateY(180deg); left: -2px; }
.fb3d-sface::after {
  content: "";
  position: absolute;
  inset: 0;
  /* la zone de chevauchement (2 px) garde la teinte du bord */
  background: linear-gradient(to right, rgba(0,0,0,var(--l0, 0)) 0, rgba(0,0,0,var(--l1, 0)) calc(100% - 2px));
}

/* Ombres portées pendant le mouvement */
.fb3d-cast {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transform: translateZ(0.5px);
}
.fb3d-cast-r { left: 50%; background: linear-gradient(to right, rgba(0,0,0,0.35), rgba(0,0,0,0.05) 60%, rgba(0,0,0,0)); }
.fb3d-cast-l { left: 0; background: linear-gradient(to left, rgba(0,0,0,0.35), rgba(0,0,0,0.05) 60%, rgba(0,0,0,0)); }

/* ---------- Barre d'outils ---------- */
.fb3d-bar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border-radius: 999px;
  background: var(--fb3d-bar-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  z-index: 5;
  opacity: 0;
  transition: opacity 0.4s ease;
  max-width: calc(100% - 20px);
}
.fb3d.fb3d-ready .fb3d-bar { opacity: 1; }
.fb3d-is-fullscreen .fb3d-bar { bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
.fb3d-group { display: flex; align-items: center; gap: 2px; }
.fb3d-group + .fb3d-group { padding-left: 6px; border-left: 1px solid rgba(255, 255, 255, 0.14); }

.fb3d-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--fb3d-bar-fg);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.fb3d-btn svg { width: 20px; height: 20px; }
.fb3d-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); color: var(--fb3d-accent); }
.fb3d-btn:focus-visible { outline: 2px solid var(--fb3d-accent); outline-offset: 1px; }
.fb3d-btn:disabled { opacity: 0.35; cursor: default; }
.fb3d-btn[aria-pressed="true"] { color: var(--fb3d-accent); }

.fb3d-counter {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 0 6px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.fb3d-counter input {
  width: auto;
  min-width: 2.2em;
  padding: 4px 6px;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font: inherit;
  text-align: center;
  box-shadow: none;
}
.fb3d-counter input:focus { outline: none; border-color: var(--fb3d-accent); background: rgba(255, 255, 255, 0.14); }
.fb3d-total { opacity: 0.7; }

/* ---------- Chargement ---------- */
.fb3d-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  transition: opacity 0.4s ease, visibility 0.4s;
  z-index: 4;
}
.fb3d-loader.fb3d-hidden { opacity: 0; visibility: hidden; }
.fb3d-loader-text { margin: 0; font-size: 14px; opacity: 0.8; max-width: 36ch; line-height: 1.5; }
.fb3d-progress { width: 140px; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.fb3d-progress div { width: 8%; height: 100%; background: var(--fb3d-accent); transition: width 0.2s ease; }
.fb3d-loader-book { position: relative; width: 44px; height: 30px; perspective: 200px; }
.fb3d-loader-book span {
  position: absolute; top: 0; left: 50%; width: 50%; height: 100%;
  background: var(--fb3d-accent); border-radius: 0 3px 3px 0;
  transform-origin: 0 50%;
}
.fb3d-loader-book span:last-child { animation: fb3d-loader-flip 1.1s ease-in-out infinite; opacity: 0.75; }
@keyframes fb3d-loader-flip { 0% { transform: rotateY(0); } 60%, 100% { transform: rotateY(-180deg); } }
.fb3d-loader.fb3d-error .fb3d-loader-book,
.fb3d-loader.fb3d-error .fb3d-progress { display: none; }

/* ---------- Petits écrans ---------- */
@media (max-width: 600px) {
  .fb3d, .fb3d-embed:not(.fb3d) { height: min(var(--fb3d-height, 620px), 62vh); }
  .fb3d-btn { width: 32px; height: 32px; }
  .fb3d-btn svg { width: 18px; height: 18px; }
  .fb3d-btn[data-action="first"], .fb3d-btn[data-action="last"],
  .fb3d-btn[data-action="zoomOut"], .fb3d-btn[data-action="zoomIn"] { display: none; }
  .fb3d-bar { bottom: 10px; gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .fb3d-book, .fb3d-edge { transition: none; }
  .fb3d-loader-book span:last-child { animation: none; }
}
