/* Palette: neutri leggermente freddi + indaco profondo come unico accento.
   Tre stati di tema: chiaro (default), scuro di sistema, scelta esplicita via data-theme. */
:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #16202e;
  --muted: #5a6577;
  --line: #dde2ec;
  --primary: #2f4bd0;
  --primary-text: #ffffff;
  --ok: #15703f;
  --ok-bg: #dcf3e4;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --warn: #8a5a00;
  --warn-bg: #fdf1d6;
  --chip: #e6eaf4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22,32,46,.05), 0 6px 20px rgba(22,32,46,.06);
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-display: "Newsreader", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101725;
    --card: #1a2436;
    --text: #e3e8f0;
    --muted: #9aa5b8;
    --line: #2d3a4f;
    --primary: #93b0ff;
    --primary-text: #101725;
    --ok: #6ee7a3;
    --ok-bg: #10402a;
    --bad: #ff9b93;
    --bad-bg: #4d1a17;
    --warn: #f5c451;
    --warn-bg: #4a3610;
    --chip: #24314a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #101725;
  --card: #1a2436;
  --text: #e3e8f0;
  --muted: #9aa5b8;
  --line: #2d3a4f;
  --primary: #93b0ff;
  --primary-text: #101725;
  --ok: #6ee7a3;
  --ok-bg: #10402a;
  --bad: #ff9b93;
  --bad-bg: #4d1a17;
  --warn: #f5c451;
  --warn-bg: #4a3610;
  --chip: #24314a;
  --shadow: none;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .5rem;
  padding: calc(.5rem + env(safe-area-inset-top)) .75rem .5rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; font-family: var(--font-display); font-size: 1.15rem; margin: 0; text-align: center; font-weight: 600; letter-spacing: .01em; }
.iconbtn {
  background: none; border: 0; font-size: 1.35rem; padding: .35rem .5rem; cursor: pointer;
  border-radius: 10px; color: var(--text);
}
.iconbtn:hover { background: var(--chip); }
.view { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 1rem .9rem 2rem; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: .5rem 1rem calc(.75rem + env(safe-area-inset-bottom)); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--line);
}
.card h2 { margin: 0 0 .8rem; font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; text-wrap: balance; }
.card h3 { margin: 1.2rem 0 .5rem; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.prose p { margin: .5rem 0; }
.prose ul { padding-left: 1.2rem; }
.prose a { color: var(--primary); word-break: break-all; }

.form .field { display: block; margin-bottom: 1rem; }
.form .field > span { display: block; font-weight: 600; margin-bottom: .4rem; font-size: .95rem; }
.form .field.check { display: flex; align-items: center; gap: .6rem; }
.form .field.check span { font-weight: 500; margin: 0; }
.form .field.check input { width: 1.25rem; height: 1.25rem; }
select, .search {
  width: 100%; font: inherit; padding: .65rem .75rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg button, .chip {
  font: inherit; font-size: .95rem; padding: .45rem .85rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--chip); color: var(--text); cursor: pointer;
}
.seg button.on, .chip.on { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
details.fonti { margin-bottom: 1rem; }
details.fonti > summary { font-weight: 600; font-size: .95rem; cursor: pointer; padding: .2rem 0; }
details.fonti > summary small { font-weight: 400; }
details.fonti > p { margin: .4rem 0 .5rem; }
.chips .chip { font-size: .85rem; padding: .35rem .7rem; }
.chips .chip small { opacity: .75; }

.btn {
  font: inherit; font-weight: 600; padding: .8rem 1rem; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  cursor: pointer; text-align: center; width: 100%;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.big { padding: 1rem; font-size: 1.1rem; margin-top: .4rem; }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: 0; color: var(--muted); font-weight: 500; width: auto; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { font-size: .85rem; padding: .5rem .8rem; width: auto; margin-top: 1rem; }
.btn small { display: block; font-weight: 400; color: inherit; opacity: .8; font-size: .8rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

/* quiz */
.progress { height: 6px; background: var(--chip); border-radius: 999px; overflow: hidden; margin-bottom: .6rem; }
.progress .bar { height: 100%; width: 0; background: var(--primary); transition: width .25s; }
.qmeta { display: flex; justify-content: space-between; align-items: center; gap: .5rem; color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }
.tag { background: var(--chip); padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; white-space: nowrap; }
.timer { font-variant-numeric: tabular-nums; }
.qtext { font-family: var(--font-display); font-size: 1.24rem; font-weight: 600; line-height: 1.35; margin: 0 0 1rem; text-wrap: pretty; }
.options { display: flex; flex-direction: column; gap: .55rem; }
.opt {
  display: flex; gap: .75rem; align-items: flex-start; text-align: left;
  font: inherit; padding: .85rem .9rem; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--line); background: var(--bg); color: var(--text); width: 100%;
}
.opt .letter {
  flex: 0 0 1.7rem; height: 1.7rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--chip); font-weight: 700; font-size: .85rem;
}
.opt.sel { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--bg)); }
.opt.sel .letter { background: var(--primary); color: var(--primary-text); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.right .letter { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.wrong .letter { background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
.feedback { margin-top: .9rem; padding: .75rem .9rem; border-radius: 10px; font-weight: 600; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }
.feedback.skip { background: var(--warn-bg); color: var(--warn); }
.warn-key { margin-top: .5rem; font-size: .8rem; color: var(--warn); background: var(--warn-bg); padding: .5rem .7rem; border-radius: 8px; }
.actions { display: flex; gap: .6rem; margin-top: .25rem; }
.actions.sub { justify-content: center; margin-top: .4rem; }
.actions .btn.ghost { flex: 0 0 38%; }

/* result */
.result .score { text-align: center; margin: .5rem 0 1rem; }
.result .score .big { font-family: var(--font-display); font-size: 3rem; font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-nums; }
.scorerow { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; text-align: center; margin-bottom: .75rem; }
.scorerow > div { background: var(--bg); border-radius: 10px; padding: .6rem .3rem; }
.scorerow strong { display: block; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.scorerow small { color: var(--muted); font-size: .75rem; }
.filterrow { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.rlist .ritem { border-left: 5px solid var(--line); }
.rlist .ritem.right { border-left-color: var(--ok); }
.rlist .ritem.wrong { border-left-color: var(--bad); }
.rlist .ritem.skipped { border-left-color: var(--warn); }
.ritem .rq { font-weight: 600; margin: 0 0 .5rem; }
.ritem .rq .num { color: var(--muted); font-weight: 500; margin-right: .3rem; }
.ritem ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .3rem; }
.ritem li { padding: .45rem .6rem; border-radius: 8px; background: var(--bg); font-size: .95rem; }
.ritem li.right { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.ritem li.wrong { background: var(--bad-bg); color: var(--bad); text-decoration: line-through; }
.ritem li .mark { font-weight: 700; margin-right: .35rem; }
.ritem .src { margin: .5rem 0 0; font-size: .78rem; color: var(--muted); }
.pill { display: inline-block; font-size: .72rem; padding: .1rem .5rem; border-radius: 999px; margin-left: .4rem; vertical-align: middle; }
.pill.right { background: var(--ok-bg); color: var(--ok); }
.pill.wrong { background: var(--bad-bg); color: var(--bad); }
.pill.skipped { background: var(--warn-bg); color: var(--warn); }

/* history */
.topicstats .row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; padding: .35rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.topicstats .meter { height: 6px; background: var(--chip); border-radius: 999px; overflow: hidden; grid-column: 1 / -1; }
.topicstats .meter > div { height: 100%; background: var(--ok); }
.hlist { list-style: none; padding: 0; margin: 0; }
.hlist li { display: flex; justify-content: space-between; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.hlist li button { font: inherit; background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; }

/* orali */
.orale { font-family: var(--font-display); font-size: 1.2rem; font-weight: 500; line-height: 1.4; min-height: 6rem; display: grid; place-items: center; text-align: center; padding: 1rem .5rem; background: var(--bg); border-radius: 12px; margin-bottom: .8rem; }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
kbd { font-family: inherit; background: var(--chip); border-radius: 5px; padding: 0 .35rem; font-size: .8em; }

/* accessibilità */
:where(a, button, input, select, summary, .opt):focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 8px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
