:root {
  --bg: #F4F4FA;
  --surface: #FFFFFF;
  --ink: #14162B;
  --ink-2: #4E5470;
  --line: #E0E0EE;
  --pre: #3366E8;
  --post: #D96A12;
  --viola: #7C4DDB;
  --accento: linear-gradient(115deg, var(--pre), var(--viola) 55%, var(--post));
  --ombra: 0 1px 2px rgb(20 22 43 / .05), 0 10px 30px -12px rgb(20 22 43 / .18);
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1020;
    --surface: #171A30;
    --ink: #ECEEF8;
    --ink-2: #A6ACC6;
    --line: #2A2F4D;
    --pre: #6690FF;
    --post: #F08A3A;
    --viola: #A07BFF;
    --ombra: 0 1px 2px rgb(0 0 0 / .3), 0 14px 34px -14px rgb(0 0 0 / .6);
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(55rem 35rem at 100% -5%, color-mix(in srgb, var(--pre) 12%, transparent), transparent 70%),
    radial-gradient(45rem 35rem at 25% 105%, color-mix(in srgb, var(--post) 9%, transparent), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 1.0625rem/1.6 var(--body);
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--pre); outline-offset: 2px; border-radius: 4px; }
.salta { position: absolute; left: -999px; }
.salta:focus { left: 1rem; top: 1rem; z-index: 10; background: var(--surface); padding: .5rem .75rem; }

/* Struttura */
.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); }
.indice {
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto;
  padding: 2rem 1.25rem 2rem 1.5rem;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}
.indice-testa { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.indice .marchio { display: flex; padding: 0; color: var(--ink); align-items: center; gap: .6rem; font: 700 1.05rem/1.2 var(--display); text-decoration: none; }
.indice .marchio::before { content: ""; flex: none; width: 1.6rem; height: 1.6rem; border-radius: 8px; background: var(--accento); box-shadow: 0 4px 12px -4px var(--viola); }
#apri-indice { display: none; }
.indice ol { list-style: none; margin: 0; padding: 0; }
#indice-lista { margin-top: 1.5rem; counter-reset: voce; }
#indice-lista > li { margin-bottom: .75rem; }
#indice-lista > li[data-numerata] { counter-increment: voce; }
#indice-lista > li[data-numerata] > a::before { content: counter(voce) ". "; }
.indice a {
  display: block; padding: .3rem .6rem; border-radius: 0 8px 8px 0;
  border-left: 3px solid transparent;
  text-decoration: none; color: var(--ink-2);
}
#indice-lista > li > a { font-weight: 700; color: var(--ink); }
.indice li ol a { padding-left: 1.4rem; font-size: .95rem; }
.indice a:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.indice a.qui { border-left-color: var(--viola); background: color-mix(in srgb, var(--viola) 10%, transparent); }
.indice a[aria-current] { border-left-color: var(--pre); color: var(--ink); background: color-mix(in srgb, var(--pre) 9%, transparent); }

main { padding: 0 clamp(1rem, 5vw, 4rem) 4rem; max-width: 56rem; }
.sezione { padding: 4rem 0 2.5rem; border-bottom: 1px solid var(--line); scroll-margin-top: 0; }
.blocco { margin-top: 3.25rem; scroll-margin-top: 1.5rem; }
main { counter-reset: sez; }
.sezione[data-numerata] { counter-increment: sez; }
.sezione[data-numerata] h1 { font-size: clamp(1.9rem, 4.5vw, 2.75rem); font-weight: 750; letter-spacing: -.02em; }
.sezione[data-numerata] h1::before { content: counter(sez) ". "; background: var(--accento); -webkit-background-clip: text; background-clip: text; color: transparent; }

h1, h2, h3 { font-family: var(--display); line-height: 1.1; margin: 0; }
h1 { font-size: clamp(2.6rem, 7vw, 4.75rem); font-weight: 800; letter-spacing: -.03em; }
h2 { font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em; }
.blocco > h2::before { content: ""; display: block; width: 2.2rem; height: 4px; margin-bottom: .7rem; border-radius: 2px; background: var(--accento); }
#progetto h1 { padding-bottom: .08em; background: linear-gradient(115deg, var(--ink) 35%, var(--viola) 70%, var(--post)); -webkit-background-clip: text; background-clip: text; color: transparent; }
p { margin: 1rem 0 0; }
.guida { font-size: 1.2rem; color: var(--ink-2); }
/* Definizione di un termine: <dl class="definizione"><dt>Termine</dt><dd>Spiegazione.</dd></dl> */
.definizione { margin: 1.5rem 0 0; padding: .8rem 1.1rem; border-left: 4px solid var(--viola); background: color-mix(in srgb, var(--viola) 8%, var(--surface)); border-radius: 0 12px 12px 0; }
.definizione dt { font: 650 1.1rem var(--display); }
.definizione dd { margin: .15rem 0 0; }
.definizione dd + dt { margin-top: .7rem; }
strong { font-weight: 700; }
.sommario { list-style: none; counter-reset: voce; display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; margin: 2.5rem 0 0; padding: 0; font: 650 1.2rem/1.25 var(--display); }
.sommario li { counter-increment: voce; display: flex; }
.sommario a { flex: 1; display: flex; flex-direction: column; gap: .5rem; padding: 1.1rem 1.2rem 1.2rem; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--ombra); text-decoration: none; transition: transform .2s, border-color .2s; }
.sommario a::before { content: counter(voce, decimal-leading-zero); align-self: flex-start; font: 800 1.9rem/1 var(--display); background: var(--accento); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sommario a:hover { transform: translateY(-3px); border-color: var(--viola); }

.punto { display: inline-block; width: .7em; height: .7em; border-radius: 50%; margin-right: .4em; }
.punto.pre { background: var(--pre); }
.punto.post { background: var(--post); }

figure { margin: 1.5rem 0 0; padding: 1.6rem; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--ombra); }
figcaption { margin-top: 1rem; font-size: .92rem; color: var(--ink-2); }
button {
  font: 700 1rem var(--body); color: #fff; background: linear-gradient(115deg, var(--pre), var(--viola));
  border: 0; border-radius: 999px; padding: .65rem 1.2rem; cursor: pointer;
  box-shadow: 0 6px 16px -6px var(--viola); transition: transform .15s, box-shadow .15s;
}
button:hover { transform: translateY(-1px); box-shadow: 0 10px 22px -8px var(--viola); }

/* Le due fasi */
.flusso { display: grid; grid-template-columns: 1fr 1.25fr 1fr 1.25fr 1fr; align-items: center; }
.stato { border: 1.5px solid var(--ink); border-radius: 10px; padding: .7rem .6rem; text-align: center; font-weight: 700; line-height: 1.25; }
.stato small, .fase small { display: block; font-weight: 400; font-size: .85rem; color: var(--ink-2); margin-top: .2rem; }
.fase { text-align: center; padding: 0 .5rem; font-weight: 700; line-height: 1.25; }
.fase.pre { --c: var(--pre); }
.fase.post { --c: var(--post); }
.binario { position: relative; display: block; height: 14px; margin: .4rem 0; overflow: hidden; }
.binario::before { content: ""; position: absolute; left: 0; right: 6px; top: 6px; height: 2px; background: var(--c); }
.binario::after { content: ""; position: absolute; right: 0; top: 2px; border: 5px solid transparent; border-left: 8px solid var(--c); border-right: 0; }
.binario i { position: absolute; top: 3px; left: -8px; width: 8px; height: 8px; border-radius: 50%; background: var(--c); animation: scorri 2.4s linear infinite; }
.binario i:nth-child(2) { animation-delay: -.4s; }
.binario i:nth-child(3) { animation-delay: -.8s; }
.binario i:nth-child(4) { animation-delay: -1.2s; }
.binario i:nth-child(5) { animation-delay: -1.6s; }
.binario i:nth-child(6) { animation-delay: -2s; }
@keyframes scorri { to { left: calc(100% - 12px); } }
@keyframes scendi { to { top: calc(100% - 12px); } }

.due { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1.5rem; }
.due > div { border-top: 4px solid var(--c); padding-top: .8rem; }
.due .pre { --c: var(--pre); }
.due .post { --c: var(--post); }
.due h3 { font: 650 1.15rem var(--display); margin: 0; }
.due p { margin-top: .4rem; }

/* Prima e dopo il post-training */
.prova { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-top: 1.25rem; }
.modello { border-top: 4px solid var(--c); padding-top: .8rem; }
.modello.pre { --c: var(--pre); }
.modello.post { --c: var(--post); }
.modello h3 { font: 650 1.1rem var(--display); margin: 0 0 .6rem; }
.uscita { min-height: 7.5rem; padding: .8rem; border-radius: 8px; background: var(--bg); line-height: 1.5; }
.uscita .dato { color: var(--ink-2); }
.uscita .generato { background: color-mix(in srgb, var(--c) 18%, transparent); border-radius: 3px; }
.risposta { display: block; margin-top: .6rem; }

/* Da cosa impara */
.frase { font: 650 1.5rem/1.3 var(--display); margin: 0; }
.vuoto { display: inline-block; min-width: 4.5em; padding: 0 .3em; border-bottom: 3px solid var(--pre); text-align: center; }
.barre { display: grid; grid-template-columns: max-content 1fr; gap: .45rem .7rem; align-items: center; margin: 1.25rem 0 0; max-width: 34rem; }
.barre .pista { display: flex; align-items: center; gap: .5rem; }
.barre .barra { flex: none; height: 14px; width: 0; background: var(--pre); border-radius: 0 4px 4px 0; transition: width .7s ease-out; }
.barre .valore { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.segnali { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.segnali h3 { font: 650 1.1rem var(--display); margin: 0; }
.segnali p { margin-top: .4rem; font-size: .98rem; }
.mini { margin-top: .7rem; padding: .6rem .7rem; border-left: 4px solid var(--post); background: var(--bg); border-radius: 0 8px 8px 0; font-size: .92rem; line-height: 1.45; }

/* Quanti dati */
.scala { display: flex; flex-wrap: wrap; gap: 1.5rem 2rem; align-items: center; }
.griglia {
  --q: 4px;
  position: relative; flex: none;
  width: calc(var(--q) * 100); height: calc(var(--q) * 100);
  background-color: color-mix(in srgb, var(--pre) 62%, var(--surface));
  background-image: linear-gradient(to right, var(--surface) 1px, transparent 1px), linear-gradient(to bottom, var(--surface) 1px, transparent 1px);
  background-size: var(--q) var(--q);
}
.griglia .uno { position: absolute; left: calc(var(--q) * 68); top: calc(var(--q) * 31); width: var(--q); height: var(--q); background: var(--post); }
.griglia .uno::after { content: ""; position: absolute; inset: -13px; border: 2.5px solid var(--post); border-radius: 50%; background: color-mix(in srgb, var(--surface) 55%, transparent); z-index: -1; }
.griglia .uno { z-index: 1; }
.legenda { list-style: none; margin: 0; padding: 0; flex: 1 1 14rem; }
.legenda li { margin-bottom: .6rem; }
.legenda b { display: block; font: 700 1.6rem/1.1 var(--display); }

/* Confronto */
.tabella { overflow-x: auto; margin-top: 1.5rem; }
table { border-collapse: collapse; width: 100%; min-width: 34rem; }
th, td { text-align: left; vertical-align: top; padding: .7rem .8rem; border-bottom: 1px solid var(--line); }
thead th { font: 650 1.1rem var(--display); border-bottom: 2px solid var(--ink); }
tbody th { font-weight: 400; color: var(--ink-2); white-space: nowrap; }
.sintesi { margin-top: 2rem; font-size: 1.2rem; }

/* Fine-tuning supervisionato */
.esempio { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0; font-size: 1.1rem; }
.gettone { padding: .2rem .55rem; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); }
.gettone.ruolo { border-style: dashed; color: var(--ink-2); }
.gettone.bersaglio { background: color-mix(in srgb, var(--post) 22%, var(--surface)); border-color: var(--post); }
.chiave { list-style: none; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; margin: 1.25rem 0 0; padding: 0; font-size: .95rem; }
.chiave .gettone { margin-right: .4rem; }
.ciclo { list-style: none; counter-reset: passo; display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.25rem; margin: 0; padding: 0; }
.ciclo li { counter-increment: passo; border-top: 4px solid var(--post); padding-top: .6rem; }
.ciclo li::before { content: counter(passo); display: block; font: 700 1.6rem/1.1 var(--display); }
.ciclo h3, .livelli h3 { font: 650 1.1rem var(--display); margin: .2rem 0 0; }
.ciclo p { margin-top: .3rem; font-size: .98rem; }
.curve { display: block; width: 100%; max-width: 30rem; height: auto; }
.curve text { font: 15px var(--body); fill: var(--ink); }
.curve .asse { stroke: var(--ink-2); stroke-width: 1; }
.curve .linea { fill: none; stroke-width: 2.5; stroke-linecap: round; }
.curve .addestramento { stroke: var(--post); }
.curve .nuovi { stroke: var(--ink); }
.curve .stop { stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 4 4; }
.curve circle { fill: var(--ink); stroke: var(--surface); stroke-width: 2; }
/* Andata (predizione) e ritorno (aggiornamento dei pesi), in un ciclo di 8 secondi */
.retro { display: block; width: 100%; max-width: 27rem; height: auto; }
.retro text { font: 15px var(--body); fill: var(--ink); }
.retro path { fill: none; stroke-width: 2.5; stroke-dasharray: 1; stroke-dashoffset: 1; }
.retro .avanti { stroke: var(--ink); animation: avanti 8s infinite; }
.retro .indietro { stroke: var(--post); animation: indietro 8s infinite; }
.retro .pesi rect { fill: var(--surface); animation: aggiorna 8s infinite; animation-delay: calc(var(--i) * .22s); }
.retro .t1 { animation: t1 8s infinite; }
.retro .t2 { animation: t2 8s infinite; }
.retro .t3 { animation: t3 8s infinite; }
@keyframes avanti { 20%, 92% { stroke-dashoffset: 0; opacity: 1; } 100% { stroke-dashoffset: 0; opacity: 0; } }
@keyframes indietro { 0%, 47% { stroke-dashoffset: 1; opacity: 0; } 48% { stroke-dashoffset: 1; opacity: 1; } 70%, 92% { stroke-dashoffset: 0; opacity: 1; } 100% { stroke-dashoffset: 0; opacity: 0; } }
@keyframes aggiorna { 0%, 55% { fill: var(--surface); } 58%, 82% { fill: var(--post); } 88%, 100% { fill: var(--surface); } }
@keyframes t1 { 0%, 20% { opacity: 0; } 26%, 92% { opacity: 1; } 100% { opacity: 0; } }
@keyframes t2 { 0%, 30% { opacity: 0; } 36%, 92% { opacity: 1; } 100% { opacity: 0; } }
@keyframes t3 { 0%, 40% { opacity: 0; } 46%, 92% { opacity: 1; } 100% { opacity: 0; } }
.livelli { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem 2rem; }
.livelli .barre { margin-top: .6rem; }
.livelli .barra { width: calc(var(--v) * 1%); background: var(--post); }
.livelli .prima { background: color-mix(in srgb, var(--ink-2) 45%, var(--surface)); }

/* Fine-tuning: pesi addestrati e pesi congelati */
.matrici { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem 2rem; }
.matrici h3 { font: 650 1.1rem var(--display); margin: 0; }
.m { flex: none; border-radius: 3px; background: var(--post); }
.m.fermo, .percorso .fermo, .retro .fermo { background: color-mix(in srgb, var(--ink-2) 35%, var(--surface)); fill: color-mix(in srgb, var(--ink-2) 35%, var(--surface)); }
.percorso { display: block; width: 100%; max-width: 28rem; height: auto; margin-top: .6rem; }
.percorso text { font: 18px var(--body); fill: var(--ink); }
.percorso .nuovo { fill: var(--post); }
.percorso .linea { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
/* Le linee si scoprono da sinistra a destra, poi compare la risposta */
.percorso .scopri { transform: scaleX(0); animation: scopri 5s linear infinite; }
.percorso .esito { opacity: 0; animation: compare 5s infinite; }
@keyframes scopri { 60%, 100% { transform: scaleX(1); } }
@keyframes compare { 0%, 60% { opacity: 0; } 68%, 100% { opacity: 1; } }
.conto { margin-top: .9rem; }
.conto b { display: block; font: 700 1.6rem/1.1 var(--display); }
.chiave .m { display: inline-block; width: .9em; height: .9em; margin-right: .4rem; vertical-align: -.1em; }

/* GRPO */
.due .neutro { --c: var(--ink); }
.gruppo { display: grid; grid-template-columns: max-content max-content max-content 1fr; gap: .5rem 1.25rem; align-items: center; margin-top: 1rem; font-variant-numeric: tabular-nums; }
.gruppo .intesta { font-size: .9rem; color: var(--ink-2); }
.gruppo .versi { display: flex; justify-content: space-between; }
.gruppo .scarto { position: relative; height: 18px; background: linear-gradient(var(--ink-2), var(--ink-2)) 50% 0 / 1.5px 100% no-repeat; }
.gruppo .scarto i { position: absolute; top: 2px; height: 14px; width: calc(var(--v) * 75%); }
.gruppo .su { left: 50%; background: var(--post); border-radius: 0 4px 4px 0; }
.gruppo .giu { right: 50%; background: color-mix(in srgb, var(--ink-2) 55%, var(--surface)); border-radius: 4px 0 0 4px; }

/* Quantizzazione: il peso scatta sulla tacca più vicina */
.tacche { display: block; width: 100%; max-width: 28rem; height: auto; }
.tacche line, .tacche path { fill: none; stroke: var(--ink-2); stroke-width: 1.5; }
.tacche text { font: 16px var(--body); fill: var(--ink); }
.tacche .origine { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.tacche .peso { fill: var(--post); animation: scatta 4s infinite; }
@keyframes scatta { 0%, 40% { transform: translateX(-11px); } 55%, 100% { transform: none; } }

/* Sezione precedente e successiva */
.passo { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3.5rem; }
.passo a, .passo span { padding: .9rem 1.1rem; border: 1px solid var(--line); border-radius: 14px; text-decoration: none; font-weight: 700; }
.passo a { background: var(--surface); box-shadow: var(--ombra); transition: transform .2s, border-color .2s; }
.passo a:hover { border-color: var(--viola); transform: translateY(-2px); }
.passo .prec small::before { content: "← "; }
.passo .succ small::after { content: " →"; }
.passo small { display: block; font-weight: 400; color: var(--ink-2); }
.passo .succ, .passo .fine { text-align: right; grid-column: 2; }
.passo .fine { color: var(--ink-2); font-weight: 400; border-style: dashed; }

@media (max-width: 900px) {
  .layout { display: block; }
  .indice { height: auto; max-height: 100vh; padding: .7rem 1rem; z-index: 5; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(12px); border-right: 0; border-bottom: 1px solid var(--line); }
  #apri-indice { display: block; padding: .4rem .9rem; }
  #indice-lista { display: none; margin-top: .8rem; }
  .indice.aperto #indice-lista { display: block; }
  .sezione, .blocco { scroll-margin-top: 4.5rem; }
  .sezione { padding-top: 2.5rem; }
}
@media (max-width: 700px) {
  figure { padding: 1rem; }
  .flusso { grid-template-columns: 1fr; }
  .fase { display: grid; grid-template-columns: 14px 1fr; column-gap: .9rem; align-items: center; text-align: left; padding: 0 0 0 1.5rem; }
  .binario { grid-row: 1 / span 2; width: 14px; height: 64px; margin: 0; }
  .binario::before { left: 6px; right: auto; top: 0; bottom: 6px; width: 2px; height: auto; }
  .binario::after { right: auto; left: 2px; top: auto; bottom: 0; border: 5px solid transparent; border-top: 8px solid var(--c); border-bottom: 0; }
  .binario i { left: 3px; top: -8px; animation-name: scendi; }
  .due, .prova, .segnali, .passo, .ciclo, .livelli, .matrici { grid-template-columns: 1fr; }
  .gruppo { grid-template-columns: max-content max-content 1fr; }
  .gruppo .versi, .gruppo .scarto { grid-column: 1 / -1; }
  .gruppo .scarto { margin: -.3rem 0 .6rem; }
  .passo .succ, .passo .fine { grid-column: 1; }
  .griglia { --q: 3px; }
  table { min-width: 0; font-size: .95rem; }
  th, td { padding: .6rem .4rem; }
  tbody th { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .binario i { animation: none; left: 45%; }
  .binario i:nth-child(n+2) { display: none; }
  .barre .barra { transition: none; }
  .sommario a, .passo a, button { transition: none; }
  .percorso .scopri { animation: none; transform: none; }
  .percorso .esito { animation: none; opacity: 1; }
  .retro .avanti, .retro .indietro { animation: none; stroke-dashoffset: 0; }
  .retro .t1, .retro .t2, .retro .t3 { animation: none; }
  .retro .pesi rect { animation: none; fill: var(--post); }
  .tacche .peso { animation: none; }
}
