/* ═══════════════════════════════════════════════════════════════
   THE PHILOSOPHY — LIBRO CHE SI SFOGLIA (2026-10-15)
   Mobile: pagina singola, le pagine girano sul dorso a sinistra.
   Desktop (≥900px): doppia pagina, il libro si centra all'apertura.
   Lo sfoglio è guidato da the-philosophy-book.js (GSAP ScrollTrigger).
═══════════════════════════════════════════════════════════════ */

.book-section {
  --gold: #A88A5B;
  --gold-soft: rgba(168, 138, 91, 0.45);
  --paper: #F3EFE8;
  --paper-dark: #E6DDCF;
  --leather: #4A3628;
  --leather-dark: #2A1E16;
  --hdr: 96px;
  --overhang: 7px;
  --ratio: 1.55;
  --book-scale: 0.765; /* libro ridotto: -15% e poi -10% (2026-10-15) */
  --page-w: calc(min(90vw, 480px, calc((100svh - var(--hdr) - 40px) / var(--ratio))) * var(--book-scale));
  --page-h: calc(var(--page-w) * var(--ratio));
  position: relative;
  z-index: 1;
}

.book-stage {
  height: 100svh;
  padding-top: var(--hdr);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  perspective: 2200px;
}

/* il libro: su mobile è largo quanto una pagina (dorso = bordo sinistro) */
.book {
  position: relative;
  width: var(--page-w);
  height: var(--page-h);
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

/* ─── PAGINA DI FONDO + SPESSORE DEL BLOCCO PAGINE ──────────── */

.book-base {
  position: absolute;
  inset: 0;
  border-radius: 2px 6px 6px 2px;
  /* spessore del blocco pagine: solo sul taglio esterno, a filo con testa e piede */
  box-shadow:
    1px 0 0 #CDBFA4, 2px 0 0 #E2D6BE,
    3px 0 0 #C9BA9E, 4px 0 0 #DED1B7,
    5px 0 0 #BFAE90;
}
/* piatto posteriore in cuoio: sporge oltre il blocco pagine */
.book-base::before {
  content: "";
  position: absolute;
  inset: calc(var(--overhang) * -1) calc(var(--overhang) * -1) calc(var(--overhang) * -1) 0;
  z-index: -1;
  border-radius: 2px 6px 6px 2px;
  background: #3E2214 url("../img/global/philosophy-book-cover-v3.webp") right center / 100% 100% no-repeat;
  box-shadow: inset 0 0 18px rgba(20, 8, 2, 0.7), 0 30px 60px rgba(0, 0, 0, 0.45);
}

/* la copertina è più grande delle pagine: chiusa, non sbuca nulla */
.leaf-cover .face { inset: calc(var(--overhang) * -1) calc(var(--overhang) * -1) calc(var(--overhang) * -1) 0; }

/* ─── SFONDO PAGINA: avorio luminoso con bordi bruniti ─────── */
.phil-page-bg { background: #F7EEDB url("../img/global/philosophy-bg-ivory.webp") center / cover no-repeat; }
body:has(.book-section) { background: #F7EEDB; }
/* su sfondo chiaro la barra in alto resta sempre verde (testo crema leggibile) */
body:has(.book-section) .site-header { background: #2F3A32; }
.book-base::before { box-shadow: inset 0 0 18px rgba(20, 8, 2, 0.7), 0 26px 50px rgba(60, 40, 25, 0.28); }

/* ─── FOGLI ─────────────────────────────────────────────────── */

.leaf {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  will-change: transform;
}

.face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: 2px 6px 6px 2px;
}

.face.back {
  transform: rotateY(180deg);
  border-radius: 6px 2px 2px 6px;
}

/* ombra che scorre sul foglio mentre gira (opacità animata dal JS) */
.shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(90deg, rgba(42, 30, 22, 0.55), rgba(42, 30, 22, 0.15));
}
.face.back .shade {
  background: linear-gradient(270deg, rgba(42, 30, 22, 0.55), rgba(42, 30, 22, 0.15));
}

/* ─── CARTA ─────────────────────────────────────────────────── */

.page {
  position: absolute;
  inset: 0;
  container-type: size;
  /* carta vecchia: ingiallita, bordi vissuti (texture) + piega verso il dorso */
  background:
    linear-gradient(90deg, rgba(90, 66, 44, 0.22) 0, rgba(90, 66, 44, 0.07) 5%, transparent 12%),
    #E8DDC7 url("../img/global/philosophy-book-page.webp") center / 100% 100% no-repeat;
  color: var(--dark-brown);
  border-radius: inherit;
}
/* pagina sinistra: piega verso destra (dorso) */
.face.back.page {
  background:
    linear-gradient(270deg, rgba(90, 66, 44, 0.22) 0, rgba(90, 66, 44, 0.07) 5%, transparent 12%),
    #E8DDC7 url("../img/global/philosophy-book-page.webp") center / 100% 100% no-repeat;
}

.page-inner {
  position: absolute;
  inset: 12px;
  border: 1px solid var(--gold-soft);
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6cqh 9cqw;
}

.page-label {
  font-family: var(--font-body);
  font-size: clamp(0.66rem, 3cqw, 0.78rem);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 1.4cqh;
}

.ornament {
  display: block;
  width: 7px;
  height: 7px;
  margin: 2.6cqh auto;
  background: var(--gold);
  transform: rotate(45deg);
  flex: none;
}

/* ─── PAGINA ANIMALE (fronte) ───────────────────────────────── */

.crest-sm {
  width: 21cqw;
  max-height: 15cqh;
  object-fit: contain;
  margin-bottom: 2cqh;
  /* stampato sulla carta: niente ombra, la grana della pagina passa attraverso */
  filter: saturate(.85) contrast(.95);
  mix-blend-mode: multiply;
  opacity: .95;
}

.animal-name {
  margin: 0 0 0.6cqh;
  font-family: var(--font-title);
  font-weight: 400;
  font-size: clamp(1.9rem, 11cqw, 3rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--dark-brown);
}

.animal-sub {
  margin: 0;
  font-family: var(--font-title);
  font-style: italic;
  font-size: clamp(1.02rem, 5cqw, 1.25rem);
  color: var(--brown);
}

.animal-desc {
  margin: 0 0 2.6cqh;
  font-family: var(--font-title);
  font-size: clamp(0.94rem, 4.55cqw, 1.1rem);
  line-height: 1.48;
  color: rgba(42, 33, 27, 0.88);
}

.animal-link {
  font-family: var(--font-body);
  font-size: clamp(0.7rem, 3.2cqw, 0.78rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brown);
  text-decoration: none;
  border-bottom: 1px solid rgba(168, 138, 91, 0.6);
  padding-bottom: 2px;
}
.animal-link:hover { color: var(--dark-brown); }

.folio {
  position: absolute;
  bottom: 1.6cqh;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-title);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--gold);
}

/* ─── PAGINA STEMMA (retro, visibile solo a doppia pagina) ──── */

.crest-lg {
  width: 49.6cqw;   /* -20% (2026-10-15) */
  max-height: 49.6cqh;
  object-fit: contain;
  margin-bottom: 4cqh;
  /* stampato sulla carta: niente ombra, la grana della pagina passa attraverso */
  filter: saturate(.85) contrast(.95);
  mix-blend-mode: multiply;
  opacity: .95;
}

/* ─── PAGINA INTRO / FINALE ─────────────────────────────────── */

.intro-title,
.end-title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 400;
  font-size: clamp(1.7rem, 9cqw, 2.6rem);
  line-height: 1.08;
  color: var(--dark-brown);
}

.end-title { font-style: italic; margin-bottom: 4cqh; }

.intro-text {
  margin: 0;
  font-family: var(--font-title);
  font-style: italic;
  font-size: clamp(1.05rem, 5.2cqw, 1.3rem);
  line-height: 1.5;
  color: var(--brown);
}

.turn-hint {
  margin-top: 5cqh;
  font-family: var(--font-body);
  font-size: 0.66rem;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--gold);
}

/* ─── COPERTINA IN CUOIO ────────────────────────────────────
   Immagine unica: cuoio fotografico (ambientCG Leather030, CC0) con
   luce sulla grana, bordi consumati, filetti e dorso in oro. */

.cover {
  container-type: size;
  background: #3E2214 url("../img/global/philosophy-book-cover-v3.webp") center / 100% 100% no-repeat;
  box-shadow: inset -1px 0 0 rgba(255, 220, 180, 0.08);
}

.cover-frame {
  position: absolute;
  inset: 12cqh 12cqw 12cqh calc(12cqw + 6.6cqw);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.cover-title {
  position: relative;
  margin: 0;
  font-family: var(--font-title);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(3rem, 19cqw, 5.6rem);
  line-height: 1;
  letter-spacing: 0.01em;
  /* oro impresso */
  background: linear-gradient(180deg, #F0DCAA 0%, #C9A96E 45%, #94733F 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 1px 0 rgba(20, 8, 2, 0.7));
}

/* retro copertina / risguardi */
.endpaper {
  background: #E9DFCB url("../img/global/philosophy-book-endpaper.webp") center / 100% 100% no-repeat;
  box-shadow: inset -10px 0 16px rgba(60, 40, 20, 0.28);
}
/* interno della copertina (pagina vuota): il cuoio rientra su testa, piede e lato esterno
   (risvolti), la carta con lo stemma è incollata all'interno */
.leaf-cover .endpaper {
  background: #3E2214 url("../img/global/philosophy-book-leather.webp") center / cover no-repeat;
  box-shadow: inset -8px 0 14px rgba(20, 8, 2, 0.45);
}
.leaf-cover .endpaper::before {
  content: "";
  position: absolute;
  /* lato sinistro = bordo esterno, lato destro = cerniera (senza risvolto) */
  top: var(--overhang);
  bottom: var(--overhang);
  left: calc(var(--overhang) + 5px);
  right: 0;
  /* pagina vuota: stessa carta delle altre pagine, piega verso il dorso */
  background:
    linear-gradient(270deg, rgba(90, 66, 44, 0.22) 0, rgba(90, 66, 44, 0.07) 5%, transparent 12%),
    #E8DDC7 url("../img/global/philosophy-book-page.webp") center / 100% 100% no-repeat;
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(20, 8, 2, 0.25), 0 1px 3px rgba(20, 8, 2, 0.55);
}

/* ─── MOBILE: retro dei fogli nascosto (escono a sinistra) ──── */

@media (max-width: 899px) {
  .face.back .page-inner { display: none; }
  /* telefono (2026-10-16): libro un po' più grande perché il testo stia
     tutto nella pagina, e niente stemmi (venivano tagliati in alto) */
  .book-section { --book-scale: 0.70; } /* -11% e poi -15% (2026-10-16) */
  .crest-sm,
  .crest-lg { display: none; }
  /* pagina piccola (2026-10-26): cornice più vicina al bordo e meno aria
     interna, così la descrizione resta più grande dentro il filetto */
  .page-inner { inset: 8px; padding: 4.5cqh 7cqw 7.5cqh; } /* sotto: spazio per il numero di pagina */
  .ornament { margin: 1.8cqh auto; }
  .animal-desc { margin-bottom: 2cqh; }
}

/* ─── DESKTOP: doppia pagina ────────────────────────────────── */

@media (min-width: 900px) {
  .book-section {
    --ratio: 1.42;
    --page-w: calc(min(43vw, 560px, calc((100svh - var(--hdr) - 48px) / var(--ratio))) * var(--book-scale));
  }
  /* il libro occupa due pagine: i fogli stanno nella metà destra */
  .book { width: calc(var(--page-w) * 2); }
  .book-base,
  .leaf { left: 50%; }
  .book-base { right: 0; }
  .leaf { width: var(--page-w); right: auto; }

  /* a doppia pagina lo stemma grande è a sinistra: sul fronte basta il testo */
  .page-animal .crest-sm { display: none; }
  .page-inner { padding: 7cqh 10cqw; }
}

/* ─── SENZA ANIMAZIONE (no JS / riduci movimento) ───────────── */

.book-static .book-stage {
  height: auto;
  display: block;
  overflow: visible;
  padding: calc(var(--hdr) + 24px) 16px 80px;
  perspective: none;
}
.book-static .book {
  width: min(100%, 520px);
  height: auto;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.book-static .book-base { order: 1; } /* pagina finale in fondo */
.book-static .book-base,
.book-static .leaf,
.book-static .face.front,
.book-static .page {
  position: relative;
  inset: auto;
  left: auto;
  width: 100%;
  transform: none;
}
.book-static .face.back { display: none; }
.book-static .face.front,
.book-static .book-base { height: auto; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); }
.book-static .face.front.cover { height: 520px; }
.book-static .page { min-height: 0; container-type: inline-size; }
.book-static .page-inner { position: relative; inset: auto; margin: 12px; padding: 40px 28px; }
.book-static .page-animal .crest-sm { display: block; max-height: none; width: 96px; }
.book-static .turn-hint { display: none; }
