/* Fumetti (fumetti.php + js/fumetti.js): scaffale di libri, libro che si
   sfoglia, vignette animate. Modello: lo scaffale del diario di bordo di Maze.
   Senza JS si vede tutto in fila (copertina e pagine); con "riduci movimento"
   niente animazioni. Legno, copertina e dorsi hanno colori fissi (sono oggetti),
   le pagine seguono il tema chiaro/scuro. */

.fm-main { padding-bottom: 56px; }

/* ===================== Scaffale ===================== */
.fm-shelf-wrap { max-width: 720px; }
.fm-shelf {
  border-radius: 12px; padding: 16px 14px 0;
  background: linear-gradient(#2a1d12, #170f09);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.6), 0 14px 30px -14px rgba(0,0,0,.55);
}
.fm-shelf-title {
  margin: 0 0 12px 4px; color: #f2e9d3;
  font-family: var(--font-display); font-weight: 900; text-transform: uppercase; letter-spacing: .06em; font-size: .95rem;
}
.fm-shelf-row { display: flex; align-items: flex-end; gap: 5px; height: 260px; padding: 0 4px; overflow: hidden; }
.fm-spine {
  position: relative; flex: 0 0 auto; width: 58px; height: 230px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 10px 0; box-sizing: border-box; border-radius: 4px 4px 0 0;
  background: linear-gradient(90deg, #ff2323, #b80000 55%, #7d0000);
  border: 1px solid rgba(0,0,0,.55);
  box-shadow: inset -5px 0 7px rgba(0,0,0,.35), inset 3px 0 4px rgba(255,255,255,.18);
  color: #fff; text-decoration: none;
  transition: transform .2s ease;
}
.fm-spine::before, .fm-spine::after {   /* fascette del dorso */
  content: ''; position: absolute; left: 0; right: 0; height: 3px; background: rgba(0,0,0,.35);
}
.fm-spine::before { top: 34px; }
.fm-spine::after { bottom: 34px; }
a.fm-spine:hover, a.fm-spine:focus-visible { transform: translateY(-10px); }
.fm-spine-num { font-family: var(--font-display); font-size: .8rem; }
.fm-spine-title {
  writing-mode: vertical-rl; transform: rotate(180deg); flex: 1 1 0; min-height: 0; margin: 8px 0; overflow: hidden; text-align: center; line-height: 1.05;
  font-family: var(--font-display); font-weight: 900; text-transform: uppercase; letter-spacing: .03em; font-size: .8rem;
}
.fm-spine-mark { font-family: var(--font-display); font-size: .62rem; opacity: .85; }
.fm-spine--soon {
  width: 46px; background: #2b2118; color: #c2aa86;   /* contrasto 7:1 (PageSpeed 10/11: #7a6650 non bastava) */
  box-shadow: inset -4px 0 6px rgba(0,0,0,.4);
}
.fm-spine--soon::before, .fm-spine--soon::after { background: rgba(0,0,0,.25); }
.fm-spine--soon .fm-spine-title { font-family: var(--font-body); font-weight: 600; text-transform: none; font-size: .72rem; }
.fm-shelf-board {
  margin: 0 -14px; height: 14px; border-radius: 0 0 12px 12px;
  background: linear-gradient(#6b5038, #3b2c1e); border-top: 1px solid #8a6a48;
}
.fm-shelf-hint { margin: 10px 0 0; text-align: center; color: var(--text-muted); font-size: .9rem; }

/* ===================== Libro ===================== */
.fm-book { max-width: 940px; margin-top: 28px; }
.fm-book-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.fm-book-name { font-weight: 700; color: var(--text-muted); font-size: .92rem; }
.fm-to-shelf { display: none; }
.fm-js .fm-book-bar .fm-to-shelf { display: inline-flex; }

/* Senza JS: tutto in fila (copertina e pagine una sotto l'altra). */
.fm-body { display: grid; gap: 18px; justify-items: center; }
.fm-cover, .fm-page { width: min(100%, 440px); }

/* Con JS: libro a doppia pagina (desktop) o a pagina singola (telefono). */
.fm-js .fm-book:not(.is-open) { display: none; }
.fm-js.fm-reading .fm-library { display: none; }
.fm-js .fm-body {
  position: relative; gap: 0; perspective: 2200px;
  width: min(100%, 440px); margin: 0 auto; touch-action: pan-y;
}
.fm-js .fm-body > * { display: none; width: 100%; grid-row: 1; grid-column: 1; }
.fm-js .fm-body > .is-shown { display: flex; }
@media (min-width: 760px) {
  .fm-js .fm-body {
    grid-template-columns: 1fr 1fr;
    width: min(100%, 900px, calc((100svh - 230px) * 1.25));
  }
  .fm-js .fm-body > .fm-page--left { grid-column: 1; }
  .fm-js .fm-body > .fm-page--right, .fm-js .fm-body > .fm-cover { grid-column: 2; }
  /* Rilegatura: ombra verso il centro della doppia pagina. */
  .fm-js .fm-page--left { border-radius: 8px 2px 2px 8px; box-shadow: inset -18px 0 22px -16px rgba(0,0,0,.35), 0 14px 24px -12px rgba(0,0,0,.35); }
  .fm-js .fm-page--right { border-radius: 2px 8px 8px 2px; box-shadow: inset 18px 0 22px -16px rgba(0,0,0,.35), 0 14px 24px -12px rgba(0,0,0,.35); }
}

/* ---- Copertina ---- */
.fm-cover {
  position: relative; box-sizing: border-box; aspect-ratio: 5 / 8; container-type: inline-size;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center;
  padding: 26px 22px 20px 34px; border-radius: 3px 10px 10px 3px; overflow: hidden;
  color: #fff; cursor: pointer;
  background:
    radial-gradient(rgba(0,0,0,.16) 1.6px, transparent 1.8px) 0 0 / 12px 12px,
    linear-gradient(135deg, #f01414, #a80000);
  border: 1px solid rgba(0,0,0,.5);
  box-shadow: 0 16px 26px -12px rgba(0,0,0,.45);
}
.fm-cover::before {   /* dorso */
  content: ''; position: absolute; inset: 0 auto 0 0; width: 16px;
  background: linear-gradient(90deg, rgba(0,0,0,.45), rgba(0,0,0,.1)); border-right: 1px solid rgba(0,0,0,.35);
}
.fm-cover-kicker { font-weight: 800; letter-spacing: .18em; text-transform: uppercase; font-size: .72rem; opacity: .92; }
.fm-cover-title {
  margin: 10px 0 0; font-family: var(--font-display); font-weight: 900; text-transform: uppercase;
  letter-spacing: -0.02em; line-height: .98; font-size: clamp(1.6rem, 10cqw, 2.6rem);
  text-shadow: 3px 3px 0 #000;
}
.fm-cover-burst {
  display: flex; align-items: center; justify-content: center; gap: 2%;
  width: 96%; aspect-ratio: 1.25; background: #fff;
  clip-path: polygon(50% 0, 59% 13%, 75% 4%, 77% 20%, 95% 18%, 88% 35%, 100% 47%, 87% 57%, 96% 74%, 78% 75%, 76% 93%, 61% 85%, 50% 100%, 39% 85%, 24% 93%, 22% 75%, 4% 74%, 13% 57%, 0 47%, 12% 35%, 5% 18%, 23% 20%, 25% 4%, 41% 13%);
}
.fm-cover-face { width: 34%; height: auto; }
.fm-cover-blurb { margin: 0; font-weight: 800; font-size: 1.05rem; }
.fm-cover-brand { font-family: var(--font-display); font-weight: 900; font-size: .95rem; letter-spacing: .04em; }
.fm-cover-brand span { color: #111; }

/* ---- Pagine ---- */
.fm-page {
  position: relative; box-sizing: border-box; aspect-ratio: 5 / 8;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 14px 28px; border-radius: 8px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
}
.fm-page-head { text-align: center; min-height: 44px; display: flex; flex-direction: column; justify-content: center; }
.fm-num, .fm-running {
  display: block; text-transform: uppercase; letter-spacing: .18em;
  font-size: .68rem; font-weight: 700; color: var(--accent-ink);
}
.fm-running { color: var(--text-muted); }
.fm-ep-title {
  margin: 3px 0 0; font-family: var(--font-display); font-weight: 900;
  text-transform: uppercase; letter-spacing: -0.02em; font-size: clamp(1.05rem, 3vw, 1.35rem);
}
.fm-page-panels { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.fm-page-panels .fm-panel { flex: 1 1 0; min-height: 0; aspect-ratio: auto; }
.fm-folio { position: absolute; bottom: 7px; left: 0; right: 0; text-align: center; font-size: .75rem; color: var(--text-muted); font-family: var(--font-display); }

/* Senza JS le pagine non hanno altezza fissa (niente ritaglio del testo). */
html:not(.fm-js) .fm-page { aspect-ratio: auto; }
html:not(.fm-js) .fm-page-panels .fm-panel { aspect-ratio: 1 / 1; flex: none; }

/* ---- Pagine finali ---- */
.fm-end { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; }
/* Cerchio bianco con il viso dentro. Misure prese dall'ingombro reale del disegno:
   il punto più lontano dal centro deve stare dentro il raggio (Grin triste: 0,667 della
   sua larghezza → al 66% arriva all'89% del raggio; Evil con le cuffie è più alto che
   largo → 82%). */
.fm-end-disc {
  width: 48%; aspect-ratio: 1; border-radius: 50%; background: #fff;
  display: grid; place-items: center;
}
.fm-end-face { width: 66%; height: 66%; object-fit: contain; }
.fm-end-disc--evil .fm-end-face { width: 82%; height: 82%; }
.fm-end-big { margin: 0; font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: 2.2rem; }
.fm-end-small { margin: 0; color: var(--text-muted); font-weight: 600; }
.fm-end-btn { margin-top: 8px; }

/* ---- Comandi ---- */
.fm-book-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 900px; margin: 16px auto 0; }
.fm-book-nav[hidden], .fm-book-tools[hidden] { display: none; }
.fm-book-nav .btn:disabled { opacity: .35; cursor: default; filter: none; }
.fm-count { color: var(--text-muted); font-size: .9rem; font-weight: 600; }
.fm-book-tools { text-align: center; margin: 12px 0 0; }

/* Foglio che gira (lo crea il JS mentre si sfoglia). */
.fm-js .fm-body > .fm-leaf { display: block; }
.fm-leaf { position: absolute; top: 0; height: 100%; z-index: 3; transform-style: preserve-3d; pointer-events: none; }
.fm-leaf > * {
  position: absolute !important; inset: 0; width: 100% !important; height: 100%; display: flex !important;
  backface-visibility: hidden; -webkit-backface-visibility: hidden; margin: 0;
}
.fm-leaf > .fm-leaf-back { transform: rotateY(180deg); }

/* ===================== Vignetta ===================== */
.fm-panel { container-type: inline-size; }
.fm-panel {
  position: relative; margin: 0;
  aspect-ratio: 1 / 1;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 3px solid var(--text);
  border-radius: 6px;
  overflow: hidden;
  padding: 18px 14px 0;
}
.fm-index {
  position: absolute; top: 6px; right: 9px;
  font-family: var(--font-display); font-size: .72rem; color: var(--text-muted);
}

/* ---- Fumetti (balloon) ---- */
.fm-bubble {
  --tail: var(--text);
  align-self: center;
  position: relative; max-width: 94%;
  padding: 12px 16px;
  background: var(--surface);
  color: var(--text);
  border: 2.5px solid var(--tail);
  border-radius: 22px;
  font-weight: 700; line-height: 1.3;
  font-size: clamp(.72rem, 4.1cqw, 1.08rem);
  text-align: center;
}
/* Coda del fumetto verso chi parla (Grin a sinistra, Evil a destra):
   due triangoli sovrapposti, il bordo sotto e il riempimento sopra. */
.fm-bubble::before, .fm-bubble::after {
  content: ''; position: absolute; top: 100%;
  border-style: solid; border-color: transparent;
}
.fm-bubble::before { border-width: 16px 10px 0; border-top-color: var(--tail); }
.fm-bubble::after  { border-width: 12px 7px 0; border-top-color: var(--surface); margin-top: -1px; }
.fm-bubble--from-grin::before { left: 22%; }
.fm-bubble--from-grin::after  { left: calc(22% + 3px); }
.fm-bubble--from-evil::before { right: 22%; }
.fm-bubble--from-evil::after  { right: calc(22% + 3px); }

/* Grin che urla: bordo rosso spesso, maiuscolo, inclinato. */
.fm-bubble--shout {
  --tail: var(--accent);
  border-width: 3.5px;
  border-radius: 6px;
  text-transform: uppercase;
  font-family: var(--font-display); font-weight: 900; letter-spacing: -0.01em;
  font-size: clamp(.68rem, 3.7cqw, 1rem);
  transform: rotate(-1.5deg);
  box-shadow: 4px 4px 0 var(--accent);
}

/* ---- Palco e personaggi ---- */
.fm-stage { position: relative; flex: 1; min-height: 0; }
.fm-char {
  position: absolute; bottom: 7%;
  width: 43%; max-height: 86%; aspect-ratio: 125 / 119;
  transition: transform .3s ease;
}
.fm-char img { width: 100%; height: 100%; object-fit: contain; }
.fm-char--grin { left: 2%; }
.fm-char--evil { right: 2%; }
.fm-char:not(.is-speaking) { transform: scale(.86); transform-origin: bottom center; }

/* Oggetti di scena */
.fm-prop { position: absolute; }
.fm-prop--phone { left: 45.5%; bottom: 4%; width: 9%; transform: rotate(-10deg); }
.fm-prop--phone svg { width: 100%; display: block; }
.fm-phone-body { fill: var(--text); }
.fm-phone-screen { fill: var(--surface-2, #eee); }
.fm-phone-line { fill: var(--text-muted); }
.fm-badge {
  position: absolute; top: -12px; right: -18px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 900; font-size: .7rem; line-height: 1;
  padding: 4px 6px; border-radius: 999px;
}


/* ===================== Animazioni (solo con JS) ===================== */
.fm-anim .fm-panel { opacity: 0; transform: translateY(18px) scale(.98); }
.fm-anim .fm-panel.is-on { opacity: 1; transform: none; transition: opacity .35s ease, transform .35s ease; }

.fm-anim .fm-bubble { opacity: 0; transform: scale(.6); }
.fm-anim .fm-bubble--shout { transform: scale(.6) rotate(-1.5deg); }
.fm-anim .is-talking .fm-bubble { opacity: 1; transform: none; transition: opacity .2s ease, transform .25s cubic-bezier(.3,1.6,.5,1); }
.fm-anim .is-talking .fm-bubble--shout { transform: rotate(-1.5deg); }

.fm-anim .fm-text .fm-ch { opacity: 0; }
.fm-anim .fm-text .fm-ch.is-in { opacity: 1; }

.fm-anim .fm-char { opacity: 0; translate: 0 20px; }
.fm-anim .is-on .fm-char { opacity: 1; translate: 0 0; transition: opacity .3s ease, translate .35s cubic-bezier(.3,1.5,.5,1); }
.fm-anim .is-on .fm-char--evil { transition-delay: .08s; }

.fm-anim .fm-prop { opacity: 0; }
.fm-anim .is-on .fm-prop { opacity: 1; animation: fm-buzz .5s ease .5s 3; }
.fm-anim .is-on .fm-badge { animation: fm-pop .4s cubic-bezier(.3,1.8,.5,1) .4s both; }

/* Chi è arrabbiato e parla (Grin o Evil): trema e si accende di rosso. */
.fm-anim .is-talking .fm-char--grin.fm-mood--angry.is-speaking img,
.fm-anim .is-talking .fm-char--evil.fm-mood--angry.is-speaking img {
  animation: fm-shake .12s linear infinite, fm-glow 1s ease-in-out infinite alternate;
}
/* Grin giù di corda: si affloscia. */
.fm-anim .is-on .fm-char--grin.fm-mood--sad img { animation: fm-slump .8s ease .6s both; }
/* Evil con le cuffie: ondeggia a ritmo, ignorando tutto. */
.fm-anim .is-on .fm-char--evil.fm-mood--dj img { animation: fm-groove .9s ease-in-out infinite; transform-origin: bottom center; }
/* Chi parla con calma: piccolo cenno. */
.fm-anim .is-talking .is-speaking.fm-mood--base img { animation: fm-nod .6s ease-in-out 2; transform-origin: bottom center; }

@keyframes fm-shake {
  0% { transform: translate(0, 0) rotate(0); }
  25% { transform: translate(-2px, 1px) rotate(-1.5deg); }
  50% { transform: translate(2px, -1px) rotate(1deg); }
  75% { transform: translate(-1px, -1px) rotate(1.5deg); }
  100% { transform: translate(1px, 1px) rotate(-1deg); }
}
@keyframes fm-glow {
  from { filter: drop-shadow(0 0 0 rgba(255, 0, 0, 0)); }
  to   { filter: drop-shadow(0 0 14px rgba(255, 0, 0, .65)); }
}
@keyframes fm-slump {
  from { transform: none; }
  to   { transform: translateY(8%) scaleY(.9) rotate(-4deg); }
}
@keyframes fm-groove {
  0%, 100% { transform: rotate(-4deg) translateY(0); }
  50% { transform: rotate(4deg) translateY(-4%); }
}
@keyframes fm-nod {
  0%, 100% { transform: none; }
  50% { transform: translateY(3%) rotate(2deg); }
}
@keyframes fm-buzz {
  0%, 100% { translate: 0 0; }
  25% { translate: -2px 0; }
  75% { translate: 2px 0; }
}
@keyframes fm-pop { from { transform: scale(0); } to { transform: scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .fm-anim .fm-panel, .fm-anim .fm-bubble, .fm-anim .fm-char, .fm-anim .fm-prop,
  .fm-anim .fm-text .fm-ch { opacity: 1 !important; transform: none !important; translate: none !important; }
  .fm-anim * { animation: none !important; transition: none !important; }
}

/* ===================== Video da condividere (js/fumetti-video.js) ===================== */
.fm-book-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.fm-book-tools[hidden] { display: none; }
.fm-video {
  width: min(100% - 24px, 760px); max-height: calc(100svh - 24px); box-sizing: border-box;
  padding: 16px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text);
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.6);
}
.fm-video::backdrop { background: rgba(0,0,0,.6); }
.fm-video-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.fm-video-title { margin: 0; font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: 1.15rem; }
.fm-video-ep { margin: 2px 0 0; color: var(--text-muted); font-weight: 600; font-size: .9rem; }
.fm-video-x {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 1.5rem; line-height: 1;
}
.fm-video-body { display: grid; gap: 14px; justify-items: center; }
.fm-video-screen { width: min(100%, calc((100svh - 440px) * 9 / 16), 300px); min-width: 150px; }
.fm-video-canvas { display: block; width: 100%; height: auto; aspect-ratio: 9 / 16; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.fm-video-bar { height: 4px; margin-top: 6px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.fm-video-bar span { display: block; width: 0; height: 100%; background: var(--accent); }
.fm-video-side { display: grid; gap: 12px; align-content: start; width: 100%; max-width: 360px; }
.fm-video-text { margin: 0; color: var(--text-muted); font-size: .9rem; }
.fm-video-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
/* Chiaro/Scuro del VIDEO: aspetto dell'interruttore del sito ma classe propria,
   altrimenti js/theme.js (che ascolta ogni .theme-toggle) cambierebbe il tema del sito. */
.fm-video-theme {
  display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px;
}
.fm-video-theme button {
  height: 30px; padding: 0 12px; border: 0; border-radius: 999px; cursor: pointer;
  background: transparent; color: var(--text-muted); font: inherit; font-weight: 700; font-size: .85rem;
}
.fm-video-theme button[aria-pressed="true"] { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow); }
.fm-video-theme button:disabled, .fm-video .btn:disabled { opacity: .45; cursor: default; filter: none; }
.fm-video-make { width: 100%; text-align: center; }
.fm-video-status { margin: 0; min-height: 2.6em; font-size: .9rem; }
.fm-video-ready { display: flex; gap: 10px; }
.fm-video-ready[hidden] { display: none; }
.fm-video-ready .btn { flex: 1; text-align: center; }
@media (min-width: 640px) {
  .fm-video-body { grid-template-columns: auto 1fr; align-items: start; justify-items: stretch; }
  .fm-video-screen { width: min(300px, calc((100svh - 150px) * 9 / 16)); }
}
.fm-video-caption { display: grid; gap: 6px; }
.fm-video-caption[hidden] { display: none; }
.fm-video-caption label { font-size: .85rem; color: var(--text-muted); font-weight: 600; }
.fm-video-caption textarea {
  font: inherit; font-size: .9rem; padding: 10px 12px; border-radius: 10px; resize: vertical;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.fm-video-caption .btn { justify-self: start; }

/* ===================== Cartello «Lo sapevi?» (fm_fact) ===================== */
/* Un foglietto giallo sotto le vignette della seconda pagina dell'episodio:
   colori fissi (è un oggetto, come la copertina), uguale nei due temi. */
.fm-fact {
  flex: 0 0 auto; margin: 0; padding: 8px 10px 9px;
  background: #ffe066; color: #1d1608; border-radius: 4px;
  box-shadow: 2px 3px 0 rgba(0,0,0,.25); transform: rotate(-.6deg);
}
.fm-fact-head {
  display: block; font-family: var(--font-display); font-weight: 900; text-transform: uppercase;
  letter-spacing: .04em; font-size: .78rem; color: #b00000;
}
.fm-fact-text { margin: 3px 0 0; font-size: .74rem; line-height: 1.32; font-weight: 600; }
/* Pagina col foglietto: niente testatina, così le vignette restano grandi quasi
   come nella pagina accanto (con la testatina la vignetta 3 diventava minuscola). */
.fm-page--fact .fm-page-head { display: none; }
.fm-page--fact .fm-fact { padding: 6px 9px 7px; }
.fm-page--fact .fm-fact-text { font-size: .68rem; line-height: 1.28; }

/* ===================== Box «raccontaci la tua lite» (sotto lo scaffale) ===================== */
.fm-tell {
  margin: 22px 0 0; padding: 18px 18px 20px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.fm-tell-title { margin: 0; font-family: var(--font-display); font-weight: 900; text-transform: uppercase; font-size: 1.05rem; line-height: 1.2; }
.fm-tell-text { margin: 8px auto 14px; max-width: 52ch; color: var(--text-muted); font-size: .92rem; }
