/* Calendario dell'Avvento 2026 — movimento.
   Due grammatiche, come nel teaser di riferimento: il collage di carta si muove
   a passo uno/due (steps, 8–12 fps, piccolo "boil"), luce e oggetti appesi in
   continuo con ease-in-out. Le sequenze (ingressi, riscatto, voli) sono in
   static/js/motion.js e static/js/letter.js con la Web Animations API. */

/* Boil stop-motion: tre fotogrammi a 8 fps attorno alla posa di ogni ritaglio */
@keyframes boil {
  0%, 100% { transform: rotate(var(--r, 0deg)) translate(0, 0); }
  33% { transform: rotate(calc(var(--r, 0deg) + 0.9deg)) translate(0.6px, -0.6px); }
  66% { transform: rotate(calc(var(--r, 0deg) - 0.7deg)) translate(-0.6px, 0.4px); }
}
.boil { animation: boil 375ms steps(1, end) infinite; }
.deco--lights { --r: -3deg; }
.deco--lines { --r: -12deg; }

/* Oggetti appesi: lanterna, palline, cartellino */
@keyframes swing { from { rotate: -5deg; } to { rotate: 5deg; } }
@keyframes swing-soft { from { rotate: -3deg; } to { rotate: 3.5deg; } }
.lantern__lamp { animation: swing 3.2s var(--ease-in-out) infinite alternate; }
.crown--hang { animation: swing-soft 3.8s var(--ease-in-out) infinite alternate; }
.crown--silver { animation-duration: 4.6s; animation-delay: -1.2s; }
.hero__tag { animation: swing-soft 4.4s var(--ease-in-out) infinite alternate; }

/* Raggi di carta della lanterna: tremolano a scatti (riferimento 1:30), mai lampi */
@keyframes flicker {
  0% { opacity: 0.22; }
  25% { opacity: 0.29; }
  50% { opacity: 0.19; }
  75% { opacity: 0.26; }
}
.lantern__rays { animation: flicker 1.6s steps(1, end) infinite; }

/* Busta disponibile: respira, e ogni 5 s una spintarella a passo */
@keyframes breathe { from { translate: 0 0; } to { translate: 0 -4px; } }
@keyframes nudge {
  0%, 86% { rotate: 0deg; }
  88% { rotate: 5deg; }
  91% { rotate: -4deg; }
  94% { rotate: 2deg; }
  97% { rotate: 0deg; }
}
.slot--available .slot__env,
.slot--teaser .slot__env {
  animation: breathe 2.4s var(--ease-in-out) infinite alternate, nudge 5s steps(1, end) infinite;
}
@keyframes spark {
  0%, 70% { opacity: 0; scale: 0.6; }
  74% { opacity: 1; scale: 1; }
  82% { opacity: 1; scale: 1.12; }
  90%, 100% { opacity: 0; scale: 0.8; }
}
.slot__spark {
  position: absolute;
  z-index: 4;
  top: -34%;
  left: -8%;
  width: 34%;
  opacity: 0;
  pointer-events: none;
  rotate: -24deg;
  animation: spark 4.2s steps(1, end) infinite;
}
@keyframes badge-beat {
  0%, 80% { scale: 1; }
  84% { scale: 1.12; }
  90% { scale: 0.96; }
  95% { scale: 1.04; }
}
.slot__badge { animation: badge-beat 3.2s steps(1, end) infinite; }

/* La prossima apertura pulsa piano (lucchetto) */
@keyframes lock-pulse {
  0%, 70% { scale: 1; }
  76% { scale: 1.3; }
  84% { scale: 1; }
  90% { scale: 1.18; }
}
.slot.is-next .slot__plate svg { animation: lock-pulse 2.8s steps(1, end) infinite; transform-origin: 50% 60%; }

/* Bloccata: tremolio al passaggio, scossa al tocco */
@keyframes rattle {
  0% { translate: -1px 0; rotate: -7deg; }
  100% { translate: 1px 0; rotate: 7deg; }
}
@keyframes shake-lock {
  0% { rotate: 0deg; }
  17% { rotate: -16deg; }
  34% { rotate: 13deg; }
  51% { rotate: -8deg; }
  68% { rotate: 5deg; }
  85%, 100% { rotate: 0deg; }
}
.slot.is-shaking .slot__plate { animation: shake-lock 420ms steps(6, end); transform-origin: 30% 0; }

/* Riscattata adesso: l'annullo si abbatte, l'adesivo del giorno spunta */
@keyframes slam {
  0% { opacity: 0; transform: scale(1.8) rotate(-30deg); }
  55% { opacity: 1; transform: scale(0.92) rotate(-12deg); }
  75% { transform: scale(1.04) rotate(-15deg); }
  100% { opacity: 0.88; transform: scale(1) rotate(-14deg); }
}
@keyframes sticker-pop {
  0% { opacity: 0; transform: translate(-50%, -40%) rotate(var(--lean, 3deg)) scale(0.7); }
  50% { opacity: 1; transform: translate(-50%, -58%) rotate(var(--lean, 3deg)) scale(1.08); }
  100% { opacity: 1; transform: translate(-50%, -54%) rotate(var(--lean, 3deg)) scale(1); }
}
.slot.is-stamping .slot__postmark { animation: slam 460ms var(--ease-out) 260ms backwards; }
.slot.is-stamping .slot__sticker { animation: sticker-pop 420ms steps(5, end) backwards; }

/* Caricamento: un timbro che batte mentre "smistiamo la posta" */
@keyframes stamp-bob {
  0%, 100% { translate: 0 -6px; rotate: -8deg; }
  50% { translate: 0 2px; rotate: -4deg; }
}
.sorting { display: inline-flex; align-items: center; gap: 10px; }
.sorting svg { width: 26px; height: 26px; animation: stamp-bob 660ms steps(2, end) infinite; }
@keyframes spin { to { rotate: 360deg; } }
.spin-mark { width: 1.3em; height: 1.3em; flex: none; animation: spin 960ms steps(8, end) infinite; }

/* Busta della lettera in attesa: trema a passo mentre la ceralacca si incrina */
@keyframes tremble {
  0%, 100% { translate: 0 0; rotate: 0deg; }
  25% { translate: -1.5px 0.5px; rotate: -0.8deg; }
  50% { translate: 1px -0.5px; rotate: 0.6deg; }
  75% { translate: -0.5px 0; rotate: -0.4deg; }
}
.env.is-waiting { animation: tremble 330ms steps(1, end) infinite; }

/* Profilo: il menu si apre dal francobollo */
.account-menu { transition: opacity var(--t-hover) var(--ease-out), transform var(--t-hover) var(--ease-out); }
@starting-style {
  .account-menu { opacity: 0; transform: translateY(-6px) scale(0.96); }
}

@keyframes backdrop-in { from { opacity: 0; } }
.letter[open]::backdrop { animation: backdrop-in 240ms var(--ease-out); }

/* Revisione 2: lo sfondo vive */
@keyframes float { from { translate: 0 -3px; } to { translate: 0 5px; } }
.float { animation: float 5.6s var(--ease-in-out) infinite alternate; }
.bg--polaroid-b.float { animation-duration: 6.8s; animation-delay: -2.2s; }
.bg--cheer.float { animation-duration: 4.8s; animation-delay: -1.1s; }
.bg--hang-a img, .bg--hang-b img, .bg--hang-c img { animation: swing-soft 3.6s var(--ease-in-out) infinite alternate; transform-origin: 50% 0; }
.bg--hang-b img { animation-duration: 4.4s; animation-delay: -1.4s; }
.bg--hang-c img { animation-duration: 5.2s; animation-delay: -2.6s; }
.how__deco--bauble img { animation: swing-soft 4.8s var(--ease-in-out) infinite alternate; transform-origin: 50% 0; }
@keyframes cue {
  0%, 60%, 100% { translate: 0 0; }
  70% { translate: 0 6px; }
  80% { translate: 0 1px; }
  90% { translate: 0 4px; }
}
.scroll-cue__arrow { animation: cue 2.4s steps(1, end) infinite; }

/* ---------------------------------------------- movimento ridotto */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .boil,
  .lantern__lamp,
  .lantern__rays,
  .crown--hang,
  .hero__tag,
  .float,
  .bg--hang-a img, .bg--hang-b img, .bg--hang-c img,
  .how__deco--bauble img,
  .scroll-cue__arrow,
  .slot--available .slot__env,
  .slot--teaser .slot__env,
  .slot__spark,
  .slot__badge,
  .slot.is-next .slot__plate svg,
  .env.is-waiting,
  .sorting svg,
  .spin-mark { animation: none; }
  .slot.is-stamping .slot__postmark,
  .slot.is-stamping .slot__sticker,
  .slot.is-shaking .slot__plate { animation-duration: 1ms; }
  .slot__spark { display: none; }
  .stamp, .slot, .stub, .ink-link::after, .moment__sticker, .slot__env, .square-btn, .text-btn { transition-duration: 1ms; }
  .account-menu { transition: opacity 120ms linear; }
  .bar::before, .bar::after { transform: none; opacity: 0; transition: opacity 120ms linear; }
  .bar--stuck::before, .bar--stuck::after { opacity: 1; }
}
