/* motion.css — animazioni carine ovunque, per qualunque sito.
   Il movimento è sempre acceso, anche con «riduci movimento» nel sistema: qui non esiste
   alcun blocco prefers-reduced-motion. Si ferma solo con l'interruttore «Animazioni»
   (classe .m-calm su <html>).
   Regole di costruzione:
   - le entrate usano animation-fill-mode: backwards, mai both/forwards: un transform lasciato
     in vigore a fine animazione batte l'hover e crea un contenitore per i position: fixed;
   - niente stili inline (CSP style-src 'self'): ritardi e progressi passano da variabili CSS
     impostate via CSSOM da motion.js;
   - solo transform, opacity, box-shadow, filter: l'altezza della pagina non cambia mai. */

/* Valori predefiniti a specificità zero: il :root del progetto vince sempre, a prescindere
   dall'ordine dei fogli. Per adattarsi a un sito basta ridefinire --m-accent e --m-lever. */
:where(:root) {
  --m-accent: #ff5a00;
  --m-light: #ff8a3d;
  --m-lever: #1f6feb;
  --m-muted: #6b6b6b;
  --m-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --m-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --m-step: 70ms;
  --m-shadow-soft: 0 4px 14px rgba(0, 0, 0, 0.12);
  --m-shadow-lift: 0 14px 32px rgba(0, 0, 0, 0.16);
  --m-glow: 0 0 34px 8px color-mix(in srgb, var(--m-accent) 45%, transparent);
  --m-glow-soft: 0 0 18px 2px color-mix(in srgb, var(--m-accent) 28%, transparent);
}

@keyframes m-rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes m-fade {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

@keyframes m-pop {
  0% { opacity: 0; transform: scale(0.92); }
  60% { opacity: 1; transform: scale(1.035); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes m-drop {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes m-ring {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--m-accent) 40%, transparent); }
  70% { box-shadow: 0 0 0 16px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@keyframes m-float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-7px) rotate(0.8deg); }
}

@keyframes m-twinkle {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.22); opacity: 0.7; }
}

@keyframes m-breathe {
  0%, 100% { box-shadow: var(--m-glow-soft); }
  50% { box-shadow: var(--m-glow); }
}

/* Gli aloni e gli spostamenti laterali escono dalla colonna: senza questo la pagina scorre di
   lato sul telefono. «clip» e non «hidden»: non crea un contenitore di scroll e lascia lo sticky. */
main { overflow-x: clip; }

/* ---------- Entrata a scalare (motion.js) ---------- */

.m-pre { opacity: 0; }

.m-in {
  animation: m-rise 560ms var(--m-ease) backwards;
  animation-delay: calc(var(--m-i, 0) * var(--m-step));
}

/* Cambio pagina: dissolvenza leggera sul contenitore, i figli salgono. */
.m-page { animation: m-fade 260ms ease backwards; }

/* Sopra la piega: aggiungi .m-seq al contenitore e i figli entrano a gradini di 0,12 s. */
.m-seq > * { animation: m-rise 640ms var(--m-ease) backwards; }
.m-seq > :nth-child(2) { animation-delay: 0.12s; }
.m-seq > :nth-child(3) { animation-delay: 0.24s; }
.m-seq > :nth-child(4) { animation-delay: 0.36s; }
.m-seq > :nth-child(5) { animation-delay: 0.48s; }
.m-seq > :nth-child(n + 6) { animation-delay: 0.6s; }

/* Sezioni che salgono entrando nello schermo, senza JavaScript, dove il browser lo sa fare.
   Senza timeline di scroll non viene nascosto nulla. */
@supports (animation-timeline: view()) {
  .m-band {
    animation: m-rise linear backwards;
    animation-timeline: view();
    animation-range: entry 0% entry 40%;
  }
}

/* ---------- Barra di avanzamento della pagina ---------- */

.m-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 9999;
  background: linear-gradient(90deg, var(--m-accent), var(--m-light));
  transform: scaleX(0);
  transform-origin: left center;
  pointer-events: none;
}

/* ---------- Bottoni ---------- */

button, .button, .btn {
  transition: transform 160ms var(--m-ease), box-shadow 220ms ease,
    background-color 200ms ease, border-color 200ms ease, color 200ms ease;
}

button:not(:disabled):hover, .button:not(:disabled):hover, .btn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: var(--m-shadow-soft);
}

button:not(:disabled):active, .button:not(:disabled):active, .btn:not(:disabled):active {
  transform: translateY(0) scale(0.97);
  box-shadow: none;
}

/* Il bottone principale: si alza, si allarga il bagliore, un riflesso scorre al passaggio. */
.m-primary:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--m-accent) 18%, transparent), var(--m-shadow-soft);
}

.m-primary { position: relative; overflow: hidden; }

.m-primary::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
  transform: translateX(-130%);
  pointer-events: none;
}

.m-primary:not(:disabled):hover::after {
  transform: translateX(130%);
  transition: transform 750ms ease;
}

/* La porta d'ingresso della pagina respira un anello, piano, ogni tanto. */
.m-cta { animation: m-ring 3.8s ease-out 2s infinite; }

/* ---------- Card, righe, pillole ---------- */

.card, .m-card {
  transition: transform 220ms var(--m-ease), box-shadow 260ms ease, border-color 200ms ease;
}
.card:hover, .m-card:hover { transform: translateY(-3px); box-shadow: var(--m-shadow-lift); }
.card:active, .m-card:active { transform: translateY(-1px) scale(0.985); }

.m-row { transition: background-color 220ms ease, transform 220ms var(--m-ease); }
.m-row:hover { transform: translateX(3px); }

.m-pill {
  transition: transform 160ms var(--m-spring), background-color 200ms ease,
    border-color 200ms ease, color 200ms ease, box-shadow 200ms ease;
}
.m-pill:not(:disabled):hover { transform: translateY(-2px); }
.m-pill:not(:disabled):active { transform: scale(0.94); }
.m-pill[aria-pressed="true"] { animation: m-pop 340ms var(--m-spring) backwards; }

nav a { display: inline-block; transition: color 200ms ease, transform 180ms var(--m-ease); }
nav a:hover { transform: translateY(-1px); }

/* ---------- Campi di testo: il fuoco accende un alone morbido ---------- */

input, textarea, select {
  transition: box-shadow 220ms ease, border-color 200ms ease, background-color 200ms ease;
}

input:focus, textarea:focus, select:focus {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--m-accent) 18%, transparent);
}

/* ---------- Messaggi e pannelli che compaiono ---------- */

[role="status"]:not([hidden]):not(:empty),
[role="alert"]:not([hidden]):not(:empty) { animation: m-rise 420ms var(--m-ease) backwards; }

details[open] > :not(summary) { animation: m-drop 320ms var(--m-ease) backwards; }

dialog[open] { animation: m-pop 240ms var(--m-spring) backwards; }

/* ---------- Atmosfera ---------- */

/* L'elemento firma della pagina: fluttua piano. */
.m-float { animation: m-float 8s ease-in-out infinite; }

/* Bagliore che respira: ciò che è attivo, chi ha la parola, l'idea appena arrivata. */
.m-glow { box-shadow: var(--m-glow); animation: m-breathe 2.4s ease-in-out infinite; }

/* Coriandoli (motion.js, coriandoli()): volano sopra tutto e non ricevono clic. */
.m-confetto {
  position: fixed;
  top: 0;
  left: 0;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  z-index: 10000;
  pointer-events: none;
}

/* ---------- Interruttore «Animazioni» ----------
   L'unico modo in cui il movimento si ferma: lo sceglie la persona, non il sistema. */

.motion-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.35em 0.8em;
  font: inherit;
  color: var(--m-lever);
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 999px;
  cursor: pointer;
}
.motion-toggle[aria-pressed="false"] { color: var(--m-muted); }
.motion-toggle__icon {
  display: inline-block;
  animation: m-twinkle 3.2s ease-in-out infinite;
  transition: transform 300ms var(--m-spring);
}
.motion-toggle:hover .motion-toggle__icon { transform: rotate(72deg) scale(1.15); }

/* Senza un posto nella testata, sta in basso a destra. */
.motion-toggle--fixed {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9998;
  background: #fff;
}

@media (max-width: 719px) {
  .motion-toggle__label { display: none; }
}

/* Da ultimo, per vincere su tutto ciò che sta sopra. */
html.m-calm *,
html.m-calm *::before,
html.m-calm *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* Fermo non vuol dire nascosto. */
html.m-calm .m-pre { opacity: 1; }
