:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --text: #16202b;
  --muted: #5b6b7b;
  --border: #e1e6ec;
  --primary: #0f5c8a;
  --primary-ink: #ffffff;
  --primary-soft: #e3f0f8;
  --accent: #f2a900;
  --good: #17844a;
  --good-soft: #e2f5ea;
  --bad: #c8304a;
  --bad-soft: #fde9ec;
  --st-new: #aab4bf;
  --st-learn: #f2a900;
  --st-know: #3b8fd1;
  --st-done: #22a05b;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 6px 20px rgba(16, 32, 48, .06);
  --radius: 16px;
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1319;
    --surface: #171f28;
    --surface-2: #1d2731;
    --text: #e7edf3;
    --muted: #94a3b2;
    --border: #2a3643;
    --primary: #5db0e8;
    --primary-ink: #06202f;
    --primary-soft: #14303f;
    --accent: #f5b72b;
    --good: #43cf82;
    --good-soft: #12301f;
    --bad: #ff7287;
    --bad-soft: #3a1720;
    --st-new: #5a6877;
    --st-learn: #f5b72b;
    --st-know: #5db0e8;
    --st-done: #43cf82;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
    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;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--primary);
  color: #fff;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 980px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.brand-mark {
  flex: none; width: 38px; height: 38px; border-radius: 11px;
  background: #fff; color: #0f5c8a; font-weight: 800; font-size: 1.05rem;
  display: grid; place-items: center; letter-spacing: -.02em;
  box-shadow: inset 0 -3px 0 var(--accent);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-text b { font-size: 1.05rem; }
.brand-text small { opacity: .8; font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-desktop { display: none; gap: 4px; }
.nav-desktop a {
  color: #fff; text-decoration: none; padding: 8px 14px; border-radius: 10px;
  font-weight: 600; font-size: .95rem; opacity: .85;
}
.nav-desktop a:hover { background: rgba(255, 255, 255, .12); opacity: 1; }
.nav-desktop a.active { background: rgba(255, 255, 255, .2); opacity: 1; }

.nav-mobile {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(4, 1fr);
}
.nav-mobile a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.nav-mobile a svg { width: 24px; height: 24px; }
.nav-mobile a.active { color: var(--primary); }

.app {
  max-width: 980px; margin: 0 auto;
  padding: 20px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
}
@media (min-width: 760px) {
  .nav-desktop { display: flex; }
  .nav-mobile { display: none; }
  .app { padding: 28px 24px 48px; }
}

/* ---------- общие элементы ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.stack > * + * { margin-top: 16px; }
.stack-lg > * + * { margin-top: 24px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.grow { flex: 1 1 auto; }
.page-title { display: flex; flex-direction: column; gap: 4px; margin-bottom: 20px; }
.page-title p { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 18px; border-radius: 12px; font-weight: 650; text-decoration: none;
  transition: transform .06s, background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn.big { padding: 16px 24px; font-size: 1.1rem; border-radius: 14px; }
.btn.block { display: flex; width: 100%; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 6px 12px; font-size: .875rem; border-radius: 10px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 650;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.chip.new { color: var(--muted); }
.chip.learn { color: #9a6700; background: #fff4d6; border-color: #f2d58a; }
.chip.know { color: #1d6aa8; background: #e3f0fb; border-color: #aacdee; }
.chip.done { color: var(--good); background: var(--good-soft); border-color: #a9dcc0; }
.chip.multi { color: #6b3fa0; background: #f0e8fa; border-color: #d5c3ec; }
@media (prefers-color-scheme: dark) {
  .chip.learn { color: #f5b72b; background: #3a2d0c; border-color: #6b5316; }
  .chip.know { color: #8ccaf5; background: #12293a; border-color: #28506d; }
  .chip.done { border-color: #1f5a38; }
  .chip.multi { color: #c8a8f0; background: #2a1d3d; border-color: #4a3470; }
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.new { background: var(--st-new); } .dot.learn { background: var(--st-learn); }
.dot.know { background: var(--st-know); } .dot.done { background: var(--st-done); }

/* полоса прогресса из сегментов */
.seg { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.seg span { display: block; height: 100%; }
.seg .new { background: var(--st-new); opacity: .45; } .seg .learn { background: var(--st-learn); }
.seg .know { background: var(--st-know); } .seg .done { background: var(--st-done); }
.seg.thin { height: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .875rem; color: var(--muted); }
.legend b { color: var(--text); font-variant-numeric: tabular-nums; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.bar { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: 1fr; }
.grid.stats { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 760px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.stats { grid-template-columns: repeat(4, 1fr); }
  .grid.tickets { grid-template-columns: repeat(3, 1fr); }
}
.grid.tickets { grid-template-columns: 1fr; }
@media (min-width: 520px) { .grid.tickets { grid-template-columns: 1fr 1fr; } }
@media (min-width: 760px) { .grid.tickets { grid-template-columns: repeat(3, 1fr); } }

.stat { padding: 16px; }
.stat .num { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.stat .sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.stat.good .num { color: var(--good); }

/* ---------- главная ---------- */
.hero { background: linear-gradient(135deg, var(--primary), #0b4467); color: #fff; border: 0; position: relative; overflow: hidden; }
@media (prefers-color-scheme: dark) { .hero { background: linear-gradient(135deg, #17506f, #0f2f44); } }
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255, 255, 255, .07);
}
.hero h1 { font-size: 1.5rem; }
.hero p { opacity: .9; margin-top: 6px; }
.hero .btn.primary { background: var(--accent); border-color: var(--accent); color: #2b1d00; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 16px; font-size: .92rem; }
.hero .meta b { font-variant-numeric: tabular-nums; }
.how li { margin: 6px 0; }
.how ul { margin: 8px 0 0; padding-left: 20px; }

/* ---------- билеты ---------- */
.ticket { display: flex; flex-direction: column; gap: 12px; }
.ticket h3 { font-size: 1.1rem; }
.ticket .numbers { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
.ticket .actions { display: flex; gap: 8px; margin-top: auto; }
.ticket .actions .btn { flex: 1; padding: 9px 10px; }
.best { font-size: .8rem; font-weight: 650; }
.seg-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.seg-toggle button { border: 0; background: transparent; padding: 8px 14px; font-weight: 600; color: var(--muted); }
.seg-toggle button.on { background: var(--primary); color: var(--primary-ink); }

/* ---------- вопрос ---------- */
.runbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.runbar .title { font-weight: 700; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.runbar .counter { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.q-card { padding: 22px; }
.q-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.q-text { font-size: 1.15rem; font-weight: 600; line-height: 1.45; white-space: pre-line; }
.choices { list-style: none; margin: 20px 0 0; padding: 0; display: grid; gap: 10px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left;
  padding: 14px 16px; border-radius: 14px; border: 2px solid var(--border); background: var(--surface);
  transition: border-color .12s, background .12s;
}
.choice:not(:disabled):hover { border-color: var(--primary); background: var(--primary-soft); }
.choice .key {
  flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); font-size: .85rem; font-weight: 700; color: var(--muted);
}
.choice .ctext { flex: 1 1 auto; padding-top: 2px; }
.choice .mark { flex: none; font-weight: 800; padding-top: 1px; }
.choice.sel { border-color: var(--primary); background: var(--primary-soft); }
.choice.sel .key { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.choice:disabled { cursor: default; }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.right .key { background: var(--good); border-color: var(--good); color: #fff; }
.choice.right .mark { color: var(--good); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .key { background: var(--bad); border-color: var(--bad); color: #fff; }
.choice.wrong .mark { color: var(--bad); }
.choice.missed { border-style: dashed; }
.choice.dim { opacity: .65; }

.submit-row { margin-top: 18px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.verdict { margin-top: 18px; padding: 14px 16px; border-radius: 14px; font-weight: 700; display: flex; gap: 10px; align-items: center; }
.verdict.ok { background: var(--good-soft); color: var(--good); }
.verdict.fail { background: var(--bad-soft); color: var(--bad); }
.verdict small { display: block; font-weight: 500; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.explain { margin-top: 14px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 14px; padding: 14px 16px; display: grid; gap: 10px; }
.explain h4 { margin: 0 0 2px; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.explain p { white-space: pre-line; }
.explain .ref-line { font-weight: 600; }
.next-row { margin-top: 18px; display: flex; justify-content: flex-end; }
.early { margin-top: 12px; font-size: .85rem; color: var(--muted); }
.kbd { font: inherit; font-size: .75rem; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 6px; color: var(--muted); background: var(--surface-2); }
@media (hover: none) { .kbd-hint { display: none; } }

/* ---------- результат ---------- */
.score-ring {
  --p: 0; width: 132px; height: 132px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--ring, var(--good)) calc(var(--p) * 1%), var(--surface-2) 0);
  display: grid; place-items: center; position: relative;
}
.score-ring::before { content: ""; position: absolute; inset: 12px; background: var(--surface); border-radius: 50%; }
.score-ring b { position: relative; font-size: 1.9rem; font-variant-numeric: tabular-nums; }
.review { display: grid; gap: 12px; }
.review-item { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.review-item > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; }
.review-item > summary::-webkit-details-marker { display: none; }
.review-item .badge { flex: none; font-weight: 800; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: .85rem; color: #fff; }
.review-item .badge.ok { background: var(--good); } .review-item .badge.fail { background: var(--bad); }
.review-item .body { padding: 0 16px 16px; }
.review-item .body .choices { margin-top: 10px; }
.review-item .body .choice { cursor: default; padding: 10px 12px; border-width: 1.5px; }
.review-item .qt { flex: 1 1 auto; font-weight: 600; }
.review-item .qt small { display: block; color: var(--muted); font-weight: 500; margin-top: 2px; }

/* ---------- статистика ---------- */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.chart .col { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 0; }
.chart .stackbar { width: 100%; max-width: 34px; display: flex; flex-direction: column-reverse; border-radius: 6px 6px 2px 2px; overflow: hidden; min-height: 2px; background: var(--surface-2); }
.chart .stackbar i.c { background: var(--st-done); display: block; }
.chart .stackbar i.w { background: var(--bad); display: block; opacity: .85; }
.chart .val { font-size: .7rem; color: var(--muted); height: 16px; line-height: 16px; font-variant-numeric: tabular-nums; }
.chart .day { font-size: .68rem; color: var(--muted); margin-top: 6px; white-space: nowrap; }
.chart .col.today .day { color: var(--text); font-weight: 700; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .minibar { min-width: 90px; }
.pill-pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.pct-good { color: var(--good); } .pct-mid { color: #b97a00; } .pct-bad { color: var(--bad); }
@media (prefers-color-scheme: dark) { .pct-mid { color: var(--accent); } }
@media (max-width: 560px) { .hide-sm { display: none; } }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 4px 0; }
.switch input { width: 22px; height: 22px; accent-color: var(--primary); }

/* ---------- каталог вопросов ---------- */
.search {
  width: 100%; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: .875rem; color: var(--muted); }
.filters button.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.qlist { display: grid; gap: 10px; }
.qlist .review-item > summary .qt { font-weight: 550; }

/* ---------- прочее ---------- */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #16202b; color: #fff; padding: 10px 18px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px); text-align: center; font-size: .92rem;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 760px) { .toast { bottom: 28px; } }
.loading { text-align: center; padding: 60px 16px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- аккаунт ---------- */
.account-btn {
  display: inline-flex; align-items: center; gap: 8px; flex: none; position: relative;
  color: #fff; text-decoration: none; font-weight: 650; font-size: .92rem;
  padding: 7px 12px; border-radius: 10px; background: rgba(255, 255, 255, .14); max-width: 46%;
}
.account-btn[hidden] { display: none; }
.account-btn svg { width: 20px; height: 20px; flex: none; }
.account-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-btn:hover, .account-btn.active { background: rgba(255, 255, 255, .26); }
.account-btn.pending::after {
  content: ""; position: absolute; top: 4px; right: 4px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--primary);
}
@media (max-width: 759px) { .brand-text small { display: none; } }

.auth-wrap { max-width: 460px; margin: 0 auto; }
.field { display: grid; gap: 6px; }
.field-label { font-weight: 650; font-size: .92rem; }
.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.input:focus { outline: 3px solid var(--accent); outline-offset: 1px; border-color: var(--primary); }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.form-error { color: var(--bad); font-weight: 600; font-size: .92rem; }
.form-error:empty { display: none; }
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.kv b { text-align: right; overflow-wrap: anywhere; }
.notice { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; border-left: 5px solid var(--primary); }
.notice.warn { border-left-color: var(--accent); }
.notice p { margin-top: 2px; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(8, 14, 20, .6);
  display: grid; place-items: center; padding: 16px;
}
.modal { width: min(460px, 100%); }
