/* =========================================================
   NumberCampus: foglio di stile
   Idea: il quaderno a quadretti. Blu penna per l'azione,
   rosso correzione solo per gli errori, giallo evidenziatore
   solo per le formule da ricordare.
   ========================================================= */

:root {
  --paper: #FBFCFE;
  --surface: #FFFFFF;
  --grid: #DCE4F0;
  --grid-strong: #C9D5E6;
  --ink: #2340B8;
  --ink-deep: #182E8A;
  --ink-tint: #EEF2FD;
  --red: #C8322B;
  --red-tint: #FCEFEE;
  --green: #1E7A4C;
  --green-tint: #E8F5EE;
  --text: #262A31;
  --muted: #5B6270;
  --line: #E1E6EE;
  --hl: #FFE36E;
  --hl-soft: rgba(255, 227, 110, .55);

  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Bricolage Grotesque", var(--font-body);

  --on-ink: #FFFFFF;       /* testo sopra il blu penna (pulsanti, avatar) */

  --sq: 20px;              /* lato del quadretto */
  --radius: 6px;
  --wrap: 1180px;
  --measure: 68ch;
  color-scheme: light;
}

/* Tema scuro: segue il sistema, salvo scelta esplicita con il pulsante
   (data-theme sull'elemento html, impostato da layout.php e app.js) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #13161C;
    --surface: #1A1E26;
    --grid: #232A37;
    --grid-strong: #2C3545;
    --ink: #8FA4FF;
    --ink-deep: #B7C4FF;
    --ink-tint: #1E2540;
    --red: #FF7B72;
    --red-tint: #33201F;
    --green: #5CCB8F;
    --green-tint: #17291F;
    --text: #E6E8EC;
    --muted: #A2A9B6;
    --line: #2A303B;
    --hl: #8A7420;
    --hl-soft: rgba(201, 170, 50, .35);
    --on-ink: #0E1220;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #13161C;
  --surface: #1A1E26;
  --grid: #232A37;
  --grid-strong: #2C3545;
  --ink: #8FA4FF;
  --ink-deep: #B7C4FF;
  --ink-tint: #1E2540;
  --red: #FF7B72;
  --red-tint: #33201F;
  --green: #5CCB8F;
  --green-tint: #17291F;
  --text: #E6E8EC;
  --muted: #A2A9B6;
  --line: #2A303B;
  --hl: #8A7420;
  --hl-soft: rgba(201, 170, 50, .35);
  --on-ink: #0E1220;
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 88px; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}
body.no-scroll { overflow: hidden; }

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

a { color: var(--ink); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { color: var(--ink-deep); text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 3px; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 .5em;
}
h1 { font-size: clamp(2rem, 1.4rem + 2.6vw, 3.1rem); }
h2 { font-size: clamp(1.4rem, 1.2rem + .8vw, 1.75rem); }
h3 { font-size: 1.2rem; }

p { margin: 0 0 1em; }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -9999px; top: 8px; background: var(--ink); color: var(--on-ink); padding: 8px 14px; z-index: 100; border-radius: var(--radius); }
.skip:focus { left: 12px; }

.lead { font-size: 1.2rem; color: var(--muted); max-width: 58ch; }

/* ---------- pulsanti ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  font: 700 1rem/1.2 var(--font-body);
  padding: .8em 1.25em;
  border-radius: var(--radius);
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--on-ink);
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--ink-deep); border-color: var(--ink-deep); color: var(--on-ink); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--ink-tint); color: var(--ink-deep); }
.btn-small { padding: .5em .9em; font-size: .95rem; }
.btn-block { width: 100%; }
.btn-done { background: var(--green-tint); border-color: var(--green); color: var(--green); }
.btn-done:hover { background: var(--green-tint); border-color: var(--green); color: var(--green); }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); border-color: var(--red); filter: brightness(.9); }

/* ---------- testata ---------- */

.site-header {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.page-lesson .site-header .wrap { max-width: 1400px; }
.header-row { display: flex; align-items: center; gap: 20px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font: 700 1.3rem/1 var(--font-display); letter-spacing: -0.02em; }
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.main-nav { display: flex; gap: 18px; white-space: nowrap; }
.main-nav a { color: var(--text); text-decoration: none; font-weight: 700; }
.main-nav a:hover, .main-nav a[aria-current] { color: var(--ink); }
.header-search { flex: 1; max-width: 420px; min-width: 140px; margin: 0 auto; }
.header-search input, .search-big input {
  width: 100%;
  font: inherit; font-size: .95rem;
  padding: .55em .9em;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.header-search input:focus, .search-big input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--ink-tint); }
.header-nav { display: flex; align-items: center; gap: 16px; white-space: nowrap; }
.header-nav > a:not(.btn) { color: var(--text); text-decoration: none; font-weight: 700; }
.header-nav > a:not(.btn):hover { color: var(--ink); }
.nav-user { display: flex; align-items: center; gap: 8px; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--ink); color: var(--on-ink); font-weight: 700; font-size: .9rem; }

/* pulsante chiaro/scuro: mostra la luna nel tema chiaro e il sole nel tema scuro */
.theme-toggle {
  display: grid; place-items: center;
  width: 36px; height: 36px; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--ink); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* pulsanti del telefono (lente e menu): compaiono solo sotto gli 860 px e con il JS attivo */
.header-icon {
  display: none; place-items: center; flex: none;
  width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.header-icon:hover, .header-icon[aria-expanded="true"] { color: var(--ink); border-color: var(--ink); }
.header-icon svg { width: 20px; height: 20px; }
.menu-toggle .icon-close, .menu-toggle[aria-expanded="true"] .icon-burger { display: none; }
.menu-toggle[aria-expanded="true"] .icon-close { display: block; }

.mobile-menu { border-top: 1px solid var(--line); padding: 8px 0 20px; }
.mobile-menu nav a {
  display: block; padding: 13px 0; border-bottom: 1px solid var(--line);
  color: var(--text); text-decoration: none; font: 700 1.1rem/1.2 var(--font-display);
}
.mobile-menu nav a[aria-current] { color: var(--ink); }
.menu-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.menu-pills { display: flex; gap: 6px; }
.menu-pills > * {
  font: inherit; font-size: .9rem; font-weight: 700; padding: 5px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none;
}
.menu-pills > [aria-pressed="true"], .menu-pills > [aria-current] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.menu-account { display: flex; gap: 10px; padding-top: 16px; }
.menu-account .btn { flex: 1; text-align: center; }
.menu-account .btn-ghost { border: 1px solid var(--ink); }
.menu-account .nav-user { color: var(--text); font-weight: 700; text-decoration: none; }

@media (max-width: 860px) {
  .header-row { flex-wrap: wrap; height: auto; min-height: 64px; padding-top: 10px; padding-bottom: 10px; gap: 10px 14px; }
  .header-search { order: 3; flex-basis: 100%; max-width: none; }
  .header-nav { margin-left: auto; }
  .nav-user-name { display: none; }
  .js .main-nav, .js .header-nav { display: none; }
  .js .header-icon { display: grid; }
  .js .search-open { margin-left: auto; }
  .js .header-search { display: none; }
  .js .site-header.is-search-open .header-search { display: block; }
}
@media (min-width: 861px) { .mobile-menu { display: none; } }

.flash { margin-top: 16px; padding: 12px 16px; border-radius: var(--radius); background: var(--green-tint); color: var(--green); font-weight: 700; }

/* ---------- home: eroe ---------- */

.hero { padding: clamp(40px, 7vw, 96px) 0 clamp(40px, 6vw, 80px); border-bottom: 1px solid var(--line); }
.hero-grid { display: grid; grid-template-columns: 1.05fr .95fr; gap: clamp(32px, 5vw, 72px); align-items: center; }
.hero h1 { font-size: clamp(2.4rem, 1.5rem + 3.6vw, 4rem); max-width: 13ch; margin-bottom: .35em; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 28px 0 14px; }
.hero-note { font-size: .95rem; color: var(--muted); }

.notebook {
  margin: 0;
  position: relative;
  background-color: var(--surface);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--sq) var(--sq);
  background-position: -1px -1px;
  border: 1px solid var(--grid-strong);
  border-radius: 4px;
  padding: calc(var(--sq) * 1.5) calc(var(--sq) * 1.5) calc(var(--sq) * 2) calc(var(--sq) * 3);
  box-shadow: 0 1px 0 var(--grid-strong), 0 18px 40px -24px rgba(35, 64, 184, .35);
  transform: rotate(-1.2deg);
}
/* margine rosso del quaderno */
.notebook::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: calc(var(--sq) * 2);
  border-left: 2px solid color-mix(in srgb, var(--red) 55%, transparent);
}
.notebook-head { font-weight: 700; color: var(--muted); margin-bottom: var(--sq); line-height: var(--sq); }
.notebook-steps { list-style: none; margin: 0; padding: 0; }
.notebook-steps li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px;
  min-height: calc(var(--sq) * 2);
  padding-top: 6px;
  color: var(--ink);
}
.nb-expr { font-size: clamp(1.25rem, 1rem + 1vw, 1.65rem); font-style: italic; letter-spacing: .01em; }
.nb-expr sup { font-size: .6em; }
.nb-note { font-size: .9rem; color: var(--muted); font-style: normal; }
.nb-check { color: var(--muted) !important; }
.nb-check .nb-expr { font-size: 1rem; }
.tick { width: 30px; height: 24px; color: var(--red); align-self: center; }

@media (prefers-reduced-motion: no-preference) {
  .notebook-steps li { opacity: 0; transform: translateY(4px); animation: write .5s ease-out forwards; }
  .notebook-steps li:nth-child(1) { animation-delay: .25s; }
  .notebook-steps li:nth-child(2) { animation-delay: 1.05s; }
  .notebook-steps li:nth-child(3) { animation-delay: 1.85s; }
  .notebook-steps li:nth-child(4) { animation-delay: 2.65s; }
  .tick path { stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw .45s ease-out 3.2s forwards; }
}
@keyframes write { to { opacity: 1; transform: none; } }
@keyframes draw { to { stroke-dashoffset: 0; } }

@media (max-width: 860px) {
  .hero-grid { grid-template-columns: 1fr; }
  .notebook { transform: none; }
}

/* ---------- home: corsi ---------- */

.section { padding: clamp(48px, 7vw, 88px) 0; }
.section-title { margin-bottom: .3em; }
.section-lead { color: var(--muted); max-width: 60ch; margin-bottom: 36px; }

/* ---------- percorsi della home ---------- */

.section-paths { border-bottom: 1px solid var(--line); }
.paths-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
@media (max-width: 1100px) { .paths-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .paths-grid { grid-template-columns: 1fr; } }
.path-card {
  display: flex; flex-direction: column;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) * 2);
}
.path-illustration { width: 104px; height: 104px; margin-bottom: 14px; }
.path-card h3 { margin-bottom: .15em; }
.path-who { font-size: .9rem; font-weight: 700; color: var(--ink); margin-bottom: .6em; }
.path-desc { font-size: .95rem; color: var(--muted); }
.path-courses {
  list-style: none; margin: 0 0 20px; padding: 0;
  display: flex; flex-wrap: wrap; gap: 6px;
  font-size: .85rem;
}
.path-courses a {
  display: inline-block; padding: 3px 9px;
  border: 1px solid var(--line); border-radius: 999px;
  color: var(--text); text-decoration: none;
}
.path-courses a:hover { border-color: var(--ink); color: var(--ink); }
.path-card .btn { margin-top: auto; text-align: center; }

.course-path { list-style: none; margin: 0; padding: 0; position: relative; max-width: 820px; }
.course-path::before { content: ""; position: absolute; left: 37px; top: 14px; bottom: 14px; border-left: 2px dotted var(--grid-strong); }
.course-path.has-trail::before { display: none; }
.course-trail { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.course-trail path { fill: none; stroke: var(--ink); stroke-opacity: .45; stroke-linecap: round; stroke-linejoin: round; }
.course-step { position: relative; display: grid; grid-template-columns: 76px 1fr; gap: 14px; padding: 0 0 46px; }
.course-step .course-dot { justify-self: center; }
@media (max-width: 560px) {
  .course-path::before { left: 21px; }
  .course-step { grid-template-columns: 44px 1fr; gap: 12px; }
}
.course-dot {
  width: 32px; height: 32px; margin-top: 0; border-radius: 50%;
  background: var(--paper); border: 2px solid var(--grid-strong); position: relative; z-index: 1;
  display: grid; place-items: center;
  font: 700 .95rem/1 var(--font-display); color: var(--on-ink);
}
.course-step.is-available .course-dot { border-color: var(--ink); background: var(--ink); box-shadow: 0 0 0 5px var(--ink-tint); }

/* numero del corso: piccolo badge tondo (percorsi, pagina del corso, indice laterale) */
.course-num {
  display: inline-grid; place-items: center;
  min-width: 1.6em; height: 1.6em; padding: 0 .3em; margin-right: .45em;
  border-radius: 999px;
  background: var(--ink); color: var(--on-ink);
  font: 700 .8em/1 var(--font-display);
  vertical-align: .1em;
}
.course-number { font-weight: 700; color: var(--ink); margin-bottom: .4em; }
.course-number .course-num { font-size: 1rem; margin-right: .3em; }
.course-step h3 { font-size: 1.35rem; margin-bottom: .2em; }
.course-step h3 a { color: var(--text); text-decoration: none; }
.course-step h3 a:hover { color: var(--ink); text-decoration: underline; }
.course-step p { margin-bottom: .35em; max-width: 62ch; }
.course-step.is-soon h3, .course-step.is-soon p { color: var(--muted); }
.course-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .9rem; color: var(--muted); }
.course-meta .soon { color: var(--muted); border: 1px dashed var(--grid-strong); padding: 0 8px; border-radius: 99px; }
.course-step.is-available .course-meta span:not(:first-child)::before { content: ""; }

.section-how { background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.how-grid { display: grid; grid-template-columns: .8fr 1.2fr; gap: 48px; }
.how-list { margin: 0; display: grid; gap: 28px; }
.how-list dt { font: 700 1.2rem/1.3 var(--font-display); margin-bottom: 4px; }
.how-list dd { margin: 0; color: var(--muted); max-width: 56ch; }
@media (max-width: 760px) { .how-grid { grid-template-columns: 1fr; gap: 8px; } }

/* ---------- barre di avanzamento ---------- */

.progress { display: grid; gap: 6px; margin: 10px 0 4px; max-width: 360px; }
.progress[hidden] { display: none; }
.progress-bar { height: 8px; border-radius: 99px; background: var(--grid); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--green); border-radius: 99px; transition: width .4s ease; }
.progress-label { font-size: .88rem; color: var(--muted); }

/* ---------- pagina corso ---------- */

.course-page { padding-top: 28px; padding-bottom: 80px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 8px; font-size: .92rem; color: var(--muted); margin-bottom: 20px; }
.crumbs a { color: var(--muted); }
.course-header { display: grid; grid-template-columns: 1fr 320px; gap: 48px; align-items: start; padding-bottom: 40px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.course-prereq { color: var(--muted); }
.course-side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.course-side .progress { max-width: none; margin-bottom: 18px; }
.course-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0 0 16px; }
.course-stats dt { font-size: .82rem; color: var(--muted); }
.course-stats dd { margin: 0; font: 700 1.5rem/1.2 var(--font-display); }
@media (max-width: 860px) { .course-header { grid-template-columns: 1fr; gap: 24px; } }

.unit { padding-top: 28px; }
.unit-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; font-size: 1.4rem; }
.unit-num { font: 400 .95rem/1 var(--font-body); color: var(--muted); }
.lesson-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.lesson-row {
  display: grid; grid-template-columns: 22px 2.2em 1fr auto; gap: 14px; align-items: center;
  padding: 14px 8px; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none;
}
.lesson-row:hover { background: var(--ink-tint); color: var(--text); text-decoration: none; }
.lesson-row:hover .lesson-row-title { color: var(--ink); }
.lesson-row-num { font: 700 1.05rem/1 var(--font-display); color: var(--muted); text-align: right; }
.lesson-row-text { display: grid; gap: 2px; min-width: 0; }
.lesson-row-title { font-weight: 700; }
.lesson-row-desc { font-size: .92rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.lesson-row-min { font-size: .88rem; color: var(--muted); }
@media (max-width: 560px) {
  .lesson-row { grid-template-columns: 22px 1fr; }
  .lesson-row-num, .lesson-row-min { display: none; }
  .lesson-row-desc { -webkit-line-clamp: 2; }
}

/* pallino di stato: vuoto, completato */
.status-dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--grid-strong); flex: none; position: relative; background: var(--surface); }
.is-done .status-dot { background: var(--green); border-color: var(--green); }
.is-done .status-dot::after {
  content: ""; position: absolute; left: 4.5px; top: 1.5px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}

/* ---------- pagina lezione ---------- */

.lesson-layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 220px;
  gap: 48px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

.course-map { position: sticky; top: 64px; align-self: start; height: calc(100vh - 64px); border-right: 1px solid var(--line); }
.course-map-inner { height: 100%; overflow-y: auto; padding: 24px 20px 40px 0; overscroll-behavior: contain; }
.course-map-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.course-map-title { font: 700 1.15rem/1.2 var(--font-display); color: var(--text); text-decoration: none; }
.map-close { display: none; }
.progress-compact { margin: 10px 0 8px; }
.map-unit { margin: 22px 0 6px; font-size: .85rem; font-weight: 700; color: var(--muted); }
.map-list { list-style: none; margin: 0; padding: 0; position: relative; }
.map-list::before { content: ""; position: absolute; left: 8px; top: 12px; bottom: 12px; border-left: 2px solid var(--grid); }
.map-list a {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 7px 8px 7px 0; font-size: .94rem; line-height: 1.35;
  color: var(--text); text-decoration: none; position: relative;
}
.map-list a .status-dot { margin-top: 1px; }
.map-list a:hover { color: var(--ink); }
.map-list a[aria-current="page"] { color: var(--ink); font-weight: 700; }
.map-list a[aria-current="page"]:not(.is-done) .status-dot { border-color: var(--ink); box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 9px var(--ink); }

.map-toggle { display: none; }
.map-backdrop { display: none; }

.lesson { padding: 28px 0 80px; min-width: 0; max-width: 760px; }
.lesson-header { margin-bottom: 32px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.lesson-kicker { font-size: .92rem; color: var(--muted); margin-bottom: 8px; }
.share-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px;
  font: 700 .9rem/1 var(--font-body);
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px;
  cursor: pointer;
}
.share-btn:hover { border-color: var(--ink); background: var(--ink-tint); }
.share-btn svg { width: 16px; height: 16px; }
.lesson-header h1 { font-size: clamp(1.9rem, 1.4rem + 2vw, 2.7rem); }

.lesson-toc { position: sticky; top: 88px; align-self: start; padding-top: 32px; font-size: .9rem; }
.toc-title { font-weight: 700; margin-bottom: 8px; }
.lesson-toc ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--grid); }
.lesson-toc a { display: block; padding: 5px 0 5px 14px; margin-left: -2px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; line-height: 1.35; }
.lesson-toc a:hover { color: var(--ink); }
.lesson-toc a.is-active { color: var(--ink); border-left-color: var(--ink); font-weight: 700; }

@media (max-width: 1240px) {
  .lesson-layout { grid-template-columns: 270px minmax(0, 1fr); gap: 40px; }
  .lesson-toc { display: none; }
}
@media (max-width: 900px) {
  .lesson-layout { display: block; }
  .lesson { margin: 0 auto; }
  .course-map {
    position: fixed; top: 0; left: 0; bottom: 0; height: 100%; width: min(88vw, 340px);
    background: var(--surface); z-index: 60; border-right: 1px solid var(--line);
    transform: translateX(-102%); transition: transform .25s ease; visibility: hidden;
  }
  .course-map.is-open { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  .course-map-inner { padding: 20px; }
  .map-close {
    display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
    border: 1px solid var(--line); background: var(--paper); color: var(--text); font-size: 1.5rem; cursor: pointer;
  }
  .map-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; background: rgba(10, 14, 25, .45); z-index: 55; }
  .map-toggle {
    display: flex; align-items: center; gap: 10px; width: 100%; margin-bottom: 22px;
    font: 700 .95rem/1.2 var(--font-body); color: var(--ink);
    background: var(--ink-tint); border: 1px solid transparent; border-radius: var(--radius); padding: 12px 14px; cursor: pointer; text-align: left;
  }
  .map-toggle::before { content: ""; width: 16px; height: 12px; border-top: 2px solid; border-bottom: 2px solid; background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat; }
}
@media (prefers-reduced-motion: reduce) { .course-map { transition: none; } }

/* ---------- testo delle lezioni ---------- */

.prose { max-width: var(--measure); }
.prose h2 { margin-top: 2.2em; padding-top: .2em; }
.prose h3 { margin-top: 1.8em; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 1.1em; }
.prose li { margin-bottom: .35em; }
.prose li::marker { color: var(--muted); }
.prose strong { font-weight: 700; }
.prose code { font-size: .9em; background: var(--ink-tint); padding: .1em .35em; border-radius: 3px; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.prose blockquote { margin: 1.2em 0; padding: .2em 0 .2em 1.1em; border-left: 3px solid var(--grid-strong); color: var(--muted); }

.math-display { overflow-x: auto; overflow-y: hidden; margin: 1em 0 1.2em; padding: 2px 0; -webkit-overflow-scrolling: touch; }
.math-display .katex-display { margin: 0; }
.katex { font-size: 1.12em; }

.table-wrap { overflow-x: auto; margin: 1.2em 0 1.5em; }
.prose table, .narrow-page table { border-collapse: collapse; min-width: 100%; font-size: .97rem; }
.prose th, .prose td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose th { font-weight: 700; border-bottom: 2px solid var(--grid-strong); background: var(--surface); }

/* ---------- riquadri ---------- */

.box { margin: 1.6em 0; padding: 18px 22px 8px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.box > :last-child { margin-bottom: 12px; }
.box-label { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; font-weight: 700; margin-bottom: 8px; color: var(--muted); font-size: .95rem; }
.box-title { font: 700 1.08rem/1.3 var(--font-display); color: var(--text); }

.box-definizione { border-left: 4px solid var(--ink); background: var(--ink-tint); border-color: transparent; border-left-color: var(--ink); }
.box-definizione .box-label { color: var(--ink); }

.box-regola { border: 2px solid var(--ink); }
.box-regola .box-label { color: var(--ink); }
.box-regola .math-display { background: linear-gradient(transparent 12%, var(--hl-soft) 12%, var(--hl-soft) 88%, transparent 88%); padding: 4px 8px; border-radius: 2px; }

/* gli esempi svolti stanno su carta a quadretti */
.box-esempio {
  background-color: var(--surface);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--sq) var(--sq);
  border-color: var(--grid-strong);
}
.box-esempio .box-label { color: var(--ink); }
.box-esempio p, .box-esempio li, .box-esempio .math-display { text-shadow: 0 0 6px var(--surface), 0 0 2px var(--surface); }

.box-attenzione { border-left: 4px solid var(--red); background: var(--red-tint); border-color: transparent; border-left-color: var(--red); }
.box-attenzione .box-label { color: var(--red); }

.box-nota { border-style: dashed; }

.box-esercizio { border: 1px solid var(--grid-strong); }
.box-esercizio .box-label { color: var(--text); }

.solution { margin: 10px 0 12px; border-top: 1px dashed var(--grid-strong); padding-top: 10px; }
.solution summary { cursor: pointer; font-weight: 700; color: var(--ink); list-style: none; display: inline-flex; align-items: center; gap: 8px; }
.solution summary::-webkit-details-marker { display: none; }
.solution summary::before { content: "+"; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 2px solid currentColor; font-size: .9rem; line-height: 1; }
.solution[open] summary::before { content: "−"; }
.solution summary { gap: 0; }
.solution summary::before { margin-right: 8px; }
.solution .sol-close, .solution[open] .sol-open { display: none; }
.solution[open] .sol-close { display: inline; }
.solution-body { padding-top: 10px; }

/* ---------- verifiche ---------- */

.quiz { margin: 2em 0; padding: 20px 22px; border-radius: var(--radius); border: 2px solid var(--text); background: var(--surface); }
.quiz .box-label { color: var(--text); }
.quiz-question p:last-child { margin-bottom: 14px; }
.quiz-options { display: grid; gap: 10px; }
.quiz-option {
  display: flex; align-items: center; gap: 12px; text-align: left;
  font: inherit; color: var(--text); background: var(--paper);
  border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 14px; cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.quiz-option:hover:not(:disabled) { border-color: var(--ink); background: var(--ink-tint); }
.quiz-option:disabled { cursor: default; }
.quiz-letter { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--grid-strong); font-weight: 700; font-size: .9rem; }
.quiz-option.is-right { border-color: var(--green); background: var(--green-tint); }
.quiz-option.is-right .quiz-letter { border-color: var(--green); background: var(--green); color: #fff; }
.quiz-option.is-wrong { border-color: var(--red); background: var(--red-tint); }
.quiz-option.is-wrong .quiz-letter { border-color: var(--red); color: var(--red); }
.quiz-option:disabled:not(.is-right):not(.is-wrong) { opacity: .6; }
.quiz-feedback { margin-top: 14px; }
.quiz-result { font-weight: 700; margin-bottom: 6px; }
.answered-right .quiz-result { color: var(--green); }
.answered-wrong .quiz-result { color: var(--red); }
.quiz-explain { color: var(--muted); }
.quiz-retry { font: 700 .95rem var(--font-body); color: var(--ink); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }

/* ---------- fine lezione ---------- */

.complete-box {
  display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: center; justify-content: space-between;
  margin: 48px 0 32px; padding: 22px 24px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.complete-box > div { flex: 1 1 280px; }
.complete-title { font: 700 1.2rem/1.3 var(--font-display); margin-bottom: 4px; }
.complete-hint { margin: 0; color: var(--muted); font-size: .95rem; }

.ad-slot { margin: 32px 0; min-height: 100px; }

.lesson-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.lesson-pager a { display: grid; gap: 4px; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); background: var(--surface); }
.lesson-pager a:hover { border-color: var(--ink); color: var(--text); }
.pager-next { text-align: right; }
.pager-label { font-size: .88rem; color: var(--muted); }
.pager-title { font-weight: 700; color: var(--ink); }
@media (max-width: 560px) { .lesson-pager { grid-template-columns: 1fr; } .pager-next { text-align: left; } }

/* ---------- moduli e pagine semplici ---------- */

.auth { max-width: 460px; padding-top: 48px; padding-bottom: 80px; }
.auth .lead { font-size: 1.05rem; }
.form { display: grid; gap: 16px; margin: 24px 0; }
.form label { display: grid; gap: 6px; font-weight: 700; }
.form .hint { font-weight: 400; color: var(--muted); font-size: .9rem; }
.form input[type="text"], .form input[type="email"], .form input[type="password"] {
  font: inherit; padding: .7em .85em; border: 1px solid var(--grid-strong); border-radius: var(--radius); background: var(--surface); color: var(--text);
}
.form input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--ink-tint); }
.form .check { display: flex; gap: 10px; align-items: center; font-weight: 400; }
.form .check input { width: 18px; height: 18px; accent-color: var(--ink); }
.form-errors { background: var(--red-tint); color: var(--red); border-radius: var(--radius); padding: 12px 16px; margin-top: 16px; }
.form-errors p { margin: 0; }
.form-errors p + p { margin-top: 4px; }
.auth-alt { color: var(--muted); }

.narrow-page { max-width: 760px; padding-top: 48px; padding-bottom: 80px; }
.narrow-page h2 { margin-top: 1.8em; }
.contact-mail { font: 700 1.4rem/1.3 var(--font-display); }
.updated { color: var(--muted); font-size: .9rem; margin-top: 2em; }

.profile { max-width: 760px; padding-top: 48px; padding-bottom: 80px; }
.profile-course, .profile-account { padding: 24px 0; border-top: 1px solid var(--line); }
.profile-course h2 a { color: var(--text); }
.inline-form { margin: 12px 0 20px; }
.danger-zone summary { cursor: pointer; color: var(--red); font-weight: 700; }
.danger-zone p { margin-top: 10px; color: var(--muted); }

.search-page { max-width: 760px; padding-top: 48px; padding-bottom: 80px; }
.search-big { display: flex; gap: 10px; margin: 20px 0 28px; }
.search-big input { font-size: 1.05rem; padding: .7em .9em; }
.search-count { color: var(--muted); }
.search-results { list-style: none; margin: 0; padding: 0; }
.search-results li { padding: 16px 0; border-bottom: 1px solid var(--line); }
.search-results a { font: 700 1.15rem/1.3 var(--font-display); }
.search-course { display: block; font-size: .88rem; color: var(--muted); margin: 2px 0 6px; }
.search-results p { margin: 0; }
.empty { color: var(--muted); }

/* ---------- piè di pagina ---------- */

.site-footer { border-top: 1px solid var(--line); padding: 40px 0 28px; background: var(--surface); font-size: .95rem; }
.footer-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 24px; }
.footer-id { display: flex; align-items: center; gap: 20px; }
.footer-logo { width: 120px; height: 120px; flex: none; }
@media (max-width: 560px) { .footer-logo { width: 72px; height: 72px; } .footer-id { gap: 14px; } }
.footer-brand { font: 700 1.15rem/1 var(--font-display); }
.footer-note { color: var(--muted); max-width: 52ch; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: flex-start; }
.site-footer nav a { color: var(--text); }
.footer-copy { color: var(--muted); font-size: .85rem; margin-top: 20px;
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
/* campus a sagome: poggia sul bordo inferiore della pagina; decorativo, nascosto sui telefoni */
.footer-campus { display: block; flex: none; width: 360px; height: auto; margin: -24px 0 -28px; color: var(--ink); opacity: .26; }
@media (max-width: 720px) { .footer-campus { display: none; } }

@media print {
  .site-header, .site-footer, .course-map, .lesson-toc, .complete-box, .lesson-pager, .ad-slot, .map-toggle { display: none !important; }
  .lesson-layout { display: block; }
  .solution { display: block; }
}
.nobr { white-space: nowrap; }

/* ---------- scelta della lingua ---------- */
.lang-switch { position: relative; }
.lang-switch summary {
  list-style: none; cursor: pointer; font-weight: 700; font-size: .9rem; color: var(--text);
  padding: 5px 9px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
.lang-switch summary::-webkit-details-marker { display: none; }
.lang-switch summary:hover { border-color: var(--ink); color: var(--ink); }
.lang-switch ul {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 150px;
  list-style: none; margin: 0; padding: 6px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px -12px rgba(20, 30, 60, .3);
}
.lang-switch li a { display: block; padding: 8px 10px; border-radius: 4px; color: var(--text); text-decoration: none; font-weight: 400; }
.lang-switch li a:hover { background: var(--ink-tint); color: var(--ink); }
.lang-switch li a[aria-current] { font-weight: 700; color: var(--ink); }
.profile-lang { margin-top: 32px; font-size: 1.1rem; color: var(--muted); }
.form .check span { font-weight: 400; }
.math-display.math-wrapped { text-align: center; line-height: 2.4; padding: 4px 0; }
.math-display.math-wrapped .katex { font-size: 1em; }
@media (max-width: 420px) {
  .header-nav { gap: 10px; }
  /* marchio e pulsante del tema un po' più piccoli: logo e comandi restano su una riga */
  .brand { font-size: 1.15rem; gap: 8px; }
  .theme-toggle { width: 31px; height: 31px; }
  .theme-toggle svg { width: 16px; height: 16px; }
}
@media (max-width: 359px) {
  .wrap, .lesson-layout { padding-left: 16px; padding-right: 16px; }
  .brand { font-size: 1.1rem; gap: 8px; }
  .brand-mark { width: 28px; height: 28px; }
  .header-nav { gap: 10px; }
}

/* ---------- strumenti ---------- */

.courses-index { padding-top: 28px; padding-bottom: 80px; }
.courses-index .tool-header { margin-bottom: 36px; }

.tools-index, .tool-page { padding-top: 28px; padding-bottom: 80px; }
.tool-header { margin-bottom: 24px; }
.tool-header h1 { margin-bottom: .25em; }
.tool-header .lead { margin: 0; }

.tools-grid { list-style: none; margin: 8px 0 40px; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 1100px) { .tools-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .tools-grid { grid-template-columns: 1fr; } }
.tool-card {
  display: flex; flex-direction: column; height: 100%;
  padding: 20px; border: 1px solid var(--line); border-radius: calc(var(--radius) * 2);
  background: var(--surface); color: var(--text); text-decoration: none;
  transition: border-color .15s, box-shadow .15s;
}
.tool-card:hover { border-color: var(--ink); color: var(--text); text-decoration: none; box-shadow: 0 10px 28px -18px rgba(35, 64, 184, .45); }
.tool-symbol {
  display: grid; place-items: center; min-width: 56px; height: 56px; padding: 0 10px; align-self: flex-start;
  margin-bottom: 14px; border-radius: var(--radius);
  background-color: var(--ink-tint);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 10px 10px;
  color: var(--ink); font: italic 700 1.35rem/1 var(--font-display); white-space: nowrap;
}
.tool-card-title { font: 700 1.12rem/1.3 var(--font-display); margin-bottom: 6px; }
.tool-card:hover .tool-card-title { color: var(--ink); }
.tool-card-desc { font-size: .93rem; color: var(--muted); }
.tools-note { color: var(--muted); }

/* pannello con i moduli */
.tool-panel {
  padding: 22px; margin-bottom: 40px;
  background: var(--surface); border: 1px solid var(--grid-strong); border-radius: calc(var(--radius) * 2);
}
.tool-form { margin: 0; }
.tf-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 14px; }
.tf-row + .tf-row { margin-top: 14px; }
.tf-field { display: grid; gap: 5px; flex: 1 1 160px; min-width: 0; }
.tf-field > span { font-size: .88rem; font-weight: 700; color: var(--muted); }
.tf-narrow { flex: 0 1 120px; }
.tf-wide { flex: 3 1 280px; }
.tf-mid { flex: 0 1 210px; }
.tool-input {
  width: 100%; font: inherit; font-size: 1.05rem;
  padding: .55em .7em; border: 1px solid var(--grid-strong); border-radius: var(--radius);
  background: var(--paper); color: var(--text);
}
select.tool-input { padding-right: .4em; height: calc(1.65em + 1.1em + 2px); }
.tool-input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--ink-tint); }
.tool-input.is-invalid { border-color: var(--red); }
.tf-word { align-self: flex-end; padding-bottom: .55em; font-weight: 700; color: var(--muted); white-space: nowrap; }
.tf-hint { margin: 12px 0 0; font-size: .9rem; color: var(--muted); }
.tf-preview { margin: 0 0 8px; min-height: 2.6em; overflow-x: auto; }
.tf-preview .katex-display { margin: 0; text-align: left; }
/* rapporto a/b (inglese): due caselle una sopra all'altra con la linea di frazione */
.tf-ratio { display: grid; gap: 6px; flex: 0 1 110px; }
.tf-ratio .tf-field + .tf-field { border-top: 2px solid var(--text); padding-top: 6px; }

/* risultato e passaggi */
.tool-result:not(:empty) { margin-top: 20px; }
.tool-answer { padding: 14px 18px 10px; border-radius: var(--radius); background: var(--ink-tint); border-left: 4px solid var(--ink); }
.tool-answer-label { margin: 0 0 4px; font-weight: 700; color: var(--ink); font-size: .92rem; }
.tool-answer-line > span { display: block; font-size: .95rem; color: var(--muted); }
.tool-answer-text { margin: 2px 0 8px; font-size: 1.2rem; font-weight: 700; }
.tool-answer-text .katex { font-size: 1.1em; }
.tool-answer-line + .tool-answer-line { margin-top: 4px; }
.tool-math { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.tool-math .katex-display { margin: .45em 0; }
.tool-answer .katex-display, .tool-answer .katex-display > .katex,
.tool-steps .katex-display, .tool-steps .katex-display > .katex,
.tf-preview .katex-display > .katex { text-align: left; }
.tool-answer-line > span + .tool-math .katex-display { margin-top: .15em; }
.tool-answer .katex { font-size: 1.25em; }
.tool-steps-title { margin: 24px 0 10px; font-size: 1.05rem; }
.tool-steps { margin: 0; padding-left: 1.4em; }
.tool-steps > li { margin-bottom: 14px; padding-left: 4px; }
.tool-steps > li::marker { color: var(--ink); font-weight: 700; }
.tool-steps p { margin: 0 0 4px; }
.tool-steps .katex-display { text-align: left; padding-left: 4px; }
.tool-steps .tool-note { color: var(--muted); }
.tool-steps .tool-note::marker { color: var(--muted); }
.tool-error { margin: 0; padding: 12px 16px; border-radius: var(--radius); background: var(--red-tint); color: var(--red); }

/* MCD: divisioni in colonna */
.ladders { display: flex; flex-wrap: wrap; gap: 14px 36px; margin: 10px 0 4px; }
.ladders figure { margin: 0; }
.ladder { border-collapse: collapse; font-variant-numeric: tabular-nums; margin-bottom: 6px; }
.ladder td { padding: 1px 12px; text-align: right; }
.ladder td:first-child { border-right: 2px solid var(--text); }
.ladder td:last-child { text-align: left; color: var(--ink); font-weight: 700; }
.ladders figcaption { font-size: .95rem; }

/* tabella di Ruffini */
.rf-scroll { overflow-x: auto; margin: 10px 0 6px; }
.ruffini { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ruffini td { padding: 6px 14px; text-align: center; min-width: 3em; }
.ruffini .rf-a { border-right: 2px solid var(--text); color: var(--ink); font-weight: 700; }
.ruffini .rf-mul td { border-bottom: 2px solid var(--text); color: var(--muted); }
.ruffini .rf-last { border-left: 2px solid var(--text); }
.ruffini .rf-res td { font-weight: 700; }
.ruffini .rf-rem { color: var(--red); }

/* percentuali */
.pct-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.pct-card { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); min-width: 0; }
.pct-card h2 { font-size: 1.1rem; margin-bottom: 12px; }
.pct-card-wide { grid-column: 1 / -1; }
.pct-card .tool-answer .katex { font-size: 1.15em; }
@media (max-width: 760px) { .pct-grid { grid-template-columns: 1fr; } }
.tf-sentence .tf-narrow { flex: 1 1 80px; max-width: 150px; }
.pct-card-wide .tf-sentence .tf-narrow { max-width: 110px; }
.tf-sentence .tf-dir { flex: 2 1 140px; max-width: none; }

/* convertitore */
.units-row .tf-field { flex: 1 1 180px; }
.units-row .tf-narrow { flex: 0 1 130px; }
.units-swap { align-self: flex-end; height: 2.7em; }

/* sistemi */
.tf-size { display: flex; flex-wrap: wrap; gap: 8px 24px; border: 0; padding: 0; margin: 0 0 16px; }
.tf-size label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.tf-size input { width: 18px; height: 18px; accent-color: var(--ink); }
.sys-grid { display: grid; gap: 10px; margin-bottom: 16px; border-left: 3px solid var(--ink); padding-left: 14px; }
.sys-row { display: flex; align-items: center; gap: 8px; }
.sys-row[hidden] { display: none; }
.sys-row .tool-input { width: 5em; flex: 0 1 5em; min-width: 3.2em; text-align: center; }
.sys-row > span { white-space: nowrap; font-size: 1.1rem; }
.sys-row var, .fn-label var { font-family: "KaTeX_Math", "Times New Roman", serif; font-size: 1.1em; }
.tool-form:not(.sys-3) .sys-z, .tool-form:not(.sys-3) .sys-plus { display: none; }
@media (max-width: 420px) {
  .sys-grid { padding-left: 10px; }
  .sys-row { gap: 5px; }
  .sys-row .tool-input { padding-left: .3em; padding-right: .3em; font-size: 1rem; }
  .sys-row > span { font-size: 1rem; }
}

/* grafico */
.graph-form { display: grid; gap: 10px; margin-bottom: 16px; }
.fn-row { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr); gap: 6px 12px; align-items: center; }
.fn-label { display: flex; align-items: center; gap: 8px; min-width: 5.4em; white-space: nowrap; font-size: 1.1rem; }
.fn-dot { width: 14px; height: 14px; border-radius: 50%; }
.fn-c1 { background: var(--ink); }
.fn-c2 { background: var(--red); }
.fn-c3 { background: var(--green); }
.fn-tex { overflow-x: auto; min-height: 1.5em; color: var(--muted); }
.fn-tex .tool-error { display: inline-block; padding: 4px 10px; font-size: .9rem; }
@media (max-width: 720px) {
  .fn-row { grid-template-columns: auto minmax(0, 1fr); }
  .fn-tex { grid-column: 2; }
  .fn-tex:empty { display: none; }
}
.graph-box { position: relative; }
.graph-canvas {
  display: block; width: 100%; height: min(62vh, 520px); min-height: 300px;
  border: 1px solid var(--grid-strong); border-radius: var(--radius);
  touch-action: none; cursor: grab;
}
.graph-canvas:active { cursor: grabbing; }
.graph-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.graph-btn {
  min-width: 38px; height: 38px; padding: 0 10px;
  font: 700 1.15rem/1 var(--font-body); color: var(--text);
  background: var(--surface); border: 1px solid var(--grid-strong); border-radius: var(--radius); cursor: pointer;
}
.graph-btn:hover { color: var(--ink); border-color: var(--ink); }
.graph-btn-text { font-size: .9rem; }
.graph-coords {
  position: absolute; left: 10px; bottom: 8px; margin: 0; padding: 2px 8px;
  font-size: .85rem; font-variant-numeric: tabular-nums; color: var(--muted);
  background: color-mix(in srgb, var(--surface) 85%, transparent); border-radius: 4px; pointer-events: none; white-space: pre;
}
.graph-coords:empty { display: none; }

/* sotto il pannello: spiegazione e collegamenti */
.tool-below { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 48px; align-items: start; }
@media (max-width: 900px) { .tool-below { grid-template-columns: 1fr; gap: 24px; } }
.tool-guide h2:first-child { margin-top: 0; }
.tool-guide h3 { font-size: 1.12rem; }
.tool-aside h2 { font-size: 1.1rem; margin-bottom: 10px; }
.tool-aside h2 + .tool-links { margin-bottom: 28px; }
.tool-links { list-style: none; margin: 0; padding: 0; }
.tool-links li { padding: 9px 0; border-bottom: 1px solid var(--line); }
.tool-links li:first-child { border-top: 1px solid var(--line); }
.tool-links a { font-weight: 700; }
.tool-links span { display: block; font-size: .85rem; color: var(--muted); }
.tool-links-plain a { font-weight: 400; }

@media (max-width: 560px) {
  .tool-panel { padding: 16px; }
  .pct-card { padding: 14px; }
  .tf-row > .tf-narrow { flex: 1 1 70px; }
  .tf-row > .btn { flex: 1 1 100%; }
  .tf-sentence > .btn { flex: 0 0 auto; }
}
@media print {
  .tool-aside, .graph-tools { display: none !important; }
}
