/* Source Serif 4 e il font principale del sito, ospitato qui invece di essere
   richiamato da fonts.googleapis.com: erano due origini terze da interrogare
   prima che il testo fosse leggibile, ~102 KB su ogni prima visita e l'IP di
   ogni visitatore mandato a Google. Licenza in font/SourceSerif4-LICENSE.md.
   E il font variabile: un solo file copre tutti i pesi da 200 a 900, dove con
   font statici ne servirebbero tre o quattro.
   Gli unicode-range sono quelli originali di Google, quindi il latino esteso
   viene scaricato solo se nella pagina compaiono quei caratteri. Dei sei
   sottoinsiemi distribuiti tengo latino e latino-esteso; per greco, cirillico
   e vietnamita interviene la catena di ripiego di --serif. */
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("font/SourceSerif4-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("font/SourceSerif4-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("font/SourceSerif4-latin-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("font/SourceSerif4-latin-ext-italic.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* OpenDyslexic e ospitato in font/ invece di arrivare da un CDN esterno: cosi
   evita un handshake verso un altro host sui dispositivi lenti, non dipende
   dalla raggiungibilita di terzi e non espone a nessuno chi attiva il font.
   Licenza e attribuzione in font/OpenDyslexic-LICENSE.md. I file restano a
   caricamento su richiesta: servono solo con [data-font="dyslexic"] attivo. */
@font-face {
  font-family: "OpenDyslexic";
  src: url("font/OpenDyslexic-Regular.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("font/OpenDyslexic-Bold.woff") format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("font/OpenDyslexic-Italic.woff") format("woff");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  --ink: #1f2328;
  --muted: #5b6470;
  --accent: var(--accent-light, #6b4f9e);
  --accent-hover: var(--accent-hover-light, #543f7e);
  --accent-soft: var(--accent-soft-light, #e7d7f5);
  --line: #d6d1de;
  --bg: #fbfaf9;
  --glass-bg: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(31, 35, 40, 0.14);
  --glass-highlight: rgba(255, 255, 255, 0.1);
  --glow-ambient: 1%;
  --glow-scale: 0.35;
  --tint-card: 40%;
  --tint-evidence: 85%;

  --serif: "Source Serif 4", Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --sans: var(--serif);
  /* --font-scale moltiplica solo le dimensioni tipografiche dei contenuti,
     non spaziature/pulsanti/icone: cosi lo slider "dimensione testo" ingrandisce
     il testo mantenendo i rapporti fra h1/h2/corpo senza deformare i controlli. */
  --font-scale: 1;
  --fs-2xs: calc(0.9375rem * var(--font-scale));
  --fs-xs: calc(0.8125rem * var(--font-scale));
  --fs-base: calc(1rem * var(--font-scale));
  --fs-h2: calc(0.9375rem * var(--font-scale));
  --fs-lg: calc(3rem * var(--font-scale));
  --fs-ref-title: calc(0.9375rem * var(--font-scale));
  --fs-ref-meta: calc(0.75rem * var(--font-scale));
  --fs-ref-summary: calc(0.875rem * var(--font-scale));

  --border-hair: 0.0625rem;
  --space-2xs: 0.25rem;
  --space-xs: 0.5rem;
  --space-sm: 0.625rem;
  --space-base: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.25rem;

  --radius: 0.5rem;
  --shadow: 0 0.0625rem 0.125rem rgba(31, 35, 40, 0.07), 0 0.25rem 0.75rem rgba(31, 35, 40, 0.1);

  --dur-fast: 0.15s;
  --dur: 0.2s;
  --dur-slow: 0.25s;
  --ease: ease;
}
:root[data-theme="dark"] {
  --ink: #e7e5e2;
  --muted: #9aa1ab;
  --accent: var(--accent-dark, #b79bf0);
  --accent-hover: var(--accent-hover-dark, #cbb6f5);
  --accent-soft: var(--accent-soft-dark, #2b2438);
  --line: #35323d;
  --bg: #16151a;
  --shadow: 0 0.0625rem 0.125rem rgba(0, 0, 0, 0.3), 0 0.25rem 0.875rem rgba(0, 0, 0, 0.35);
  --glass-bg: rgba(30, 29, 36, 0.45);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-highlight: rgba(255, 255, 255, 0.12);
  --glow-ambient: 5%;
  --glow-scale: 1;
  --tint-card: 32%;
  --tint-evidence: 68%;
}
:root[data-font="dyslexic"] {
  --serif: "OpenDyslexic", Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
}

* { box-sizing: border-box; }
html {
  font-size: 100%;
  background: var(--bg);
  scrollbar-width: none;
  -ms-overflow-style: none;
}
button { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 0; height: 0; }

body {
  margin: 0 auto;
  max-width: 48.75rem;
  padding: 3.5rem 1.75rem 6.25rem;
  font-family: var(--serif);
  color: var(--ink);
  line-height: 1.45;
  font-size: var(--fs-base);
  transition: background-color var(--dur-slow) var(--ease), color var(--dur-slow) var(--ease);
}

/* Il gap dello stack crea spazio fra le due barre solo quando la seconda e
   visibile: un elemento con [hidden] non e un flex item, quindi non riceve
   gap. Le due .toolbar restano senza margini propri: li eredita lo stack. */
.toolbar-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-top: calc(var(--space-lg) - 3.5rem);
  margin-bottom: var(--space-lg);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.toolbar-submenu {
  justify-content: flex-end;
  gap: var(--space-xs);
}
.toolbar-submenu[hidden] { display: none; }

.toolbar-items {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.theme-toggle {
  width: 2.625rem;
  height: 2.625rem;
  flex: none;
  border-radius: 50%;
  border: var(--border-hair) solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(0.75rem) saturate(160%);
  -webkit-backdrop-filter: blur(0.75rem) saturate(160%);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight),
    0 0 0.0625rem 0 color-mix(in srgb, var(--accent) var(--glow-ambient), transparent);
  transition: background-color var(--dur-slow) var(--ease), border-color var(--dur-slow) var(--ease),
    transform var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease);
}
@media (hover: hover) {
  .theme-toggle:hover {
    transform: scale(1.06);
    color: var(--accent-hover);
    background: color-mix(in srgb, var(--accent) 10%, var(--glass-bg));
    border-color: color-mix(in srgb, var(--accent) 22%, var(--glass-border));
    box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight),
      0 0 0.1875rem 0 color-mix(in srgb, var(--accent) calc(10% * var(--glow-scale)), transparent);
  }
}
.theme-toggle:active {
  transform: scale(0.94);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight),
    0 0 0.125rem 0 color-mix(in srgb, var(--accent) calc(14% * var(--glow-scale)), transparent);
}
.theme-toggle-icon {
  width: 1.125rem;
  height: 1.125rem;
  display: block;
}
.theme-toggle-icon svg {
  width: 100%;
  height: 100%;
}
#accent-toggle .theme-toggle-icon {
  color: var(--accent);
}
.pill-toggle {
  width: auto;
  padding: 0 var(--space-md);
  border-radius: 999px;
}
.pill-toggle-label {
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  display: block;
}

/* Stato attivo dei pill-toggle: aria-expanded="true" segnala che il submenu
   di quel trigger e aperto (font-toggle/sections-menu-toggle), aria-pressed
   che l'opzione e attiva (font per dislessia) -- stesso trattamento
   accent-tint gia usato per section-toggle/ref-toggle. */
.pill-toggle[aria-pressed="true"],
.pill-toggle[aria-expanded="true"] {
  color: var(--accent-hover);
  background: color-mix(in srgb, var(--accent) 14%, var(--glass-bg));
  border-color: color-mix(in srgb, var(--accent) 30%, var(--glass-border));
}

.scale-control {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  height: 2.625rem;
  flex: none;
  padding: 0 var(--space-md);
  border-radius: 999px;
  border: var(--border-hair) solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(0.75rem) saturate(160%);
  -webkit-backdrop-filter: blur(0.75rem) saturate(160%);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight),
    0 0 0.0625rem 0 color-mix(in srgb, var(--accent) var(--glow-ambient), transparent);
}
.scale-control-label {
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.scale-control input[type="range"] {
  width: 6rem;
  accent-color: var(--accent);
}
.scale-control-value {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--muted);
  min-width: 2.5rem;
  text-align: right;
}

header.doc-header {
  border: var(--border-hair) solid var(--glass-border);
  border-radius: var(--radius);
  background: var(--glass-bg);
  backdrop-filter: blur(0.75rem) saturate(160%);
  -webkit-backdrop-filter: blur(0.75rem) saturate(160%);
  box-shadow: inset 0 1px 0 var(--glass-highlight),
    0 0 0.0625rem 0 color-mix(in srgb, var(--accent) var(--glow-ambient), transparent);
  padding: var(--space-md) var(--space-sm);
  margin: 0 0 var(--space-base);
  transition: background-color var(--dur-slow) var(--ease), border-color var(--dur-slow) var(--ease),
    box-shadow var(--dur) var(--ease);
}
header.doc-header p.kicker {
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: var(--fs-2xs);
  color: var(--accent);
  font-weight: 500;
  margin: 0 0 var(--space-2xs);
}
header.doc-header p.doc-meta {
  font-family: var(--sans);
  font-size: calc(1.0625rem * var(--font-scale));
  color: var(--muted);
  margin: 0;
}
h1 {
  font-size: var(--fs-lg);
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-xs);
  font-weight: 400;
}
h2 {
  font-family: var(--sans);
  font-size: var(--fs-h2);
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-align: left;
  margin-top: 0;
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-sm);
  border-bottom: var(--border-hair) solid var(--line);
}
.sections-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-base);
}
.section-card {
  min-width: 0;
}
.section-card.expanded {
  background: color-mix(in srgb, var(--accent-soft) var(--tint-card), var(--glass-bg));
  backdrop-filter: blur(0.75rem) saturate(160%);
  -webkit-backdrop-filter: blur(0.75rem) saturate(160%);
  border: var(--border-hair) solid color-mix(in srgb, var(--accent) 8%, var(--glass-border));
  border-radius: var(--radius);
  padding: var(--space-sm);
  box-shadow: inset 0 1px 0 var(--glass-highlight),
    0 0.125rem 0.375rem 0 color-mix(in srgb, var(--accent) calc(2% * var(--glow-scale)), transparent);
  transition: background-color var(--dur-slow) var(--ease), border-color var(--dur-slow) var(--ease);
}
h2.collapsible {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-base);
  text-align: left;
  border: var(--border-hair) solid var(--glass-border);
  border-radius: var(--radius);
  background: var(--glass-bg);
  backdrop-filter: blur(0.75rem) saturate(160%);
  -webkit-backdrop-filter: blur(0.75rem) saturate(160%);
  box-shadow: inset 0 1px 0 var(--glass-highlight),
    0 0 0.0625rem 0 color-mix(in srgb, var(--accent) var(--glow-ambient), transparent);
  padding-top: var(--space-sm);
  padding-left: var(--space-sm);
  padding-right: var(--space-sm);
  margin-top: 0;
  margin-left: 0;
  margin-right: 0;
  margin-bottom: 0;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease);
}
h2.collapsible:not(.collapsed) {
  background: color-mix(in srgb, var(--accent-soft) var(--tint-evidence), var(--glass-bg));
  margin: 0 0 var(--space-xs);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight),
    0 0 0.0625rem 0 color-mix(in srgb, var(--accent) var(--glow-ambient), transparent);
}
.section-title,
.ref-heading-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1;
  transform: translateY(0.04em);
}

.section-toggle,
.ref-toggle {
  width: 1.75rem;
  height: 1.75rem;
  flex: none;
  border-radius: 50%;
  border: var(--border-hair) solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(0.75rem) saturate(160%);
  -webkit-backdrop-filter: blur(0.75rem) saturate(160%);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: inset 0 1px 0 var(--glass-highlight),
    0 0 0.0625rem 0 color-mix(in srgb, var(--accent) var(--glow-ambient), transparent);
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    transform var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease), color var(--dur) var(--ease);
}
@media (hover: hover) {
  .section-toggle:hover,
  .ref-toggle:hover {
    transform: scale(1.04);
    background: color-mix(in srgb, var(--accent) 6%, var(--glass-bg));
    border-color: color-mix(in srgb, var(--accent) 14%, var(--glass-border));
    box-shadow: inset 0 1px 0 var(--glass-highlight),
      0 0 0.125rem 0 color-mix(in srgb, var(--accent) calc(6% * var(--glow-scale)), transparent);
  }
}
.section-toggle:active,
.ref-toggle:active {
  transform: scale(0.92);
}
.section-toggle[aria-expanded="true"],
.ref-toggle[aria-expanded="true"] {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--glass-bg));
  border-color: color-mix(in srgb, var(--accent) 24%, var(--glass-border));
  box-shadow: inset 0 1px 0 var(--glass-highlight),
    0 0 0.1875rem 0 color-mix(in srgb, var(--accent) calc(10% * var(--glow-scale)), transparent);
}
.ref-toggle {
  position: absolute;
  top: var(--space-xs);
  right: var(--space-xs);
  width: 1.5rem;
  height: 1.5rem;
}
.section-toggle-icon,
.ref-toggle-icon {
  width: 0.4375rem;
  height: 0.4375rem;
  flex: none;
  border-right: 0.125rem solid currentColor;
  border-bottom: 0.125rem solid currentColor;
  border-radius: 0 0 0.0625rem 0;
  margin-bottom: 0.0625rem;
  transform: rotate(45deg);
  transition: transform var(--dur) var(--ease);
}
.section-toggle[aria-expanded="true"] .section-toggle-icon,
.ref-toggle[aria-expanded="true"] .ref-toggle-icon {
  transform: rotate(225deg);
}
.section-content.collapsed { display: none; }

h3,
.ref-heading,
.section-highlight,
ul:not(.reference-list) > li,
ul.reference-list > li {
  border: var(--border-hair) solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(0.75rem) saturate(160%);
  -webkit-backdrop-filter: blur(0.75rem) saturate(160%);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-highlight),
    0 0 0.0625rem 0 color-mix(in srgb, var(--accent) var(--glow-ambient), transparent);
  transition: background-color var(--dur-slow) var(--ease), border-color var(--dur-slow) var(--ease),
    box-shadow var(--dur) var(--ease);
}
h3,
.ref-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-base);
  font-family: var(--sans);
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent-soft) var(--tint-evidence), var(--glass-bg));
  padding: var(--space-xs) var(--space-sm);
  margin: var(--space-lg) 0 var(--space-sm);
}

.section-content > p {
  margin: var(--space-sm) 0;
}
.section-content > *:last-child {
  margin-bottom: 0;
}
.section-highlight {
  background: color-mix(in srgb, var(--accent-soft) var(--tint-evidence), var(--glass-bg));
  padding: var(--space-md);
  margin: var(--space-sm) 0 var(--space-lg);
}
.section-highlight p {
  margin: 0;
  line-height: 1.5;
  font-weight: 500;
}
ul {
  list-style: none;
  padding-left: 0;
  margin: var(--space-sm) 0;
}
ul:not(.reference-list) > li {
  background: var(--glass-bg);
  padding: var(--space-sm) var(--space-md);
  margin: var(--space-sm) 0;
}
em { color: var(--ink); }

/* Reference list styling: turn each <li> in a "Riferimenti" block into a card */
ul.reference-list > li {
  position: relative;
  list-style: none;
  background: var(--glass-bg);
  padding: var(--space-xs) 2.25rem var(--space-xs) var(--space-sm);
  margin: var(--space-sm) 0;
}
ul.reference-list { padding-left: 0; }
ul.reference-list.collapsed { display: none; }
ul.reference-list > li:last-child,
ul:not(.reference-list) > li:last-child {
  margin-bottom: 0;
}
ul.reference-list p { margin: 0 0 var(--space-xs); }
ul.reference-list > li > p:first-of-type {
  font-size: var(--fs-ref-title);
  margin-bottom: var(--space-2xs);
}
.ref-link {
  display: block;
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: break-all;
  font-family: var(--sans);
  font-size: var(--fs-ref-meta);
  font-weight: 400;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 0;
  transition: color var(--dur) var(--ease);
}
@media (hover: hover) {
  .ref-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
  }
}
.ref-details > p:first-of-type {
  font-family: var(--sans);
  font-size: var(--fs-ref-meta);
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-bottom: var(--space-sm);
}
.ref-details > p:last-of-type {
  font-size: var(--fs-ref-summary);
  line-height: 1.5;
  margin-bottom: 0;
}

.ref-details { margin-top: var(--space-base); }
.ref-details.collapsed { display: none; }

@media (max-width: 37.5rem) {
  body { padding: 3.5rem 1.125rem 4.375rem; font-size: calc(0.875rem * var(--font-scale)); }
  h1 { font-size: calc(2rem * var(--font-scale)); }
  header.doc-header p.doc-meta { font-size: calc(0.8125rem * var(--font-scale)); }
  /* I due gruppi (nav a sinistra, impostazioni a destra) diventano
     display:contents: cosi i sei pulsanti vanno a capo tutti insieme in un
     solo contesto flex, invece che ciascun gruppo per conto proprio con un
     proprio allineamento a destra -- che e quello che creava righe con un
     bordo destro diverso da riga a riga. */
  .toolbar { flex-wrap: wrap; row-gap: var(--space-xs); }
  #toolbar-items-left,
  #toolbar-items { display: contents; }
  .theme-toggle { width: 2.375rem; height: 2.375rem; }
  .theme-toggle-icon { width: 1rem; height: 1rem; }
  .pill-toggle { width: auto; height: 2.375rem; padding: 0 var(--space-sm); }
  .scale-control { height: 2.375rem; padding: 0 var(--space-sm); }
  .scale-control input[type="range"] { width: 4.5rem; }
}

@media (min-width: 48rem) {
  body { max-width: 60rem; }
  .sections-grid {
    display: block;
    column-count: 2;
    column-gap: var(--space-base);
  }
  .section-card {
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    margin-bottom: var(--space-base);
  }
}
