/*
 * Feuilletage « Les Cahiers TVPSDT » — composant isolé, sans dépendance.
 * Toutes les règles sont préfixées par .tvpsdt-fb : rien ne touche au reste de la page.
 * Sans JavaScript : liste d'extraits lisible (défilement horizontal).
 * Avec JavaScript : carnet fermé, puis ouverture et feuilletage (voir tvpsdt-flipbook.js).
 */

.tvpsdt-fb {
  --fb-ink: #3a2635;
  --fb-soft: #6f5d68;
  --fb-paper: #fffdf9;
  --fb-cover-edge: #e6d3bf;
  --fb-accent: #b9684f;
  --fb-ring: #7a5a9e;
  --fb-scene: #faf5ee;
  --fb-radius: 24px;
  position: relative;
  box-sizing: border-box;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  color: var(--fb-ink);
  font: inherit;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
.tvpsdt-fb *, .tvpsdt-fb *::before, .tvpsdt-fb *::after { box-sizing: border-box; }

/* ---------- Mode statique (sans JavaScript) ---------- */
.tvpsdt-fb__static { padding: 4px 0 0; }
.tvpsdt-fb .tvpsdt-fb__list {
  display: flex;
  gap: 18px;
  margin: 0;
  padding: 6px 4px 18px;
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
}
.tvpsdt-fb .tvpsdt-fb__item {
  flex: 0 0 clamp(220px, 30%, 320px);
  margin: 0;
  padding: 0;
  scroll-snap-align: center;
  list-style: none;
}
.tvpsdt-fb .tvpsdt-fb__item::before, .tvpsdt-fb .tvpsdt-fb__item::marker { content: none; }
.tvpsdt-fb .tvpsdt-fb__item figure { margin: 0; }
.tvpsdt-fb .tvpsdt-fb__item img {
  display: block;
  width: 100% !important;
  height: auto !important;
  max-width: none !important;
  aspect-ratio: 148 / 210;
  object-fit: contain;
  margin: 0;
  border: 0;
  border-radius: 2px;
  background: var(--fb-paper);
  box-shadow: 0 1px 2px rgba(40, 25, 35, .12), 0 10px 24px -12px rgba(40, 25, 35, .35);
}
.tvpsdt-fb .tvpsdt-fb__item figcaption {
  margin-top: 10px;
  font-size: 14px;
  color: var(--fb-soft);
  text-align: center;
}
.tvpsdt-fb__note {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--fb-soft);
  text-align: center;
}
@media (max-width: 600px) {
  .tvpsdt-fb .tvpsdt-fb__item { flex-basis: 84%; }
}

/* ---------- Mode carnet (avec JavaScript) ---------- */
.tvpsdt-fb--js .tvpsdt-fb__static { display: none; }
.tvpsdt-fb__scene {
  position: relative;
  padding: clamp(22px, 4.5vw, 54px) clamp(10px, 3vw, 40px) clamp(14px, 2.4vw, 26px);
  border-radius: var(--fb-radius);
  background:
    radial-gradient(ellipse 70% 55% at 50% 62%, rgba(179, 163, 211, .20), transparent 72%),
    radial-gradient(ellipse 60% 45% at 20% 20%, rgba(233, 199, 168, .18), transparent 70%),
    var(--fb-scene);
  overflow: hidden;
}
.tvpsdt-fb__stage {
  position: relative;
  margin: 0 auto;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  outline: none;
}
.tvpsdt-fb[data-fb-mode="spread"] .tvpsdt-fb__stage {
  width: min(100%, 940px, calc((100vh - 190px) * 1.4095));
  width: min(100%, 940px, calc((100svh - 190px) * 1.4095));
  aspect-ratio: 296 / 210;
}
.tvpsdt-fb[data-fb-mode="single"] .tvpsdt-fb__stage {
  width: min(100%, 520px, calc((100vh - 170px) * .7048));
  width: min(100%, 520px, calc((100svh - 170px) * .7048));
  aspect-ratio: 148 / 210;
}
.tvpsdt-fb__stage:focus-visible { box-shadow: 0 0 0 3px var(--fb-scene), 0 0 0 5px var(--fb-ring); border-radius: 6px; }

.tvpsdt-fb__book {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
  will-change: transform;
}
.tvpsdt-fb__floor {
  position: absolute;
  left: 50%;
  bottom: -5%;
  width: 100%;
  height: 12%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(52, 33, 48, .30), rgba(52, 33, 48, .12) 55%, transparent 100%);
  filter: blur(6px);
  transform: translateX(-50%);
  pointer-events: none;
}

/* bords de pages empilées (épaisseur du carnet agrafé) */
.tvpsdt-fb__edges {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--fb-paper);
  pointer-events: none;
}
.tvpsdt-fb[data-fb-mode="spread"] .tvpsdt-fb__edges { width: 50%; }
.tvpsdt-fb[data-fb-mode="single"] .tvpsdt-fb__edges { width: 100%; left: 0; }
.tvpsdt-fb__edges--right {
  left: 50%;
  border-radius: 1px 4px 4px 1px;
  box-shadow:
    1px 1px 0 #fbf8f2, 2px 1.5px 0 #ddd5ca, 3px 2px 0 #fcfaf6, 4px 2.5px 0 #d9d0c4,
    5px 3px 0 var(--fb-cover-edge), 6px 3.5px 0 #cdb79f,
    10px 16px 26px -8px rgba(48, 30, 44, .30);
}
.tvpsdt-fb[data-fb-mode="single"] .tvpsdt-fb__edges--right { left: 0; }
.tvpsdt-fb__edges--left {
  left: 0;
  border-radius: 4px 1px 1px 4px;
  box-shadow:
    -1px 1px 0 #fbf8f2, -2px 1.5px 0 #ddd5ca, -3px 2px 0 #fcfaf6, -4px 2.5px 0 #d9d0c4,
    -5px 3px 0 var(--fb-cover-edge), -6px 3.5px 0 #cdb79f,
    -10px 16px 26px -8px rgba(48, 30, 44, .26);
  opacity: 0;
}

/* feuillets */
.tvpsdt-fb__leaf {
  position: absolute;
  top: 0;
  height: 100%;
  transform-style: preserve-3d;
  transform-origin: 0 50%;
  will-change: transform;
}
.tvpsdt-fb[data-fb-mode="spread"] .tvpsdt-fb__leaf { left: 50%; width: 50%; }
.tvpsdt-fb[data-fb-mode="single"] .tvpsdt-fb__leaf { left: 0; width: 100%; }
.tvpsdt-fb__face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--fb-paper);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 1px 4px 4px 1px;
  box-shadow: 0 1px 2px rgba(40, 25, 35, .10);
}
.tvpsdt-fb__face--back { transform: rotateY(180deg); border-radius: 4px 1px 1px 4px; }
.tvpsdt-fb .tvpsdt-fb__face img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}
.tvpsdt-fb__blank { position: absolute; inset: 0; background: linear-gradient(180deg, #fbf8f3, #f7f2ea); }

/* ombre de reliure (pli) + lumière dynamique pendant le tour de page */
.tvpsdt-fb__face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(28, 16, 26, var(--fb-shade, 0)), rgba(28, 16, 26, var(--fb-shade, 0))),
    linear-gradient(90deg, rgba(35, 20, 32, .20) 0, rgba(35, 20, 32, .07) 2.6%, rgba(35, 20, 32, 0) 8%, rgba(255, 255, 255, 0) 94%, rgba(35, 20, 32, .05) 100%);
}
.tvpsdt-fb__face--back::after {
  background:
    linear-gradient(rgba(28, 16, 26, var(--fb-shade, 0)), rgba(28, 16, 26, var(--fb-shade, 0))),
    linear-gradient(270deg, rgba(35, 20, 32, .20) 0, rgba(35, 20, 32, .07) 2.6%, rgba(35, 20, 32, 0) 8%, rgba(255, 255, 255, 0) 94%, rgba(35, 20, 32, .05) 100%);
}
/* la couverture fermée n'a pas de pli intérieur visible */
.tvpsdt-fb__leaf--cover .tvpsdt-fb__face--front::after {
  background:
    linear-gradient(rgba(28, 16, 26, var(--fb-shade, 0)), rgba(28, 16, 26, var(--fb-shade, 0))),
    linear-gradient(90deg, rgba(35, 20, 32, .16) 0, rgba(255, 255, 255, .10) 1.4%, rgba(35, 20, 32, 0) 4%);
}

/* ombre portée par la page qui tourne sur la page découverte */
.tvpsdt-fb__cast {
  position: absolute;
  top: 0;
  height: 100%;
  pointer-events: none;
  opacity: 0;
}
.tvpsdt-fb[data-fb-mode="spread"] .tvpsdt-fb__cast { width: 50%; }
.tvpsdt-fb[data-fb-mode="single"] .tvpsdt-fb__cast { width: 100%; left: 0; }
.tvpsdt-fb__cast--right {
  left: 50%;
  background: linear-gradient(90deg, rgba(30, 18, 28, 0) 0, rgba(30, 18, 28, 0) var(--fb-edge, 0%),
    rgba(30, 18, 28, .42) var(--fb-edge, 0%), rgba(30, 18, 28, 0) calc(var(--fb-edge, 0%) + 22%));
}
.tvpsdt-fb[data-fb-mode="single"] .tvpsdt-fb__cast--right { left: 0; }
.tvpsdt-fb__cast--left {
  left: 0;
  background: linear-gradient(270deg, rgba(30, 18, 28, 0) 0, rgba(30, 18, 28, 0) var(--fb-edge, 0%),
    rgba(30, 18, 28, .38) var(--fb-edge, 0%), rgba(30, 18, 28, 0) calc(var(--fb-edge, 0%) + 22%));
}

/* survol du carnet fermé : la couverture se soulève à peine (pas d'animation automatique) */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .tvpsdt-fb[data-fb-state="0"][data-fb-idle]:not([data-fb-reduced]) .tvpsdt-fb__leaf--cover { transition: transform .45s cubic-bezier(.45, 0, .2, 1); }
  .tvpsdt-fb[data-fb-state="0"][data-fb-idle]:not([data-fb-reduced]) .tvpsdt-fb__stage:hover .tvpsdt-fb__leaf--cover { transform: rotateY(-9deg); }
}

/* ---------- Commandes ---------- */
.tvpsdt-fb__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  margin-top: clamp(14px, 2.2vw, 22px);
}
.tvpsdt-fb .tvpsdt-fb__btn {
  all: unset;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid rgba(58, 38, 53, .22);
  border-radius: 999px;
  background: rgba(255, 255, 255, .78);
  color: var(--fb-ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: border-color .15s, opacity .15s;
}
.tvpsdt-fb .tvpsdt-fb__btn:hover { background: #fff; border-color: rgba(58, 38, 53, .45); }
.tvpsdt-fb .tvpsdt-fb__btn:focus-visible { outline: 3px solid var(--fb-ring); outline-offset: 2px; }
.tvpsdt-fb .tvpsdt-fb__btn[disabled] { opacity: .38; cursor: default; }
.tvpsdt-fb .tvpsdt-fb__btn--icon { padding: 0; width: 46px; }
.tvpsdt-fb .tvpsdt-fb__btn--primary { background: var(--fb-ink); border-color: var(--fb-ink); color: #fff; }
.tvpsdt-fb .tvpsdt-fb__btn--primary:hover { background: #241722; border-color: #241722; }
.tvpsdt-fb .tvpsdt-fb__btn svg { width: 18px; height: 18px; flex: none; }
.tvpsdt-fb__where {
  min-width: 9.5em;
  font-size: 15px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.tvpsdt-fb__where small { display: block; margin-top: 2px; font-size: 13px; color: var(--fb-soft); }
.tvpsdt-fb__sr {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
@media (max-width: 600px) {
  .tvpsdt-fb .tvpsdt-fb__btn { font-size: 14px; padding: 0 14px; }
  .tvpsdt-fb__where { min-width: 7.5em; font-size: 14px; }
  .tvpsdt-fb__bar .tvpsdt-fb__btn--zoom { flex-basis: 100%; max-width: 240px; }
}

/* ---------- Lecture en grand ---------- */
.tvpsdt-fb__dialog {
  width: min(1180px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: #f4efe8;
  color: var(--fb-ink);
  box-shadow: 0 30px 90px rgba(25, 12, 22, .40);
  overflow: auto;
}
.tvpsdt-fb__dialog::backdrop { background: rgba(32, 20, 30, .62); }
.tvpsdt-fb__dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 20px;
  background: rgba(244, 239, 232, .94);
  font-size: 15px;
  font-weight: 600;
}
.tvpsdt-fb__dialog-pages {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 6px 16px 22px;
}
.tvpsdt-fb__dialog-hint { margin: 0; padding: 0 20px 4px; font-size: 13px; font-weight: 400; color: var(--fb-soft, #6f5d68); }
.tvpsdt-fb__dialog-pages img { cursor: zoom-in; }
.tvpsdt-fb__dialog-pages.is-zoomed { justify-content: flex-start; }
.tvpsdt-fb .tvpsdt-fb__dialog-pages.is-zoomed img,
.tvpsdt-fb__dialog-pages.is-zoomed img { width: min(200%, 1100px) !important; max-width: none !important; cursor: zoom-out; }
@media (max-width: 600px) {
  .tvpsdt-fb__dialog { width: calc(100vw - 12px); max-height: calc(100vh - 12px); max-height: calc(100dvh - 12px); border-radius: 14px; }
  .tvpsdt-fb__dialog-pages { padding: 4px 8px 16px; }
}
.tvpsdt-fb .tvpsdt-fb__dialog-pages img,
.tvpsdt-fb__dialog-pages img {
  display: block;
  width: min(100%, 560px) !important;
  height: auto !important;
  max-width: 100% !important;
  aspect-ratio: 148 / 210;
  margin: 0;
  border-radius: 2px;
  background: var(--fb-paper);
  box-shadow: 0 2px 10px rgba(40, 25, 35, .18);
}

/* ---------- Mouvement réduit : aucune rotation ni inclinaison ---------- */
.tvpsdt-fb[data-fb-reduced] .tvpsdt-fb__leaf,
.tvpsdt-fb[data-fb-reduced] .tvpsdt-fb__book { transition: none !important; }

@media (forced-colors: active) {
  .tvpsdt-fb__face::after, .tvpsdt-fb__cast, .tvpsdt-fb__floor { display: none; }
  .tvpsdt-fb .tvpsdt-fb__btn { border: 1px solid ButtonText; }
}
