:root {
  --green: #58cc02; --green-d: #46a302; --blue: #1cb0f6; --blue-d: #1899d6;
  --orange: #ff9600; --orange-d: #d97c00; --red: #ff4b4b; --red-d: #d93a3a;
  --purple: #ce82ff; --gold: #ffc800;
  --bg: #ffffff; --bg2: #f7f7f7; --line: #e5e5e5; --text: #3c3c3c; --muted: #777;
  --card: #ffffff; --ok-bg: #d7ffb8; --ok-t: #3b8a00; --bad-bg: #ffdfe0; --bad-t: #c52e2e;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131f24; --bg2: #1b2a31; --line: #2f424b; --text: #e8eef0; --muted: #9db0b8; --card: #1b2a31;
    --ok-bg: #234d17; --ok-t: #b7f28a; --bad-bg: #5a1f22; --bad-t: #ffb3b3;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 17px; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
a { color: var(--blue-d); }

.shell { max-width: 640px; margin: 0 auto; min-height: 100vh; padding: 0 16px calc(90px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 10; background: var(--bg); display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 2px solid var(--line); margin-bottom: 12px; }
.brand { font-weight: 800; font-size: 20px; color: var(--green); letter-spacing: -.02em; }
.stats { display: flex; gap: 14px; font-weight: 800; }
.stat { display: flex; align-items: center; gap: 4px; }
.stat.streak { color: var(--orange); } .stat.xp { color: var(--blue); }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--bg); border-top: 2px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); }
.tabbar-in { display: flex; width: 100%; max-width: 640px; }
.tab { flex: 1; text-align: center; padding: 10px 4px 8px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; border: 2px solid transparent; border-radius: 12px; margin: 6px 3px; }
.tab svg { display: block; margin: 0 auto 2px; width: 26px; height: 26px; }
.tab.on { color: var(--blue); background: rgba(28,176,246,.12); border-color: var(--blue); }

.btn { display: inline-block; width: 100%; padding: 14px 18px; border: 0; border-radius: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; text-align: center; text-decoration: none; background: var(--green); color: #fff; box-shadow: 0 4px 0 var(--green-d); transition: transform .05s, box-shadow .05s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-d); }
.btn:disabled { background: var(--line); color: var(--muted); box-shadow: 0 4px 0 var(--line); cursor: not-allowed; }
.btn.blue { background: var(--blue); box-shadow: 0 4px 0 var(--blue-d); }
.btn.ghost { background: var(--card); color: var(--blue); border: 2px solid var(--line); box-shadow: 0 4px 0 var(--line); }
.btn.red { background: var(--red); box-shadow: 0 4px 0 var(--red-d); }

/* ── Percorso ── */
.unit { margin: 18px 0 8px; }
.unit-head { color: #fff; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px; }
.unit-head h2 { margin: 0; font-size: 20px; } .unit-head p { margin: 2px 0 0; font-size: 15px; opacity: .92; }
.path { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 12px 0 20px; }
.node { position: relative; width: 84px; height: 78px; border-radius: 50%; border: 0; display: grid; place-items: center; font-weight: 800; font-size: 28px; color: #fff; background: var(--c); box-shadow: 0 7px 0 var(--cd); }
.node:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 2px 0 var(--cd); }
.node.locked { background: #b5b5b5; box-shadow: 0 7px 0 #8f8f8f; cursor: not-allowed; }
.node.current::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 4px solid var(--c); opacity: .5; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { transform: scale(.95); opacity: .7; } 100% { transform: scale(1.18); opacity: 0; } }
.node-label { font-size: 14px; font-weight: 800; max-width: 180px; text-align: center; margin-top: 8px; }
.node-wrap { display: flex; flex-direction: column; align-items: center; }
.stars { font-size: 13px; color: var(--gold); letter-spacing: 1px; margin-top: 2px; }
.node-badge { position: absolute; top: -6px; right: -6px; background: var(--gold); color: #6a4b00; border-radius: 50%; width: 26px; height: 26px; font-size: 15px; display: grid; place-items: center; box-shadow: 0 2px 0 #c89b00; }

/* ── Lezione ── */
.lesson { display: flex; flex-direction: column; min-height: 100vh; max-width: 640px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
.lesson-top { display: flex; align-items: center; gap: 14px; padding: 16px 0; }
.close { background: none; border: 0; font-size: 28px; color: var(--muted); padding: 0 6px; line-height: 1; }
.bar { flex: 1; height: 16px; border-radius: 10px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 10px; transition: width .3s; }
.lesson-body { flex: 1; padding: 6px 0 16px; }
.lesson-foot { position: sticky; bottom: 0; margin: 0 -16px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 2px solid var(--line); }
.lesson-foot.ok { background: var(--ok-bg); border-color: transparent; } .lesson-foot.bad { background: var(--bad-bg); border-color: transparent; }
.fb { font-weight: 700; margin-bottom: 10px; } .fb h3 { margin: 0 0 4px; } .lesson-foot.ok .fb { color: var(--ok-t); } .lesson-foot.bad .fb { color: var(--bad-t); }
.fb p { margin: 0; font-weight: 600; }

.card-t { font-size: 26px; font-weight: 800; margin: 8px 0 14px; }
.card-p { margin: 0 0 12px; } .card-p b { font-weight: 800; }
.tip { background: rgba(28,176,246,.12); border-left: 5px solid var(--blue); border-radius: 10px; padding: 10px 14px; margin: 14px 0; font-weight: 600; }
.tip::before { content: "Consiglio: "; font-weight: 800; color: var(--blue-d); }

.q { font-size: 22px; font-weight: 800; margin: 8px 0 18px; }
.opts { display: grid; gap: 10px; }
.opt { text-align: left; padding: 14px 16px; background: var(--card); border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 14px; font-weight: 700; }
.opt:hover:not(:disabled) { background: var(--bg2); }
.opt.sel { border-color: var(--blue); background: rgba(28,176,246,.12); color: var(--blue-d); }
.opt.right { border-color: var(--green); background: var(--ok-bg); color: var(--ok-t); }
.opt.wrong { border-color: var(--red); background: var(--bad-bg); color: var(--bad-t); }
.opt:disabled { cursor: default; }
.blank { display: inline-block; min-width: 90px; border-bottom: 3px solid var(--line); text-align: center; color: var(--blue-d); padding: 0 6px; }

.order-ans { min-height: 58px; border: 2px dashed var(--line); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.order-ans .hint { color: var(--muted); font-weight: 600; align-self: center; margin: auto; }
.chip { padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); border-bottom-width: 4px; background: var(--card); font-weight: 700; text-align: left; }
.chip.used { opacity: .25; pointer-events: none; }
.chip .n { display: inline-block; width: 24px; height: 24px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 13px; text-align: center; line-height: 24px; margin-right: 8px; }
.chips { display: grid; gap: 8px; }

.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match .col { display: grid; gap: 10px; align-content: start; }
.mbtn { padding: 12px; border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 14px; background: var(--card); font-weight: 700; font-size: 15px; min-height: 64px; }
.mbtn.sel { border-color: var(--blue); background: rgba(28,176,246,.12); }
.mbtn.p0 { border-color: #ff9600; background: rgba(255,150,0,.15); } .mbtn.p1 { border-color: #ce82ff; background: rgba(206,130,255,.18); }
.mbtn.p2 { border-color: #1cb0f6; background: rgba(28,176,246,.15); } .mbtn.p3 { border-color: #58cc02; background: rgba(88,204,2,.15); }
.mbtn.p4 { border-color: #ff4b4b; background: rgba(255,75,75,.13); } .mbtn.p5 { border-color: #ffc800; background: rgba(255,200,0,.18); }
.mbtn.right { outline: 3px solid var(--green); } .mbtn.wrong { outline: 3px solid var(--red); }

.result { text-align: center; padding: 30px 0 10px; }
.result h1 { font-size: 30px; } .big { font-size: 64px; }
.rgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 22px 0; }
.rbox { border: 2px solid var(--line); border-radius: 16px; overflow: hidden; }
.rbox h4 { margin: 0; padding: 4px; font-size: 12px; text-transform: uppercase; color: #fff; letter-spacing: .06em; }
.rbox div { padding: 14px 6px; font-weight: 800; font-size: 22px; }

/* ── Diagrammi e video ── */
.diagram { margin: 12px 0; border-radius: 14px; overflow: hidden; border: 2px solid var(--line); background: var(--card); }
.diagram svg { display: block; width: 100%; height: auto; }
.diagram figcaption { padding: 8px 12px; font-size: 14px; color: var(--muted); font-weight: 600; }
.legend { display: flex; gap: 14px; padding: 0 12px 10px; font-size: 13px; font-weight: 700; color: var(--muted); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.video { margin: 14px 0; } .video iframe, .video video { width: 100%; border: 0; border-radius: 14px; background: #000; }
.video iframe.ig { height: 600px; background: #fff; }
.video iframe.yt { aspect-ratio: 16/9; }

/* ── Enciclopedia ── */
.search { width: 100%; padding: 12px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--bg2); color: var(--text); font: inherit; margin-bottom: 12px; }
.search:focus { outline: none; border-color: var(--blue); }
.cats { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; scrollbar-width: none; }
.cats button { flex: 0 0 auto; padding: 8px 14px; border-radius: 20px; border: 2px solid var(--line); background: var(--card); font-weight: 800; font-size: 14px; }
.cats button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.entry { display: block; text-decoration: none; color: inherit; border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; background: var(--card); }
.entry:hover { background: var(--bg2); }
.entry h3 { margin: 0 0 2px; font-size: 18px; } .entry p { margin: 0; color: var(--muted); font-weight: 600; font-size: 15px; }
.entry .cat { font-size: 11px; text-transform: uppercase; font-weight: 800; color: var(--blue-d); letter-spacing: .06em; }
.back { display: inline-block; margin: 6px 0 10px; color: var(--blue-d); font-weight: 800; text-decoration: none; }
.notice { font-size: 13px; color: var(--muted); background: var(--bg2); border-radius: 12px; padding: 10px 14px; margin: 16px 0; }
.docs a { display: block; padding: 10px 14px; border: 2px solid var(--line); border-radius: 12px; margin-bottom: 8px; font-weight: 700; text-decoration: none; }
.related { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; } .tag { background: var(--bg2); border-radius: 20px; padding: 3px 10px; font-size: 13px; font-weight: 700; color: var(--muted); }

/* ── Classifica ── */
.seg { display: flex; border: 2px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 14px; }
.seg button { flex: 1; padding: 10px; border: 0; background: var(--card); font-weight: 800; }
.seg button.on { background: var(--blue); color: #fff; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; border: 2px solid transparent; }
.row.me { background: rgba(88,204,2,.14); border-color: var(--green); }
.row + .row { margin-top: 4px; }
.rank { width: 32px; text-align: center; font-weight: 800; font-size: 18px; color: var(--muted); }
.medal { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; background: var(--blue); flex: 0 0 auto; }
.rname { flex: 1; font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .rname small { display: block; font-weight: 600; color: var(--muted); font-size: 12px; }
.rxp { font-weight: 800; color: var(--blue-d); }

/* ── Auth / profilo ── */
.auth { max-width: 420px; margin: 0 auto; padding: 40px 16px; }
.auth h1 { text-align: center; color: var(--green); font-size: 34px; margin-bottom: 4px; }
.auth .sub { text-align: center; color: var(--muted); font-weight: 600; margin-bottom: 24px; }
.field { display: block; margin-bottom: 12px; font-weight: 800; font-size: 14px; }
.field input { display: block; width: 100%; margin-top: 4px; padding: 13px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg2); color: var(--text); font: inherit; font-weight: 600; }
.field input:focus { outline: none; border-color: var(--blue); }
.err { background: var(--bad-bg); color: var(--bad-t); padding: 10px 14px; border-radius: 12px; font-weight: 700; margin-bottom: 12px; }
.profile { text-align: center; padding-top: 20px; } .profile .avatar { width: 88px; height: 88px; font-size: 38px; margin: 0 auto 10px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin: 20px 0; }
.kpi { border: 2px solid var(--line); border-radius: 14px; padding: 12px 4px; } .kpi b { display: block; font-size: 24px; } .kpi span { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 24px; }
.badge { border: 2px solid var(--line); border-radius: 14px; padding: 10px 4px; font-size: 13px; font-weight: 800; } .badge.off { opacity: .35; filter: grayscale(1); } .badge i { display: block; font-size: 28px; font-style: normal; }
.spacer { height: 12px; }
.center { text-align: center; } .muted { color: var(--muted); }

/* ── Libreria tattiche ── */
.cat-h { margin: 18px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.vchips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.vchips button { flex: 0 0 auto; text-align: left; padding: 8px 14px; border-radius: 14px; border: 2px solid var(--line); border-bottom-width: 4px; background: var(--card); line-height: 1.2; }
.vchips button b { display: block; font-size: 14px; } .vchips button small { color: var(--muted); font-weight: 700; font-size: 12px; }
.vchips button.on { border-color: var(--blue); background: rgba(28,176,246,.12); } .vchips button.on small { color: var(--blue-d); }
.anim { margin: 4px 0 14px; border: 2px solid var(--line); border-radius: 16px; overflow: hidden; background: var(--card); }
.anim svg { display: block; width: 100%; height: auto; }
.legend.big { padding: 8px 12px 0; flex-wrap: wrap; gap: 10px; }
.acap { padding: 8px 14px 4px; font-weight: 600; min-height: 92px; } .acap b { display: block; font-size: 12px; text-transform: uppercase; color: var(--blue-d); letter-spacing: .05em; }
.actl { display: flex; align-items: center; gap: 8px; padding: 6px 12px 12px; }
.actl button { border: 2px solid var(--line); border-bottom-width: 4px; background: var(--card); border-radius: 12px; width: 44px; height: 40px; font-size: 16px; }
.actl button.play { background: var(--green); border-color: var(--green-d); color: #fff; width: 56px; }
.actl button.speed { width: 52px; font-size: 13px; font-weight: 800; }
.dots { flex: 1; display: flex; justify-content: center; gap: 8px; }
.dots i { width: 12px; height: 12px; border-radius: 50%; background: var(--line); cursor: pointer; }
.dots i.past { background: var(--green); opacity: .6; } .dots i.on { background: var(--green); transform: scale(1.35); }
img.schema { width: 100%; height: auto; border-radius: 14px; border: 2px solid var(--line); }
ol.steps { padding-left: 22px; } ol.steps li { margin-bottom: 8px; }

.gifbtn { margin: 4px 0 16px; font-size: 14px; }
