:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #eaeef6;
  --text: #0f172a;
  --muted: #5a6478;
  --border: #dde2ee;
  --primary: #1d4ed8;
  --primary-hover: #1a44bd;
  --primary-soft: #e4ecff;
  --on-primary: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --learn: #3b82f6;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 6px 18px rgba(15, 23, 42, 0.05);
  --radius: 16px;
  --c-law: #2563eb;
  --c-safety: #d97706;
  --c-signs: #dc2626;
  --c-ed: #059669;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0b1220;
  --surface: #131c2f;
  --surface-2: #1c2842;
  --text: #e8edf7;
  --muted: #9aa7c0;
  --border: #26324e;
  --primary: #5b8dff;
  --primary-hover: #7aa2ff;
  --primary-soft: #1a2b57;
  --on-primary: #0b1220;
  --ok: #4ade80;
  --ok-soft: #12351f;
  --bad: #f87171;
  --bad-soft: #3a1618;
  --warn: #fbbf24;
  --warn-soft: #3a2d10;
  --learn: #60a5fa;
  --focus: #93b4ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.25);
  --c-law: #60a5fa;
  --c-safety: #fbbf24;
  --c-signs: #f87171;
  --c-ed: #34d399;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b1220;
    --surface: #131c2f;
    --surface-2: #1c2842;
    --text: #e8edf7;
    --muted: #9aa7c0;
    --border: #26324e;
    --primary: #5b8dff;
    --primary-hover: #7aa2ff;
    --primary-soft: #1a2b57;
    --on-primary: #0b1220;
    --ok: #4ade80;
    --ok-soft: #12351f;
    --bad: #f87171;
    --bad-soft: #3a1618;
    --warn: #fbbf24;
    --warn-soft: #3a2d10;
    --learn: #60a5fa;
    --focus: #93b4ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.25);
    --c-law: #60a5fa;
    --c-safety: #fbbf24;
    --c-signs: #f87171;
    --c-ed: #34d399;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body.modal-open { overflow: hidden; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 0.6rem; }
a { color: var(--primary); }
hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
small { font-size: 0.82em; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.grow { flex: 1; }
.center { text-align: center; margin: 18px 0; }
.link { font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
#app:focus { outline: none; }
.ico { flex: none; vertical-align: -3px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px; height: 60px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; color: var(--text); text-decoration: none; letter-spacing: -0.02em; white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.93rem; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.app { max-width: 1040px; margin: 0 auto; padding: 24px 20px 64px; }
.app.page-quiz { max-width: 780px; }
.app.page-results { max-width: 820px; }

/* ---------- generic ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card > h2:first-child { margin-bottom: 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 14px; flex-wrap: wrap; }
.section-head.tight { margin: 0 0 12px; }
.grid { display: grid; gap: 14px; }
.grid.topics { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.grid.topics .card { margin: 0; }
.grid.presets { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-bottom: 18px; }
.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; }
.cols .card { margin: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cta-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.empty { text-align: center; padding: 40px 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 650; font-size: 0.95rem; cursor: pointer; text-decoration: none;
  background: var(--surface-2); color: var(--text); transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.danger-ghost { background: transparent; border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); color: var(--bad); }
.btn.danger-ghost:hover { background: var(--bad-soft); }
.btn.sm { padding: 6px 12px; font-size: 0.86rem; border-radius: 10px; }
.btn.lg { padding: 14px 22px; font-size: 1.02rem; border-radius: 14px; }
.btn[disabled], .btn[aria-disabled='true'] { opacity: 0.45; cursor: not-allowed; }
.btn.flagged { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.bad-btn:hover { background: var(--bad-soft) !important; color: var(--bad); }
.btn small { opacity: 0.7; font-weight: 500; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.star.on { color: #f59e0b; }
.icon-btn.danger:hover { color: var(--bad); background: var(--bad-soft); }
.icon-btn[disabled] { opacity: 0.35; pointer-events: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 0.9rem; font-weight: 550; cursor: pointer;
}
.chip small { color: var(--muted); font-weight: 500; }
.chip:hover { border-color: var(--primary); }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.chip.on small { color: inherit; opacity: 0.8; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button, .seg a { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; font: inherit; font-size: 0.9rem; font-weight: 600; color: var(--muted); cursor: pointer; text-decoration: none; }
.seg button:hover, .seg a:hover { color: var(--text); }
.seg .on { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.02em; background: var(--surface-2); color: var(--muted); }
.tag.t-Law { background: color-mix(in srgb, var(--c-law) 16%, transparent); color: var(--c-law); }
.tag.t-Safety { background: color-mix(in srgb, var(--c-safety) 18%, transparent); color: var(--c-safety); }
.tag.t-Signs { background: color-mix(in srgb, var(--c-signs) 15%, transparent); color: var(--c-signs); }
.tag.t-ED { background: color-mix(in srgb, var(--c-ed) 16%, transparent); color: var(--c-ed); }
.tag.t-cat { background: transparent; border: 1px solid var(--border); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 8px; font-size: 0.74rem; font-weight: 700; white-space: nowrap; }
.st-new { background: var(--surface-2); color: var(--muted); }
.st-wrong { background: var(--bad-soft); color: var(--bad); }
.st-learning { background: var(--primary-soft); color: var(--primary); }
.st-mastered { background: var(--ok-soft); color: var(--ok); }

.field { margin: 14px 0; }
.field > label, .field > summary { display: block; font-weight: 700; font-size: 0.84rem; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
details.field > summary { cursor: pointer; margin-bottom: 0; }
details.field[open] > summary { margin-bottom: 8px; }
input[type='text'], input[type='search'], input.num, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; min-width: 0;
}
input.num { width: 110px; }
input[type='search'], .search { width: 100%; }
input:focus, select:focus { border-color: var(--primary); }
.opts-row { display: flex; flex-wrap: wrap; gap: 8px 28px; align-items: flex-end; }
.opts-row .field { margin: 10px 0; }
.builder-cta { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.filters { display: grid; gap: 12px; }
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; }
.filter-row select { flex: 1 1 170px; }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 0.94rem; }
.switch input { position: absolute; opacity: 0; }
.switch span { flex: none; width: 42px; height: 24px; border-radius: 999px; background: var(--border); position: relative; transition: background 0.15s; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.radios { display: grid; gap: 8px; }
.radio { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.radio:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.radio span { display: grid; }

/* ---------- progress primitives ---------- */
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.3s; }
.bar.ok span { background: var(--ok); }
.bar.bad span { background: var(--bad); }
.segbar { display: flex; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.segbar span { display: block; height: 100%; }
.s-mastered { background: var(--ok); }
.s-learning { background: var(--learn); }
.s-wrong { background: var(--bad); }
.s-new { background: var(--border); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.85rem; color: var(--muted); margin-top: 8px; }
.ring { position: relative; width: 84px; height: 84px; flex: none; }
.ring svg { display: block; }
.ring circle { fill: none; stroke-width: 8; }
.ring-bg { stroke: var(--surface-2); }
.ring-fg { stroke: var(--primary); stroke-linecap: round; transition: stroke-dashoffset 0.5s; }
.ring.good .ring-fg { stroke: var(--ok); }
.ring.mid .ring-fg { stroke: var(--warn); }
.ring.low .ring-fg { stroke: var(--bad); }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.1; }
.ring-label b { font-size: 1.15rem; }
.ring-label small { color: var(--muted); font-size: 0.68rem; }

/* ---------- home ---------- */
.hero { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding: 26px; background: linear-gradient(135deg, var(--primary-soft), var(--surface) 70%); }
.hero h1 { font-size: 1.9rem; margin-bottom: 4px; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-color: var(--primary); }
.banner p { margin: 2px 0 0; }
.banner.warn { border-color: var(--warn); background: var(--warn-soft); }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.tile { display: flex; align-items: center; gap: 14px; margin: 0; padding: 16px; flex-wrap: wrap; }
.tile > div:not(.ring):not(.tile-num) { display: grid; line-height: 1.3; flex: 1; min-width: 100px; justify-items: start; }
.tile .btn { margin-top: 6px; }
.tile-num { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; min-width: 64px; display: flex; align-items: center; gap: 6px; }
.tile-num.bad { color: var(--bad); }
.tile-num .ico { color: #f97316; }
.topic-card { display: grid; gap: 4px; align-content: start; }
.tc-head { display: grid; gap: 2px; }
.tc-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.84rem; color: var(--muted); margin-bottom: 8px; }
.tc-stats b { color: var(--text); }
.session-list { display: grid; }
.session-row { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-radius: 12px; text-decoration: none; color: inherit; }
.session-row:hover { background: var(--surface-2); }
.session-row + .session-row { border-top: 1px solid var(--border); }
.sr-score { flex: none; width: 52px; height: 40px; display: grid; place-items: center; border-radius: 10px; font-weight: 800; }
.sr-score.good { background: var(--ok-soft); color: var(--ok); }
.sr-score.mid { background: var(--warn-soft); color: var(--warn); }
.sr-score.low { background: var(--bad-soft); color: var(--bad); }
.sr-main { flex: 1; display: grid; min-width: 0; }
.sr-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- study ---------- */
.preset { display: grid; gap: 4px; text-align: left; align-content: start; cursor: pointer; font: inherit; color: inherit; text-decoration: none; margin: 0; transition: border-color 0.15s, transform 0.1s; }
.preset:hover:not([disabled]) { border-color: var(--primary); transform: translateY(-1px); }
.preset[disabled] { opacity: 0.5; cursor: not-allowed; }
.preset-ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); margin-bottom: 6px; }

/* ---------- library ---------- */
.qrow { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; }
.qrow-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.qid { font-weight: 800; }
.stat-line { white-space: nowrap; }
.qrow-q { font-weight: 650; margin-bottom: 10px; }
.li-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; border: 1px solid transparent; }
.opt-key { flex: none; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 0.78rem; font-weight: 800; }
#lib-list:not(.hide-ans) .li.correct, .qrow.revealed .li.correct { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
#lib-list:not(.hide-ans) .li.correct .opt-key, .qrow.revealed .li.correct .opt-key { background: var(--ok); color: #fff; }
#lib-list:not(.hide-ans) .reveal-btn { display: none; }
.lib-count { margin-bottom: 10px; }

/* ---------- images ---------- */
.plate { display: grid; place-items: center; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.plate img { display: block; max-width: 100%; height: auto; object-fit: contain; image-rendering: auto; }
.plate.big { margin: 4px auto 16px; width: fit-content; max-width: 100%; }
.plate.big img { max-height: 240px; }
.plate.huge { margin: 8px auto; width: fit-content; max-width: 100%; padding: 16px; }
.plate.huge img { max-height: 300px; }
.plate.mini img { max-height: 84px; }
.plate.thumb { padding: 4px; border-radius: 8px; flex: none; }
.plate.thumb img { width: 44px; height: 44px; }
.plate.row-img { width: fit-content; margin: 4px 0 10px; }
.plate.row-img img { max-height: 130px; }
.plate.review-img { width: fit-content; margin: 4px 0 10px; }
.plate.review-img img { max-height: 120px; }

/* ---------- quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: 14px; }
.quiz-progress { flex: 1; display: grid; gap: 4px; }
.timer { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--surface-2); font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.9rem; white-space: nowrap; }
.timer.danger { background: var(--bad-soft); color: var(--bad); }
.quiz-label { margin: 10px 2px 8px; }
.q-card { padding: 22px; }
.q-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.q-tags { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-actions { display: flex; gap: 2px; }
.q-text { font-size: 1.3rem; font-weight: 700; margin-bottom: 16px; letter-spacing: -0.015em; }
.opts { display: grid; gap: 10px; }
.opts.grid2 { grid-template-columns: 1fr 1fr; }
.opt {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  padding: 14px 16px; border-radius: 14px; border: 2px solid var(--border); background: var(--surface);
  font: inherit; font-size: 1.02rem; color: var(--text); cursor: pointer; transition: border-color 0.12s, background 0.12s;
}
.opt:hover:not(.locked) { border-color: var(--primary); background: var(--primary-soft); }
.opt .opt-text { flex: 1; }
.opt .opt-key { width: 28px; height: 28px; font-size: 0.85rem; }
.opt-mark { flex: none; width: 22px; display: grid; place-items: center; }
.opts.grid2 .opt { flex-direction: column; align-items: stretch; text-align: center; gap: 8px; position: relative; }
.opts.grid2 .opt .opt-key { position: absolute; top: 8px; left: 8px; z-index: 1; }
.opts.grid2 .opt .opt-mark { position: absolute; top: 8px; right: 8px; z-index: 1; }
.opts.grid2 .plate { min-height: 120px; }
.opts.grid2 .plate img { max-height: 120px; }
.opt.sel { border-color: var(--primary); background: var(--primary-soft); }
.opt.sel .opt-key { background: var(--primary); color: var(--on-primary); }
.opt.ok { border-color: var(--ok); background: var(--ok-soft); }
.opt.ok .opt-key { background: var(--ok); color: #fff; }
.opt.ok .opt-mark { color: var(--ok); }
.opt.bad { border-color: var(--bad); background: var(--bad-soft); }
.opt.bad .opt-key { background: var(--bad); color: #fff; }
.opt.bad .opt-mark { color: var(--bad); }
.opt.dim { opacity: 0.55; }
.opt.locked { cursor: default; }
.feedback { margin-top: 16px; padding: 12px 14px; border-radius: 12px; border-left: 4px solid; display: grid; gap: 4px; }
.feedback.ok { background: var(--ok-soft); border-color: var(--ok); }
.feedback.bad { background: var(--bad-soft); border-color: var(--bad); }
.feedback p { margin: 0; }
.note { padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--text); font-size: 0.9rem; border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }
.quiz-nav { display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; position: sticky; bottom: 12px; padding: 8px 0; z-index: 5; }
.qmap { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.qm { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font: inherit; font-weight: 700; font-size: 0.85rem; cursor: pointer; color: var(--muted); position: relative; }
.qm.done { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.qm.flag::after { content: ''; position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.qm.cur { outline: 3px solid var(--focus); outline-offset: 1px; color: var(--text); }

/* ---------- results ---------- */
.result-hero { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.result-hero .ring { width: 120px; height: 120px; }
.result-hero .ring svg { width: 120px; height: 120px; }
.result-hero .ring-label b { font-size: 1.6rem; }
.result-hero .ring-label small { font-size: 0.85rem; }
.result-hero.pass { border-color: var(--ok); }
.result-hero.fail { border-color: var(--bad); }
.result-text { flex: 1; min-width: 240px; display: grid; gap: 8px; }
.mini-row { display: grid; grid-template-columns: 1fr 1.2fr 56px; align-items: center; gap: 12px; padding: 5px 0; }
.mini-row b { text-align: right; font-variant-numeric: tabular-nums; }
.review { background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--border); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; }
.review.bad { border-left-color: var(--bad); }
.review.ok { border-left-color: var(--ok); }
.review-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.review-q { font-weight: 650; margin-bottom: 8px; }
.review-ans { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.ans { padding: 8px 12px; border-radius: 10px; }
.ans small { display: block; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.7rem; margin-bottom: 2px; }
.ans.ok { background: var(--ok-soft); }
.ans.ok small { color: var(--ok); }
.ans.bad { background: var(--bad-soft); }
.ans.bad small { color: var(--bad); }
.review .note { margin: 8px 0 0; }

/* ---------- signs ---------- */
.sec-title { margin: 22px 0 10px; color: var(--muted); font-size: 0.86rem; text-transform: uppercase; letter-spacing: 0.05em; }
.sign-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.sign-card { position: relative; display: grid; gap: 8px; align-content: start; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; cursor: pointer; font: inherit; color: var(--text); text-align: left; transition: border-color 0.12s, transform 0.1s; }
.sign-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.sign-card .plate { height: 128px; border: 0; padding: 4px; }
.sign-card .plate img { max-height: 118px; }
.sc-name { font-size: 0.82rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.sign-card .dot { position: absolute; top: 10px; right: 8px; margin: 0; }
.sign-modal { text-align: center; }
.sign-modal h3 { font-size: 1.2rem; margin-top: 6px; }
.flashcard { text-align: center; cursor: pointer; padding: 22px; min-height: 380px; display: grid; align-content: start; gap: 12px; user-select: none; }
.flashcard .q-meta { text-align: left; }
.signs.flash { max-width: 760px; margin: 0 auto; }
.fc-answer { font-size: 1.5rem; }
.fc-hint { margin-top: 10px; }

/* ---------- progress ---------- */
.br-row { display: grid; grid-template-columns: minmax(150px, 1.1fr) 2fr minmax(120px, 0.7fr); gap: 14px; align-items: center; padding: 9px 0; }
.br-row + .br-row { border-top: 1px solid var(--border); }
.br-label { display: grid; line-height: 1.25; }
.br-num { text-align: right; display: grid; line-height: 1.25; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.lesson { display: grid; gap: 2px; padding: 10px 6px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; font: inherit; color: var(--text);
  background: color-mix(in srgb, var(--ok) calc(var(--m) * 0.75%), var(--surface)); }
.lesson:hover { border-color: var(--primary); }
.lesson.w { box-shadow: inset 0 -3px 0 var(--bad); }
.lesson small { color: var(--muted); }
.activity { display: flex; gap: 6px; align-items: flex-end; height: 120px; }
.act-col { flex: 1; display: grid; gap: 4px; justify-items: center; height: 100%; grid-template-rows: 1fr auto; }
.act-bar { width: 100%; max-width: 30px; background: var(--surface-2); border-radius: 6px; display: flex; align-items: flex-end; overflow: hidden; }
.act-bar span { display: block; width: 100%; background: var(--primary); border-radius: 6px 6px 0 0; min-height: 2px; }
.work-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; }
.work-row + .work-row { border-top: 1px solid var(--border); }
.wr-main { flex: 1; display: grid; min-width: 0; }
.wr-text { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- modal & toast ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(8, 12, 24, 0.55); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal { width: 100%; max-width: 500px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 24px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); }
.modal.small { max-width: 420px; }
.modal.wide { max-width: 560px; }
.modal h3 { font-size: 1.15rem; margin-bottom: 8px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.modal-actions.col { flex-direction: column; align-items: stretch; }
.modal-actions.between { justify-content: space-between; }
.modal-actions.between > div { display: flex; gap: 6px; align-items: center; }
.check-list, .set-list { display: grid; gap: 6px; margin: 12px 0; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.check-row span { flex: 1; }
.check-row input { width: 18px; height: 18px; accent-color: var(--primary); }
.set-row { display: flex; align-items: center; gap: 8px; }
.set-row input { flex: 1; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { flex: 1; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); z-index: 80; background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 0.92rem; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.file-btn { cursor: pointer; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .tiles, .grid.topics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .cols { grid-template-columns: 1fr; }
  .br-row { grid-template-columns: 1fr; gap: 4px; }
  .br-num { text-align: left; grid-auto-flow: column; justify-content: space-between; }
}
@media (max-width: 520px) {
  .tiles, .grid.topics { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar { padding: 0 14px; backdrop-filter: none; background: var(--surface); }
  .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; justify-content: space-around; gap: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 0.68rem; flex: 1; min-width: 0; align-items: center; justify-content: center; text-align: center; }
  .app { padding: 16px 14px 96px; }
  h1 { font-size: 1.45rem; }
  .hero h1 { font-size: 1.5rem; }
  .hero .cta-row .btn { flex: 1 1 100%; }
  .q-text { font-size: 1.15rem; }
  .quiz-nav { bottom: 74px; }
  .quiz-nav .btn.lg { flex: 1; }
  .toast { bottom: 84px; }
  .mini-row { grid-template-columns: 1fr 1fr 48px; }
  .opts.grid2 { gap: 8px; }
  .card { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
