/* ==========================================================================
   Finanza personale, passo dopo passo — stile
   Mobile first (iPhone 13: 390×844, area sicura, barra in basso), poi tablet e desktop.
   ========================================================================== */
:root {
  --bg: #f6f3ec; --surface: #fffdf9; --surface2: #efeadf; --ink: #1c2233; --muted: #565d76; --line: #ddd5c4;
  --brand: #2a3a8f; --brand-ink: #ffffff; --brand-soft: #e4e8fb;
  --accent: #b0430a; --accent-soft: #fbe6d6;
  --ok: #13694a; --ok-soft: #dff2e8; --bad: #a3262a; --bad-soft: #fbe5e3; --warn: #7a4f00; --warn-soft: #fff2d1;
  --focus: #1a56db; --shadow: 0 1px 2px rgba(28,34,51,.06), 0 6px 18px rgba(28,34,51,.07);
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs: 1; --r: 14px; --tabh: 62px; --topbarh: 54px;
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px); --sb: env(safe-area-inset-bottom, 0px); --st: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] { color-scheme: dark; --bg: #11141d; --surface: #1a1f2d; --surface2: #222a3c; --ink: #edf0f7; --muted: #a9b1c9; --line: #323b54; --brand: #a9b8ff; --brand-ink: #11141d; --brand-soft: #262f59; --accent: #ffa768; --accent-soft: #3b2a1e; --ok: #74d6a8; --ok-soft: #163a2b; --bad: #ff9d96; --bad-soft: #3d1f22; --warn: #f2c35e; --warn-soft: #3a2f12; --focus: #8fb4ff; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; --bg: #11141d; --surface: #1a1f2d; --surface2: #222a3c; --ink: #edf0f7; --muted: #a9b1c9; --line: #323b54; --brand: #a9b8ff; --brand-ink: #11141d; --brand-soft: #262f59; --accent: #ffa768; --accent-soft: #3b2a1e; --ok: #74d6a8; --ok-soft: #163a2b; --bad: #ff9d96; --bad-soft: #3d1f22; --warn: #f2c35e; --warn-soft: #3a2f12; --focus: #8fb4ff; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3); }
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: calc(100% * var(--fs)); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--topbarh) + 12px); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 1.0625rem/1.65 var(--sans); -webkit-tap-highlight-color: transparent; overflow-wrap: break-word; }
img, svg { max-width: 100%; }
a { color: var(--brand); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
#pagetitle:focus, #pagetitle:focus-visible, main#view:focus { outline: none; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; letter-spacing: -.01em; margin: 0 0 .5em; text-wrap: balance; }
h1 { font-size: clamp(1.75rem, 6.4vw, 2.5rem); font-weight: 700; }
h2 { font-size: clamp(1.3rem, 4.4vw, 1.65rem); margin-top: 1.6em; }
h3 { font-size: 1.14rem; margin-top: 1.4em; }
p { margin: 0 0 1em; }
em { font-style: italic; }
h1 em { color: var(--accent); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--brand); color: var(--brand-ink); padding: 10px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { top: 8px; }
.hint { font-size: .9rem; color: var(--muted); margin: .3em 0 .8em; }
.eyebrow { font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 .5em; }
.eyebrow a { color: inherit; }
.lead { font-size: 1.12rem; color: var(--ink); }
.mono, code { font-family: var(--mono); font-size: .92em; }

/* ---------------- struttura ---------------- */
.app { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
.topbar { grid-area: top; position: sticky; top: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 92%, transparent); -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); padding: var(--st) calc(12px + var(--sr)) 0 calc(14px + var(--sl)); }
.topbar-in { display: flex; align-items: center; gap: 8px; min-height: var(--topbarh); }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 8px; margin-right: auto; line-height: 1.1; }
.brand .logo { width: 28px; height: 28px; flex: none; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: .85rem; }
.brand .bt small { display: block; font-family: var(--sans); font-weight: 500; font-size: .7rem; color: var(--muted); letter-spacing: .02em; }
.topnav { display: none; }
.iconbtn { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 0; background: transparent; border-radius: 12px; color: var(--ink); }
.iconbtn:hover { background: var(--surface2); }
.fsgroup { display: none; }
main#view { grid-area: main; min-width: 0; padding: 18px calc(16px + var(--sr)) calc(var(--tabh) + var(--sb) + 28px) calc(16px + var(--sl)); outline: none; }
#rail, #outline { display: none; }
.warnbar { background: var(--warn-soft); color: var(--warn); padding: 10px 16px; font-size: .9rem; border-bottom: 1px solid var(--line); }

/* barra inferiore (mobile) */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding: 4px calc(4px + var(--sr)) var(--sb) calc(4px + var(--sl)); box-shadow: 0 -6px 20px rgba(28,34,51,.06); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 54px; text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600; border-radius: 12px; padding: 4px 2px; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--brand); background: var(--brand-soft); }
body.in-lesson .tabbar { display: none; }
.lessonbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; align-items: center; background: var(--surface); border-top: 1px solid var(--line); padding: 8px calc(12px + var(--sr)) calc(8px + var(--sb)) calc(12px + var(--sl)); box-shadow: 0 -6px 20px rgba(28,34,51,.08); }
body:not(.in-lesson) .lessonbar { display: none; }
.lb-btn { height: 48px; display: grid; place-items: center; border-radius: 14px; background: var(--surface2); color: var(--ink); text-decoration: none; }
.lb-btn.primary { background: var(--brand); color: var(--brand-ink); }
.lb-btn.disabled { opacity: .35; pointer-events: none; }
.lb-mid { height: 48px; display: flex; align-items: center; gap: 8px; justify-content: center; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 0 12px; min-width: 0; }
.lb-n { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand); }
.lb-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; font-weight: 600; }
body.in-lesson main#view { padding-bottom: calc(var(--tabh) + var(--sb) + 36px); }

/* ---------------- pulsanti, chip ---------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px; border-radius: 14px; border: 1px solid transparent; font-weight: 650; text-decoration: none; background: var(--surface2); color: var(--ink); line-height: 1.2; text-align: center; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: var(--bad); color: var(--bg); }
.btn.small { min-height: 44px; padding: 8px 14px; font-size: .92rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:not(:disabled):hover { filter: brightness(.97); }
.btn.pulse { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 30%, transparent); }
.btnrow { display: flex; flex-wrap: wrap; gap: 10px; margin: 1.2em 0; }
.btnrow.between { justify-content: space-between; }
.btnrow > .btn { flex: 1 1 auto; }
.linklike { background: none; border: 0; padding: 0; color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; min-height: 30px; border-radius: 999px; background: var(--surface2); color: var(--ink); font-size: .8rem; font-weight: 650; border: 1px solid var(--line); text-decoration: none; margin: 2px 4px 2px 0; }
.chip.opt, .chip.extra { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
button.chip, a.chip { min-height: 44px; padding: 8px 16px; font-size: .9rem; }
.chip.filter.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip.st { font-size: .72rem; min-height: 24px; padding: 2px 10px; }
.chips { margin: .5em 0 1em; }
.term { background: none; border: 0; border-bottom: 1.5px dotted var(--brand); color: var(--brand); padding: 0; margin: 0; font-weight: 600; cursor: help; font: inherit; font-weight: 600; text-decoration: none; }
.term.chip { border: 1px solid var(--line); color: var(--ink); cursor: pointer; }
.wiki { font-size: .85em; background: var(--surface2); border: 1px solid var(--line); border-radius: 8px; padding: 1px 8px; text-decoration: none; color: var(--ink); white-space: normal; display: inline-block; margin: 2px 2px; }
.wiki::before { content: "W"; font-weight: 800; color: var(--accent); margin-right: 6px; font-size: .78em; }
.wiki-missing { color: var(--bad); }
.path { font-size: .78rem; color: var(--muted); font-family: var(--mono); }

/* ---------------- home ---------------- */
.home { max-width: 62rem; margin: 0 auto; }
.hero { padding: 6px 0 4px; }
.hero h1 { font-size: clamp(2rem, 8.6vw, 3.3rem); margin-bottom: .3em; }
.facts { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 1em 0; }
.facts li { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; font-size: .9rem; }
.facts strong { font-family: var(--serif); font-size: 1.15rem; color: var(--brand); }
.offline { display: flex; gap: 8px; align-items: flex-start; font-size: .9rem; color: var(--muted); }
.offline svg { color: var(--ok); flex: none; margin-top: 3px; width: 18px; height: 18px; }
.resume { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; padding: 16px 18px; margin: 18px 0; background: var(--brand); color: var(--brand-ink); border-radius: 18px; text-decoration: none; box-shadow: var(--shadow); }
.resume-k { grid-column: 1; font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; opacity: .85; }
.resume-t { grid-column: 1; font-family: var(--serif); font-size: 1.2rem; font-weight: 700; line-height: 1.25; }
.resume-s { grid-column: 1; font-size: .9rem; opacity: .9; }
.resume svg { grid-column: 2; grid-row: 1 / span 3; width: 28px; height: 28px; }
.progline { font-size: .9rem; color: var(--muted); }
.bar { height: 8px; border-radius: 999px; background: var(--surface2); overflow: hidden; margin: 6px 0; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width .3s; }
.routes { display: grid; gap: 10px; margin-bottom: 18px; }
.routecard { display: flex; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.routecard strong { display: block; font-family: var(--serif); }
.routecard span { font-size: .88rem; color: var(--muted); display: block; line-height: 1.4; }
.ring { flex: none; }
.ring-bg { fill: none; stroke: var(--surface2); stroke-width: 5; }
.ring-fg { fill: none; stroke: var(--brand); stroke-width: 5; stroke-linecap: round; }
.ring-t { font-size: 11px; font-weight: 700; fill: var(--ink); }
.grp { margin: 14px 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); overflow: clip; }
.grp > summary { list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px; min-height: 56px; cursor: pointer; font-family: var(--serif); font-weight: 700; font-size: 1.12rem; }
.grp > summary::-webkit-details-marker { display: none; }
.grp > summary::after { content: ""; width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s; margin-left: 6px; flex: none; }
.grp[open] > summary::after { transform: rotate(-135deg); }
.grp-t { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-right: auto; }
.grp-r { font-family: var(--sans); font-size: .78rem; color: var(--brand); background: var(--brand-soft); padding: 2px 8px; border-radius: 8px; font-weight: 700; }
.grp-p { font-family: var(--sans); font-size: .85rem; font-weight: 600; color: var(--muted); }
.grp-d { padding: 0 16px; color: var(--muted); font-size: .92rem; margin: 0 0 8px; }
.trail { list-style: none; margin: 0; padding: 4px 8px 12px 8px; position: relative; }
.node { position: relative; }
.nodelink { display: flex; gap: 12px; padding: 12px 8px; text-decoration: none; color: var(--ink); border-radius: 14px; min-height: 64px; }
.nodelink:hover { background: var(--surface2); }
.nodenum { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .9rem; background: var(--surface2); border: 2px solid var(--line); color: var(--ink); position: relative; z-index: 1; }
.st-doing .nodenum { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.st-done .nodenum { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.node:not(:last-child)::before { content: ""; position: absolute; left: 27px; top: 50px; bottom: -14px; width: 2px; background: var(--line); }
.nodebody { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nodetitle { font-weight: 700; line-height: 1.3; }
.nodesub { font-size: .88rem; color: var(--muted); line-height: 1.4; }
.nodemeta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: .78rem; color: var(--muted); margin-top: 3px; }
.st-done .chip.st { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.st-doing .chip.st { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tiles { display: grid; gap: 10px; margin: 22px 0; }
.tile { display: grid; grid-template-columns: 28px 1fr; gap: 2px 12px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); text-decoration: none; color: var(--ink); }
.tile svg { grid-row: 1 / span 2; color: var(--brand); margin-top: 3px; }
.tile span { font-size: .88rem; color: var(--muted); }
.disclaimer { font-size: .85rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 24px; }

/* ---------------- lezione ---------------- */
.lesson, .page { max-width: 46rem; margin: 0 auto; }
.lesson-head { margin-bottom: 18px; }
.lesson-head h1 { margin-bottom: .2em; }
.stepno { font-size: .85rem; color: var(--muted); margin: 0; }
.lesson-body > * + * { margin-top: 1em; }
.lesson-body h2 { margin-top: 1.5em; }
.hook { background: var(--accent-soft); border-radius: 18px; padding: 16px 18px; border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); }
.hook h2 { font-size: 1.08rem; margin: 1.1em 0 .35em; }
.hook h2:first-child { margin-top: 0; }
.hook-k { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; }
.hook-k svg { width: 18px; height: 18px; }
.hook p:last-child { margin-bottom: 0; }
.goal { border-left: 4px solid var(--brand); padding: 4px 0 4px 16px; }
.goal h2 { margin-top: 0; font-size: 1.1rem; }
.list { padding-left: 1.2em; margin: .6em 0 1em; }
.list li { margin: .45em 0; padding-left: .2em; }
.list.ticks { list-style: none; padding-left: 0; }
.list.ticks li { position: relative; padding-left: 30px; }
.list.ticks li::before { content: "✓"; position: absolute; left: 0; top: 0; color: var(--ok); font-weight: 800; }
.callout { border-radius: 14px; padding: 12px 16px; margin: 1.2em 0; background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--brand); }
.callout-t { display: flex; gap: 8px; align-items: center; font-weight: 750; margin: 0 0 4px; }
.callout-t svg { width: 20px; height: 20px; flex: none; }
.callout-b p:last-child, .callout-b ul:last-child { margin-bottom: 0; }
.c-warn, .c-date { border-left-color: var(--warn); background: var(--warn-soft); color: var(--ink); }
.c-warn .callout-t, .c-date .callout-t { color: var(--warn); }
.c-def { border-left-color: var(--brand); background: var(--brand-soft); }
.c-tip { border-left-color: var(--ok); background: var(--ok-soft); }
.c-formula { border-left-color: var(--accent); }
.formula { background: var(--surface2); border-radius: 12px; padding: 12px 16px; margin: 1em 0; overflow-x: auto; }
.formula code { display: block; font-size: 1rem; white-space: pre-wrap; }
.formula p { margin: 6px 0 0; font-size: .9rem; color: var(--muted); }
.cardgrid { display: grid; gap: 10px; }
.minicard { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.minicard p { margin: 4px 0 0; font-size: .95rem; }
.tablewrap { overflow-x: auto; margin: 1em 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
caption { text-align: left; font-weight: 700; padding: 10px 12px; }
th, td { text-align: left; padding: 9px 12px; border-top: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--surface2); border-top: 0; white-space: nowrap; }
tbody th { font-weight: 650; }
.wikiline { font-size: .9rem; margin-top: 1.6em; }
.wikilist, .linklist, .officials { list-style: none; padding: 0; margin: .5em 0; }
.wikilist li, .linklist li, .officials li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.officials p { margin: 4px 0; font-size: .92rem; }
.caveat { color: var(--warn); }
.inl { width: 15px; height: 15px; vertical-align: -2px; }
.check { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 4px 16px 16px; margin-top: 1.6em; }
.check h2 { margin-top: .8em; font-size: 1.15rem; }
.pager { display: none; }
.stepsmall { font-size: .85rem; }

/* esempi svolti */
.example { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin: 18px 0; }
.example header h2 { margin: 6px 0 8px; font-size: 1.25rem; }
.setup { background: var(--surface2); border-radius: 12px; padding: 10px 14px; margin: 8px 0; }
.setup p:last-child { margin-bottom: 0; }
.ask { background: var(--brand-soft); border-radius: 12px; padding: 10px 14px; }
ol.steps { padding-left: 1.4em; margin: .8em 0; }
ol.steps li { margin: .55em 0; padding-left: .2em; }
ol.steps.big li { padding: 6px 4px 6px 6px; border-left: 3px solid var(--brand); margin: .5em 0 .5em -0.2em; list-style-position: inside; background: color-mix(in srgb, var(--brand-soft) 45%, transparent); border-radius: 0 10px 10px 0; padding-left: 12px; }
.result { background: var(--ok-soft); border-left: 5px solid var(--ok); border-radius: 0 12px 12px 0; padding: 10px 14px; font-weight: 500; }
.result p:last-child { margin-bottom: 0; }

/* errori */
.flip { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); margin: 12px 0; overflow: clip; }
.flip > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; min-height: 56px; }
.flip > summary::-webkit-details-marker { display: none; }
.flip-k { flex: none; background: var(--bad-soft); color: var(--bad); font-weight: 800; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; padding: 4px 8px; border-radius: 8px; margin-top: 2px; }
.flip-t { font-weight: 600; }
.flip[open] > summary { border-bottom: 1px solid var(--line); background: var(--bad-soft); }
.flip-b { padding: 4px 16px 10px; }
details.more { margin: .8em 0; }
details.more > summary { cursor: pointer; font-weight: 650; color: var(--brand); padding: 8px 0; min-height: 44px; display: flex; align-items: center; }

/* domande */
.qitem { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin: 14px 0; box-shadow: var(--shadow); }
.qhead { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.qtype { color: var(--brand); } .qtries { color: var(--muted); font-weight: 600; letter-spacing: 0; text-transform: none; }
.qprompt { font-size: 1.04rem; font-weight: 500; margin-bottom: 12px; }
.qprompt p { margin: 0 0 .7em; }
.qinput, .cwrap { display: flex; align-items: center; gap: 8px; }
input.num, .qopen textarea, textarea, select, input[type=search] { width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); font-size: max(16px, 1rem); }
input.num { text-align: right; font-variant-numeric: tabular-nums; max-width: 240px; font-weight: 600; }
input.num[readonly], textarea[readonly] { background: var(--surface2); }
input[aria-invalid="true"] { border-color: var(--bad); }
input:focus, textarea:focus, select:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 35%, transparent); }
.unit { color: var(--muted); font-size: .9rem; min-width: 2.2em; }
textarea { resize: vertical; line-height: 1.5; }
.opts { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; min-width: 0; }
.opt { position: relative; display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px; background: var(--bg); min-height: 52px; }
.opt input { flex: none; width: 24px; height: 24px; margin: 1px 0 0; accent-color: var(--brand); }
.opt label { flex: 1; cursor: pointer; display: block; }
.opt-mark { display: block; font-size: .8rem; font-weight: 800; margin-top: 2px; }
.opt:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.opt.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.is-correct .opt-mark { color: var(--ok); }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.is-wrong .opt-mark { color: var(--bad); }
.opt.rub { margin: 6px 0; }
.matches { display: grid; gap: 10px; }
.mrow { display: grid; gap: 6px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 14px; background: var(--bg); }
.mrow.is-correct { border-color: var(--ok); background: var(--ok-soft); } .mrow.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.mrow .opt-mark { font-weight: 800; }
.mrow.is-correct .opt-mark { color: var(--ok); } .mrow.is-wrong .opt-mark { color: var(--bad); }
.qactions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.qactions .btn { flex: 1 1 140px; }
.hintbox { background: var(--warn-soft); color: var(--ink); border-radius: 12px; padding: 10px 14px; margin: 10px 0 0; font-size: .95rem; }
.fb { border-radius: 14px; padding: 12px 16px; margin-top: 14px; border: 1px solid var(--line); }
.fb:focus { outline: none; }
.fb-ok { background: var(--ok-soft); border-color: var(--ok); }
.fb-bad { background: var(--bad-soft); border-color: var(--bad); }
.fb-info { background: var(--brand-soft); border-color: var(--brand); }
.fb-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--ink); }
.fb-title { font-weight: 800; font-size: 1.05rem; margin: 0 0 6px; }
.fb-ok .fb-title { color: var(--ok); } .fb-bad .fb-title { color: var(--bad); } .fb-info .fb-title { color: var(--brand); }
.fb-h { font-weight: 750; margin: .8em 0 .2em; }
.fb-note { font-size: .92rem; color: var(--muted); }
.fb-body p:last-child { margin-bottom: .4em; }
ul.why { padding-left: 1.1em; } ul.why li { margin: .5em 0; }
.guide { background: var(--bg); border-radius: 12px; padding: 4px 14px; border: 1px solid var(--line); }
.rubcount { font-size: .9rem; font-weight: 650; margin-top: 6px; }
.retry { margin-top: 8px; }
.qprog { display: flex; align-items: center; gap: 12px; font-size: .9rem; font-weight: 650; }
.qprog .bar { flex: 1; }
.summary h2 { margin-top: .4em; }
.statrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.statrow.big { grid-template-columns: repeat(2, 1fr); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; text-align: center; }
.stat strong { display: block; font-family: var(--serif); font-size: 1.5rem; color: var(--brand); }
.stat span { font-size: .78rem; color: var(--muted); line-height: 1.3; display: block; }
.sumlist { list-style: none; padding: 0; } .sumlist li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.sum-ok strong { color: var(--ok); } .sum-bad strong { color: var(--bad); }

/* pratica */
.practice { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; margin: 12px 0; }
.practice .opt { border: 0; background: transparent; padding: 4px 0; }
.status-box { display: flex; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 16px; margin: 1.2em 0; }
.status-box span { display: block; font-size: .9rem; color: var(--muted); }
.oneline { background: var(--brand-soft); border-radius: 14px; padding: 12px 16px; }

/* calcolatori */
.calc { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin: 18px 0; box-shadow: var(--shadow); }
.chead h2 { margin-top: 0; font-size: 1.25rem; }
.h3like, .lesson-body h2.h3like { font-size: 1.14rem; margin-top: 1.4em; }
.cintro { color: var(--muted); font-size: .95rem; }
.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 8px 0; }
.presets-l { font-size: .85rem; font-weight: 700; color: var(--muted); }
.cfields { display: grid; gap: 14px; margin: 14px 0; }
.cfield label { font-weight: 650; display: block; margin-bottom: 4px; font-size: .95rem; }
.cfield .hint { margin: 2px 0 6px; }
.ferr { color: var(--bad); font-size: .88rem; font-weight: 650; margin: 4px 0 0; }
.cout { margin-top: 14px; }
dl.rows { margin: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--bg); }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 10px 14px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row dt { color: var(--muted); font-size: .92rem; }
.row dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.row.strong { background: var(--brand-soft); } .row.strong dt { color: var(--ink); font-weight: 650; } .row.strong dd { font-size: 1.12rem; }
.tone-bad dd { color: var(--bad); } .tone-ok dd { color: var(--ok); } .tone-warn dd { color: var(--warn); }
.cdisc { font-size: .8rem; color: var(--muted); margin: 14px 0 0; }
.figure { margin: 14px 0; } .figure figcaption { font-weight: 700; font-size: .92rem; margin-bottom: 4px; }
.chart { width: 100%; max-width: 560px; height: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; } .chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { stroke-width: 2.6; stroke-linejoin: round; }
.chart .s0 { stroke: var(--muted); fill: var(--muted); } .chart .s1 { stroke: var(--brand); fill: var(--brand); } .chart .s2 { stroke: var(--accent); fill: var(--accent); }
.chart path.line { fill: none; }
.chart .line.s0 { stroke-dasharray: 6 4; } .chart .lbl { font-size: 11px; font-weight: 700; } .chart .dot { stroke: none; }
.datatable { font-size: .85rem; }
.toolgrid { display: grid; gap: 10px; }
.toolcard { display: grid; gap: 4px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); text-decoration: none; color: var(--ink); }
.toolcard span:last-child { font-size: .9rem; color: var(--muted); }

/* casi */
.caselist { list-style: none; padding: 0; display: grid; gap: 8px; }
.caselist a { display: flex; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; text-decoration: none; color: var(--ink); min-height: 64px; }
.stages { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 0; margin: 0 0 16px; }
.stages button { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 2px; background: transparent; border: 0; border-bottom: 3px solid var(--line); color: var(--muted); font-size: .72rem; font-weight: 650; min-height: 56px; }
.stages .sn { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface2); font-weight: 800; font-size: .8rem; }
.stages li.cur button { color: var(--brand); border-bottom-color: var(--brand); }
.stages li.cur .sn { background: var(--brand); color: var(--brand-ink); }
.stages li.past .sn { background: var(--ok-soft); color: var(--ok); }
.casebox { background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 14px; padding: 4px 16px 8px; }
.gate { background: var(--surface); border: 1px dashed var(--muted); border-radius: 16px; padding: 4px 16px 10px; }
.okk { color: var(--ok); font-weight: 650; }
.solution { background: var(--ok-soft); border-radius: 16px; padding: 4px 16px 12px; border: 1px solid var(--ok); }

/* glossario */
.gtools { display: grid; gap: 4px; position: sticky; top: calc(var(--topbarh) + var(--st)); background: var(--bg); padding: 8px 0 2px; z-index: 5; }
.catbar { display: flex; gap: 4px; overflow-x: auto; padding: 4px 0 8px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.catbar .chip { flex: none; white-space: nowrap; }
.letter { font-size: 1.5rem; margin: 1.2em 0 .3em; color: var(--accent); border-bottom: 1px solid var(--line); }
.gentry { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 16px; margin: 10px 0; scroll-margin-top: 140px; }
.gentry.hl { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 30%, transparent); }
.gentry h3 { margin: 0 0 6px; font-size: 1.12rem; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.gentry p { margin: 0 0 .6em; }
.notbox { background: var(--warn-soft); border-radius: 10px; padding: 8px 12px; font-size: .93rem; }
.glinks { font-size: .88rem; color: var(--muted); }
.empty { color: var(--muted); padding: 20px 0; }
.distinctions { margin-top: 2em; }

/* progressi, altro, ricerca */
.prglist { list-style: none; padding: 0; margin: 0; }
.prglist a { display: grid; grid-template-columns: 40px 1fr auto; gap: 2px 12px; align-items: center; padding: 10px 0; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); }
.prglist .bar { grid-column: 2 / span 2; margin: 0; } .prglist .nodenum { grid-row: 1 / span 2; }
.prg-p { font-weight: 700; color: var(--brand); }
.seg { border: 0; padding: 0; margin: 0 0 16px; display: flex; flex-wrap: wrap; gap: 6px; }
.seg legend { font-weight: 700; padding: 0; margin-bottom: 6px; width: 100%; }
.segopt { position: relative; }
.segopt input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segopt label { display: block; padding: 10px 16px; min-height: 44px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); font-weight: 650; }
.segopt input:checked + label { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.segopt input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
.menu { list-style: none; padding: 0; display: grid; gap: 8px; }
.menu a { display: grid; grid-template-columns: 28px 1fr 22px; gap: 12px; align-items: center; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; text-decoration: none; color: var(--ink); min-height: 64px; }
.menu small { display: block; color: var(--muted); font-size: .82rem; }
.sresult { display: grid; gap: 4px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin: 8px 0; text-decoration: none; color: var(--ink); }

.snip { font-size: .88rem; color: var(--muted); }
.legacy-note { white-space: pre-wrap; }

/* finestre */
dialog { border: 0; padding: 0; background: var(--surface); color: var(--ink); max-width: min(34rem, calc(100vw - 24px)); width: 100%; border-radius: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,12,20,.55); }
.dlg-in { padding: 18px 20px calc(20px + var(--sb)); max-height: 80dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; min-height: 44px; }
dialog h2:focus, dialog h2:focus-visible { outline: none; }
.dlg-head h2 { padding-top: 2px; }
.dlg-head h2 { margin: 0 0 6px; }
dialog h2 { margin-top: 0; }
.outline-list, .sheet-list { list-style: none; padding: 0; margin: 10px 0; }
.outline-list a, .sheet-list a { display: flex; gap: 10px; align-items: center; padding: 10px 8px; text-decoration: none; color: var(--ink); border-radius: 10px; min-height: 44px; }
.outline-list a.on, .sheet-list a.on { background: var(--brand-soft); font-weight: 700; color: var(--brand); }
.outline-list .sn, .sheet-list .sn { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--surface2); display: grid; place-items: center; font-size: .75rem; font-weight: 800; }
a.seen .sn { background: var(--ok-soft); color: var(--ok); } a.on .sn { background: var(--brand); color: var(--brand-ink); }
@media (max-width: 760px) {
  dialog { position: fixed; inset: auto 0 0 0; margin: 0; max-width: none; width: 100%; border-radius: 22px 22px 0 0; max-height: 86dvh; }
  dialog[open] { animation: slideup .22s ease-out; }
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------- tablet e desktop ---------------- */
@media (min-width: 761px) {
  .routes { grid-template-columns: repeat(3, 1fr); }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .toolgrid { grid-template-columns: repeat(2, 1fr); }
  .cardgrid { grid-template-columns: repeat(2, 1fr); }
  .cfields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .statrow.big { grid-template-columns: repeat(5, 1fr); }
  .stages button { flex-direction: row; justify-content: center; font-size: .9rem; }
  main#view { padding-left: 28px; padding-right: 28px; }
  .qitem, .calc, .example { padding: 22px; }
}
@media (min-width: 1024px) {
  :root { --topbarh: 60px; }
  body { font-size: 1.1rem; }
  .app { grid-template-columns: 290px minmax(0, 1fr); grid-template-areas: "top top" "rail main"; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  .topnav { display: flex; gap: 2px; }
  .topnav a { padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: .95rem; }
  .topnav a:hover { background: var(--surface2); } .topnav a.on { background: var(--brand-soft); color: var(--brand); }
  .brand { margin-right: 18px; }
  .topnav { margin-right: auto; }
  .fsgroup { display: inline-flex; }
  #rail { display: block; grid-area: rail; position: sticky; top: var(--topbarh); height: calc(100dvh - var(--topbarh)); overflow-y: auto; border-right: 1px solid var(--line); padding: 18px 12px 28px 18px; }
  .rail-h { font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
  .rail-g { margin: 6px 0; } .rail-g > summary { cursor: pointer; font-weight: 700; font-size: .92rem; padding: 6px 4px; list-style: none; } .rail-g > summary::-webkit-details-marker { display: none; }
  .rail-g > summary span { color: var(--brand); font-size: .75rem; margin-right: 4px; }
  .rail-g ol { list-style: none; padding: 0; margin: 0 0 6px; }
  .rail-g a { display: flex; gap: 10px; align-items: center; padding: 7px 8px; border-radius: 10px; text-decoration: none; color: var(--ink); font-size: .9rem; line-height: 1.3; }
  .rail-g a:hover { background: var(--surface2); } .rail-g a.on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
  .rn { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: .7rem; font-weight: 800; }
  a.st-doing .rn { border-color: var(--accent); color: var(--accent); } a.st-done .rn { background: var(--ok); border-color: var(--ok); color: var(--bg); }
  main#view { padding: 30px 40px 80px; }
  body.in-lesson main#view, main#view { padding-bottom: 80px; }
  .tabbar, .lessonbar, body.in-lesson .lessonbar { display: none !important; }
  .pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--line); }
  .pager .btn { max-width: 48%; }
  .pager .btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .routes { margin-bottom: 24px; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .toolgrid { grid-template-columns: repeat(3, 1fr); }
  .resume { padding: 22px 26px; }
  .gtools { top: var(--topbarh); }
}
@media (min-width: 1320px) {
  .app { grid-template-columns: 290px minmax(0, 1fr) 280px; grid-template-areas: "top top top" "rail main outline"; }
  #outline { display: block; grid-area: outline; position: sticky; top: var(--topbarh); height: calc(100dvh - var(--topbarh)); overflow-y: auto; padding: 22px 18px; border-left: 1px solid var(--line); }
  #outline[hidden] { display: none !important; }
  .o-title { font-family: var(--serif); font-weight: 700; margin: 0 0 6px; }
}
@media (max-height: 480px) and (orientation: landscape) {
  :root { --tabh: 52px; --topbarh: 46px; }
  .tab { min-height: 44px; flex-direction: row; gap: 6px; } .tab svg { width: 20px; height: 20px; }
  .lb-btn, .lb-mid { height: 42px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media print { .topbar, .tabbar, .lessonbar, #rail, #outline, .pager, .btnrow, .qactions { display: none !important; } body { background: #fff; color: #000; } .app { display: block; } main#view { padding: 0; } }
@media (forced-colors: active) { .opt, .btn, .qitem, .calc { border: 2px solid CanvasText; } }

/* policy builder */
.policybox { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 4px 16px 12px; margin-top: 1.6em; }
