:root {
  --bg: #fbfaf7;
  --panel: #f2f0ea;
  --text: #1f2328;
  --muted: #5f646b;
  --line: #dedbd2;
  --accent: #2b5fd9;
  --accent-soft: #e4ebfb;
  --warn: #b83a08;
  --code-bg: #eeece5;
  --pt: #2b5fd9;
  --pt-alt: #c2410c;
  --band: rgba(43, 95, 217, 0.16);
  --axis: #8a8f96;
  --sidebar-w: clamp(272px, 17vw, 340px);
  --ease: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16181c;
  --panel: #1e2126;
  --text: #e6e6e3;
  --muted: #9ea3aa;
  --line: #2f333a;
  --accent: #7ba2ff;
  --accent-soft: #232b3f;
  --warn: #f08a5d;
  --code-bg: #23262c;
  --pt: #7ba2ff;
  --pt-alt: #f08a5d;
  --band: rgba(123, 162, 255, 0.2);
  --axis: #7a7f86;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c;
    --panel: #1e2126;
    --text: #e6e6e3;
    --muted: #9ea3aa;
    --line: #2f333a;
    --accent: #7ba2ff;
    --accent-soft: #232b3f;
    --warn: #f08a5d;
    --code-bg: #23262c;
    --pt: #7ba2ff;
    --pt-alt: #f08a5d;
    --band: rgba(123, 162, 255, 0.2);
    --axis: #7a7f86;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
html { scroll-behavior: smooth; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: clamp(17px, 0.55vw + 11px, 21px) / 1.7 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
input { caret-color: var(--accent); }

/* Barra superiore */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 52px;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); z-index: 20;
  font-size: 16px;
}
.brand { font-weight: 700; letter-spacing: .01em; color: inherit; text-decoration: none; }
.brand:hover { color: var(--accent); }
.titolo-nota { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: grid; place-items: center; background: none; border: 1px solid var(--line);
  color: var(--text); width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
#menu { display: none; }

.layout { display: flex; padding-top: 52px; min-height: 100vh; min-height: 100svh; }  /* svh: su iPhone 100vh è più alto dello schermo visibile e la home diventava scorrevole */

/* Indice laterale */
.sidebar {
  position: fixed; top: 52px; bottom: 0; left: 0; width: var(--sidebar-w);
  overflow-y: auto; padding: 14px 12px 28px; background: var(--panel);
  border-right: 1px solid var(--line); z-index: 10; font-size: 16px;
}
.sidebar input[type="search"] {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; margin-bottom: 14px;
}
.sidebar input[type="search"]:focus-visible { outline-offset: 0; }
.indietro {
  display: block; padding: 2px 8px 10px; font-size: .85rem; color: var(--muted); text-decoration: none;
}
.indietro:hover { color: var(--accent); }
.corso-link {
  display: block; padding: 6px 8px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 1.05rem; line-height: 1.3; color: var(--text); text-decoration: none;
}
.corso-link:hover, .corso-link.attiva { color: var(--accent); }
.capitolo { margin: 2px 0; }
.capitolo > summary {
  display: flex; align-items: baseline; gap: 10px;
  padding: 7px 8px; border-radius: 7px; cursor: pointer; list-style: none;
  font-weight: 600; line-height: 1.35;
}
.capitolo > summary::-webkit-details-marker { display: none; }
.capitolo > summary:hover { background: var(--accent-soft); }
.capitolo > summary .cap-tit { flex: 1; min-width: 0; }
.capitolo > summary::after {
  content: ""; width: 6px; height: 6px; flex: none; align-self: center;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s;
}
.capitolo[open] > summary::after { transform: rotate(45deg); }
.capitolo > .nota { margin-left: 26px; }
.capitolo.lezioni > .nota { margin-left: 8px; }
.num {
  display: inline-grid; place-items: center; flex: none; min-width: 1.45em; height: 1.45em; padding: 0 .3em;
  border-radius: 6px; background: var(--accent-soft); color: var(--accent);
  font-size: .78em; font-weight: 700; font-variant-numeric: tabular-nums;
}
.conta { font-size: .78rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.gruppo {
  margin: 10px 8px 3px 34px; font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.risultati-corso .gruppo, .risultati-home .gruppo { margin-left: 8px; }
.risultati-conta { margin: 0 8px 6px; font-size: .8rem; color: var(--muted); }
.nota.risultato .dove { color: var(--accent); }
.nota.risultato .sezione { color: var(--text); font-weight: 500; }
.nota.risultato mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 1px; }
.nota {
  display: block; padding: 6px 10px; margin: 1px 0; border-radius: 7px;
  color: var(--text); text-decoration: none; line-height: 1.35;
  transition: background .12s;
}
.nota:hover { background: var(--accent-soft); }
.nota.es { font-size: .95em; }
.nota.attiva { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nota small { display: block; margin-top: 2px; color: var(--muted); font-size: .8rem; font-weight: 400; line-height: 1.35; }
.vuoto, .risultati-vuoti { color: var(--muted); padding: 8px 10px; font-size: .9rem; }

/* Area di lettura: testo + indice della pagina */
.content {
  margin-left: var(--sidebar-w); width: calc(100% - var(--sidebar-w));
  padding: 36px clamp(16px, 3vw, 48px) 72px;
  display: grid; grid-template-columns: minmax(0, 75ch) 15.5rem;
  justify-content: center; column-gap: clamp(32px, 3.5vw, 64px); align-items: start;
}
.content.senza-toc { grid-template-columns: minmax(0, 75ch); }
.content > article { animation: entra .5s var(--ease) both; }
@keyframes entra {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

article h1 { font-size: clamp(2rem, 1.2rem + 1.8vw, 2.9rem); line-height: 1.15; margin: 0 0 .25em; text-wrap: balance; letter-spacing: -.015em; }
article h2 {
  font-size: 1.45rem; line-height: 1.3; margin: 2.1em 0 .5em; padding-bottom: .25em;
  border-bottom: 1px solid var(--line); text-wrap: balance; scroll-margin-top: 76px;
}
article h3 { font-size: 1.15rem; line-height: 1.35; margin: 1.7em 0 .4em; scroll-margin-top: 76px; }
article p, article ul, article ol { margin: .75em 0; text-wrap: pretty; }
article li { margin: .3em 0; }
article li::marker { color: var(--muted); }
article a { color: var(--accent); }
article a.wiki { text-decoration: none; border-bottom: 1px dashed var(--accent); }
article a.wiki.rotto { color: var(--warn); border-color: var(--warn); }
article code { background: var(--code-bg); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
article pre { background: var(--code-bg); padding: 12px 14px; border-radius: 8px; overflow-x: auto; }
article pre code { background: none; padding: 0; }
article blockquote {
  margin: 1.2em 0; padding: .5em 1.1em; background: var(--accent-soft);
  border: 1px solid var(--line); border-radius: 10px;
}
article hr { border: 0; border-top: 1px solid var(--line); margin: 2.2em 0; }
.meta { color: var(--muted); font-size: .9rem; margin: 0 0 1.2em; }
.briciole {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px;
  margin: 0 0 1em; font-size: .85rem; color: var(--muted); line-height: 1.4;
}
.briciole a { color: var(--muted); text-decoration: none; }
.briciole a:hover { color: var(--accent); }
.briciole span { opacity: .6; }

/* Collegamenti automatici in fondo alla nota */
.collegamenti {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 18px 28px;
  margin-top: 3.2em; padding-top: 1.4em; border-top: 1px solid var(--line);
}
article .collegamenti .coll-tit {
  margin: 0 0 .4em; padding: 0; border: 0; font-size: .75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.collegamenti ul { list-style: none; padding: 0; margin: 0; }
.collegamenti li { margin: .25em 0; line-height: 1.4; }
.collegamenti a { text-decoration: none; }
.collegamenti a:hover { text-decoration: underline; }

.tabella { overflow-x: auto; margin: 1.2em 0; border: 1px solid var(--line); border-radius: 10px; }
.tabella table { border-collapse: collapse; width: 100%; font-size: .95em; font-variant-numeric: tabular-nums; }
.tabella th, .tabella td { padding: 8px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.tabella tr:last-child td { border-bottom: 0; }
.tabella th { background: var(--panel); font-weight: 600; }

.katex { font-size: 1.12em; }
.katex-display { margin: 1.1em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

/* Codice */
:root {
  --hl-kw: #a1307a; --hl-str: #17692f; --hl-num: #a8470a; --hl-com: #5f6670;
  --hl-title: #2b5fd9; --hl-type: #0f766e; --hl-meta: #8a5a00;
}
:root[data-theme="dark"] {
  --hl-kw: #d68cf2; --hl-str: #8bd6a0; --hl-num: #f0a16b; --hl-com: #8d949e;
  --hl-title: #7ba2ff; --hl-type: #5fd3c8; --hl-meta: #e0b35c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --hl-kw: #d68cf2; --hl-str: #8bd6a0; --hl-num: #f0a16b; --hl-com: #8d949e;
    --hl-title: #7ba2ff; --hl-type: #5fd3c8; --hl-meta: #e0b35c;
  }
}
figure.codice {
  margin: 1.3em 0; border: 1px solid var(--line); border-radius: 10px;
  background: var(--code-bg); overflow: hidden;
}
.codice-head {
  display: flex; align-items: center; gap: 10px; padding: 5px 8px 5px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  font-size: .8rem; line-height: 1.3; min-height: 36px;
}
.codice-nome { flex: 1; font: 600 .92em ui-monospace, "Cascadia Code", Consolas, monospace; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.codice-nome a { color: inherit; text-decoration: none; border-bottom: 1px dashed var(--muted); }
.codice-nome a:hover { color: var(--accent); border-color: var(--accent); }
.codice-lang { margin-left: auto; text-transform: uppercase; letter-spacing: .07em; font-size: .72rem; font-weight: 600; color: var(--muted); }
.codice-lang + .copia { margin-left: 0; }
.copia {
  margin-left: auto;
  font: inherit; font-size: .78rem; font-weight: 600; cursor: pointer;
  padding: 3px 10px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); min-width: 4.8em;
  transition: background .15s, border-color .15s, color .15s;
}
.copia:hover { background: var(--accent-soft); border-color: var(--accent); }
.copia.ok { color: var(--hl-str); border-color: var(--hl-str); }
.copia.ko { color: var(--warn); border-color: var(--warn); }
figure.codice pre {
  margin: 0; padding: 12px 14px; background: none; border-radius: 0; overflow-x: auto;
  font: .88em/1.55 ui-monospace, "Cascadia Code", Consolas, monospace; tab-size: 4;
  font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; /* niente legature: <= resta <= */
}
figure.codice pre code { background: none; padding: 0; font: inherit; color: var(--text); }
.hljs-keyword, .hljs-literal, .hljs-selector-tag { color: var(--hl-kw); }
.hljs-string, .hljs-regexp, .hljs-char { color: var(--hl-str); }
.hljs-number { color: var(--hl-num); }
.hljs-comment, .hljs-quote { color: var(--hl-com); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--hl-title); }
.hljs-title.class_, .hljs-type, .hljs-built_in, .hljs-class .hljs-title { color: var(--hl-type); }
.hljs-meta, .hljs-doctag, .hljs-attr, .hljs-symbol { color: var(--hl-meta); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
.codice-errore {
  margin: 1.3em 0; padding: 10px 14px; border: 1px dashed var(--warn); border-radius: 10px;
  color: var(--warn); font-size: .92rem;
}
.nota .lang { margin-left: 8px; }

/* Indice della pagina */
.toc {
  position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow-y: auto;
  font-size: .84rem; line-height: 1.4; padding-top: 6px;
  animation: entra .5s var(--ease) .1s both;
}
.toc-titolo { font-weight: 700; margin: 0 0 6px 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.toc a {
  display: block; padding: 5px 10px; margin: 1px 0; border-radius: 7px;
  color: var(--muted); text-decoration: none; transition: background .12s, color .12s;
}
.toc a.sub { padding-left: 22px; font-size: .95em; }
.toc a:hover { color: var(--text); background: var(--accent-soft); }
.toc a.attiva { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.toc .katex { font-size: 1em; }

/* Precedente / successiva */
.pagine { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 3.2em; }
.pagine a {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  color: var(--text); text-decoration: none; line-height: 1.35;
  transition: border-color .15s, background .15s;
}
.pagine a:hover { border-color: var(--accent); background: var(--accent-soft); }
.pagine a.succ { text-align: right; grid-column: 2; }
.pagine span { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.pagine strong { font-weight: 600; color: var(--accent); }

/* Grafici */
figure.grafico {
  margin: 1.6em 0; padding: 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--panel);
}
figure.grafico svg { width: 100%; height: auto; display: block; }
figure.grafico figcaption { font-size: .88rem; color: var(--muted); margin-top: 10px; line-height: 1.45; }
.grafico .asse { stroke: var(--axis); stroke-width: 1.3; fill: none; }
.grafico .griglia { stroke: var(--line); stroke-width: 1; }
.grafico .tick { stroke: var(--axis); stroke-width: 1; }
.grafico text { fill: var(--text); font: 12px system-ui, sans-serif; font-variant-numeric: tabular-nums; }
.grafico text.tenue { fill: var(--muted); }
.grafico .punto { fill: var(--pt); transition: fill .12s; }
.grafico .punto:hover { fill: var(--pt-alt); }
.grafico .punto.dentro { fill: var(--pt-alt); }
.grafico .estremo-pieno { fill: var(--pt); stroke: var(--pt); stroke-width: 2; }
.grafico .estremo-vuoto { fill: var(--panel); stroke: var(--pt); stroke-width: 2.4; }
.grafico .curva { stroke: var(--pt); stroke-width: 2; fill: none; }
.grafico .linea { stroke: var(--pt-alt); stroke-width: 1.6; }
.grafico .linea.tratt { stroke-dasharray: 6 5; }
.grafico .linea-et { fill: var(--pt-alt); font-weight: 600; }
.grafico .seg { stroke: var(--pt); stroke-width: 5; stroke-linecap: butt; }
.grafico .marker-pieno { fill: var(--pt-alt); stroke: var(--pt-alt); stroke-width: 2; }
.grafico .marker-vuoto { fill: var(--panel); stroke: var(--pt-alt); stroke-width: 2.4; }
.grafico .fascia { fill: var(--band); }
.grafico-controlli { display: flex; align-items: center; gap: 12px; margin-top: 12px; font-size: .9rem; flex-wrap: wrap; }
.grafico-controlli label { font-weight: 700; font-size: 1.1rem; }
.grafico-controlli input[type="range"] { flex: 1 1 200px; min-width: 160px; accent-color: var(--accent); height: 28px; }
.grafico-controlli output { flex: 1 1 100%; font-variant-numeric: tabular-nums; color: var(--muted); line-height: 1.45; }
.grafico-errore { color: var(--warn); font-size: .9rem; padding: 8px 0; }
/* segnaposto visibile solo finché JavaScript non disegna il grafico (o se è disattivato) */
.grafico-attesa {
  margin: 1.6em 0; padding: 14px; border: 1px dashed var(--line); border-radius: 12px;
  background: var(--panel); color: var(--muted); font-size: .9rem;
}

/* Pagine senza barra laterale (home, 404) */
body.senza-sidebar .content { margin-left: 0; width: 100%; grid-template-columns: minmax(0, 46rem); padding-top: clamp(40px, 8vh, 96px); }
article .intro { color: var(--muted); font-size: 1.1rem; margin: .2em 0 1.4em; text-wrap: pretty; }

/* Home */
.home .hero h1 { font-size: clamp(2.3rem, 1.4rem + 2.6vw, 3.4rem); margin-bottom: .2em; }
.home .hero .intro { font-size: 1.15rem; max-width: 36rem; }
.cerca-home input {
  width: 100%; padding: 14px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-size: 1.05rem;
  transition: border-color .15s, background .15s;
}
.cerca-home input:focus { border-color: var(--accent); background: var(--bg); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.risultati-home { margin-top: 18px; }
.risultati-home .nota { padding: 10px 12px; }
article.home h2, .home article h2 {
  font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); border: 0; margin: 2.6em 0 .6em; padding: 0;
}
.lista-corsi { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.lista-corsi li { margin: 0; border-bottom: 1px solid var(--line); }
.corso {
  display: grid; grid-template-columns: 1fr auto; column-gap: 16px; align-items: baseline;
  padding: 14px 8px; color: var(--text); text-decoration: none; border-radius: 8px;
  transition: background .15s;
}
a.corso:hover { background: var(--accent-soft); }
a.corso:hover .corso-nome { color: var(--accent); }
.corso-nome { font-weight: 650; font-size: 1.08rem; line-height: 1.3; }
.corso-info { grid-column: 1; color: var(--muted); font-size: .88rem; line-height: 1.4; }
.corso-conti { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; text-align: right; }
.corso.in-arrivo .corso-nome { color: var(--muted); font-weight: 500; }
.come dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 18px 26px; margin: 0; }
.come dt { font-weight: 650; margin-bottom: .2em; }
.come dd { margin: 0; color: var(--muted); font-size: .92rem; line-height: 1.5; }
.piede { margin-top: 3.4em; padding-top: 1.2em; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; }

/* Pagina del corso */
.salti { display: flex; flex-wrap: wrap; gap: 8px; margin: 1.4em 0 .4em; }
.salti a {
  display: inline-flex; align-items: baseline; gap: 8px; padding: 6px 14px; border: 1px solid var(--line);
  border-radius: 999px; color: var(--text); text-decoration: none; font-size: .92rem; font-weight: 600;
  transition: border-color .15s, background .15s;
}
.salti a span { color: var(--muted); font-weight: 400; font-size: .85em; }
.salti a:hover { border-color: var(--accent); background: var(--accent-soft); }
.pagina-corso .cap { margin: 1.6em 0 2em; scroll-margin-top: 76px; }
.pagina-corso .cap h3 { display: flex; align-items: center; gap: 12px; margin: 0 0 .3em; font-size: 1.2rem; }
.cap-descr { color: var(--muted); font-size: .95rem; margin: 0 0 .7em; }
.voci { list-style: none; padding: 0; margin: 0; }
article .voci li { margin: 0; }
.voci a {
  display: block; padding: 7px 10px; margin: 0 -10px; border-radius: 8px;
  color: var(--text); text-decoration: none; line-height: 1.4; transition: background .12s;
}
.voci a:hover { background: var(--accent-soft); color: var(--accent); }
.cap-es { margin-top: .6em; padding-left: 14px; border-left: 2px solid var(--line); }
.cap-es .gruppo { margin: .3em 0 .2em; display: block; }
.voci.es a { font-size: .95em; }
.vuoto-grande { color: var(--muted); padding: 1.2em 0; }
.nota .lang {
  display: inline-block; padding: 0 6px; border: 1px solid var(--line);
  border-radius: 4px; font-size: .68rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); vertical-align: 1px;
}

@media (max-width: 1180px) {
  .toc { display: none; }
  .content, .content.senza-toc { grid-template-columns: minmax(0, 75ch); }
}
@media (max-width: 860px) {
  #menu { display: grid; }
  .titolo-nota { display: none; }  /* da telefono nella barra resta il nome del sito, che porta alla home */
  .sidebar { transform: translateX(-100%); transition: transform .25s var(--ease), box-shadow .25s; width: min(86vw, 330px); }
  body.menu-aperto .sidebar { transform: none; box-shadow: 6px 0 24px rgba(0,0,0,.22); }
  .content, .content.senza-toc, body.senza-sidebar .content { margin-left: 0; width: 100%; padding: 24px 16px 56px; }
  .corso { grid-template-columns: 1fr; }
  .corso-conti { grid-column: 1; grid-row: auto; text-align: left; margin-top: 2px; }
  .pagine { grid-template-columns: 1fr; }
  .pagine a.succ { grid-column: 1; }
  figure.grafico { padding: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .content > article, .toc { animation: none; }
  * { transition: none !important; }
}

/* Spiegazioni a comparsa su termini e simboli ([[Nota|testo|spiegazione]], {{termine|spiegazione}}) */
.glossa { position: relative; }
span.glossa { color: var(--accent); border-bottom: 1px dotted var(--accent); cursor: help; }
span.glossa:focus-visible { outline-offset: 3px; }
.spiega {
  position: absolute; left: 50%; bottom: 100%; z-index: 30;
  display: flex; flex-direction: column; align-items: stretch;
  width: max-content; max-width: min(22rem, 86vw); padding-bottom: 3px;
  transform: translate(calc(-50% + var(--dx, 0px)), 6px); opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .16s ease, transform .22s var(--ease), visibility 0s linear .22s;
  font-weight: 400; font-style: normal; letter-spacing: normal; text-transform: none; text-align: left;
}
.glossa:hover > .spiega, .glossa:focus-visible > .spiega, .glossa.aperta > .spiega {
  opacity: 1; visibility: visible; transform: translate(calc(-50% + var(--dx, 0px)), 0);
  transition: opacity .16s ease .12s, transform .22s var(--ease) .12s, visibility 0s linear 0s;
}
.spiega-testo {
  display: block; padding: 9px 13px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .12);
  color: var(--text); font-size: .86rem; line-height: 1.5; white-space: normal;
}
.spiega-testo .katex { font-size: 1.05em; }
.spiega-vai { display: block; margin-top: 5px; font-size: .74rem; font-weight: 600; color: var(--accent); }
.graffa { display: none; }
/* Stile "graffa" (Analisi 1): la spiegazione sta "dentro" una parentesi graffa orizzontale
   larga quanto il riquadro, con la punta rivolta verso il termine */
[data-glosse="graffa"] .graffa { display: flex; width: 100%; height: 13px; margin-top: 3px; color: var(--accent); transform: scaleY(-1); }
[data-glosse="graffa"] .spiega-testo { box-shadow: 0 6px 16px rgba(0, 0, 0, .12); }
.glossa:hover > .spiega, .glossa.aperta > .spiega { pointer-events: auto; }
span.glossa { border-bottom-style: dotted; border-bottom-width: 2px; }
.graffa i { display: block; height: 13px; flex: none; background: currentColor; }
.graffa .g-l, .graffa .g-r { width: 8px; }
.graffa .g-punta { width: 16px; }
.graffa .g-linea { flex: 1 1 0; min-width: 0; background: linear-gradient(currentColor, currentColor) center / 100% 1.6px no-repeat; }
.graffa .g-linea:nth-child(2) { flex: var(--g1, 1 1 0); }
.graffa .g-l { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 12'%3E%3Cpath d='M0.8 12C0.8 8 3 6 8 6' fill='none' stroke='black' stroke-width='1.6'/%3E%3C/svg%3E") center / 100% 100% no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 12'%3E%3Cpath d='M0.8 12C0.8 8 3 6 8 6' fill='none' stroke='black' stroke-width='1.6'/%3E%3C/svg%3E") center / 100% 100% no-repeat; }
.graffa .g-r { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 12'%3E%3Cpath d='M0 6C5 6 7.2 8 7.2 12' fill='none' stroke='black' stroke-width='1.6'/%3E%3C/svg%3E") center / 100% 100% no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 12'%3E%3Cpath d='M0 6C5 6 7.2 8 7.2 12' fill='none' stroke='black' stroke-width='1.6'/%3E%3C/svg%3E") center / 100% 100% no-repeat; }
.graffa .g-punta { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 12'%3E%3Cpath d='M0 6C5 6 8 4.6 8 0.8M16 6C11 6 8 4.6 8 0.8' fill='none' stroke='black' stroke-width='1.6'/%3E%3C/svg%3E") center / 100% 100% no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 12'%3E%3Cpath d='M0 6C5 6 8 4.6 8 0.8M16 6C11 6 8 4.6 8 0.8' fill='none' stroke='black' stroke-width='1.6'/%3E%3C/svg%3E") center / 100% 100% no-repeat; }
/* se in alto non c'è spazio la spiegazione si apre sotto (graffa capovolta) */
.glossa.sotto > .spiega { bottom: auto; top: 100%; flex-direction: column-reverse; padding: 3px 0 0; transform: translate(calc(-50% + var(--dx, 0px)), -6px); }
.glossa.sotto:hover > .spiega, .glossa.sotto.aperta > .spiega, .glossa.sotto:focus-visible > .spiega { transform: translate(calc(-50% + var(--dx, 0px)), 0); }
[data-glosse="graffa"] .glossa.sotto .graffa { transform: none; margin: 0 0 3px; }
@media (prefers-reduced-motion: reduce) { .spiega { transition: none !important; } }


/* ---------- Rifinitura (revisione di design) ---------- */
.salta {
  position: absolute; left: 12px; top: 10px; z-index: 50; padding: 8px 14px; border-radius: 8px;
  background: var(--accent); color: var(--bg); font-weight: 600; text-decoration: none;
  transform: translateY(calc(-100% - 20px)); transition: transform .15s; /* fuori schermo qualunque sia l'altezza (zoom, caratteri grandi) */
}
.salta:focus { transform: none; }
main:focus { outline: none; }
.h1-sub { display: block; margin-top: .35em; font-size: .46em; line-height: 1.35; font-weight: 500; letter-spacing: 0; color: var(--muted); text-wrap: balance; }
article h1 sup, .voci sup, .nota sup, .pagine sup, .collegamenti sup, .titolo-nota sup { font-size: .7em; line-height: 0; }

/* indice della pagina su schermi piccoli */
.toc-mobile { display: none; margin: .4em 0 1.6em; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.toc-mobile summary { padding: 11px 14px; cursor: pointer; font-weight: 600; font-size: .95rem; list-style: none; display: flex; justify-content: space-between; align-items: center; min-height: 44px; }
.toc-mobile summary::-webkit-details-marker { display: none; }
.toc-mobile summary span { color: var(--muted); font-weight: 500; font-size: .85em; font-variant-numeric: tabular-nums; }
.toc-mobile nav { padding: 0 6px 8px; display: grid; }
.toc-mobile a { padding: 9px 10px; border-radius: 7px; color: var(--text); text-decoration: none; line-height: 1.35; font-size: .95rem; }
.toc-mobile a:hover { background: var(--accent-soft); }
@media (max-width: 1180px) { .toc-mobile { display: block; } }

/* torna su */
.su {
  position: fixed; right: 18px; bottom: 18px; z-index: 25; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .12); transition: opacity .2s, transform .2s var(--ease);
}
.su:hover { border-color: var(--accent); color: var(--accent); }
.su[hidden] { display: grid; opacity: 0; transform: translateY(8px); pointer-events: none; }

/* home e corsi di laurea: più larghe, niente vuoti */
body.senza-sidebar .content { grid-template-columns: minmax(0, 68rem); }
.home .hero { max-width: 46rem; }
.home .hero h1 { font-size: clamp(2.6rem, 1.6rem + 3vw, 4.2rem); letter-spacing: -.025em; margin-bottom: .45em; }
.cerca-home { position: relative; }
.cerca-home input { padding-right: 52px; }
.tasto {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%); pointer-events: none;
  font: 600 .8rem ui-monospace, Consolas, monospace; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; background: var(--bg);
}
.cerca-home input:focus + .tasto, .cerca-home input:not(:placeholder-shown) + .tasto { display: none; }
.home article h2, .pagina-laurea article h2 {
  font-size: 1.3rem; font-weight: 650; text-transform: none; letter-spacing: -.005em;
  color: var(--text); border: 0; margin: 0 0 .5em; padding: 0;
}
.corsi { columns: 2 28rem; column-gap: 3.4em; margin-top: 2.8em; }
.corsi .area { break-inside: avoid; margin-bottom: 2.6em; }
.lista-lauree { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.lista-lauree .laurea { margin: 0; padding: 14px 4px 15px; border-bottom: 1px solid var(--line); display: grid; gap: 3px; }
.laurea-nome { font-weight: 650; font-size: 1.08rem; line-height: 1.3; color: var(--text); text-decoration: none; }
.laurea-nome:hover { color: var(--accent); }
.laurea.in-arrivo .laurea-nome { color: var(--muted); font-weight: 550; }
.materie-vive { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.materie-vive a {
  padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); text-decoration: none; font-size: .88rem; line-height: 1.4; transition: border-color .15s, color .15s;
}
.materie-vive a:hover { border-color: var(--accent); color: var(--accent); }
.pagina-laurea .anno { margin: 2.2em 0 0; }
.pagina-laurea .semestre { margin: 1.1em 0 0; }
.pagina-laurea .semestre h3 {
  margin: 0 0 .45em; font-size: .78rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.pagina-laurea .corso.in-arrivo { cursor: default; }
.pagina-laurea .corso.in-arrivo .corso-nome { overflow-wrap: anywhere; }
/* home: materie senza appunti, testo spento e non cliccabile */
.senza-appunti { padding: 4px 6px; color: var(--muted); font-size: .88rem; line-height: 1.4; overflow-wrap: anywhere; }
.senza-appunti small { font-size: .85em; white-space: nowrap; }
.piede { max-width: 46rem; }
.risultati-vuoti a { color: var(--accent); }

@media (max-width: 860px) {
  .sidebar { visibility: hidden; transition: transform .25s var(--ease), box-shadow .25s, visibility 0s linear .25s; }
  body.menu-aperto .sidebar { visibility: visible; transition: transform .25s var(--ease), box-shadow .25s, visibility 0s; }
  .icon-btn { width: 44px; height: 44px; }
  .briciole { font-size: .9rem; gap: 2px 6px; }
  .briciole a { padding: 6px 0; }
  .corsi .area { margin-bottom: 2em; }
}

/* ---------- Ripasso: versione abbreviata (interruttore nella barra in alto) ---------- */
.interruttore {
  margin-left: auto; display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px 0 10px;
  border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--text);
  font: inherit; font-size: .9rem; font-weight: 550; cursor: pointer; transition: border-color .15s, background .15s, color .15s;
}
.interruttore + .icon-btn { margin-left: 0; }
.interruttore:hover { border-color: var(--accent); }
.interruttore .pallino {
  width: 26px; height: 15px; border-radius: 999px; background: var(--line); position: relative; transition: background .18s;
}
.interruttore .pallino::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--bg); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .18s var(--ease);
}
.interruttore[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.interruttore[aria-pressed="true"] .pallino { background: var(--accent); }
.interruttore[aria-pressed="true"] .pallino::after { transform: translateX(11px); }
html:not([data-ripasso]) .vers-ripasso, html:not([data-ripasso]) .manca-ripasso { display: none !important; }
html[data-ripasso] .vers-completa { display: none !important; }
.etichetta-ripasso {
  display: inline-block; margin: 0 0 1.2em; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 650;
  letter-spacing: .03em; color: var(--accent); background: var(--accent-soft);
}
.manca-ripasso { margin: 0 0 1.4em; padding: 10px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: .92rem; }
@media (max-width: 860px) {
  .interruttore { height: 44px; padding: 0 12px; }
}
@media (max-width: 420px) {
  .interruttore { font-size: 0; gap: 0; padding: 0 9px; }
  .interruttore .pallino { font-size: 1rem; }
}

/* ---------- Strumenti per lo studio: studiato, prova da solo, esame, formulario ---------- */
.azioni-nota { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -.4em 0 1.6em; }
.studiato {
  display: inline-flex; align-items: center; min-height: 34px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: none; color: var(--muted); font: inherit; font-size: .88rem; font-weight: 550;
  transition: border-color .15s, color .15s, background .15s;
}
.studiato:hover { border-color: var(--accent); color: var(--accent); }
.studiato[aria-pressed="true"] { border-color: transparent; background: var(--ok-soft, rgba(46, 160, 67, .14)); color: var(--ok, #2e9e48); }
.badge-esame {
  display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 6px; vertical-align: 1px;
  font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; line-height: 1.6;
  color: var(--esame, #b25d00); background: var(--esame-soft, rgba(230, 126, 34, .14));
}
.azioni-nota .badge-esame { margin-left: 0; font-size: .74rem; padding: 2px 9px; }
a.nota.fatto::after, .voci a.fatto::after { content: " ✓"; color: var(--ok, #2e9e48); font-weight: 700; }
.progresso { margin-left: auto; padding-left: 8px; font-size: .74rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.progresso.completo { color: var(--ok, #2e9e48); }
section.cap h3 { display: flex; align-items: baseline; gap: 6px; }
.prova { display: flex; flex-wrap: wrap; gap: 8px; margin: 1.6em 0 .4em; }
.prova-btn {
  min-height: 38px; padding: 0 16px; border-radius: 10px; cursor: pointer; font: inherit; font-size: .92rem; font-weight: 600;
  border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent);
}
html[data-prova] .soluzione, html[data-prova] article:has(.soluzione) ~ .toc, html[data-prova] article:has(.soluzione) .toc-mobile { display: none !important; }
.soluzione > hr:first-child { margin-top: .8em; }
.link-formulario { margin: -.2em 0 1.4em; }
.link-formulario a { font-weight: 650; }
.link-formulario span { color: var(--muted); font-size: .9rem; margin-left: 4px; }
.formulario-link { display: block; margin: 4px 0 10px; padding: 7px 10px; border-radius: 8px; font-weight: 600; font-size: .92rem; color: var(--text); text-decoration: none; }
.formulario-link:hover, .formulario-link.attiva { background: var(--accent-soft); color: var(--accent); }
.pagina-formulario h3.form-nota { margin: 1.6em 0 .5em; font-size: 1rem; }
.pagina-formulario h3.form-nota a { color: var(--text); }
.pagina-formulario blockquote { margin: .5em 0 .9em; }

/* ---------- Stampa: solo il contenuto ---------- */
@media print {
  .topbar, .sidebar, .toc, .toc-mobile, .su, .salta, .pagine, .prova, .azioni-nota .studiato, .interruttore, .manca-ripasso, .etichetta-ripasso { display: none !important; }
  .layout, .content, main { display: block !important; margin: 0 !important; padding: 0 !important; max-width: none !important; }
  body { background: #fff !important; color: #000 !important; }
  .soluzione { display: block !important; }
  .spiega { display: none !important; }
  a { color: inherit !important; text-decoration: none !important; }
  .glossa { border-bottom: 0 !important; }
  h2, h3 { break-after: avoid; }
  blockquote, pre, .katex-display, table { break-inside: avoid; }
}
.riprendi { margin: .2em 0 1.2em; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); font-size: .95rem; }
.riprendi a { font-weight: 650; }
.riprendi span { color: var(--muted); font-size: .88em; margin-left: 4px; }
.totale-studiate { margin: -.4em 0 1.2em; color: var(--muted); font-size: .9rem; }
@media print { .riprendi, .totale-studiate { display: none !important; } }

/* home: materie di ogni corso di laurea divise per semestre */
.sem-riga { display: grid; grid-template-columns: 8.2rem 1fr; align-items: start; gap: 4px 10px; margin-top: 8px; }
.sem-riga .materie-vive { margin-top: 0; }
.sem-nome { padding-top: 5px; font-size: .78rem; font-weight: 600; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .sem-riga { grid-template-columns: 1fr; } .sem-nome { padding-top: 0; } }

/* home: titolo e ricerca sulla stessa riga, "riprendi" sotto con un po' di respiro */
.home .hero { max-width: none; display: flex; flex-wrap: wrap; align-items: center; gap: 14px 40px; }
.home .hero h1 { margin: 0; flex: 0 0 auto; }
.home .hero .cerca-home { flex: 1 1 20rem; max-width: 34rem; }
.home .hero .risultati-home { flex: 1 0 100%; margin-top: 4px; }
.home .riprendi { max-width: 46rem; margin: 2em 0 0; }
.home .corsi { margin-top: 2.4em; }
@media (max-width: 720px) { .home .hero { gap: 14px; } .home .hero .cerca-home { flex-basis: 100%; max-width: none; } }
.sem-nome { color: var(--text); font-size: .86rem; font-weight: 500; opacity: .85; }
.sem-nome strong { font-weight: 700; color: var(--accent); }
.sem-riga.nuovo-anno { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
/* etichette anno · semestre in home: più grandi e leggibili */
.sem-riga { grid-template-columns: 10rem 1fr; }
.sem-nome { font-size: .98rem; font-weight: 600; opacity: 1; color: var(--text); padding-top: 4px; }
.sem-nome strong { font-weight: 800; }
@media (max-width: 520px) { .sem-riga { grid-template-columns: 1fr; } .sem-nome { padding-top: 0; } }
.sem-nome .ripetuto { visibility: hidden; }
/* home: titoli delle aree (Ingegneria, Economia, ...) più grandi */
.home .area h2 { font-size: clamp(1.55rem, 1.2rem + 1vw, 1.95rem); font-weight: 750; letter-spacing: -.015em; margin-bottom: .45em; }
/* grafici: più curve, asintoti verticali, aree */
.grafico .curva.c2 { stroke: var(--pt-alt); }
.grafico .curva.c3 { stroke: #2e9e48; }
.grafico .curva.c4 { stroke: #b25d00; }
.grafico .curva.tratt { stroke-dasharray: 7 5; }
.grafico .vert { stroke: var(--pt-alt); stroke-width: 1.4; }
.grafico .vert.tratt { stroke-dasharray: 5 5; }
.grafico .area { fill: var(--pt); opacity: .18; stroke: none; }

/* grafici di geometria */
.grafico .geo-linea { fill: none; stroke: var(--pt); stroke-width: 2; }
.grafico .geo-linea.tratt, .grafico .geo-vett.tratt, .grafico .geo-bordo.tratt { stroke-dasharray: 6 5; }
.grafico .geo-area { fill: var(--pt); fill-opacity: .2; stroke: none; }
.grafico .geo-area.geo-bordo { stroke: var(--pt); stroke-width: 1.6; }
.grafico .geo-vett { stroke: var(--pt); stroke-width: 2.2; }
.grafico .geo-punta, .grafico .geo-punto { fill: var(--pt); }
.grafico .geo-et { fill: var(--pt); font-weight: 650; }
.grafico .c2.geo-linea, .grafico .c2.geo-vett, .grafico .c2.geo-bordo { stroke: var(--pt-alt); }
.grafico .c2.geo-area, .grafico .c2.geo-punta, .grafico .c2.geo-punto, .grafico .c2.geo-et { fill: var(--pt-alt); }
.grafico .c3.geo-linea, .grafico .c3.geo-vett, .grafico .c3.geo-bordo { stroke: #2e9e48; }
.grafico .c3.geo-area, .grafico .c3.geo-punta, .grafico .c3.geo-punto, .grafico .c3.geo-et { fill: #2e9e48; }
.grafico .c4.geo-linea, .grafico .c4.geo-vett, .grafico .c4.geo-bordo { stroke: #b25d00; }
.grafico .c4.geo-area, .grafico .c4.geo-punta, .grafico .c4.geo-punto, .grafico .c4.geo-et { fill: #b25d00; }

/* =====================================================================
   Stile Apple (revisione con le Human Interface Guidelines)
   Neutri freddi al posto del crema, blu di sistema per link e azioni,
   barra superiore traslucida (unico livello funzionale sopra il contenuto),
   campi di ricerca riempiti, "Ripasso" come pulsante-toggle e non come switch.
   Contrasti: testo 16.8:1 / 17.6:1, secondario 4.7:1 su #f5f5f7 e 6.6:1 su #1c1c1e,
   link #0066cc 5.6:1 su bianco, #2997ff 5.6:1 su #1c1c1e.
   ===================================================================== */
:root {
  --bg: #ffffff; --panel: #f5f5f7; --fill: #e8e8ed; --text: #1d1d1f; --muted: #6e6e73; --line: #d2d2d7;
  --accent: #0066cc; --accent-strong: #0071e3; --accent-soft: #e8f1fc; --warn: #c93400; --code-bg: #f5f5f7;
  --pt: #0071e3; --pt-alt: #e8590c; --band: rgba(0, 113, 227, 0.14); --axis: #86868b;
  --ok: #248a3d; --ok-soft: rgba(52, 199, 89, .14);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", system-ui, Roboto, "Helvetica Neue", sans-serif;
}
:root[data-theme="dark"] {
  --bg: #101012; --panel: #1c1c1e; --fill: #2c2c2e; --text: #f5f5f7; --muted: #a1a1a6; --line: #38383a;
  --accent: #2997ff; --accent-strong: #0a84ff; --accent-soft: #10273f; --warn: #ff9f0a; --code-bg: #1c1c1e;
  --pt: #2997ff; --pt-alt: #ff9f0a; --band: rgba(41, 151, 255, 0.2); --axis: #8e8e93;
  --ok: #30d158; --ok-soft: rgba(48, 209, 88, .16);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101012; --panel: #1c1c1e; --fill: #2c2c2e; --text: #f5f5f7; --muted: #a1a1a6; --line: #38383a;
    --accent: #2997ff; --accent-strong: #0a84ff; --accent-soft: #10273f; --warn: #ff9f0a; --code-bg: #1c1c1e;
    --pt: #2997ff; --pt-alt: #ff9f0a; --band: rgba(41, 151, 255, 0.2); --axis: #8e8e93;
    --ok: #30d158; --ok-soft: rgba(48, 209, 88, .16);
  }
}
body { font-family: var(--font); letter-spacing: -.003em; }
h1, h2, h3, .brand, .laurea-nome, .home .area h2 { font-family: var(--font-display); }
article h1 { letter-spacing: -.025em; font-weight: 700; }
article h2 { letter-spacing: -.015em; }
.home .hero h1 { letter-spacing: -.035em; }

/* barra superiore: materiale traslucido; opaca se l'utente riduce la trasparenza */
.topbar {
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .topbar { background: var(--bg); } }
@media (prefers-reduced-transparency: reduce) { .topbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; } }
.icon-btn { border-color: transparent; border-radius: 999px; }
.icon-btn:hover { background: var(--fill); border-color: transparent; color: var(--text); }

/* "Ripasso": pulsante che si comporta da toggle (HIG: niente switch fuori da una lista o in una barra) */
.interruttore { gap: 0; padding: 0 14px; border: 0; background: var(--fill); font-weight: 600; }
.interruttore .pallino { display: none; }
.interruttore:hover { background: color-mix(in srgb, var(--fill) 70%, var(--text) 8%); }
.interruttore[aria-pressed="true"] { background: var(--accent-strong); color: #fff; }
.interruttore[aria-pressed="true"]:hover { background: color-mix(in srgb, var(--accent-strong) 88%, #000); }
@media (max-width: 420px) { .interruttore { font-size: .85rem; padding: 0 11px; } }

/* campi di ricerca riempiti, con la lente */
.cerca-home input, .sidebar input[type="search"] {
  background: var(--fill) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.6-3.6'/%3E%3C/svg%3E") no-repeat 14px 50%;
  border: 1px solid transparent; padding-left: 40px;
}
.sidebar input[type="search"] { border-radius: 10px; background-position: 12px 50%; padding-left: 36px; }
.cerca-home input:focus, .sidebar input[type="search"]:focus { background-color: var(--bg); border-color: var(--accent-strong); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-strong) 22%, transparent); outline: none; }
.tasto { background: var(--bg); border-color: var(--line); }

/* indice laterale: voce attiva come pillola, numeri dei capitoli discreti */
.nota { border-radius: 8px; }
.nota:hover { background: var(--fill); }
.nota.attiva { background: var(--accent-strong); color: #fff; }
.nota.attiva .badge-esame { background: rgba(255, 255, 255, .22); color: #fff; }
.capitolo summary:hover { background: var(--fill); }

/* superfici: angoli coerenti (12 px riquadri, pillole per etichette e pulsanti) */
article blockquote { border-radius: 14px; border-color: transparent; background: var(--panel); }
.tabella, figure.grafico, .toc-mobile, .manca-ripasso, .riprendi { border-radius: 14px; }
figure.grafico { border-color: transparent; }
article pre, .codice { border-radius: 12px; }
.materie-vive a { border-color: transparent; background: var(--fill); font-weight: 500; }
.materie-vive a:hover { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.studiato { border-color: transparent; background: var(--fill); color: var(--text); }
.studiato:hover { border-color: transparent; color: var(--accent); }
.prova-btn { border-color: transparent; background: var(--accent-strong); color: #fff; border-radius: 999px; }
.su { border-color: transparent; background: color-mix(in srgb, var(--panel) 85%, transparent); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.riprendi { background: var(--panel); }

/* movimento: niente animazioni per chi chiede di ridurle */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* "Ripasso": interruttore a scorrimento in stile Apple (scelta dell'utente al posto del pulsante-toggle) */
.interruttore { gap: 9px; padding: 0 4px 0 12px; background: none; font-weight: 600; }
.interruttore:hover, .interruttore[aria-pressed="true"], .interruttore[aria-pressed="true"]:hover { background: none; color: var(--text); }
.interruttore .pallino {
  display: block; position: relative; width: 42px; height: 26px; border-radius: 999px; flex: 0 0 auto;
  background: var(--fill); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--line) 60%, transparent);
  transition: background .25s ease, box-shadow .25s ease;
}
.interruttore .pallino::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .25), 0 0 1px rgba(0, 0, 0, .2);
  transition: transform .3s cubic-bezier(.3, 1.4, .6, 1);
}
.interruttore[aria-pressed="true"] .pallino { background: var(--accent-strong); box-shadow: none; }
.interruttore[aria-pressed="true"] .pallino::after { transform: translateX(16px); }
.interruttore:active .pallino::after { width: 26px; }
.interruttore[aria-pressed="true"]:active .pallino::after { transform: translateX(12px); }
@media (max-width: 420px) { .interruttore { font-size: .85rem; gap: 7px; padding: 0 2px 0 6px; } }

.grafico text.asse-et { fill: var(--muted); font-size: 12px; font-style: italic; }

/* telefono: etichette anno · semestre centrate (e materie centrate sotto) */
@media (max-width: 520px) {
  .sem-riga { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 6px; }
  .sem-nome { padding-top: 0; }
  .sem-nome .ripetuto { display: none; }
  .sem-riga .materie-vive { justify-content: center; }
}

/* la lente nei campi di ricerca resta anche quando il campo è attivo (la regola :focus della home azzerava l'immagine) */
.cerca-home input:focus, .sidebar input[type="search"]:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.6-3.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 14px 50%;
}
.sidebar input[type="search"]:focus { background-position: 12px 50%; }

/* =====================================================================
   Telefono (360-430 px, vale fino a 860 px dove non è specificato)
   Solo regole in media query: il desktop non cambia.
   ===================================================================== */
@media (max-width: 860px) {
  /* i riquadri a comparsa nascosti (position: absolute) non devono allargare la pagina */
  .layout { overflow-x: clip; }
  body.menu-aperto { overflow: hidden; }

  /* barra in alto: niente trabocco, bersagli da 44 px, titolo con i puntini */
  .topbar { gap: 6px; padding: 0 8px; }
  body.senza-sidebar .topbar { padding-left: 16px; }
  .topbar .brand { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 44px; }
  .titolo-nota { padding-left: 4px; }
  .icon-btn { flex: none; }
  .interruttore { flex: none; }

  /* menu laterale: quasi tutto lo schermo, il resto è un velo che lo chiude al tocco */
  .sidebar { width: min(88vw, 360px); overscroll-behavior: contain; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  body.menu-aperto #contenuto::after { content: ""; position: fixed; inset: 52px 0 0 0; z-index: 9; background: rgba(0, 0, 0, .45); }
  .indietro { padding: 12px 8px; font-size: .9rem; }
  .nota { padding: 10px 10px; }
  .capitolo > summary { padding: 10px 8px; }
  .formulario-link { padding: 11px 10px; }
  .corso-link { padding-top: 10px; }

  /* lettura: spazi laterali di 16 px e un po' di fondo per il pulsante "torna su" */
  .content, .content.senza-toc, body.senza-sidebar .content { padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }
  body.senza-sidebar .content { padding-top: 28px; }
  .su { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  article h2 { scroll-margin-top: 68px; margin-top: 1.8em; }
  article h3 { scroll-margin-top: 68px; }
  article blockquote { padding: .4em 14px; margin-left: 0; margin-right: 0; }
  .azioni-nota { margin-top: .6em; }
  .studiato { min-height: 44px; padding: 0 18px; font-size: .92rem; }
  .prova-btn { min-height: 44px; }
  .prova { margin-top: 1.2em; }
  .toc-mobile a { display: flex; align-items: center; min-height: 44px; padding: 6px 10px; }

  /* briciole di pane: una riga che scorre di lato (si apre sull'ultima voce), bersagli da 44 px */
  .briciole { flex-wrap: nowrap; overflow-x: auto; gap: 0 8px; margin: 0 -16px .6em; padding: 0 16px; white-space: nowrap; scrollbar-width: none; font-size: .88rem; }
  .briciole::-webkit-scrollbar { display: none; }
  .briciole { -webkit-mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 16px), transparent); mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 16px), transparent); }
  .briciole > * { flex: none; }
  .briciole a { display: inline-flex; align-items: center; min-height: 44px; padding: 0; }

  /* elenchi di voci nella pagina della materia e nel formulario */
  .voci a { padding: 11px 10px; }
  .cap-es { padding-left: 10px; }
  .salti a { min-height: 44px; align-items: center; }
  .materie-vive a { padding: 9px 13px; }
  .corso { padding: 14px 4px; }
  .lista-lauree .laurea { padding-left: 0; padding-right: 0; }

  /* formule larghe, tabelle e codice scorrono nel loro riquadro */
  .katex-display { max-width: 100%; padding: 2px 0 8px; -webkit-overflow-scrolling: touch; }
  .tabella { max-width: 100%; -webkit-overflow-scrolling: touch; }
  .tabella th, .tabella td { padding: 8px 10px; }
  figure.codice pre { font-size: .8em; padding: 12px; }
  .copia { min-height: 32px; padding: 3px 12px; }

  /* grafici */
  figure.grafico { padding: 8px 8px 12px; margin-left: 0; margin-right: 0; }
  figure.grafico figcaption { padding: 0 4px; font-size: .9rem; }
  .grafico-controlli input[type="range"] { min-width: 0; height: 44px; }

  /* barra di ricerca: si scrive senza lo zoom di iOS (font da 16 px o più) */
  .sidebar input[type="search"] { font-size: 17px; padding-top: 11px; padding-bottom: 11px; }
  .cerca-home .tasto { display: none; }

  /* precedente / successiva */
  .pagine { margin-top: 2.4em; gap: 10px; }
}
@media (max-width: 600px) {
  /* grafici: la tela è di 460 unità (vedi grafici.js) mostrata a ~330 px: testo più grande per restare leggibile */
  .grafico text, .grafico text.asse-et { font-size: 15px; }
  .grafico text.geo-et { font-size: 13px; }
  .grafico .curva, .grafico .geo-linea { stroke-width: 2.4; }
  .grafico .linea { stroke-width: 2; }
}
@media (max-width: 420px) {
  .topbar .titolo-nota { font-size: .95rem; }
  .interruttore { padding: 0 2px 0 8px; }
}

/* formulario: esempio breve sotto il riquadro */
.pagina-formulario .form-esempio { margin: -.3em 0 1.1em; padding: 2px 0 2px 14px; border-left: 3px solid var(--accent-soft); color: var(--text); font-size: .95em; }
.pagina-formulario .form-esempio p { margin: .3em 0; }

/* Prestazioni: il browser impagina solo i blocchi vicini allo schermo. Rende istantaneo il passaggio
   Normale/Ripasso (prima 80-570 ms di blocco su una nota lunga, ora pochi ms) e alleggerisce i formulari. */
.vers-completa > *, .vers-ripasso > *, .pagina-formulario article > * { content-visibility: auto; contain-intrinsic-size: auto 3em; }
/* una spiegazione a comparsa aperta esce dal suo blocco: lì il contenimento va tolto, altrimenti verrebbe tagliata */
.vers-completa > :has(.glossa:hover, .glossa:focus-visible, .glossa.aperta),
.vers-ripasso > :has(.glossa:hover, .glossa:focus-visible, .glossa.aperta),
.pagina-formulario article > :has(.glossa:hover, .glossa:focus-visible, .glossa.aperta) { content-visibility: visible; }
@media print { .vers-completa > *, .vers-ripasso > *, .pagina-formulario article > * { content-visibility: visible; } }

/* Indice laterale richiudibile anche su computer (pulsante a sinistra nella barra; scelta salvata in "studio-menu") */
@media (min-width: 861px) {
  #menu { display: grid; }
  .sidebar { transition: transform .22s var(--ease), visibility 0s; }
  html[data-menu-chiuso] .sidebar { transform: translateX(-100%); visibility: hidden; transition: transform .22s var(--ease), visibility 0s linear .22s; }
  html[data-menu-chiuso] .content { margin-left: 0; width: 100%; }
}

/* home: frase sotto il titolo */
.home .hero .intro { flex: 1 0 100%; margin: -4px 0 0; font-size: 1.05rem; color: var(--muted); }

/* home: le aree sono <details>. Su desktop restano aperte e il titolo è un'intestazione fissa;
   da telefono sono tendine chiuse con l'elenco dei corsi di laurea (le materie stanno nella pagina del corso) */
.corsi .area summary { display: flex; align-items: baseline; gap: 6px 14px; flex-wrap: wrap; list-style: none; pointer-events: none; }
.corsi .area summary::-webkit-details-marker { display: none; }
.corsi .area summary .corso-info { display: none; }
@media (max-width: 720px) {
  .corsi .area { margin-bottom: 0; border-bottom: 1px solid var(--line); }
  .corsi .area summary { pointer-events: auto; cursor: pointer; position: relative; min-height: 44px; padding: 16px 36px 16px 2px; }
  .corsi .area summary h2 { margin: 0; }
  .corsi .area summary .corso-info { display: inline; }
  .corsi .area summary::after {
    content: ""; position: absolute; right: 8px; top: 50%; width: 9px; height: 9px; margin-top: -7px;
    border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .2s var(--ease);
  }
  .corsi .area[open] summary::after { transform: rotate(-135deg); margin-top: -2px; }
  .corsi .lista-lauree { margin-bottom: 10px; }
  .lista-lauree .sem-riga { display: none; }
  .lista-lauree .laurea { position: relative; padding-left: 14px; }
  .lista-lauree .laurea-nome::after { content: ""; position: absolute; inset: 0; }
}

/* numeri dei capitoli: cifre romane in un serif antico, color bronzo, senza riquadro */
:root { --antico: #8a5a1c; --antico-riga: #d9c3a0; }
:root[data-theme="dark"] { --antico: #d4ae72; --antico-riga: #5c4a2e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --antico: #d4ae72; --antico-riga: #5c4a2e; } }
.num {
  display: inline-block; min-width: 2.3em; height: auto; padding: 0 .35em 0 0; margin-right: .1em;
  border-radius: 0; background: none; border-right: 1px solid var(--antico-riga);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  font-size: 1.08em; font-weight: 600; font-variant-numeric: normal; letter-spacing: .06em;
  color: var(--antico); text-align: center; line-height: 1.2;
}
.capitolo summary .num { min-width: 2.6em; font-size: .9em; }
/* desktop: ricerca sulla stessa riga del titolo, la frase su Unipd sotto entrambi */
@media (min-width: 721px) {
  .home .hero .intro { order: 1; margin-top: -2px; }
  .home .hero .risultati-home { order: 2; }
}
