/* ==========================================================================
   Efectes especials (js/magia.js i js/primer.js). Cada un es tria al panell → Animacions
   i s'activa amb una classe a <html>:
     .vt-on      transicions entre pàgines        .es-guia    estel de Betlem a la barra de progrés
     .cr-holo    cromos hologràfics (.cr-tilt)    .neu-viva   neu sobre el cartell
     .dm-on      el dimoni tafaner                .tt-gargot  subratllat dibuixat a mà als títols
   Tots s'apaguen amb prefers-reduced-motion (a base.css i a js/magia.js).
   ========================================================================== */

/* ---------- Transicions entre pàgines (View Transitions entre documents) ---------- */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
}
/* La capçalera es queda al seu lloc mentre canvia el contingut (si ha de sortir l'entrada, no) */
.page-header, .no-intro .hd { view-transition-name: capcalera; }
::view-transition-group(capcalera) { z-index: 2; }
::view-transition-old(root) { animation: vt-surt .2s ease-in both; }
::view-transition-new(root) { animation: vt-entra .45s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes vt-surt { to { opacity: 0; transform: translateY(-8px); } }
@keyframes vt-entra { from { opacity: 0; transform: translateY(16px); } }
/* La foto d'una història viatja de la targeta a la pàgina (js/primer.js posa el nom a la targeta) */
.story-page-photo img { view-transition-name: historia-foto; }
::view-transition-group(historia-foto) { animation-duration: .55s; animation-timing-function: cubic-bezier(.3, .9, .3, 1); z-index: 1; }
::view-transition-old(historia-foto), ::view-transition-new(historia-foto) { width: 100%; height: 100%; object-fit: cover; border-radius: 18px; }

/* ---------- Estel de Betlem que guia la lectura (capçalera de l'inici) ----------
   js/main.js desa el progrés (0–1) a --p; la barra fa de cua i l'estel va a la punta. */
.hd-estel { display: none; }
.es-guia .hd { container-type: inline-size; }
.es-guia .hd-bar { height: 3px; background: linear-gradient(90deg, rgba(211, 155, 42, 0), #D39B2A 72%, #F2CB62); }
.es-guia .hd-compact .hd-estel, .es-guia .hd-progress .hd-estel {
  display: block; position: absolute; left: 0; bottom: -12px; z-index: 1; width: 24px; height: 24px; pointer-events: none;
  translate: calc(var(--p, 0) * (100cqw - 24px)) 0;
  opacity: 0; transition: opacity .4s ease;
  filter: drop-shadow(0 0 5px rgba(233, 185, 73, .95)) drop-shadow(0 1px 1px rgba(30, 53, 69, .35));
}
.es-guia .hd.is-scrolled .hd-estel { opacity: 1; }
.hd-estel svg { display: block; width: 100%; height: 100%; animation: estel-gira 10s linear infinite; }
.es-guia .hd.is-arribat .hd-estel svg { animation: estel-arriba 1.4s cubic-bezier(.16, 1, .3, 1); }
@keyframes estel-gira { to { transform: rotate(360deg); } }
@keyframes estel-arriba { 0% { transform: scale(1); } 30% { transform: scale(2.1) rotate(90deg); } 100% { transform: scale(1) rotate(180deg); } }

/* ---------- Títols de secció: subratllat dibuixat a mà, que es traça en aparèixer ---------- */
.tt-gargot [data-anim] .section-title::after {
  content: ''; display: block; width: min(100%, 190px); height: 10px; margin-top: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 12' preserveAspectRatio='none'%3E%3Cpath d='M3 8 C 30 2 52 11 80 6 S 130 2 156 7 S 186 9 197 4' fill='none' stroke='%23CF331C' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat 0 0 / 100% 100%;
  clip-path: inset(0 0 0 0);
  transition: clip-path 1s var(--rv-ease, ease-out) .45s;
}
.tt-gargot [data-anim] .section-title--on-dark::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 12' preserveAspectRatio='none'%3E%3Cpath d='M3 8 C 30 2 52 11 80 6 S 130 2 156 7 S 186 9 197 4' fill='none' stroke='%23E9B949' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E");
}
.rv-on.tt-gargot [data-anim]:not(.a-none) .rv:not(.is-shown) .section-title::after,
.rv-on.tt-gargot [data-anim]:not(.a-none) .ai.section-title:not(.is-shown)::after { clip-path: inset(0 100% 0 0); transition: none; }

/* ---------- Cromos: s'inclinen en 3D amb el cursor; els protagonistes són hologràfics ----------
   Tot va darrere de html.mg, que js/magia.js posa quan la pàgina ja ha carregat (no competeix amb el cartell).
   js/magia.js posa .is-tilt, l'eix i l'angle (propietat rotate, que no xoca amb el transform dels reveals)
   i la posició del cursor a --mx / --my. */
html.mg:is(.cr-holo, .cr-tilt) .cards-grid { perspective: 1200px; }
html.mg:is(.cr-holo, .cr-tilt) .char-card { isolation: isolate; }
html.mg:is(.cr-holo, .cr-tilt) .char-card.is-tilt {
  z-index: 2; translate: 0 -6px; will-change: rotate;
  transition: rotate .12s linear, translate .35s cubic-bezier(.16, 1, .3, 1), box-shadow .35s ease;
  box-shadow: 0 1px 0 #fff inset, 0 6px 12px rgba(30, 53, 69, .1), 0 30px 44px -20px rgba(30, 53, 69, .55);
}
/* Reflex de llum que segueix el cursor (tots els cromos) */
.mg.cr-holo .char-card::after {
  /* Només sobre la foto (mateix marc que .char-photo): el nom i el text no perden contrast */
  content: ''; position: absolute; inset: 10px 10px auto; aspect-ratio: 3 / 4; z-index: 1; border-radius: 10px; pointer-events: none;
  opacity: 0; transition: opacity .45s ease;
  background: radial-gradient(farthest-corner circle at var(--mx, 50%) var(--my, 50%), rgba(255, 255, 255, .7) 0%, rgba(255, 255, 255, .18) 30%, rgba(255, 255, 255, 0) 62%);
  mix-blend-mode: soft-light;
}
/* Làmina hologràfica (protagonistes: els cromos «difícils» de l'àlbum) */
.mg.cr-holo .char-card:has(.chip--gold)::after {
  background:
    radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(255, 255, 255, .5) 0%, rgba(255, 255, 255, 0) 38%),
    repeating-linear-gradient(112deg, #E9547B 0%, #F2C14E 6%, #6FD6A8 12%, #5FA8F0 18%, #B98AF0 24%, #E9547B 30%);
  background-size: 100% 100%, 240% 240%;
  background-position: 0 0, var(--mx, 50%) var(--my, 50%);
  /* «screen» perquè l'irisat també es vegi sobre fotos fosques (teatre); la màscara el concentra al voltant de la llum */
  mix-blend-mode: screen;
  -webkit-mask-image: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), #000 0%, rgba(0, 0, 0, .55) 42%, rgba(0, 0, 0, .12) 85%);
  mask-image: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), #000 0%, rgba(0, 0, 0, .55) 42%, rgba(0, 0, 0, .12) 85%);
}
.mg.cr-holo .char-card.is-tilt::after { opacity: .85; }
.mg.cr-holo .char-card.is-tilt:has(.chip--gold)::after { opacity: .5; }

.mg.cr-holo .char-card > .chip { z-index: 2; }
@media (max-width: 600px) { .mg.cr-holo .char-card::after { inset: 7px 7px auto; border-radius: 7px; } }

/* Pantalles tàctils: el cromo es balanceja i la làmina canvia mentre es fa scroll, com quan s'inclina a la mà */
@media (hover: none) and (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    html.mg:is(.cr-holo, .cr-tilt) .char-card { animation: cromo-balanceig linear both; animation-timeline: view(); animation-range: entry 10% exit 90%; }
    .mg.cr-holo .char-card:has(.chip--gold)::after {
      opacity: .3; -webkit-mask-image: none; mask-image: none;
      background: repeating-linear-gradient(112deg, #E9547B 0%, #F2C14E 6%, #6FD6A8 12%, #5FA8F0 18%, #B98AF0 24%, #E9547B 30%) 0 0 / 320% 320%;
      animation: holo-passa linear both; animation-timeline: view(); animation-range: entry 0% exit 100%;
    }
  }
}
@keyframes cromo-balanceig { from { rotate: 1 0 0 7deg; } to { rotate: 1 0 0 -7deg; } }
@keyframes holo-passa { from { background-position: 0% 0%; } to { background-position: 100% 100%; } }

/* ---------- Neu viva sobre el cartell (canvas, darrere del teló) ---------- */
.hero-neu { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; pointer-events: none; }

/* ---------- El dimoni tafaner: treu el cap per sota de la pantalla i s'amaga si t'hi acostes ---------- */
.tafaner {
  position: fixed; right: clamp(10px, 7vw, 120px); bottom: 0; z-index: 60; width: clamp(104px, 13vw, 184px);
  translate: 0 108%; pointer-events: none; -webkit-tap-highlight-color: transparent; user-select: none;
  transition: translate .75s cubic-bezier(.34, 1.56, .64, 1);
  font-family: var(--font-text);
}
.tafaner.is-out { translate: 0 0; pointer-events: auto; cursor: pointer; }
.tafaner.is-fuig { transition: translate .2s cubic-bezier(.5, 0, .9, .4); }
.tafaner img { display: block; width: 100%; height: auto; transform-origin: 50% 100%; filter: drop-shadow(0 -2px 6px rgba(23, 42, 55, .25)); }
.tafaner.is-out img { animation: tafaner-mira 2.6s ease-in-out .75s; }
@keyframes tafaner-mira { 0%, 100% { transform: none; } 22% { transform: translateX(-5px) rotate(-5deg); } 44% { transform: translateX(-5px) rotate(-5deg); } 66% { transform: translateX(5px) rotate(4deg); } 86% { transform: translateX(5px) rotate(4deg); } }
.tafaner-bafarada {
  position: absolute; right: 8%; bottom: calc(100% + 6px); padding: 8px 13px; border-radius: 14px 14px 4px 14px;
  background: #fff; color: var(--forest); font-size: 14px; font-weight: 700; line-height: 1.3; white-space: nowrap;
  box-shadow: 0 8px 22px -8px rgba(23, 42, 55, .5), 0 0 0 1px #DDD8CE;
  opacity: 0; transform: translateY(8px) scale(.9); transform-origin: 100% 100%; transition: opacity .2s ease, transform .35s cubic-bezier(.34, 1.56, .64, 1);
}
.tafaner.is-enxampat .tafaner-bafarada { opacity: 1; transform: none; }
.tafaner-espurna { position: absolute; left: 50%; top: 30%; width: 14px; height: 14px; pointer-events: none; }

/* ---------- «Afegeix al calendari» a cada funció ---------- */
.funcio-cal {
  align-self: center; margin-top: 6px; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 8px;
  border: 0; border-radius: 8px; background: none; cursor: pointer;
  font: 600 13px/1.2 var(--font-text); color: var(--muted);
  text-decoration: underline; text-decoration-color: #BDB6A8; text-underline-offset: 3px;
}
.funcio-cal:hover { color: var(--red-text); text-decoration-color: currentColor; }
.funcio-cal svg { flex: none; }

@media (prefers-reduced-motion: reduce) {
  .hd-estel, .tafaner, .hero-neu { display: none !important; }
  .char-card::after { display: none; }
}
