:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --ink: #1b1d33;
  --muted: #5b6078;
  --line: #dfe2ee;
  --primary: #4338ca;
  --primary-ink: #ffffff;
  --primary-soft: #eceafd;
  --ok: #15803d;
  --ok-soft: #e4f6ea;
  --bad: #b91c1c;
  --bad-soft: #fdebeb;
  --warn: #92400e;
  --warn-soft: #fff4d6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(27, 29, 51, 0.06), 0 6px 20px rgba(27, 29, 51, 0.06);
  --nav-h: 64px;
  --side-w: 232px;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.5; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; border-radius: 6px; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--primary); color: #fff; padding: 0.6rem 1rem; z-index: 100; }
.skip-link:focus { left: 0; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.en { font-family: Georgia, 'Times New Roman', serif; }

/* ---------- shell ---------- */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.65rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--ink); font-weight: 700; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; font-family: Georgia, serif; font-size: 0.95rem; }
.topbar-selected { text-decoration: none; background: var(--primary-soft); color: var(--primary); padding: 0.35rem 0.8rem; border-radius: 999px; font-size: 0.875rem; font-weight: 600; white-space: nowrap; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(6, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--nav-h); padding: 6px 2px; text-decoration: none; color: var(--muted); font-size: 0.68rem; font-weight: 600; text-align: center; }
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current='page'] { color: var(--primary); background: var(--primary-soft); }
.main { padding: 1rem; max-width: 1080px; width: 100%; min-width: 0; margin: 0 auto; outline: none; }
.loading { color: var(--muted); }

@media (min-width: 900px) {
  .app-shell { grid-template-columns: var(--side-w) minmax(0, 1fr); grid-template-rows: auto 1fr; padding-bottom: 0; }
  .topbar { grid-column: 1 / -1; }
  .nav { position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px); grid-template-columns: 1fr; grid-auto-rows: min-content; gap: 4px; padding: 1rem 0.75rem; border-top: 0; border-right: 1px solid var(--line); }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 0.7rem; min-height: 44px; padding: 0.55rem 0.85rem; border-radius: 10px; font-size: 0.95rem; text-align: left; }
  .main { padding: 1.75rem 2rem; }
}

/* ---------- componenti ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.page-head p { margin: 0; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.kpis { display: grid; gap: 0.75rem; grid-template-columns: repeat(2, 1fr); margin-bottom: 1rem; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; box-shadow: var(--shadow); }
.kpi .v { font-size: 1.75rem; font-weight: 800; color: var(--primary); line-height: 1.1; }
.kpi .l { font-size: 0.85rem; color: var(--muted); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 44px; padding: 0.5rem 1.1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink); }
.btn:hover { background: #f0f1f8; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: #3730a3; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn.small { min-height: 36px; padding: 0.25rem 0.75rem; font-size: 0.875rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 700; background: var(--primary-soft); color: var(--primary); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.t-affirmative { background: #e0f2fe; color: #075985; }
.badge.t-negative { background: #fde8f1; color: #9d174d; }
.badge.t-interrogative { background: #ede9fe; color: #5b21b6; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty h2 { color: var(--ink); }
.bar { height: 10px; background: #e8eaf4; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar.ok > span { background: #16a34a; }
.bar.bad > span { background: #dc2626; }
.bar.warn > span { background: #d97706; }
.row-bar { display: grid; grid-template-columns: 8.5rem 1fr 3.5rem; gap: 0.75rem; align-items: center; margin: 0.5rem 0; }
.row-bar .pct { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.notice { border-radius: 10px; padding: 0.7rem 0.9rem; background: var(--warn-soft); color: var(--warn); margin-bottom: 1rem; }
.notice.info { background: var(--primary-soft); color: #312e81; }
.notice.bad { background: var(--bad-soft); color: var(--bad); }

/* form */
.field { display: grid; gap: 0.3rem; margin-bottom: 0.9rem; }
.field > label, fieldset legend { font-weight: 700; font-size: 0.95rem; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 0.7rem 0.9rem; margin: 0 0 0.9rem; }
input[type='text'], input[type='search'], input[type='number'], select { width: 100%; min-height: 44px; padding: 0.45rem 0.7rem; border: 1px solid #b9bed6; border-radius: 10px; background: #fff; }
input[type='checkbox'], input[type='radio'] { width: 20px; height: 20px; accent-color: var(--primary); }
.check { display: flex; align-items: center; gap: 0.55rem; min-height: 36px; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { min-height: 34px; min-width: 34px; padding: 0.15rem 0.6rem; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.875rem; }
.chip[aria-pressed='true'] { background: var(--primary); border-color: var(--primary); color: #fff; }
.toolbar { display: grid; gap: 0.6rem; grid-template-columns: 1fr; margin-bottom: 0.75rem; }
@media (min-width: 700px) { .toolbar { grid-template-columns: 2fr 1fr 1fr; } }

/* tabella */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); max-height: 70vh; }
table.verbs { width: 100%; border-collapse: collapse; min-width: 320px; }
table.verbs th, table.verbs td { padding: 0.5rem 0.65rem; text-align: left; border-bottom: 1px solid #eceef6; vertical-align: middle; }
table.verbs thead th { position: sticky; top: 0; background: #f0f1fa; z-index: 2; font-size: 0.85rem; }
table.verbs th button { all: unset; cursor: pointer; font-weight: 700; display: inline-flex; gap: 0.3rem; align-items: center; padding: 0.2rem 0; }
table.verbs th button:focus-visible { outline: 3px solid #f59e0b; }
table.verbs tbody tr.is-selected { background: var(--primary-soft); box-shadow: inset 4px 0 0 var(--primary); }
table.verbs td.col-check, table.verbs th.col-check { width: 44px; text-align: center; }
table.verbs td.col-info { width: 44px; text-align: right; }
table.verbs .infinitive { font-weight: 700; font-family: Georgia, serif; }
table.verbs .variant { color: var(--muted); font-size: 0.82em; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; color: var(--primary); }
.sticky-bar { position: sticky; top: 56px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem 0.9rem; margin-bottom: 0.75rem; box-shadow: var(--shadow); }
.counter { font-weight: 700; }

/* esercizio */
.session-meta { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.exercise .prompt { font-size: 1.35rem; line-height: 1.4; background: #f7f7fe; border-left: 5px solid var(--primary); padding: 0.9rem 1rem; border-radius: 10px; margin: 0.5rem 0 1rem; font-family: Georgia, serif; }
.exercise input[type='text'] { font-size: 1.15rem; min-height: 52px; font-family: Georgia, serif; }
.feedback { margin-top: 1rem; padding: 1rem; border-radius: 12px; }
.feedback.ok { background: var(--ok-soft); color: #14532d; border: 1px solid #86d9a0; }
.feedback.review { background: var(--warn-soft); color: var(--warn); border: 1px solid #f3cf7a; }
.feedback h3 { margin-bottom: 0.25rem; }
.progress-line { height: 8px; background: #e5e7f2; border-radius: 99px; overflow: hidden; margin: 0.25rem 0 0.75rem; }
.progress-line > span { display: block; height: 100%; background: var(--primary); }

/* dialog */
.overlay { position: fixed; inset: 0; background: rgba(20, 22, 45, 0.55); display: grid; place-items: center; padding: 1rem; z-index: 200; overflow: auto; }
.dialog { background: #fff; border-radius: 16px; max-width: 560px; width: 100%; padding: 1.25rem; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); max-height: calc(100vh - 2rem); overflow: auto; }
.dialog h2 { margin-bottom: 0.75rem; }
.dialog.error { border-top: 6px solid var(--bad); }
.dialog dl { display: grid; gap: 0.15rem 0.75rem; margin: 0 0 1rem; }
.dialog dt { font-size: 0.78rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin-top: 0.55rem; }
.dialog dd { margin: 0; }
.dialog .mono-en { font-family: Georgia, serif; font-size: 1.1rem; }
.wrong-answer { background: var(--bad-soft); border-radius: 8px; padding: 0.35rem 0.6rem; }
.right-answer { background: var(--ok-soft); border-radius: 8px; padding: 0.35rem 0.6rem; }
.hl { background: #fecaca; border-radius: 4px; padding: 0 3px; font-weight: 700; }
.dialog .actions { justify-content: flex-end; margin-top: 0.5rem; }

.toast-region { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); z-index: 300; display: grid; gap: 0.5rem; width: min(92vw, 460px); }
@media (min-width: 900px) { .toast-region { bottom: 20px; } }
.toast { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; background: #22243d; color: #fff; padding: 0.7rem 0.9rem; border-radius: 12px; box-shadow: var(--shadow); }
.toast button { background: transparent; border: 1px solid #8e93c4; color: #fff; border-radius: 8px; padding: 0.25rem 0.7rem; cursor: pointer; font-weight: 700; }
.toast.bad { background: var(--bad); }

/* grafici */
.chart { width: 100%; height: 160px; }
.chart text { font-size: 10px; fill: #5b6078; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid #eceef6; }
.list-plain li:last-child { border-bottom: 0; }

@media (max-width: 520px) {
  h1 { font-size: 1.4rem; }
  .row-bar { grid-template-columns: 6.5rem 1fr 3rem; }
  .exercise .prompt { font-size: 1.15rem; }
  table.verbs th, table.verbs td { padding: 0.5rem 0.4rem; }
  .hide-xs { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media print { .nav, .topbar, .toast-region { display: none; } }

/* etichette di navigazione: corte su mobile, lunghe su desktop */
.lbl-long { display: none; }
@media (min-width: 900px) { .lbl-long { display: inline; } .lbl-short { display: none; } }
.hl { background: #fecaca; border-radius: 4px; padding: 0 3px; font-weight: 700; color: #7f1d1d; }
.hero { background: linear-gradient(135deg, #4338ca, #6d5ee8); color: #fff; border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.hero h1 { color: #fff; }
.hero p { color: #e4e2ff; }
.hero .btn { border-color: transparent; }
.hero .btn.primary { background: #fff; color: #3730a3; }
.hero .btn:not(.primary) { background: rgba(255, 255, 255, 0.16); color: #fff; }
.verb-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.verb-chip { font-family: Georgia, serif; background: var(--primary-soft); color: #312e81; border-radius: 8px; padding: 0.15rem 0.55rem; font-weight: 600; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; }
details.fold summary { cursor: pointer; font-weight: 600; color: var(--primary); }
