/* ============================================================
   INTRO "la chiave cammina" — solo home, una volta per visita.
   Si disattiva con prefers-reduced-motion. Per spegnerla del tutto:
   togliere <div id="intro"> e intro.js dalla home.
   ============================================================ */
#intro { position: fixed; inset: 0; z-index: 100; background: var(--avorio); display: grid; place-items: center; overflow: hidden; }
/* la scena occupa tutta la larghezza della pagina; l'allontanamento scala dall'angolo in alto a sinistra
   e la partitura, allargandosi e aggiungendo righi, continua a riempire la pagina */
#intro .scena { width: min(96vw, 128vh); height: auto; overflow: visible; transform-origin: 0 0; }
#intro { align-items: start; justify-items: start; padding-top: max(80px, 10vh); padding-left: 2vw; }
#intro.play .scena { animation: allontana 6.5s cubic-bezier(.4,0,.2,1) 5.8s forwards; }
@keyframes allontana { to { transform: scale(var(--k, .4)); } }
#intro .salta { position: fixed; right: 20px; bottom: 20px; z-index: 101; background: var(--rosso); border: 2px solid var(--rosso); color: var(--bianco); font: inherit; font-size: .95rem; font-weight: 700; padding: .6em 1.2em; border-radius: 999px; cursor: pointer; opacity: 1; box-shadow: 0 4px 14px rgba(74,0,0,.25); }
#intro .salta::after { content: " \2192"; }
#intro .suggerimento { position: fixed; right: 20px; bottom: 68px; z-index: 101; font-size: .8rem; color: var(--grigio, #6b6760); background: rgba(255,255,255,.7); padding: .25em .7em; border-radius: 999px; }
#intro .salta:hover { background: var(--rosso-scuro); border-color: var(--rosso-scuro); }

/* rigo: 5 linee che si disegnano da destra verso sinistra */
#intro .rigo line { stroke: var(--oro); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 820; stroke-dashoffset: 820; }
#intro.play .rigo line { animation: disegna 1.1s cubic-bezier(.4,0,.2,1) forwards; }
#intro.play .rigo line:nth-child(1) { animation-delay: .25s } #intro.play .rigo line:nth-child(2) { animation-delay: .35s }
#intro.play .rigo line:nth-child(3) { animation-delay: .45s } #intro.play .rigo line:nth-child(4) { animation-delay: .55s }
#intro.play .rigo line:nth-child(5) { animation-delay: .65s }
@keyframes disegna { to { stroke-dashoffset: 0; } }

/* chiave: cammina da sinistra (traslazione) + passo (sobbalzo e inclinazione) */
#intro .chiave { fill: var(--rosso); }
/* righi aggiuntivi, graffa, chiavi e note della partitura */
#intro .rigo-b line { stroke-dasharray: 820; stroke-dashoffset: 820; }
#intro.play .rigo-b line { animation: disegna .7s cubic-bezier(.4,0,.2,1) forwards; }
#intro .graffa { fill: none; stroke: var(--rosso); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 600; stroke-dashoffset: 600; }
#intro.play .graffa { animation: disegna .6s ease-out forwards; }
#intro .graffa-2 { stroke-dasharray: 2300; stroke-dashoffset: 2300; }
#intro .rigo-w line { stroke-dasharray: 2400; stroke-dashoffset: 2400; }
#intro .rigo-ext line { stroke-dasharray: 1600; stroke-dashoffset: 1600; }
#intro.play .rigo-ext line { animation-duration: 1.1s; }
#intro.play .rigo-w line { animation-duration: 1.1s; }
#intro.play .graffa-2 { animation: disegna 1.2s ease-out forwards; }
/* le altre chiavi entrano tutte insieme, in marcia coordinata con lo stesso passo della prima */
#intro .chiave-pop { opacity: 0; transform-box: fill-box; transform-origin: 50% 90%; transform: translateX(-340px); will-change: transform, opacity; }
#intro.play .chiave-marcia { animation: marcia 1.7s cubic-bezier(.3,.1,.4,1) forwards, passo-m .42s ease-in-out 4; }
@keyframes marcia { 0% { opacity: 0; transform: translateX(-340px); } 8% { opacity: 1; } 100% { opacity: 1; transform: none; } }
/* il passo e' sovrapposto alla marcia tramite un wrapper: qui lo simuliamo con un leggero rollio */
@keyframes passo-m { 0%,100% { rotate: -3deg; translate: 0 0; } 50% { rotate: 3deg; translate: 0 -14px; } }
/* le note arrivano da destra e si fermano sul rigo (--dx = distanza dal bordo destro) */
#intro .nota { fill: var(--rosso); opacity: 0; transform-box: fill-box; transform-origin: 50% 100%; transform: translateX(var(--dx, 800px)); }
#intro.play .nota { animation: arriva .75s cubic-bezier(.15,.7,.25,1) forwards; }
@keyframes arriva { 0% { opacity: 0; transform: translateX(var(--dx, 800px)); } 15% { opacity: 1; } 85% { transform: translateX(-4px); } 100% { opacity: 1; transform: none; } }
#intro .gambo, #intro .barra { stroke: var(--rosso); stroke-width: 2; stroke-linecap: round; }
#intro .trave { stroke: var(--rosso); stroke-width: 5; stroke-linecap: butt; }
#intro .barra { stroke: var(--oro); stroke-width: 2; }
#intro .cammino { transform: translateX(-220px); }
#intro.play .cammino { animation: cammina 1.7s cubic-bezier(.3,.1,.4,1) forwards; }
@keyframes cammina { to { transform: translateX(0); } }
#intro.play .passo { animation: passo .42s ease-in-out 4; transform-origin: 50% 90%; }
@keyframes passo { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-16px) rotate(3deg); } }
#intro.play .assesta { animation: assesta .5s cubic-bezier(.34,1.56,.64,1) 1.7s both; transform-origin: 50% 100%; }
@keyframes assesta { 0% { transform: scaleY(.96) translateY(0); } 40% { transform: scaleY(1.03) translateY(-6px); } 100% { transform: scaleY(1) translateY(0); } }

/* orme: notine oro che appaiono dietro i passi e svaniscono */
#intro .orme text { fill: var(--oro); opacity: 0; font-family: "Segoe UI Symbol", "DejaVu Sans", serif; }
#intro.play .orme text { animation: orma 1.2s ease-out forwards; }
@keyframes orma { 0% { opacity: 0; transform: translateY(6px); } 20% { opacity: .9; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-14px); } }

/* scritta DAL 1882: in alto, fissa, compare quando inizia l'allontanamento (il maestro: da valutare piu' avanti) */
#intro .dal { position: fixed; top: 12px; left: 0; right: 0; margin: 0; text-align: center; font-family: var(--display); color: var(--rosso); font-size: clamp(1.4rem, 3.2vw, 2.4rem); letter-spacing: .22em; opacity: 0; z-index: 101; }
#intro.play .dal { animation: appari .9s ease-out 5.8s forwards; }
@keyframes appari { to { opacity: 1; } }

/* uscita: dissolvenza lenta della partitura mentre sotto emerge la home */
#intro.via { animation: velo 1.8s ease-in-out forwards; pointer-events: none; }
@keyframes velo { to { opacity: 0; } }
#intro[hidden] { display: none; }

/* pulsante "intro" nella testata: piccola chiave + parola */
.btn-intro { display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; vertical-align: middle; background: rgba(0,0,0,.18); border: 1px solid rgba(255,255,255,.45); color: var(--bianco); border-radius: 999px; padding: 1px 8px 1px 5px; font: inherit; font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; cursor: pointer; line-height: 1.4; }
.btn-intro:hover { background: rgba(0,0,0,.32); border-color: #f0c46a; }
.btn-intro svg { width: 8px; height: 20px; fill: #f0c46a; }
.btn-intro.pulsa { animation: pulsa .6s ease-out 1; }
@keyframes pulsa { 0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(240,196,106,.8); } 100% { transform: scale(1); box-shadow: 0 0 0 10px rgba(240,196,106,0); } }
@media (max-width: 860px) { .btn-intro span { display: none; } .btn-intro { padding: 1px 6px; } }

/* hero: ingresso a scalare dopo l'intro (o subito se l'intro non c'è) */
.hero-testo > * { opacity: 0; transform: translateY(14px); }
body.pronto .hero-testo > * { animation: sali .6s ease-out forwards; }
body.pronto .hero-testo > :nth-child(1) { animation-delay: .05s } body.pronto .hero-testo > :nth-child(2) { animation-delay: .17s }
body.pronto .hero-testo > :nth-child(3) { animation-delay: .29s } body.pronto .hero-testo > :nth-child(4) { animation-delay: .41s }
@keyframes sali { to { opacity: 1; transform: none; } }
body.pronto .hero img.sfondo { animation: kenburns 22s ease-out forwards; }
@keyframes kenburns { from { transform: scale(1); } to { transform: scale(1.07); } }
.hero .stemma { opacity: 0; transform: translateY(-24px); }
body.pronto .hero .stemma { animation: stemma .7s cubic-bezier(.34,1.56,.64,1) .5s forwards; }
@keyframes stemma { to { opacity: 1; transform: none; } }

/* quando la home emerge dalla dissolvenza dell'intro, e' gia' completa e ferma: nessuna animazione sovrapposta */
body.pronto.statico .hero-testo > *, body.pronto.statico .hero .stemma { animation: none; opacity: 1; transform: none; }
body.pronto.statico .hero img.sfondo { animation: none; }

@media (prefers-reduced-motion: reduce) {
  #intro { display: none; }
  .hero-testo > *, .hero .stemma { opacity: 1; transform: none; animation: none !important; }
  .btn-intro { display: none; }
  body.pronto .hero img.sfondo { animation: none; }
}

/* ===== VARIANTE "solo il rigo" (scelta dei responsabili): un solo pentagramma, la chiave cammina, le note arrivano.
   Per tornare alla partitura completa: SOLO=False in site-src/gen_intro.py, rigenerare e togliere class="solo". ===== */
#intro.solo { align-items: center; justify-items: center; padding: 0; }
#intro.solo .scena { width: min(94vw, 150vh); }
#intro.solo.play .scena { animation: none; }
#intro.solo.play .dal { animation: appari .9s ease-out 5.4s forwards; }
