/* Fabio Andrian · pagina di presentazione
   Ordine: gettoni, base, impianto, testata, apertura, linea del tempo, sezioni,
   filo e indice, arrivo, firma, movimento, stampa. */

/* ---------- 1. Gettoni ---------- */

:root {
  --blu-falabi: #004f9c;            /* il blu del logo, letto dal file originale */
  --carta: #faf8f3;
  --inchiostro: #15202d;
  --inchiostro-2: #4a5665;
  --blu: #004f9c;                   /* filo, accenti, link */
  --logo: #004f9c;
  --riga: rgba(21, 32, 45, 0.16);
  --pannello: #ffffff;
  --azione-fondo: #004f9c;
  --azione-testo: #ffffff;
  --alone: rgba(0, 79, 156, 0.3);
  --ombra: 0 14px 34px rgba(21, 32, 45, 0.18), 0 2px 6px rgba(21, 32, 45, 0.1);

  --filo: 2px;                      /* lo spessore del filo: quello dei tratti del logo in testata */
  --bordo: 20px;                    /* margine laterale della pagina */
  --rotaia: -4px;                   /* dove corre il filo rispetto al bordo destro del contenuto */
  --gola: 18px;                     /* aria fra il testo e il filo */
  --colonna: 35rem;
  --h2: clamp(1.75rem, 1.4rem + 1.7vw, 2.6rem);
  --aria: clamp(3.5rem, 2.4rem + 5vw, 6.5rem);
  --tasto: 3.25rem;
  --sotto: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  --y-nodo: calc(2rem + var(--filo) / 2);          /* centro del nodo «oggi», dall'alto del percorso */
  --y-arrivo: calc(var(--aria) + var(--tasto) / 2); /* centro del tasto finale, dal fondo del percorso */
  --anni: 15;                       /* lo aggiorna pagina.js */

  color-scheme: light dark;
}

@media (min-width: 48rem) {
  :root { --bordo: 2.5rem; --rotaia: 0px; --gola: 2.25rem; }
}

@media (min-width: 100rem) {
  :root { --filo: 3px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --carta: #0d1722;
    --inchiostro: #e9eef4;
    --inchiostro-2: #a8b4c3;
    --blu: #74aef0;
    --logo: #f4f7fb;
    --riga: rgba(233, 238, 244, 0.18);
    --pannello: #172536;
    --azione-fondo: #74aef0;
    --azione-testo: #0b1520;
    --alone: rgba(116, 174, 240, 0.35);
    --ombra: 0 14px 34px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.35);
  }
}

/* ---------- 2. Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: clamp(1.0625rem, 1.016rem + 0.185vw, 1.3125rem);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 1rem;
}

body {
  margin: 0;
  background: var(--carta);
  color: var(--inchiostro);
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
a { color: var(--blu); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--blu); outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }

.deposito { position: absolute; width: 0; height: 0; overflow: hidden; }

.salta {
  position: absolute;
  left: var(--bordo);
  top: 0.75rem;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 1.1rem;
  border-radius: 999px;
  background: var(--azione-fondo);
  color: var(--azione-testo);
  font-weight: 600;
  text-decoration: none;
}
.salta:not(:focus) { opacity: 0; pointer-events: none; }

/* ---------- 3. Impianto ---------- */

.pagina {
  width: 100%;
  max-width: 70rem;
  margin-inline: auto;
  padding-inline: var(--bordo);
}

/* ---------- 4. Testata ---------- */

.testata {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1rem;
}

.testata__logo {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--logo);
  border-radius: 6px;
}

.logo { display: block; width: auto; height: 1.65rem; }

.testata__voci { display: none; }

@media (min-width: 48rem) {
  .testata__voci { display: flex; align-items: center; gap: 0.25rem; }
  .testata__voci a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding-inline: 0.95rem;
    border-radius: 999px;
    color: var(--inchiostro);
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
  }
  .testata__voci .testata__scrivimi {
    margin-left: 0.5rem;
    border: 1.5px solid currentColor;
    color: var(--blu);
    font-weight: 600;
  }
}

/* ---------- 5. Apertura ---------- */

.apertura { padding-block: clamp(2rem, 1rem + 5vw, 5rem) clamp(2.5rem, 1.5rem + 4vw, 4.5rem); }

.apertura__chi { margin-bottom: 1.25rem; color: var(--inchiostro-2); }
.apertura__chi strong { margin-right: 0.35em; color: var(--inchiostro); font-weight: 600; }
.apertura__chi span { white-space: nowrap; }

h1 {
  max-width: 20ch;
  margin-bottom: 1.5rem;
  font-size: clamp(2.3rem, 1.25rem + 5vw, 4.4rem);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.apertura__resto { display: block; color: var(--blu); font-weight: 600; }

.apertura__lancio { max-width: 34rem; margin-bottom: 2rem; font-size: 1.2rem; line-height: 1.5; }

.bottone {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tasto);
  padding: 0 1.7rem;
  border: 0;
  border-radius: 999px;
  background: var(--azione-fondo);
  color: var(--azione-testo);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bottone:active { transform: scale(0.97); }

/* ---------- 6. Linea del tempo ---------- */

.percorso { position: relative; }
.percorso__contenuto { padding-right: calc(var(--gola) + var(--rotaia)); }

.tempo__riga {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  row-gap: 0.5rem;
}

.tempo__anno {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.5rem;
  letter-spacing: 0.04em;
  color: var(--inchiostro-2);
  font-variant-numeric: tabular-nums;
}

/* La linea arriva fino al filo, oltre il bordo del testo. */
.tempo__linea {
  position: relative;
  grid-column: 1 / -1;
  width: calc(100% + var(--gola));
  height: var(--filo);
  background: var(--blu);
  transform-origin: 0 50%;
}

/* Una tacca per anno. */
.tempo__linea::after {
  content: "";
  position: absolute;
  inset: 100% 0 auto 0;
  height: 6px;
  background: repeating-linear-gradient(to right, var(--blu) 0 1.5px, transparent 1.5px calc(100% / var(--anni)));
}

.tempo__nodo,
.sezione__nodo {
  position: absolute;
  z-index: 2;
  width: 12px;
  height: 12px;
  border: var(--filo) solid var(--blu);
  border-radius: 50%;
  background: var(--carta);
}

.tempo__nodo { right: calc(-1 * var(--gola)); bottom: calc(var(--filo) / 2); transform: translate(50%, 50%); }

.tempo__nota { margin-top: 1.1rem; font-size: 0.9375rem; color: var(--inchiostro-2); }
.tempo__nota b { color: var(--inchiostro); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- 7. Sezioni ---------- */

.sezione { position: relative; padding-top: var(--aria); }

.sezione__nodo { right: calc(-1 * var(--gola)); top: calc(var(--aria) + 0.575 * var(--h2)); transform: translate(50%, -50%); }

.sezione__titolo {
  max-width: var(--colonna);
  margin-bottom: 1.5rem;
  font-size: var(--h2);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.sezione__intro { font-size: 1.2rem; line-height: 1.5; }

.blocco { margin-top: 2.25rem; }
.sezione__titolo + .blocco,
.elenco--primo > .blocco:first-child { margin-top: 0; }

.blocco__testo { max-width: var(--colonna); }
.blocco h3 { margin-bottom: 0.45rem; font-size: 1.2rem; font-weight: 600; line-height: 1.3; }
.blocco p + p { margin-top: 0.9rem; }

.elenco { counter-reset: voce; }
.elenco > li { counter-increment: voce; }
.elenco .blocco__testo::before {
  content: counter(voce, decimal-leading-zero);
  display: block;
  margin-bottom: 0.3rem;
  color: var(--blu);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.mai { margin-top: 0.8rem; border-bottom: 1px solid var(--riga); }
.mai li { padding-block: 0.75rem; border-top: 1px solid var(--riga); }

.ponte { color: var(--blu); font-weight: 600; }

/* Le stazioni: i fatti, appesi al filo con una tacca. */
.stazione {
  position: relative;
  width: fit-content;
  max-width: 15rem;
  margin: 1.1rem 0 0 auto;
  color: var(--inchiostro-2);
  font-size: 0.9375rem;
  line-height: 1.35;
  text-align: right;
}
.stazione b { display: block; color: var(--inchiostro); font-size: 1.1rem; font-weight: 600; }
.stazione::after {
  content: "";
  position: absolute;
  left: calc(100% + 0.4rem);
  top: 0.74rem;
  width: calc(var(--gola) - 0.4rem);
  height: 1.5px;
  background: var(--blu);
}

@media (min-width: 62rem) {
  .blocco {
    display: grid;
    grid-template-columns: minmax(0, var(--colonna)) minmax(11rem, 1fr);
    column-gap: 3rem;
    align-items: start;
  }
  .stazione { grid-column: 2; margin-top: 0.15rem; }
  .elenco .stazione { margin-top: 1.75rem; }
}

/* ---------- 8. Il filo e l'indice ---------- */

.filo {
  position: absolute;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

/* Due binari gemelli: uno ritaglia la scia, l'altro porta il punto e l'indice (che non va ritagliato). */
.filo--scia {
  z-index: 1;
  top: var(--y-nodo);
  bottom: var(--y-arrivo);
  right: calc(var(--bordo) + var(--rotaia) - var(--filo) / 2);
  width: var(--filo);
  clip-path: inset(0);
}

.filo__scia { position: sticky; bottom: calc(var(--sotto) + 24px); height: 0; margin-top: auto; }
.filo__scia::before {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 250vh;
  background: var(--blu);
}

.filo--testa {
  z-index: 5;
  top: calc(var(--y-nodo) - 24px);
  bottom: calc(var(--y-arrivo) - 24px);
  right: calc(var(--bordo) + var(--rotaia) - 16px);
  width: 48px;
}

.filo__presa { position: sticky; bottom: var(--sotto); height: 48px; margin-top: auto; }

.filo__punto {
  position: relative;
  display: block;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--blu);
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}
.filo__punto:focus-visible { outline: none; }
.filo__punto:focus-visible .filo__goccia { outline: 3px solid var(--blu); outline-offset: 4px; }

.filo__goccia {
  position: absolute;
  top: 17px;
  right: 9px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: currentColor;
}
.filo__punto:active .filo__goccia { transform: scale(0.85); }
.filo__punto[aria-expanded="true"] .filo__goccia { background: var(--carta); box-shadow: inset 0 0 0 3px var(--blu); transform: scale(1.3); }

.filo__etichetta {
  position: absolute;
  top: 50%;
  right: 38px;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: var(--inchiostro);
  color: var(--carta);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  opacity: 0;
  transform: translate(0.5rem, -50%);
}
.filo__etichetta.is-vista { opacity: 1; transform: translate(0, -50%); }

.indice {
  position: absolute;
  right: 6px;
  bottom: calc(100% + 4px);
  min-width: 14.5rem;
  padding: 0.4rem;
  border-radius: 1rem;
  background: var(--pannello);
  box-shadow: var(--ombra);
  pointer-events: auto;
  transform-origin: 100% 100%;
}
.indice a {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 1rem;
  border-radius: 0.7rem;
  color: var(--inchiostro);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.indice a[aria-current="true"] { color: var(--blu); font-weight: 600; }
.indice__su { margin-top: 0.3rem; padding-top: 0.3rem; border-top: 1px solid var(--riga); }
.indice__su a { color: var(--inchiostro-2); }

/* ---------- 9. Arrivo ---------- */

.sezione--arrivo { padding-bottom: var(--aria); }

.arrivo {
  position: relative;
  display: flex;
  align-items: center;
  height: var(--tasto);
  margin: 2.25rem calc(-1 * var(--gola)) 0 0;
}

.arrivo__linea { flex: 1 1 0; min-width: 0; height: var(--filo); background: var(--blu); transform-origin: 100% 50%; }

.arrivo__manca {
  display: inline-flex;
  align-items: center;
  height: var(--tasto);
  padding: 0 1.3rem;
  border: 1.5px dashed var(--blu);
  border-radius: 999px;
  color: var(--blu);
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
}

.arrivo__aiuto {
  position: absolute;
  inset: calc(100% + 0.6rem) var(--gola) auto 0;
  color: var(--inchiostro-2);
  font-size: 0.875rem;
  line-height: 1.4;
}
.arrivo__aiuto code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.875rem; color: var(--inchiostro); }

/* ---------- 10. Firma ---------- */

/* Fondo fissato, colori fissati: il blocco resta blu Falabi nei due temi. */
.firma { background: var(--blu-falabi); color: #ffffff; }

.firma__dentro { display: grid; gap: 2rem; padding-block: clamp(3rem, 2rem + 5vw, 5rem); }

.firma__logo { display: block; width: min(100%, 21rem); height: auto; color: #ffffff; }

.firma__nome { color: rgba(255, 255, 255, 0.86); }
.firma__nome strong { display: block; color: #ffffff; font-size: 1.2rem; font-weight: 600; }

.firma__recapito { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; margin-top: 0.75rem; }

.firma__indirizzo {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: #ffffff;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.copia {
  min-height: 44px;
  padding: 0 1.1rem;
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  background: none;
  color: #ffffff;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.copia:active { transform: scale(0.96); }
.copia.is-fatto { background: #ffffff; color: var(--blu-falabi); border-color: #ffffff; }
.copia__esito { flex-basis: 100%; font-size: 0.875rem; color: rgba(255, 255, 255, 0.86); }
.copia__esito:empty { display: none; }

.firma__note { color: rgba(255, 255, 255, 0.86); font-size: 0.875rem; }

.firma :focus-visible { outline-color: #ffffff; }

.scrittura path { stroke-dasharray: 1; stroke-dashoffset: 0; }
.scrittura__punto { transform-box: fill-box; transform-origin: center; }

@media (min-width: 48rem) {
  .firma__dentro { grid-template-columns: 1fr auto; align-items: end; }
  .firma__note { grid-column: 1 / -1; }
}

/* ---------- 11. Movimento ---------- */

@media (hover: hover) and (pointer: fine) {
  .bottone, .copia, .testata__voci a, .indice a, .filo__goccia { transition: transform 0.18s ease, box-shadow 0.2s ease, background-color 0.18s ease, color 0.18s ease; }
  .bottone:hover { transform: translateY(-2px); box-shadow: 0 8px 22px var(--alone); }
  .bottone:active { transform: scale(0.97); }
  .testata__voci a:hover, .indice a:hover { background: var(--riga); }
  .copia:hover { background: rgba(255, 255, 255, 0.14); }
  .copia.is-fatto:hover { background: #ffffff; }
  .filo__punto:hover .filo__goccia { transform: scale(1.3); }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }

  @keyframes entra { from { opacity: 0; transform: translateY(0.9rem); } }
  @keyframes affiora { from { opacity: 0; } }
  @keyframes traccia { from { transform: scaleX(0); } }
  @keyframes spunta { from { opacity: 0; transform: translate(50%, 50%) scale(0); } }
  @keyframes scendi { from { transform: translateY(var(--discesa, 0px)); } }
  @keyframes apri { from { opacity: 0; transform: scale(0.92); } }
  @keyframes battito { from { box-shadow: 0 0 0 0 var(--alone); } to { box-shadow: 0 0 0 16px transparent; } }

  /* All'apertura: il testo sale, la linea del tempo si traccia, il punto scende dal nodo «oggi». */
  .apertura > * { animation: entra 0.8s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .apertura > :nth-child(2) { animation-delay: 0.1s; }
  .apertura > :nth-child(3) { animation-delay: 0.22s; }
  .apertura > :nth-child(4) { animation-delay: 0.34s; }
  .tempo__anno, .tempo__nota { animation: affiora 0.6s ease-out 0.5s both; }
  .tempo__linea { animation: traccia 1.1s cubic-bezier(0.6, 0, 0.2, 1) 0.5s both; }
  .tempo__nodo { animation: spunta 0.35s cubic-bezier(0.3, 1.6, 0.5, 1) 1.5s both; }
  .filo__presa, .filo__scia { animation: affiora 0.2s ease-out 1.7s both, scendi 0.85s cubic-bezier(0.5, 0, 0.2, 1) 1.75s both; }

  .indice { animation: apri 0.16s ease-out; }
  .filo__etichetta { transition: opacity 0.25s ease, transform 0.25s ease; }

  /* Le comparse allo scorrimento valgono solo se JavaScript c'è (classe messa da avvio.js). */
  .js .rivela { opacity: 0; transform: translateY(0.9rem); transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1); }
  .js .stazione.rivela { transition-delay: 0.15s; }
  .js .rivela.is-vista { opacity: 1; transform: none; }

  /* L'arrivo: il filo raggiunge il tasto. */
  .js .arrivo__linea { transition: transform 0.7s cubic-bezier(0.6, 0, 0.2, 1); }
  .js .percorso:not(.is-arrivato) .arrivo__linea { transform: scaleX(0); }
  .percorso.is-arrivato .filo__goccia { animation: battito 0.9s ease-out 2; }
  .percorso.is-arrivato .arrivo__tasto { animation: battito 0.9s ease-out 0.7s 1; }

  /* La firma si scrive quando entra in vista. */
  .js .scrittura path { transition: stroke-dashoffset 0.22s cubic-bezier(0.5, 0, 0.3, 1); }
  .js .scrittura__punto { transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1) 1.76s; }
  .js .firma__logo:not(.is-scritta) .scrittura path { stroke-dashoffset: 1; transition: none; }
  .js .firma__logo:not(.is-scritta) .scrittura__punto { transform: scale(0); transition: none; }
  .js .scrittura path:nth-child(1) { transition-duration: 0.45s; }
  .js .scrittura path:nth-child(2) { transition-delay: 0.3s; }
  .js .scrittura path:nth-child(3) { transition-delay: 0.42s; }
  .js .scrittura path:nth-child(4) { transition-delay: 0.52s; }
  .js .scrittura path:nth-child(5) { transition-delay: 0.64s; }
  .js .scrittura path:nth-child(6) { transition-delay: 0.8s; }
  .js .scrittura path:nth-child(7) { transition-delay: 0.92s; transition-duration: 0.32s; }
  .js .scrittura path:nth-child(8) { transition-delay: 1.14s; }
  .js .scrittura path:nth-child(9) { transition-delay: 1.24s; }
  .js .scrittura path:nth-child(10) { transition-delay: 1.36s; transition-duration: 0.32s; }
  .js .scrittura path:nth-child(11) { transition-delay: 1.6s; }
}

/* ---------- 12. Stampa ---------- */

@media print {
  .filo, .testata__voci, .salta, .apertura__gesto, .copia, .arrivo__linea { display: none !important; }
  .rivela { opacity: 1 !important; transform: none !important; }
  .scrittura path { stroke-dashoffset: 0 !important; }
  .scrittura__punto { transform: none !important; }
  .firma { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
