/* PatenteGuida — stile base (mobile-first) */
:root {
  --blue: #1a56a8; --blue-dark: #14467a; --blue-light: #e8f0fb;
  --green: #1f8a4c; --green-light: #e7f6ee; --red: #c0392b; --red-light: #fdecea;
  --yellow: #e2b007; --yellow-light: #fff8df; --purple: #5b3da8; --purple-light: #f0ecfb;
  --ink: #1c2530; --muted: #5a6b7d; --line: #dde5ee; --bg: #f4f6fa; --card: #ffffff;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,40,70,.06), 0 4px 14px rgba(20,40,70,.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Liberation Sans", sans-serif;
  /* layout: altezze della barra superiore/inferiore e spaziatura della pagina */
  --topbar-h: 56px; --tabbar-h: 58px; --pad: 1rem;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --bottom-inset: 0px; /* spazio occupato dalla barra inferiore (solo mobile) */
  --focus: #7fb0f0;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + var(--safe-t) + 1rem); overflow-x: clip; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); line-height: 1.5; font-size: 16px;
  padding-bottom: calc(var(--bottom-inset) + var(--safe-b)); min-height: 100vh; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
a, button { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; } h4 { font-size: 1rem; }
p { margin: .4rem 0; }
img { max-width: 100%; }
button { font: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: .5rem; z-index: 200; background: #fff; color: var(--blue-dark); padding: .5rem .8rem; border-radius: 8px; font-weight: 700; }
.skip:focus { left: .5rem; }

/* icone SVG inline (sprite in base.html) */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 1.25em; height: 1.25em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.3em; flex: none; }

/* ------------------------------------------------------------------ */
/* barra superiore                                                       */
/* ------------------------------------------------------------------ */
.topbar { background: var(--blue-dark); color: #fff; position: sticky; top: 0; z-index: 50; box-shadow: 0 2px 8px rgba(0,0,0,.15); padding-top: var(--safe-t); }
.topbar .in { display: flex; align-items: center; gap: .5rem; padding: 0 var(--pad); min-height: var(--topbar-h); max-width: 1100px; margin: 0 auto; }
.brand { font-weight: 800; font-size: 1.15rem; color: #fff; display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.tb-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 10px; color: #fff; background: transparent; border: none; cursor: pointer; flex: none; font-size: 1rem; }
.tb-btn:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.tb-btn.active { background: rgba(255,255,255,.18); }
.menu-btn { margin-left: auto; }
.tb-btn .ico { width: 26px; height: 26px; }
.tb-btn.dark { color: var(--muted); }
.tb-btn.dark:hover { background: var(--bg); }
/* striscia: fiamma accesa (oggi hai studiato) o grigia (non ancora), con i giorni di fila */
.flame { width: 1.25em; height: 1.25em; flex: none; vertical-align: -.25em; --flame-out: #ff6a1a; --flame-in: #ffd23f; }
.off .flame, .flame.off { --flame-out: #aab4bf; --flame-in: #d6dce3; }
.tb-streak { display: inline-flex; align-items: center; gap: .25rem; height: 44px; padding: 0 .55rem; border-radius: 10px; color: #fff; font-weight: 800; font-variant-numeric: tabular-nums; margin-left: auto; position: relative; flex: none; }
.tb-streak:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.tb-streak .flame { width: 24px; height: 24px; }
.tb-streak.off { color: #b9c6d4; }
.tb-streak.off .flame { --flame-out: #7d8fa3; --flame-in: #a3b1c0; }
.tb-streak.lost::after { content: ""; position: absolute; top: 9px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: #ff8a3d; box-shadow: 0 0 0 2px var(--blue-dark); }
.tb-streak.ignite .flame { animation: ignite .9s cubic-bezier(.3,1.6,.5,1); transform-origin: 50% 90%; }
@keyframes ignite { 0% { transform: scale(.3); filter: grayscale(1); } 45% { transform: scale(1.45); filter: drop-shadow(0 0 6px #ffb347); } 100% { transform: scale(1); } }
.tb-streak ~ .menu-btn { margin-left: 0; }
/* obiettivo di oggi raggiunto durante una sessione a schermo intero (fx.streakLit): fiamma che si accende in alto */
.streak-pop { position: fixed; top: calc(var(--topbar-h) + var(--safe-t) + .7rem); left: 50%; z-index: 100; display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem .5rem .7rem; border-radius: 999px; background: #fff; color: var(--ink); box-shadow: 0 8px 24px rgba(20,40,70,.25); white-space: nowrap; pointer-events: none; animation: streak-pop 2.6s ease forwards; }
.streak-pop .flame { width: 36px; height: 36px; animation: ignite .9s .15s cubic-bezier(.3,1.6,.5,1) backwards; transform-origin: 50% 90%; }
@keyframes streak-pop { 0% { opacity: 0; transform: translate(-50%, -12px); } 10%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -12px); } }
.search-btn { margin-left: auto; }
.search-btn ~ .tb-streak, .search-btn ~ .menu-btn { margin-left: 0; }
.tb-title { flex: 1; text-align: center; font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-spacer { width: 44px; flex: none; }

/* menu desktop */
.nav { display: none; align-items: center; gap: .1rem; margin-left: auto; }
.nav a { color: #dbe7f6; padding: .45rem .55rem; border-radius: 8px; font-size: .88rem; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: .35rem; }
.nav a:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 700; }
.nav .sep { width: 1px; height: 22px; background: rgba(255,255,255,.25); margin: 0 .3rem; }
.nav .user { color: #fff; font-weight: 600; background: rgba(255,255,255,.08); }
.cnt { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff; font-size: .68rem; font-weight: 800; line-height: 1; }

/* barra inferiore (mobile) */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b); box-shadow: 0 -2px 10px rgba(20,40,70,.06); }
.tabbar a { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tabbar-h); font-size: .68rem; font-weight: 600; color: var(--muted); position: relative; }
.tabbar a:hover { text-decoration: none; }
.tabbar a.active { color: var(--blue); }
.tabbar a .ico { width: 24px; height: 24px; }
.tabbar a.active .ico { stroke-width: 2.5; }
.tabbar a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tabbar .cnt { position: absolute; top: 5px; left: calc(50% + 4px); }

/* menu "altro" (foglio dal basso) */
.sheet { border: none; padding: 0; margin: 0; width: 100%; max-width: 100%; max-height: 88vh; position: fixed; inset: auto 0 0 0; border-radius: 18px 18px 0 0; background: #fff; color: var(--ink); box-shadow: 0 -10px 40px rgba(0,0,0,.25); overflow: auto; }
.sheet::backdrop { background: rgba(0,0,0,.35); }
.sheet[open] { animation: sheet-up .2s ease-out; }
@keyframes sheet-up { from { transform: translateY(100%); } }
.sheet-in { padding-bottom: calc(var(--safe-b) + .6rem); }
.sheet-grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: .6rem auto .2rem; }
.sheet-user { display: flex; align-items: center; gap: .8rem; padding: .6rem var(--pad) .8rem; border-bottom: 1px solid var(--line); }
.sheet-user .main { flex: 1; min-width: 0; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--blue-light); color: var(--blue-dark); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; flex: none; }
.menu-list { list-style: none; margin: 0; padding: .4rem 0; }
.menu-list a { display: flex; align-items: center; gap: .8rem; width: 100%; min-height: 52px; padding: .7rem var(--pad); color: var(--ink); font-weight: 600; font-size: 1rem; }
.menu-list a:hover { background: var(--bg); text-decoration: none; }
.menu-list a.active { color: var(--blue); background: var(--blue-light); }
.menu-list .ico { width: 22px; height: 22px; color: var(--muted); }
.menu-list a.active .ico { color: var(--blue); }
.menu-list .chev { margin-left: auto; color: #c3ccd6; width: 20px; height: 20px; }
.menu-list .cnt { margin-left: auto; }
.menu-list .cnt + .chev { margin-left: 0; }
.sheet-foot { padding: .4rem var(--pad) 0; border-top: 1px solid var(--line); margin-top: .3rem; }

/* lingua dell'interfaccia: controllo segmentato (impostazioni; piè di pagina delle pagine senza account) */
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; background: var(--card); padding: 2px; gap: 2px; }
.lang-switch button { border: none; background: transparent; color: var(--muted); border-radius: 999px; padding: .3rem .8rem; min-height: 32px; font-size: .85rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.lang-switch button:hover { background: var(--bg); color: var(--ink); }
.lang-switch button.on { background: var(--blue); color: #fff; }
.lang-switch.wide { display: flex; max-width: 420px; margin: .3rem 0 .5rem; }
.lang-switch.wide button { flex: 1 1 0; min-height: 44px; font-size: .92rem; }

/* ------------------------------------------------------------------ */
/* layout                                                                */
/* ------------------------------------------------------------------ */
.wrap { max-width: 1100px; margin: 0 auto; padding: var(--pad); }
.wrap.narrow { max-width: 760px; }
.grid { display: grid; gap: 1rem; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.right { text-align: right; } .center { text-align: center; }
.muted { color: var(--muted); } .small { font-size: .88rem; } .tiny { font-size: .78rem; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; } .mt2 { margin-top: 2rem; }
.nowrap { white-space: nowrap; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* intestazione di pagina: titolo + sottotitolo a sinistra, azioni a destra */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head > div:first-child { min-width: 0; flex: 1 1 260px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: .92rem; margin-top: .15rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem .8rem; flex-wrap: wrap; }
.card-head > div:first-child { min-width: 0; flex: 1 1 200px; }
.card-head h2, .card-head h3 { margin: 0; }

/* briciole di pane */
.crumbs { display: flex; align-items: center; gap: .25rem; font-size: .85rem; color: var(--muted); margin-bottom: .5rem; white-space: nowrap; min-width: 0; }
.crumbs a { color: var(--muted); display: inline-flex; align-items: center; gap: .2rem; }
.crumbs a:hover { color: var(--blue); }
.crumbs .ico { width: 16px; height: 16px; color: #b3bfcc; }
.crumbs .cur { overflow: hidden; text-overflow: ellipsis; color: var(--ink); }

/* elenco a righe (sostituisce le tabelle su mobile) */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li { display: flex; align-items: center; gap: .5rem 1rem; padding: .7rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.rows > li:last-child { border-bottom: none; }
.rows .main { flex: 1 1 220px; min-width: 0; }
.rows .meta { color: var(--muted); font-size: .8rem; }
.rows .mastery { flex: 0 0 170px; }
.rows .acts { display: flex; gap: .4rem; margin-left: auto; align-items: center; }
.rows .badges { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }
.rows li.link { padding: 0; }
.rows li.link > a { display: flex; align-items: center; gap: .5rem 1rem; width: 100%; padding: .7rem 0; color: inherit; flex-wrap: wrap; }
.rows li.link > a:hover { text-decoration: none; background: var(--bg); }
.rows .chev { color: #c3ccd6; width: 20px; height: 20px; margin-left: auto; }

/* paginazione precedente/successivo */
.pager { display: flex; justify-content: space-between; gap: .6rem; margin-top: 2rem; }
.pager > span { flex: 1 1 0; }
.pager a { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); }
.pager a:hover { border-color: var(--blue); text-decoration: none; }
.pager .lbl { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.pager .ttl { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pager a.next { text-align: right; }

/* barre appiccicose nelle sessioni (timer in alto, azioni in basso) */
.sticky-top { position: sticky; top: calc(var(--topbar-h) + var(--safe-t)); z-index: 20; background: var(--bg); margin: calc(-1 * var(--pad)) calc(-1 * var(--pad)) .8rem; padding: .6rem var(--pad); box-shadow: 0 8px 16px -12px rgba(20,40,70,.35); }
.sticky-bottom { position: sticky; bottom: calc(var(--bottom-inset) + var(--safe-b)); z-index: 20; background: var(--bg); margin: .8rem calc(-1 * var(--pad)) 0; padding: .6rem var(--pad); box-shadow: 0 -8px 16px -12px rgba(20,40,70,.35); }

/* cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; }
.card.pad0 { padding: 0; overflow: hidden; }
.card.hl { border-left: 5px solid var(--blue); }
.card.ok { border-left: 5px solid var(--green); background: var(--green-light); }
.card.ko { border-left: 5px solid var(--red); background: var(--red-light); }
.card.warn { border-left: 5px solid var(--yellow); background: var(--yellow-light); }
.card.info { border-left: 5px solid var(--purple); background: var(--purple-light); }
.card h2, .card h3 { margin-top: 0; }
a.card { color: inherit; display: block; }
a.card:hover { text-decoration: none; box-shadow: 0 1px 2px rgba(20,40,70,.08), 0 8px 22px rgba(20,40,70,.12); }
.stat { display: flex; flex-direction: column; gap: .1rem; }
.stat .n { font-size: 1.9rem; font-weight: 800; color: var(--blue-dark); line-height: 1.1; }
.stat .n.red { color: var(--red); } .stat .n.green { color: var(--green); }
.stat .l { font-size: .85rem; color: var(--muted); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid transparent;
  background: var(--blue); color: #fff; padding: .55rem 1rem; min-height: 44px; border-radius: 10px; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: filter .12s, transform .05s; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.sec { background: #fff; color: var(--blue-dark); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--blue); }
.btn.green { background: var(--green); } .btn.red { background: var(--red); }
.btn.yellow { background: var(--yellow); color: #3b2f00; } .btn.purple { background: var(--purple); }
.btn.big { padding: .9rem 1.4rem; min-height: 52px; font-size: 1.1rem; border-radius: 12px; }
.btn.sm { padding: .3rem .65rem; min-height: 36px; font-size: .85rem; border-radius: 8px; }
.btn.wide { width: 100%; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }

/* badges & bars */
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--blue-light); color: var(--blue-dark); white-space: nowrap; }
.badge.ok { background: var(--green-light); color: var(--green); }
.badge.ko { background: var(--red-light); color: var(--red); }
.badge.warn { background: var(--yellow-light); color: #8a6400; }
.badge.purple { background: var(--purple-light); color: var(--purple); }
.badge.grey { background: #eef1f5; color: var(--muted); }
.bar { height: 8px; background: #e6ebf2; border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: 999px; }
.bar.strong > i { background: var(--green); } .bar.mid > i { background: var(--yellow); } .bar.weak > i { background: var(--red); }
.bar.none > i { background: #c9d2dd; }
.pill-list { display: flex; flex-wrap: wrap; gap: .4rem; }
.pill { display: inline-flex; align-items: center; min-height: 36px; padding: .3rem .8rem; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: .88rem; color: var(--ink); }
.pill.active, .pill:hover { background: var(--blue); color: #fff; border-color: var(--blue); text-decoration: none; }
.pill-scroll { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; padding: .2rem 0; margin: 0 calc(-1 * var(--pad)); padding-left: var(--pad); padding-right: var(--pad); }
.pill-scroll::-webkit-scrollbar { display: none; }
.pill-scroll .pill { flex: none; }

/* forms */
label { display: block; font-weight: 600; margin: .6rem 0 .25rem; font-size: .92rem; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-light); border-color: var(--blue); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .8rem; }
.field-row.compact { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.field-row label { margin-top: 0; }
.alert { padding: .7rem 1rem; border-radius: 10px; margin: .6rem 0; }
.alert.err { background: var(--red-light); color: var(--red); }
.alert.ok { background: var(--green-light); color: var(--green); }
.alert.info { background: var(--blue-light); color: var(--blue-dark); }
.search { display: flex; gap: .4rem; }
.search input { flex: 1; min-width: 0; }

/* tables / lists */
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .02em; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.weak-table .weak-mastery { min-width: 140px; }
.mobile-only { display: none; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }

/* question */
.q-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.q-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.q-body { display: flex; gap: 1rem; align-items: flex-start; }
.q-img { flex: 0 0 auto; width: 120px; }
.q-img img { width: 120px; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.q-text { font-size: 1.15rem; font-weight: 500; line-height: 1.5; flex: 1; }
.q-text .w { cursor: pointer; border-radius: 4px; padding: 0 1px; }
.q-text .w:hover { background: var(--yellow-light); }
.q-text .w.hl { background: var(--yellow-light); box-shadow: 0 2px 0 var(--yellow); }
.q-tr { margin-top: .6rem; padding: .6rem .8rem; background: var(--purple-light); border-radius: 10px; font-size: .98rem; }
.vf { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin-top: 1rem; }
.vf button { text-align: center; padding: .95rem; min-height: 56px; font-size: 1.15rem; font-weight: 800; border-radius: 12px; border: 2px solid var(--line); background: #fff; cursor: pointer; color: var(--ink); }
.vf button.v:hover, .vf button.v.sel { border-color: var(--green); background: var(--green-light); color: var(--green); }
.vf button.f:hover, .vf button.f.sel { border-color: var(--red); background: var(--red-light); color: var(--red); }
.vf:has(.idk) { grid-template-columns: 1fr 1fr auto; }
.vf button.idk { font-size: .95rem; font-weight: 700; background: var(--yellow-light); border-color: var(--yellow); color: #8a6a00; }
.vf button.idk:hover { background: #fdeeb5; }
.vf button:disabled { cursor: default; }
.vf button.is-right { border-color: var(--green); background: var(--green-light); color: var(--green); }
.vf button.is-wrong { border-color: var(--red); background: var(--red-light); color: var(--red); }
.feedback { margin-top: .9rem; padding: .8rem 1rem; border-radius: 12px; }
.feedback.ok { background: var(--green-light); border-left: 5px solid var(--green); }
.feedback.ko { background: var(--red-light); border-left: 5px solid var(--red); }
.feedback .title { font-weight: 800; font-size: 1.05rem; }
.hint { margin-top: .8rem; padding: .7rem .9rem; border-radius: 12px; background: var(--yellow-light); border-left: 5px solid var(--yellow); }
.hint .title { font-weight: 800; }
.hint-after { margin-top: .4rem; color: #6b5300; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.chips .badge { font-weight: 600; }
.debrief-text { margin-top: .6rem; font-size: 1.02rem; line-height: 1.5; }
.key-line { margin: .35rem 0 .15rem; font-weight: 600; line-height: 1.45; }
.key-line .kw { background: var(--yellow-light); box-shadow: 0 2px 0 var(--yellow); border-radius: 3px; padding: 0 2px; font-weight: 800; }
.key-native { color: var(--muted); font-size: .88rem; margin-bottom: .4rem; }
.key-line + .key-native + div, .key-line + div[lang="it"] { margin-top: .3rem; }
mark.diff { background: var(--yellow-light); color: inherit; box-shadow: 0 2px 0 var(--yellow); border-radius: 3px; padding: 0 1px; }
mark.num { border-radius: 4px; padding: 0 3px; font-weight: 700; }
mark.num.ok { background: var(--green-light); color: var(--green); }
mark.num.ko { background: var(--red-light); color: var(--red); text-decoration: line-through; }
body.hide-num mark.num:not(.shown) { background: #e6ebf2; color: transparent; text-decoration: none; cursor: pointer; min-width: 2.2em; display: inline-block; text-align: center; }
.num-block { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.num-block:last-child { border-bottom: none; }
.num-img { width: 44px; height: 44px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 2px; }
.rules tr.ex td { padding-top: 0; border-bottom: 1px solid var(--line); }
.rules tr.ex .stmt { border-bottom: none; padding: .15rem 0; }
.siblings { margin-top: .7rem; }
.siblings li { font-size: .9rem; padding: .3rem 0; border-bottom: 1px dashed var(--line); }
.siblings .vf-tag { display: inline-block; width: 2.6rem; font-weight: 800; font-size: .78rem; }
.vf-tag.v { color: var(--green); } .vf-tag.f { color: var(--red); }
.q-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .8rem; }
.q-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; gap: .5rem; flex-wrap: nowrap; }
.q-footer .btn { flex: none; }
.progress { display: flex; gap: .4rem; align-items: center; font-size: .9rem; color: var(--muted); min-width: 0; flex-wrap: wrap; }
.progress .bar { width: 120px; }

/* exam grid */
.exam-top { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .8rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.3rem; padding: .3rem .8rem; border-radius: 10px; background: var(--blue-light); color: var(--blue-dark); }
.timer.low { background: var(--red-light); color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.qgrid { display: grid; grid-template-columns: repeat(10, 1fr); gap: .3rem; margin-top: .8rem; }
.qgrid button { aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; font-size: .85rem; padding: 0; }
.qgrid button.cur { outline: 3px solid var(--blue); }
.qgrid button.a { background: var(--blue-light); color: var(--blue-dark); }
.qgrid button.d { background: var(--yellow-light); border-color: var(--yellow); }
.qgrid button.ok { background: var(--green-light); color: var(--green); border-color: var(--green); }
.qgrid button.ko { background: var(--red-light); color: var(--red); border-color: var(--red); }

/* flashcards */
.fc-rate { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .5rem; margin-top: .9rem; }
.fc-rate button { padding: .7rem .3rem; min-height: 56px; min-width: 0; border-radius: 10px; border: 2px solid var(--line); background: #fff; cursor: pointer; font-weight: 700; }
.fc-rate button small { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; }
.fc-rate .again { border-color: var(--red); color: var(--red); } .fc-rate .hard { border-color: var(--yellow); color: #8a6400; }
.fc-rate .good { border-color: var(--green); color: var(--green); } .fc-rate .easy { border-color: var(--blue); color: var(--blue); }
.fc-word { font-size: 2rem; font-weight: 800; text-align: center; padding: 1.5rem 0; color: var(--blue-dark); }
.fc-answer { text-align: center; font-size: 1.4rem; padding: .5rem 0; }
.counts { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; font-size: .9rem; }
.counts > span { white-space: nowrap; }
.counts b { font-weight: 800; }
.counts .new { color: var(--blue); } .counts .learn { color: var(--red); } .counts .rev { color: var(--green); }
/* statistiche delle flashcard: barra delle parti con legenda, colonne per giorno (suggerimento al passaggio) */
.k-new, .k-due, .k-g3 { background: var(--blue); } .k-learn, .k-again, .k-g0 { background: var(--red); }
.k-young { background: #6cbf8c; } .k-mature, .k-ok, .k-g2 { background: var(--green); } .k-g1 { background: #c99400; }
.stack { display: flex; gap: 2px; height: 14px; margin: .6rem 0 .2rem; }
.stack > i { flex: 1 1 0; min-width: 3px; }
.stack > i:first-child { border-radius: 4px 0 0 4px; } .stack > i:last-child { border-radius: 0 4px 4px 0; }
.stack > i:only-child { border-radius: 4px; }
.legend { list-style: none; margin: .4rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .2rem 1.1rem; font-size: .88rem; }
.legend li, .legend a { display: inline-flex; align-items: center; gap: .4rem; }
.legend a { color: var(--ink); min-height: 32px; }
.key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cols { display: flex; gap: 2px; height: 110px; padding-top: 1.1rem; margin-top: .4rem; border-bottom: 1px solid var(--line); }
.cols > span { flex: 1 1 0; min-width: 0; position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; }
.cols > span > i { width: 100%; max-width: 24px; min-height: 2px; }
.cols > span > i:first-child { border-radius: 4px 4px 0 0; }
.cols > span:hover > i { filter: brightness(1.15); }
.cols .cap { position: absolute; font-size: .75rem; line-height: 1; font-variant-numeric: tabular-nums; }
.cols > span:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 0; z-index: 5; background: var(--ink); color: #fff; font-size: .78rem; padding: .25rem .5rem; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.cols > span.r:hover::after { left: auto; right: 0; }
.cols-x { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: .25rem; font-variant-numeric: tabular-nums; }
.fc-list { margin-top: .4rem; }
.fc-list .late { color: var(--red); font-weight: 600; }
.sr .tag.w { background: var(--purple-light); color: var(--purple); }

/* signs trainer */
.sign-img { text-align: center; padding: .5rem 0; }
.sign-img img { width: 180px; height: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 6px; }
.options { display: grid; gap: .5rem; margin-top: .8rem; }
.options button { text-align: left; padding: .7rem .9rem; min-height: 48px; border-radius: 10px; border: 2px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; }
.options button:hover { border-color: var(--blue); }
.options button.is-right { border-color: var(--green); background: var(--green-light); }
.options button.is-wrong { border-color: var(--red); background: var(--red-light); }

/* topic blocks */
.block { border: 1px solid var(--line); border-radius: 12px; margin-bottom: .7rem; background: #fff; overflow: hidden; }
.block > summary { list-style: none; cursor: pointer; display: flex; gap: .8rem; align-items: center; padding: .7rem .9rem; min-height: 52px; }
.block > summary::-webkit-details-marker { display: none; }
.block > summary img { width: 54px; height: 54px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 2px; }
.block .b-name { font-weight: 700; flex: 1; }
.block .b-body { padding: 0 .9rem .9rem; border-top: 1px solid var(--line); }
.stmt { display: flex; gap: .6rem; padding: .4rem 0; border-bottom: 1px dashed var(--line); align-items: flex-start; }
.stmt:last-child { border-bottom: none; }
.stmt .tag { flex: 0 0 auto; width: 3.4rem; text-align: center; font-weight: 800; font-size: .78rem; border-radius: 6px; padding: .15rem 0; }
.stmt .tag.v { background: var(--green-light); color: var(--green); } .stmt .tag.f { background: var(--red-light); color: var(--red); }
.stmt .tag.hidden { background: #eef1f5; color: var(--muted); cursor: pointer; }
.stmt .txt { flex: 1; }
.stmt .st { flex: 0 0 auto; font-size: .8rem; }
.stmt .why { display: block; color: var(--muted); font-size: .86rem; margin-top: .15rem; }
/* ricerca: una riga per domanda trovata, tutta cliccabile */
mark.hit { background: var(--yellow-light); color: inherit; font-weight: 700; border-radius: 3px; padding: 0 1px; }
.search-results { padding-top: .2rem; padding-bottom: .2rem; }
.sr { display: flex; gap: .6rem; padding: .6rem 0; border-bottom: 1px solid var(--line); align-items: flex-start; color: inherit; }
.sr:last-child { border-bottom: none; }
.sr:hover { text-decoration: none; background: var(--bg); }
.sr .tag, .ta-q .tag { flex: 0 0 auto; width: 3.4rem; text-align: center; font-weight: 800; font-size: .78rem; border-radius: 6px; padding: .15rem 0; margin-top: .1rem; }
.sr .tag.v, .ta-q .tag.v { background: var(--green-light); color: var(--green); } .sr .tag.f, .ta-q .tag.f { background: var(--red-light); color: var(--red); }
.sr-main { flex: 1; min-width: 0; }
.sr-main .txt { display: block; }
.sr-main .meta { display: block; color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.sr-img { flex: none; width: 52px; height: 52px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 2px; }
/* suggerimenti mentre si scrive (search.js): elenco sotto la casella, il focus resta nella casella */
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.ta { flex: 1; min-width: 0; position: relative; }
.ta-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 40; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(20,40,70,.18); overflow-y: auto; overscroll-behavior: contain; padding: .25rem 0; }
.ta-list > div + div { border-top: 1px solid var(--line); margin-top: .25rem; padding-top: .25rem; }
.ta-head { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .4rem .8rem .1rem; }
.ta-opt { display: flex; align-items: center; gap: .6rem; min-height: 44px; padding: .4rem .8rem; color: var(--ink); }
.ta-opt:hover { text-decoration: none; }
.ta-opt.active { background: var(--blue-light); }
.ta-opt > .ico { color: var(--muted); }
.ta-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ta-n { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.ta-fill, .ta-del { flex: none; display: grid; place-items: center; width: 36px; height: 36px; margin: -.4rem -.5rem -.4rem 0; border-radius: 8px; color: var(--muted); font-size: 1.2rem; }
.ta-fill:hover, .ta-del:hover { background: var(--card); color: var(--ink); }
.ta-q { align-items: flex-start; padding-top: .5rem; padding-bottom: .5rem; }
.ta-qtxt { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .92rem; line-height: 1.35; }
.ta-q .meta { display: block; color: var(--muted); font-size: .76rem; margin-top: .15rem; }
.ta-q .sr-img { width: 40px; height: 40px; }
.ta-all { justify-content: center; color: var(--blue); font-weight: 600; font-size: .92rem; }
@media (max-width: 640px) { .ta-topic { display: none; } .ta-q .tag { width: 3rem; } }
.topic-tabs { display: flex; gap: .3rem; border-bottom: 2px solid var(--line); margin: 1rem 0; overflow-x: auto; scrollbar-width: none; }
.topic-tabs::-webkit-scrollbar { display: none; }
.topic-tabs a { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .55rem .8rem; min-height: 44px; border-bottom: 3px solid transparent; margin-bottom: -2px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.topic-tabs a.active { color: var(--blue-dark); border-color: var(--blue); }
.topic-tabs a:hover { text-decoration: none; color: var(--blue-dark); }
.topic-tabs .badge { font-size: .72rem; padding: .05rem .4rem; }

/* markdown notes */
.md h4 { margin-top: 1rem; padding: .35rem .7rem; border-radius: 8px; background: var(--blue-light); color: var(--blue-dark); }
.md table { margin: .6rem 0; } .md td img { height: 56px; width: auto; }
.md img { max-height: 70px; width: auto; vertical-align: middle; }
.md img.fig { display: block; width: 260px; max-width: 100%; height: auto; max-height: none; margin: .6rem 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.md blockquote { margin: .5rem 0; padding: .5rem .9rem; background: var(--blue-light); border-left: 4px solid var(--blue); border-radius: 0 8px 8px 0; }
.md ul { padding-left: 1.3rem; }

/* popover traduzione */
.pop { position: absolute; z-index: 80; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(20,40,70,.18); padding: .8rem .9rem; width: min(320px, calc(100vw - 2rem)); font-size: .95rem; }
.pop .term { font-weight: 800; color: var(--blue-dark); }
.pop .tr { font-size: 1.1rem; font-weight: 700; margin: .2rem 0; }
.pop .ex { color: var(--muted); font-size: .88rem; }
.pop .close { position: absolute; right: .2rem; top: .2rem; width: 36px; height: 36px; border: none; background: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); border-radius: 8px; }

/* tutor drawer */
.drawer { position: fixed; inset: 0 0 0 auto; width: min(440px, 100vw); background: #fff; z-index: 90; box-shadow: -6px 0 30px rgba(0,0,0,.18); transform: translateX(100%); transition: transform .2s; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer .d-head { padding: .6rem .6rem .6rem 1rem; padding-top: calc(.6rem + var(--safe-t)); background: var(--blue-dark); color: #fff; display: flex; align-items: center; gap: .5rem; min-height: var(--topbar-h); }
.drawer .d-head .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.drawer .d-head button { margin-left: auto; background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer; width: 44px; height: 44px; border-radius: 10px; flex: none; }
.drawer .d-head button:hover { background: rgba(255,255,255,.12); }
.drawer .d-ctx { padding: .5rem 1rem; background: var(--blue-light); font-size: .85rem; color: var(--blue-dark); border-bottom: 1px solid var(--line); max-height: 90px; overflow: auto; }
.drawer .d-msgs { flex: 1; overflow-y: auto; padding: .8rem 1rem; display: flex; flex-direction: column; gap: .6rem; overscroll-behavior: contain; }
.msg { max-width: 92%; padding: .6rem .8rem; border-radius: 12px; font-size: .95rem; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: #f1f4f8; border-bottom-left-radius: 4px; }
.msg.assistant.md { white-space: normal; } .msg.assistant.md p { margin: .25rem 0; } .msg.assistant.md ul { padding-left: 1.2rem; margin: .25rem 0; }
.drawer .d-chips { padding: .3rem 1rem; display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; }
.drawer .d-chips::-webkit-scrollbar { display: none; }
.drawer .d-chips button { font-size: .8rem; padding: .35rem .7rem; min-height: 32px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; white-space: nowrap; flex: none; }
.drawer .d-form { display: flex; gap: .5rem; padding: .7rem 1rem; padding-bottom: calc(.7rem + var(--safe-b)); border-top: 1px solid var(--line); }
.drawer .d-form input { flex: 1; min-width: 0; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 85; display: none; }
.backdrop.open { display: block; }
.fab { position: fixed; right: 1rem; bottom: calc(1rem + var(--bottom-inset) + var(--safe-b)); z-index: 60; border-radius: 999px; padding: .7rem 1rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); }

/* activity chart */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 60px; }
.spark i { flex: 1; background: var(--blue); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.spark i.today { background: var(--yellow); }
.exam-dots { display: flex; gap: 4px; flex-wrap: wrap; }
.exam-dots a, .exam-dots b { width: 26px; height: 26px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 800; color: #fff; }
.exam-dots .ok { background: var(--green); } .exam-dots .ko { background: var(--red); }

/* striscia nella dashboard: numero con fiamma; riquadro per recuperare la striscia persa */
.stat .n .flame { width: .9em; height: .9em; vertical-align: -.08em; margin-right: .1rem; }
.streak-lost { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; border-left: 5px solid #ff6a1a; background: #fff3ea; }
.streak-lost .flame { width: 48px; height: 48px; }
.streak-lost .main { flex: 1 1 220px; min-width: 0; }
.streak-lost .btn { background: #e8590c; }

.readiness { padding: 1rem; border-radius: 12px; color: #fff; }
.readiness.lvl-none { background: #7a8794; } .readiness.lvl-weak { background: var(--red); } .readiness.lvl-progress { background: #d58a00; }
.readiness.lvl-almost { background: #2a7fbf; } .readiness.lvl-ready { background: var(--green); }
.readiness .big { font-size: 1.4rem; font-weight: 800; }
.readiness .prob { font-size: 1.1rem; font-weight: 700; opacity: .9; margin-left: .3rem; white-space: nowrap; }

footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 1rem; }
footer .lang-switch { margin-bottom: .8rem; }
.hidden { display: none !important; }
.loading { opacity: .6; pointer-events: none; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 120; }
.toast { position: fixed; left: 50%; bottom: calc(1.2rem + var(--bottom-inset) + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 10px; z-index: 100; font-size: .92rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100vw - 2rem); }

/* ------------------------------------------------------------------ */
/* responsive                                                            */
/* ------------------------------------------------------------------ */
/* desktop: menu completo nella barra superiore, niente barra inferiore (da 1000 px: 11 voci + utente) */
@media (min-width: 1000px) {
  .nav { display: flex; }
  .menu-btn, .tabbar, .sheet { display: none; }
  .nav a { padding: .45rem .48rem; }
  .tb-streak { margin-left: 0; padding: 0 .35rem; }
  .search-btn { margin-left: 0; width: 36px; }
}
/* desktop stretto: dell'utente resta solo l'icona (il nome è nel menu Impostazioni), del marchio il semaforo */
@media (min-width: 1000px) and (max-width: 1199px) {
  .nav .user span, .brand span { display: none; }
  .nav a { padding: .45rem .36rem; }
}
/* amministratori: lo scudo del pannello prende il posto del nome dell'utente anche sul desktop largo */
@media (min-width: 1200px) { .nav.with-admin .user span { display: none; } }
/* mobile e tablet: barra inferiore + menu "altro" */
@media (max-width: 999px) {
  :root { --topbar-h: 52px; }
  body.has-tabbar { --bottom-inset: var(--tabbar-h); }
}
@media (max-width: 640px) {
  :root { --pad: .8rem; }
  h1 { font-size: 1.45rem; }
  .q-body { flex-direction: column; }
  .q-img { width: 100%; text-align: center; }
  .q-img img { width: 150px; }
  .q-text { font-size: 1.08rem; }
  .qgrid { grid-template-columns: repeat(6, 1fr); }
  .fc-rate { gap: .35rem; }
  .fc-rate button { font-size: .88rem; }
  .fc-rate button small { font-size: .68rem; }
  .mobile-only { display: inline; }
  .m-wide { width: 100%; }
  .grid.c4 { grid-template-columns: repeat(2, 1fr); }
  .page-head .actions { width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .page-head .actions .btn { width: 100%; }
  .card-head .btn-group { width: 100%; }
  .card-head .btn-group .btn { flex: 1 1 auto; }
  .rows .mastery { flex: 1 1 100%; order: 3; }
  .rows .acts { order: 2; }
  .rows .acts .btn { flex: 1 1 auto; }
  .topic-tabs { gap: .15rem; }
  .topic-tabs a { flex: 1 1 0; padding: .55rem .25rem; font-size: .88rem; }
  .progress .bar { width: 70px; }
  .weak-table thead { display: none; }
  .weak-table tr { display: grid; grid-template-columns: 1fr 4.5rem auto; align-items: center; gap: .35rem .75rem;
    padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .weak-table td { padding: 0; border: none; white-space: nowrap; }
  .weak-table td:first-child { grid-column: 1 / -1; white-space: normal; }
  .weak-table .weak-mastery { min-width: 0; }
  .weak-table td:nth-child(3) { text-align: right; }
  .drawer { width: 100vw; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet[open] { animation: none; }
  .drawer { transition: none; }
  .timer.low { animation: none; }
  .tb-streak.ignite .flame, .streak-pop .flame { animation: none; }
  .streak-pop { animation: none; transform: translateX(-50%); }
}
