:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #15201e;
  --muted: #5d6b68;
  --line: #dde4e2;
  --brand: #0f766e;
  --brand-soft: #d6efec;
  --ok: #15803d;
  --ok-soft: #dcf3e3;
  --bad: #b42318;
  --bad-soft: #fde4e1;
  --warn: #92400e;
  --warn-soft: #fdf0d8;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 14px rgba(16, 24, 22, .05);
  --tabbar-h: 48px;
  --pad-b: max(6px, calc(env(safe-area-inset-bottom, 0px) - 14px));
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1312;
    --surface: #161e1c;
    --surface-2: #1d2725;
    --text: #e8efed;
    --muted: #94a3a0;
    --line: #26322f;
    --brand: #2dd4bf;
    --brand-soft: #123532;
    --ok: #4ade80;
    --ok-soft: #12301d;
    --bad: #f87171;
    --bad-soft: #3a1714;
    --warn: #fbbf24;
    --warn-soft: #33270e;
    --shadow: none;
    color-scheme: dark;
  }
}

/* colori per argomento */
.c-slate  { --accent: #64748b; }
.c-indigo { --accent: #6366f1; }
.c-teal   { --accent: #0d9488; }
.c-violet { --accent: #8b5cf6; }
.c-red    { --accent: #e11d48; }
.c-amber  { --accent: #d97706; }
.c-orange { --accent: #ea580c; }
.c-cyan   { --accent: #0891b2; }
.c-lime   { --accent: #65a30d; }
.c-pink   { --accent: #db2777; }
.c-fuchsia { --accent: #c026d3; }
.c-blue   { --accent: #2563eb; }
.c-emerald { --accent: #059669; }
.c-sky    { --accent: #0284c7; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; height: 100%; overflow: hidden; background: var(--bg); }
/* struttura fissa: la pagina intera non scorre mai, scorre solo il contenuto in mezzo.
   Così la barra in basso non può spostarsi (rimbalzo di iOS, tastiera, ecc.) */
body {
  margin: 0;
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  overflow: hidden; overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ── barra superiore ── */
.topbar {
  flex: none; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-t) + 8px) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.back[hidden] { display: none; }
.back {
  border: 0; background: none; padding: 6px; margin-left: -8px;
  color: var(--brand); display: grid; place-items: center; border-radius: 10px;
}

/* ── contenitore pagine ── */
main {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
  padding: 16px 16px 28px;
  outline: none;
}
main > .fade { max-width: 720px; margin: 0 auto; }
.h2 { font-size: 22px; font-weight: 750; margin: 8px 0 4px; letter-spacing: -.015em; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.label { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 4px 8px; }

/* ── barra inferiore ── */
.tabbar {
  flex: none; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--pad-b));
  padding-bottom: var(--pad-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  color: var(--muted); font-size: 10.5px; font-weight: 600;
}
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--brand); }

/* ── blocchi ── */
.panel {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 16px;
}
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent, var(--brand)); border-radius: inherit; transition: width .4s ease; }

.hero { display: flex; align-items: center; gap: 16px; }
.ring { width: 76px; height: 76px; flex: none; }
.ring circle { fill: none; stroke-width: 8; }
.ring .bg { stroke: var(--surface-2); }
.ring .fg { stroke: var(--brand); stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset .5s ease; }
.ring text { font-size: 20px; font-weight: 750; fill: var(--text); text-anchor: middle; dominant-baseline: central; }
.hero h2 { margin: 0 0 2px; font-size: 19px; }
.hero p { margin: 0; color: var(--muted); font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 650; font-size: 16px;
  background: var(--brand); color: #fff; cursor: pointer; width: 100%;
}
@media (prefers-color-scheme: dark) { .btn { color: #052421; } }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn:active { transform: scale(.98); }

/* lista argomenti */
.list { display: flex; flex-direction: column; gap: 10px; }
.topic {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.topic .num {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent);
  font-weight: 800; font-size: 16px;
}
.topic .t { font-weight: 650; line-height: 1.3; }
.topic .m { font-size: 13px; color: var(--muted); margin-top: 4px; display: flex; align-items: center; gap: 8px; }
.topic .m .progress { flex: 1; height: 5px; max-width: 120px; }
.chev { width: 18px; height: 18px; color: var(--muted); }
.done-badge { color: var(--ok); font-weight: 700; }

/* ricerca */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 0 12px; margin-bottom: 14px;
}
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input {
  border: 0; outline: 0; background: none; color: var(--text);
  font: inherit; font-size: 16px; padding: 11px 0; width: 100%;
}
.hit { padding: 12px 14px; }
.hit .where { font-size: 12.5px; color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.hit .t { font-weight: 650; margin: 2px 0; }
.hit .snip { font-size: 14.5px; color: var(--muted); }
mark { background: var(--warn-soft); color: inherit; border-radius: 3px; padding: 0 2px; }

/* sezioni (fisarmonica) */
.sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.sec + .sec { margin-top: 10px; }
.sec > summary {
  list-style: none; cursor: pointer;
  display: grid; grid-template-columns: 22px 1fr 18px; align-items: center; gap: 12px;
  padding: 15px 14px; font-weight: 650; line-height: 1.3;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary .chev { transition: transform .2s ease; transform: rotate(90deg); }
.sec[open] > summary .chev { transform: rotate(-90deg); }
.dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line); display: grid; place-items: center;
}
.dot.on { background: var(--ok); border-color: var(--ok); }
.dot.on::after { content: ""; width: 10px; height: 6px; border: solid #fff; border-width: 0 0 2.4px 2.4px; transform: translateY(-1px) rotate(-45deg); }
.sec .body { padding: 0 16px 16px; border-top: 1px solid var(--line); }

/* testo di studio */
.body { font-size: 16.5px; line-height: 1.58; }
.body p { margin: 14px 0 0; }
.body ul, .body ol { margin: 12px 0 0; padding-left: 22px; }
.body li { margin: 6px 0; }
.body li::marker { color: var(--accent); font-weight: 700; }
.body b { font-weight: 700; }
.kv { margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.kv-row { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; }
.kv-row + .kv-row { border-top: 1px solid var(--line); }
.kv-row b { color: var(--accent); font-size: 15px; }
.kv-row span { font-size: 15.5px; }
.cards { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.card-row { background: var(--surface-2); border-radius: 12px; padding: 12px; }
.card-title { font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.card-line { display: flex; flex-direction: column; margin-top: 6px; }
.card-line small { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; }
.card-line span { font-size: 15.5px; }
.tip, .alert { margin-top: 14px; border-radius: 12px; padding: 12px 14px; font-size: 15.5px; }
.tip { background: var(--brand-soft); }
.alert { background: var(--warn-soft); border-left: 4px solid var(--warn); }

.mark-btn {
  margin-top: 16px; width: 100%; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 12px; padding: 12px; font-weight: 650; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.mark-btn.on { background: var(--ok-soft); border-color: transparent; color: var(--ok); }

.topic-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.topic-head .num { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); font-weight: 800; font-size: 18px; flex: none; }
.topic-head .info { flex: 1; }
.topic-head .info .m { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.pager a { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 14px; color: var(--muted); }
.pager a b { display: block; color: var(--text); font-size: 15px; }
.pager a.next { text-align: right; }

/* piano ripasso */
.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; cursor: pointer; }
.check + .check { border-top: 1px solid var(--line); }
.check input { appearance: none; -webkit-appearance: none; flex: none; width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line); margin: 1px 0 0; display: grid; place-items: center; }
.check input:checked { background: var(--ok); border-color: var(--ok); }
.check input:checked::after { content: ""; width: 11px; height: 6px; border: solid #fff; border-width: 0 0 2.4px 2.4px; transform: translateY(-1px) rotate(-45deg); }
.check b { display: block; }
.check span { font-size: 14.5px; color: var(--muted); }
.check input:checked + div b { text-decoration: line-through; color: var(--muted); }

/* quiz */
.qmeta { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.qtext { font-size: 19px; font-weight: 700; line-height: 1.35; margin: 14px 0 18px; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  text-align: left; border: 1.5px solid var(--line); background: var(--surface);
  border-radius: 14px; padding: 14px 14px; font-size: 16px; line-height: 1.35; cursor: pointer;
  display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start;
}
.opt .l { width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; font-size: 14px; color: var(--muted); }
.opt.ok { border-color: var(--ok); background: var(--ok-soft); }
.opt.ok .l { background: var(--ok); color: #fff; }
.opt.ko { border-color: var(--bad); background: var(--bad-soft); }
.opt.ko .l { background: var(--bad); color: #fff; }
.opt[disabled] { cursor: default; }
.explain { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-size: 15.5px; }
.explain b { display: block; margin-bottom: 2px; }
.qnav { margin-top: 16px; }
.score { text-align: center; padding: 24px 16px; }
.score .big { font-size: 54px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.score .big small { font-size: 22px; color: var(--muted); font-weight: 650; }
.score .verdict { margin-top: 8px; font-weight: 700; font-size: 18px; }
.score .verdict.ok { color: var(--ok); }
.score .verdict.ko { color: var(--bad); }
.review { margin-top: 10px; }
.review .item { padding: 12px 0; border-top: 1px solid var(--line); font-size: 15px; }
.review .item b { display: block; margin-bottom: 4px; }
.review .right { color: var(--ok); font-weight: 650; }
.best { font-size: 13px; color: var(--muted); }
.best b { color: var(--text); }

/* flashcard */
.fc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fc { perspective: 800px; height: 132px; cursor: pointer; }
.fc-in { position: relative; width: 100%; height: 100%; transition: transform .45s ease; transform-style: preserve-3d; }
.fc.flip .fc-in { transform: rotateY(180deg); }
.fc-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 14px; padding: 12px; display: flex; align-items: center; justify-content: center; text-align: center;
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.fc-front { background: var(--surface); font-size: 14.5px; font-weight: 600; line-height: 1.3; }
.fc-back { background: var(--brand); color: #fff; transform: rotateY(180deg); font-size: 18px; font-weight: 800; line-height: 1.25; }
@media (prefers-color-scheme: dark) { .fc-back { color: #052421; } }
.seg { display: flex; gap: 8px; margin-bottom: 14px; }
.seg button { flex: 1; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px; font-size: 14.5px; font-weight: 650; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.fade { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (min-width: 560px) { .fc-grid { grid-template-columns: repeat(3, 1fr); } }

/* pagina Cerca */
.search.big { padding: 0 8px 0 14px; border-radius: 14px; border-width: 1.5px; }
.search.big:focus-within { border-color: var(--brand); }
.search.big input { font-size: 17px; padding: 13px 0; }
.search input::-webkit-search-cancel-button { display: none; }
.clear { border: 0; background: var(--surface-2); color: var(--muted); width: 28px; height: 28px; border-radius: 50%; font-size: 13px; flex: none; display: grid; place-items: center; }
.clear[hidden] { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 8px 14px; font-size: 15px; font-weight: 600; }
.chip:active { background: var(--brand-soft); }
.res-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.res-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--accent, var(--brand)) 8%, var(--surface)); }
.res-head .t { flex: 1; font-weight: 700; line-height: 1.3; }
.num.sm { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; font-size: 14px; flex: none; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.cnt { font-size: 13px; font-weight: 700; color: var(--accent, var(--brand)); background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; }
.res-item { display: block; padding: 12px 14px; }
.res-item + .res-item { border-top: 1px solid var(--line); }
.res-item .t { font-weight: 650; margin-bottom: 3px; }
.res-item .snip { font-size: 14.5px; color: var(--muted); line-height: 1.45; }
.num-back { font-weight: 800; color: var(--brand); margin-top: 2px; }
.body mark { scroll-margin: 120px; }

/* leggi */
.law-group { margin: 22px 0 8px; font-size: 13px; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.law { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 10px; }
.law-h { display: flex; flex-direction: column; gap: 1px; }
.law-h b { color: var(--accent); font-size: 16px; }
.law-h span { font-size: 14px; color: var(--muted); font-weight: 600; }
.law p { margin: 8px 0 0; font-size: 15.5px; }
.law .law-oss { background: var(--brand-soft); border-radius: 8px; padding: 8px 10px; font-size: 15px; }

/* aree d'esame con più argomenti */
.area-box { border: 1.5px dashed color-mix(in srgb, var(--muted) 40%, transparent); border-radius: calc(var(--radius) + 4px); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.area-head { display: flex; align-items: center; gap: 10px; padding: 2px 4px 2px; }
.area-head .num.sm { --accent: var(--muted); }
.area-head .at { font-weight: 750; font-size: 15px; line-height: 1.3; }
.area-quiz { font-size: 14px; font-weight: 650; color: var(--brand); padding: 2px 4px 4px; }
.area-card .num { background: var(--surface-2); color: var(--text); }
.sub-count { margin-bottom: 2px; }
