/* ============================================================
   Analisi Matematica 1 — Guida di studio interattiva
   Politecnico di Milano · Prof. Giulia Meglioli · a.a. 2026/27
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --bg:            #f7f8fa;
  --bg-elev:       #ffffff;
  --bg-sunken:     #eef0f4;
  --text:          #16181d;
  --text-muted:    #5c6370;
  --text-faint:    #8a919e;
  --border:        #dcdfe6;
  --border-strong: #c3c8d2;

  --accent:        #1f5fa8;
  --accent-hover:  #17497f;
  --accent-soft:   #e7f0fa;
  --accent-border: #a9c8e8;

  --ok:            #1c7a4e;
  --ok-soft:       #e3f4ec;
  --ok-border:     #a3d9bf;

  --warn:          #a8690a;
  --warn-soft:     #fdf1dd;
  --warn-border:   #e8c78a;

  --danger:        #b3261e;
  --danger-soft:   #fbe9e7;
  --danger-border: #edb0ab;

  --purple:        #6b3fa0;
  --purple-soft:   #f0eaf9;
  --purple-border: #c9b3e6;

  --radius:        10px;
  --radius-sm:     6px;
  --radius-lg:     16px;
  --shadow:        0 1px 2px rgba(16,24,40,.05), 0 4px 14px rgba(16,24,40,.06);
  --shadow-lg:     0 8px 32px rgba(16,24,40,.12);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;

  --maxw: 880px;
  --sidebar-w: 268px;
}

/* Dark mode: system preference, unless the user forced light */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #101216;
    --bg-elev:       #181b21;
    --bg-sunken:     #0b0d10;
    --text:          #e6e8ed;
    --text-muted:    #9aa2b1;
    --text-faint:    #6e7785;
    --border:        #2a2e37;
    --border-strong: #3b414d;

    --accent:        #67a8ec;
    --accent-hover:  #8cbef3;
    --accent-soft:   #16273c;
    --accent-border: #2d4d72;

    --ok:            #5cc99a;
    --ok-soft:       #12281f;
    --ok-border:     #2a5443;

    --warn:          #e0b062;
    --warn-soft:     #2a2114;
    --warn-border:   #574526;

    --danger:        #f08a82;
    --danger-soft:   #2d1715;
    --danger-border: #5c2e2a;

    --purple:        #b394e0;
    --purple-soft:   #211a30;
    --purple-border: #443561;

    --shadow:        0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
    --shadow-lg:     0 8px 32px rgba(0,0,0,.5);
  }
}

/* Manual dark override */
:root[data-theme="dark"] {
  --bg:            #101216;
  --bg-elev:       #181b21;
  --bg-sunken:     #0b0d10;
  --text:          #e6e8ed;
  --text-muted:    #9aa2b1;
  --text-faint:    #6e7785;
  --border:        #2a2e37;
  --border-strong: #3b414d;

  --accent:        #67a8ec;
  --accent-hover:  #8cbef3;
  --accent-soft:   #16273c;
  --accent-border: #2d4d72;

  --ok:            #5cc99a;
  --ok-soft:       #12281f;
  --ok-border:     #2a5443;

  --warn:          #e0b062;
  --warn-soft:     #2a2114;
  --warn-border:   #574526;

  --danger:        #f08a82;
  --danger-soft:   #2d1715;
  --danger-border: #5c2e2a;

  --purple:        #b394e0;
  --purple-soft:   #211a30;
  --purple-border: #443561;

  --shadow:        0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  --shadow-lg:     0 8px 32px rgba(0,0,0,.5);
}

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

/* --tb = altezza reale della barra in alto (la aggiorna app.js: sul telefono è su due righe) */
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--tb, 58px) + 18px); -webkit-text-size-adjust: 100%; }
/* La copia MathML nascosta di KaTeX è position:absolute: senza un antenato posizionato
   sfugge ai contenitori scorrevoli (tabelle) e allarga tutta la pagina sul telefono. */
.katex { position: relative; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16.5px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img, canvas, svg { max-width: 100%; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font: inherit; cursor: pointer; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 60;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto;
  padding: 0 16px;
  height: 58px;
  display: flex; align-items: center; gap: 14px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; letter-spacing: -.01em; color: var(--text);
  white-space: nowrap; font-size: 15px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: #fff; display: grid; place-items: center;
  font-size: 13px; font-weight: 800; font-family: var(--font-serif);
}
.topnav { display: flex; gap: 2px; margin-left: 8px; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  padding: 6px 11px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 14px; font-weight: 500; white-space: nowrap;
}
.topnav a:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar-spacer { flex: 1; }

.icon-btn {
  width: 34px; height: 34px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--bg-elev);
  border-radius: var(--radius-sm); color: var(--text-muted);
  transition: .15s;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); border-color: var(--border-strong); }

/* ---------- Layout ---------- */
.layout {
  max-width: 1280px; margin: 0 auto;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 36px; padding: 0 16px;
  align-items: start;
}
.layout.no-sidebar { grid-template-columns: minmax(0, 1fr); max-width: 980px; }

.sidebar {
  position: sticky; top: var(--tb, 58px);
  max-height: calc(100vh - var(--tb, 58px));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 24px 0 48px;
  font-size: 13.5px;
  scrollbar-width: thin;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.sidebar h4 {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint); margin: 20px 0 8px; font-weight: 700;
}
.sidebar h4:first-child { margin-top: 0; }
.sidebar a {
  display: block; padding: 5px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); line-height: 1.45; border-left: 2px solid transparent;
}
.sidebar a:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.sidebar a.active { color: var(--accent); background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }
.sidebar a.sub { padding-left: 22px; font-size: 12.8px; }

main { padding: 32px 0 120px; min-width: 0; }

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5 { line-height: 1.26; letter-spacing: -.017em; font-weight: 700; }
h1 { font-size: clamp(27px, 4.4vw, 38px); margin: 0 0 10px; }
h2 {
  font-size: clamp(21px, 3vw, 26px); margin: 52px 0 16px;
  padding-bottom: 9px; border-bottom: 2px solid var(--border);
}
h3 { font-size: 18.5px; margin: 34px 0 12px; }
h4 { font-size: 16px; margin: 24px 0 8px; }
p { margin: 0 0 15px; }
ul, ol { margin: 0 0 15px; padding-left: 24px; }
li { margin-bottom: 7px; }
li > ul, li > ol { margin-top: 7px; }
strong { font-weight: 650; }
hr { border: none; border-top: 1px solid var(--border); margin: 36px 0; }

.lead { font-size: 17.5px; color: var(--text-muted); margin-bottom: 26px; line-height: 1.62; }
.small { font-size: 13.5px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.center { text-align: center; }

code:not([class*="language"]) {
  font-family: var(--font-mono); font-size: .88em;
  background: var(--bg-sunken); padding: .12em .38em; border-radius: 4px;
  border: 1px solid var(--border);
}

/* Page header block */
.page-head { margin-bottom: 30px; }
.eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 8px;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 650; letter-spacing: .01em;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-sunken); color: var(--text-muted);
  vertical-align: middle; white-space: nowrap;
}
.badge.star   { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.badge.star2  { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.badge.ok     { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-border); }
.badge.warn   { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.badge.purple { background: var(--purple-soft); color: var(--purple); border-color: var(--purple-border); }

/* ---------- Boxes ---------- */
.box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 16px 20px; margin: 20px 0;
  box-shadow: var(--shadow);
}
.box > :first-child { margin-top: 0; }
.box > :last-child { margin-bottom: 0; }
.box-title {
  font-weight: 700; font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  margin-bottom: 9px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

.box.def   { border-left-color: var(--accent); }
.box.def   .box-title { color: var(--accent); }
.box.teo   { border-left-color: var(--danger); }
.box.teo   .box-title { color: var(--danger); }
.box.prop  { border-left-color: var(--purple); }
.box.prop  .box-title { color: var(--purple); }
.box.ex    { border-left-color: var(--ok); }
.box.ex    .box-title { color: var(--ok); }
.box.warnb { border-left-color: var(--warn); background: var(--warn-soft); }
.box.warnb .box-title { color: var(--warn); }
.box.tip   { border-left-color: var(--ok); background: var(--ok-soft); }
.box.tip   .box-title { color: var(--ok); }
.box.trap  { border-left-color: var(--danger); background: var(--danger-soft); }
.box.trap  .box-title { color: var(--danger); }

/* ---------- Reveal / spoiler ---------- */
.reveal { margin: 16px 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg-elev); }
.reveal > summary {
  list-style: none; cursor: pointer;
  padding: 11px 16px; font-weight: 600; font-size: 14.5px;
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-sunken); color: var(--text);
  transition: background .15s; user-select: none;
}
.reveal > summary::-webkit-details-marker { display: none; }
.reveal > summary:hover { background: color-mix(in srgb, var(--accent-soft) 60%, var(--bg-sunken)); }
.reveal > summary::before {
  content: "▸"; color: var(--accent); font-size: 13px;
  transition: transform .18s; display: inline-block; flex: 0 0 auto;
}
.reveal[open] > summary::before { transform: rotate(90deg); }
.reveal[open] > summary { border-bottom: 1px solid var(--border); }
.reveal-body { padding: 16px 20px; }
.reveal-body > :first-child { margin-top: 0; }
.reveal-body > :last-child { margin-bottom: 0; }

.reveal.sol > summary { background: var(--ok-soft); color: var(--ok); }
.reveal.sol > summary::before { color: var(--ok); }
.reveal.hint > summary { background: var(--warn-soft); color: var(--warn); }
.reveal.hint > summary::before { color: var(--warn); }
.reveal.proof > summary { background: var(--danger-soft); color: var(--danger); }
.reveal.proof > summary::before { color: var(--danger); }

/* Inline blur-to-reveal */
.blur {
  filter: blur(5px); cursor: pointer; transition: filter .25s;
  background: var(--bg-sunken); border-radius: 4px; user-select: none;
}
.blur.shown { filter: none; background: var(--ok-soft); user-select: auto; }

/* ---------- Proof step trainer ---------- */
.steps { counter-reset: st; margin: 18px 0; }
.step {
  display: flex; gap: 14px; padding: 13px 0;
  border-bottom: 1px dashed var(--border);
}
.step:last-child { border-bottom: none; }
.step-n {
  counter-increment: st; flex: 0 0 26px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
}
.step-n::before { content: counter(st); }
.step-body { flex: 1; min-width: 0; }
.step-cue { font-weight: 600; margin-bottom: 6px; }
.step-content {
  filter: blur(5px); cursor: pointer; transition: filter .22s;
  border-radius: var(--radius-sm); padding: 2px 0;
}
.step-content.shown { filter: none; cursor: auto; }
.step-content::after {
  content: ""; display: block;
}

/* ---------- Tables ---------- */
.tablewrap { overflow-x: auto; margin: 20px 0; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; background: var(--bg-elev); }
th, td { padding: 9px 13px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg-sunken); font-weight: 650; font-size: 13px; letter-spacing: .01em; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.c, th.c { text-align: center; }

/* ---------- Cards / grids ---------- */
.grid { display: grid; gap: 16px; }
.grid.g2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.g3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.g4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow); transition: .18s;
  display: block; color: inherit;
}
a.card:hover { border-color: var(--accent-border); box-shadow: var(--shadow-lg); transform: translateY(-2px); text-decoration: none; }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card h3 { margin: 0 0 6px; font-size: 16.5px; }
.card p { font-size: 14px; color: var(--text-muted); margin: 0; }

.stat { text-align: center; padding: 16px 12px; }
.stat-val { font-size: 27px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat-lab { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ---------- Controls ---------- */
.controls {
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center;
  padding: 13px 16px; background: var(--bg-sunken);
  border: 1px solid var(--border); border-radius: var(--radius); margin: 16px 0;
}
.ctrl { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; font-size: 13.5px; min-width: 0; max-width: 100%; }
/* un <select> si allarga quanto la sua voce più lunga: senza limiti sfonda la pagina sul telefono */
.ctrl select { min-width: 0; max-width: 100%; text-overflow: ellipsis; }
.ctrl label { color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.ctrl output { font-family: var(--font-mono); font-size: 13px; min-width: 46px; color: var(--accent); font-weight: 600; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 130px; height: 4px; border-radius: 2px;
  background: var(--border-strong); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--bg-elev);
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--bg-elev);
  background: var(--accent); cursor: pointer;
}

input[type="text"], input[type="number"], select, textarea {
  font: inherit; font-size: 14.5px;
  padding: 7px 11px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg-elev); color: var(--text);
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text);
  font-size: 14px; font-weight: 600; transition: .15s;
}
.btn:hover { background: var(--bg-sunken); border-color: var(--text-faint); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--bg-sunken); color: var(--text); }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btnrow { display: flex; flex-wrap: wrap; gap: 9px; margin: 16px 0; }

/* Chips / filters */
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 14px 0; }
.chip {
  padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text-muted);
  transition: .14s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Progress ---------- */
.pbar { height: 7px; background: var(--bg-sunken); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.pbar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--purple)); transition: width .4s ease; }
.pbar.ok > span { background: linear-gradient(90deg, var(--ok), #4bbd8c); }

/* Topic checkbox rows */
.checklist { list-style: none; padding: 0; margin: 14px 0; }
.checklist li {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 7px; background: var(--bg-elev); transition: .15s;
}
.checklist li:has(input:checked) { background: var(--ok-soft); border-color: var(--ok-border); }
.checklist input[type="checkbox"] { margin-top: 5px; width: 16px; height: 16px; accent-color: var(--ok); flex: 0 0 auto; cursor: pointer; }
.checklist label { cursor: pointer; flex: 1; }
.checklist li:has(input:checked) label { color: var(--text-muted); }

/* ---------- Plot widgets ---------- */
.widget {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-elev); margin: 22px 0; overflow: hidden;
  box-shadow: var(--shadow);
}
.widget-head {
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 13px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--text-muted);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.widget-body { padding: 14px 16px 16px; }
.widget .controls { margin: 0 0 12px; }
.plot { width: 100%; display: block; touch-action: pan-y; border-radius: var(--radius-sm); }
.readout {
  font-family: var(--font-mono); font-size: 13px; color: var(--text-muted);
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 13px; margin-top: 12px;
  line-height: 1.7; overflow-x: auto;
}
.readout b { color: var(--text); font-weight: 650; }

/* ---------- Matrici (Geometria) ---------- */
.matrice { border-collapse: collapse; width: auto; margin: 0 auto; background: none; font-variant-numeric: tabular-nums; }
.matrice td {
  border: none; padding: 5px 11px; text-align: center;
  font-family: var(--font-mono); font-size: 14.5px; white-space: nowrap;
  transition: background .2s;
}
.matrice td.lab { color: var(--text-faint); font-size: 11.5px; font-family: var(--font-sans); padding: 5px 8px; }
.matrice td.elle { color: var(--accent); font-weight: 600; }
.matrice td.bra, .matrice td.ket { padding: 0; width: 8px; border-top: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted); }
.matrice td.bra { border-left: 2px solid var(--text-muted); }
.matrice td.ket { border-right: 2px solid var(--text-muted); }
.matrice td.sep { border-left: 2px dashed var(--border-strong); }
.matrice td.pivot {
  background: var(--danger-soft); color: var(--danger); font-weight: 700;
  border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--danger);
}
.matrice td.zeropivot {
  background: var(--warn-soft); color: var(--warn); font-weight: 700;
  box-shadow: inset 0 0 0 2px var(--warn);
}
.matrice tr.attiva td:not(.lab) { background: var(--accent-soft); }
.matrice tr.attiva td.pivot { background: var(--danger-soft); }
.matrice-wrap { overflow-x: auto; padding: 6px 0; }

.meg-op {
  text-align: center; font-family: var(--font-mono); font-size: 14px;
  color: var(--accent); font-weight: 600; margin: 4px 0 2px;
}
.meg-spiega { text-align: center; font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }

/* ---------- Quiz ---------- */
.quiz { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); padding: 18px 20px; margin: 20px 0; box-shadow: var(--shadow); }
.quiz-q { font-weight: 600; margin-bottom: 14px; }
.quiz-opts { display: flex; flex-direction: column; gap: 8px; }
.quiz-opt {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); cursor: pointer; transition: .14s; text-align: left; width: 100%;
  font-weight: 450; line-height: 1.55; color: var(--text);
}
.quiz-opt:hover:not(.locked) { border-color: var(--accent); background: var(--accent-soft); }
.quiz-opt .k {
  flex: 0 0 22px; width: 22px; height: 22px; border-radius: 5px;
  background: var(--bg-sunken); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--text-muted);
}
.quiz-opt.right { background: var(--ok-soft); border-color: var(--ok); }
.quiz-opt.right .k { background: var(--ok); color: #fff; border-color: var(--ok); }
.quiz-opt.wrong { background: var(--danger-soft); border-color: var(--danger); }
.quiz-opt.wrong .k { background: var(--danger); color: #fff; border-color: var(--danger); }
.quiz-opt.locked { cursor: default; }
.quiz-fb {
  margin-top: 13px; padding: 11px 14px; border-radius: var(--radius-sm);
  font-size: 14px; border: 1px solid var(--border); background: var(--bg-sunken);
}
.quiz-fb.right { background: var(--ok-soft); border-color: var(--ok-border); }
.quiz-fb.wrong { background: var(--danger-soft); border-color: var(--danger-border); }
.quiz-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--text-faint); margin-bottom: 10px; gap: 10px; }

/* ---------- Flashcards ---------- */
.fc {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--bg-elev); box-shadow: var(--shadow); overflow: hidden; margin: 20px 0;
}
.fc-head { padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--bg-sunken); display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; flex-wrap: wrap; }
.fc-front { padding: 26px 24px; font-size: 17px; font-weight: 600; line-height: 1.55; min-height: 110px; display: flex; align-items: center; }
.fc-back { padding: 0 24px 22px; border-top: 1px dashed var(--border); }
.fc-back.hidden { display: none; }
.fc-actions { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--bg-sunken); display: flex; gap: 9px; flex-wrap: wrap; justify-content: center; }
.fc-empty { padding: 44px 24px; text-align: center; color: var(--text-muted); }

/* ---------- Timer ---------- */
.timer {
  font-family: var(--font-mono); font-size: 30px; font-weight: 700;
  letter-spacing: .03em; text-align: center; padding: 10px;
}
.timer.low { color: var(--danger); }

/* ---------- KaTeX tweaks ---------- */
.katex { font-size: 1.04em; }
.katex-display { margin: 1.05em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.katex-display > .katex { white-space: normal; }

/* ---------- Footer ---------- */
footer {
  border-top: 1px solid var(--border); margin-top: 60px;
  padding: 26px 16px 40px; text-align: center;
  font-size: 13px; color: var(--text-faint);
}

/* ---------- Utilities ---------- */
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.mt0 { margin-top: 0; }
.mb0 { margin-bottom: 0; }
.stack-sm > * + * { margin-top: 8px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(90px);
  background: var(--text); color: var(--bg); padding: 11px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 200; box-shadow: var(--shadow-lg);
  transition: transform .28s cubic-bezier(.2,.8,.3,1); pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- Mobile ---------- */
.menu-btn { display: none; }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .menu-btn { display: grid; }
  .sidebar {
    position: fixed; top: var(--tb, 58px); left: 0; bottom: 0; width: 280px; z-index: 55;
    background: var(--bg-elev); border-right: 1px solid var(--border);
    padding: 20px 14px 40px; max-height: none;
    transform: translateX(-102%); transition: transform .24s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim {
    position: fixed; inset: var(--tb, 58px) 0 0 0; background: rgba(0,0,0,.35);
    z-index: 54; opacity: 0; pointer-events: none; transition: opacity .24s;
  }
  .scrim.on { opacity: 1; pointer-events: auto; }
  /* Sul telefono la navigazione non si nasconde: diventa una seconda riga di pulsanti
     grandi, scorrevole col dito. */
  .topbar-inner { height: auto; min-height: 58px; flex-wrap: wrap; row-gap: 0; }
  .topbar-inner > .brand, .topbar-inner > .icon-btn { margin: 12px 0; }
  .topnav {
    order: 10; flex: 0 0 calc(100% + 32px); margin: 0 -16px; padding: 0 16px 10px;
    gap: 6px; scroll-padding: 0 16px; -webkit-overflow-scrolling: touch;
  }
  .topnav a {
    display: flex; align-items: center; min-height: 40px; padding: 8px 14px;
    font-size: 14.5px; border-radius: 999px;
    background: var(--bg-sunken); border: 1px solid var(--border); color: var(--text);
  }
  .topnav a.active { border-color: var(--accent); }
  main { padding: 24px 0 90px; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .box { padding: 14px 15px; }
  .reveal-body { padding: 14px 15px; }
  .card { padding: 15px 16px; }
  .widget-body { padding: 12px 12px 14px; }
  .katex-display { font-size: .92em; }
  .step { gap: 10px; }
}

@media print {
  .topbar, .sidebar, .scrim, .btnrow, .fc-actions, footer { display: none !important; }
  .reveal[open] > summary { background: none; }
  .reveal, .box, .card, .widget { box-shadow: none; break-inside: avoid; }
  .blur, .step-content { filter: none !important; }
  body { background: #fff; color: #000; }
}
