/* ===== Токены ===== */
:root {
  --bg: #f4f1ea;
  --surface: #fffdf9;
  --surface-2: #f0ece3;
  --ink: #1f1d19;
  --muted: #6c675d;
  --faint: #9a9488;
  --line: #e2dccf;
  --accent: #1f5f5b;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe8;
  --ok: #1b6e3f;
  --ok-bg: #e2f2e7;
  --ok-line: #7cc095;
  --bad: #a8261d;
  --bad-bg: #fbe7e4;
  --bad-line: #e59a92;
  --warn: #b5620e;
  --shadow: 0 1px 2px rgb(40 30 10 / .05), 0 4px 16px rgb(40 30 10 / .05);
  --radius: 14px;
  --nav-h: 64px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "PT Serif", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1e1d1a;
    --surface-2: #272521;
    --ink: #ece7dd;
    --muted: #a7a093;
    --faint: #7c766b;
    --line: #34312b;
    --accent: #72b8ae;
    --accent-ink: #0d1f1d;
    --accent-soft: #1f3532;
    --ok: #7fd39c;
    --ok-bg: #1d3d2a;
    --ok-line: #4a9e68;
    --bad: #f19a90;
    --bad-bg: #45211c;
    --bad-line: #8a3b33;
    --warn: #f0b060;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

/* ===== База ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 var(--sans);
  overflow-x: hidden;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-family: var(--serif); font-size: 1.75rem; font-weight: 600; letter-spacing: -.01em; }
.h2 { font-family: var(--serif); font-size: 1.3rem; font-weight: 600; margin: 32px 0 12px; }
.h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin: 4px 0 12px; }
.h3:not(:first-child) { margin-top: 24px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.eyebrow { margin: 0 0 4px; font-size: .85rem; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 860px; margin: 0 auto; padding: 16px 16px 24px; }
.page-head { margin: 8px 0 16px; }
.page-head p { margin: 8px 0 0; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.flash { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; margin: 0 0 12px; }

/* ===== Шапка и навигация ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 860px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--serif); font-weight: 600; font-size: 1.1rem; }
.brand svg { width: 30px; height: 30px; padding: 5px; border-radius: 9px; background: var(--accent); fill: none; stroke: var(--accent-ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.brand small { font-family: var(--sans); font-weight: 500; font-size: .75rem; color: var(--muted); margin-left: 6px; letter-spacing: .04em; }

.nav {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 500;
}
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a.on { color: var(--accent); }
.nav a.on svg { stroke-width: 2.3; }

@media (min-width: 760px) {
  body { padding-bottom: 32px; }
  .topbar { padding: 18px 24px 8px; }
  .wrap { padding: 16px 24px 32px; }
  .nav {
    position: static; display: flex; gap: 4px; height: auto; padding: 4px;
    background: var(--surface-2); border: 0; border-radius: 12px; backdrop-filter: none;
  }
  .nav a { flex-direction: row; gap: 8px; padding: 8px 14px; border-radius: 9px; font-size: .95rem; }
  .nav svg { width: 18px; height: 18px; }
  .nav a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
  .nav a.on svg { color: var(--accent); }
  h1 { font-size: 2.1rem; }
}

/* ===== Кнопки и поля ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: .95rem; font-weight: 600; text-decoration: none;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad-line); }
.btn-lg { min-height: 52px; padding: 0 24px; font-size: 1.05rem; }
.btn-block { width: 100%; }

input[type="search"], input[type="password"], select {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px;
}
select { appearance: none; padding-right: 36px; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 18px top 50%, right 13px top 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.field { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; }

/* ===== Фильтры ===== */
.filters { display: grid; gap: 10px; padding: 12px; }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; }
.search input { padding-left: 38px; }
@media (min-width: 760px) {
  .filters { grid-template-columns: 1fr 1.4fr 1fr auto auto; align-items: center; }
  .filters .search { grid-column: 1 / -1; }
  #problems .filters { grid-template-columns: 1fr 1.4fr auto; }
}
.count { margin: 14px 2px 10px; font-size: .9rem; }

/* ===== Вопрос ===== */
.qlist { display: grid; gap: 14px; }
.q { padding: 16px 14px; scroll-margin-top: 12px; }
.q-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 8px; }
.q-num { font-size: .78rem; color: var(--faint); font-variant-numeric: tabular-nums; letter-spacing: .02em; white-space: nowrap; }
.q-topic { font-size: .78rem; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.q-verdict:empty { display: none; }
.q-head .tag, .q-verdict { margin-left: auto; }
.q-text { font-family: var(--serif); font-size: 1.16rem; font-weight: 600; margin: 0 0 14px; overflow-wrap: anywhere; }

.opts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.opt {
  position: relative;
  display: grid; grid-template-columns: 24px 18px 1fr 22px; align-items: center; gap: 10px;
  min-height: 52px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .12s, background .12s;
}
.opt:hover { border-color: var(--faint); }
.opt input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.box {
  width: 22px; height: 22px; border: 2px solid var(--faint); border-radius: 6px;
  display: grid; place-items: center; background: var(--surface);
  transition: background .12s, border-color .12s;
}
.box::after { content: ""; width: 10px; height: 6px; border: solid transparent; border-width: 0 0 2.5px 2.5px; transform: rotate(-45deg) translate(1px, -1px); }
.opt input:checked ~ .box { background: var(--accent); border-color: var(--accent); }
.opt input:checked ~ .box::after { border-color: var(--accent-ink); }
.opt input:focus-visible ~ .box { outline: 3px solid var(--accent); outline-offset: 2px; }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt:has(input:disabled) { cursor: default; }
.opt-n { font-size: .8rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.opt-text { min-width: 0; overflow-wrap: anywhere; }
.mark { font-weight: 800; font-size: 1.1rem; text-align: center; }

/* состояния разбора: цвет + иконка */
.opt.is-correct, .opt.is-correct:has(input:checked) { border-color: var(--ok-line); background: var(--ok-bg); }
.opt.is-correct .mark::after { content: "✓"; color: var(--ok); }
.opt.is-correct .opt-text { color: var(--ink); font-weight: 600; }
.opt.is-wrong, .opt.is-wrong:has(input:checked) { border-color: var(--bad-line); background: var(--bad-bg); }
.opt.is-wrong .mark::after { content: "✗"; color: var(--bad); }
.opt.is-wrong .opt-text { text-decoration: line-through; text-decoration-color: var(--bad-line); }
.opt.is-correct input:checked ~ .box { background: var(--ok); border-color: var(--ok); }
.opt.is-wrong input:checked ~ .box { background: var(--bad); border-color: var(--bad); }
.opt.is-correct:not(.is-picked) { border-style: dashed; }

.q-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 10px; margin-top: 14px; }
.reveal summary { list-style: none; }
.reveal summary::-webkit-details-marker { display: none; }
.reveal .when-open, .reveal[open] .when-closed { display: none; }
.reveal[open] .when-open { display: inline; }
.reveal[open] summary { background: var(--surface-2); }
.reveal-text { display: none; }
.reveal[open] .reveal-text { display: block; margin: 8px 2px 0; color: var(--ok); font-weight: 600; font-size: .95rem; }
.verdict { margin: 0; flex-basis: 100%; min-height: 0; }
.verdict:empty { display: none; }

.tag {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px; font-size: .85rem; font-weight: 700;
  background: var(--surface-2); color: var(--muted);
}
.tag-ok { background: var(--ok-bg); color: var(--ok); }
.tag-bad { background: var(--bad-bg); color: var(--bad); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 20px 0 0; }
.pager-info { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ===== Вход ===== */
.page-login .wrap { min-height: 100dvh; display: grid; place-items: center; padding-bottom: 0; }
.page-login { padding-bottom: 0; }
.login { width: 100%; max-width: 380px; display: grid; gap: 14px; padding: 28px 22px; }
.login-mark { width: 44px; height: 44px; padding: 8px; border-radius: 12px; background: var(--accent); fill: none; stroke: var(--accent-ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.login p { margin: 0; }
.error { color: var(--bad); font-weight: 600; }

/* ===== Симуляция: старт ===== */
.sim-intro { display: grid; gap: 18px; }
.rules { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.rules li { padding-left: 28px; position: relative; }
.rules li::before { content: "→"; position: absolute; left: 4px; color: var(--accent); font-weight: 700; }
.sim-intro .btn { width: 100%; }
@media (min-width: 760px) { .sim-intro .btn { width: auto; } }

.rows { list-style: none; margin: 0; padding: 4px 16px; }
ol.rows { padding-left: 16px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.row .btn { flex-shrink: 0; }

/* ===== Прохождение ===== */
.page-run .brand { display: none; }
.page-run .topbar { padding: 0; }
.page-run { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 130px); }
@media (min-width: 760px) {
  .page-run { padding-bottom: 32px; }
  .page-run .brand { display: flex; }
  .page-run .topbar { padding: 18px 24px 8px; }
}
.run { display: grid; gap: 12px; }
.run-top { display: flex; align-items: baseline; gap: 12px; font-size: .9rem; }
.run-mode { font-weight: 700; }
.run-pos { color: var(--muted); font-variant-numeric: tabular-nums; }
.run-score { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.timer { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 12px; }
.timer-num { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; text-align: center; line-height: 1; }
.timer-track { height: 10px; border-radius: 10px; background: var(--line); overflow: hidden; }
.timer-track span { display: block; height: 100%; width: 100%; background: var(--accent); border-radius: 10px; transition: width .1s linear; }
.timer.danger .timer-num { color: var(--bad); }
.timer.danger .timer-track span { background: var(--bad); }
.timer.paused { opacity: .45; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 20;
  display: grid; gap: 6px;
  padding: 10px 16px 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.actionbar .btn { width: 100%; }
.actionbar-note { margin: 0; font-size: .9rem; color: var(--muted); text-align: center; min-height: 1.35em; }
@media (min-width: 760px) {
  .actionbar { position: static; margin: 0; padding: 0; background: none; border: 0; backdrop-filter: none;
    grid-template-columns: 1fr auto; align-items: center; }
  .actionbar-note { text-align: left; }
  .actionbar .btn { width: auto; min-width: 200px; }
}

/* ===== Результат ===== */
.result-hero { display: grid; gap: 18px; justify-items: center; text-align: center; }
.score-ring {
  --p: 0; width: 148px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(closest-side, var(--surface) 78%, transparent 79%),
              conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0);
}
.score-ring span { display: grid; line-height: 1.1; }
.score-ring b { font-size: 2.5rem; font-family: var(--serif); }
.score-ring small { color: var(--muted); }
.result-facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 24px; margin: 0; }
.result-facts div { display: grid; }
.result-facts dt { font-size: .8rem; color: var(--muted); }
.result-facts dd { margin: 0; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-actions { display: grid; gap: 8px; width: 100%; }
.result-actions form, .result-actions .btn { width: 100%; }
@media (min-width: 760px) {
  .result-hero { grid-template-columns: auto 1fr; justify-items: start; text-align: left; column-gap: 32px; }
  .score-ring { grid-row: span 2; }
  .result-facts { justify-content: flex-start; }
  .result-actions { display: flex; flex-wrap: wrap; width: auto; }
  .result-actions form, .result-actions .btn { width: auto; }
}
.all-items summary { cursor: pointer; }
.all-items .row { font-size: .95rem; }

/* ===== Статистика ===== */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { display: grid; gap: 2px; padding: 14px; }
.kpi-val { font-family: var(--serif); font-size: 1.8rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-val small { font-size: 1rem; color: var(--muted); }
.kpi-lbl { font-size: .82rem; color: var(--muted); }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.grid2 { display: grid; gap: 14px; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1.3fr; align-items: start; } }

.meter { margin-bottom: 12px; }
.meter-top { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; margin-bottom: 5px; }
.meter-label { min-width: 0; overflow-wrap: anywhere; }
.meter-val { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-val b { color: var(--ink); }
.meter-track { height: 8px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.meter-track span { display: block; height: 100%; border-radius: 8px; background: var(--accent); }
.meter-track span.lo { background: var(--bad); }
.meter-track span.mid { background: var(--warn); }

.retry-form { margin: 12px 0; }
.retry-form .btn { width: 100%; }
@media (min-width: 760px) { .retry-form .btn { width: auto; } }
.row-problem { align-items: flex-start; }
.row-main { display: grid; gap: 2px; }
.row-main small { font-size: .82rem; }
.err-count { flex-shrink: 0; font-weight: 800; color: var(--bad); font-variant-numeric: tabular-nums; white-space: nowrap; }
.err-count small { color: var(--muted); font-weight: 500; }

.danger-zone .card { display: grid; gap: 14px; }
.check-line { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check-line input { width: 20px; height: 20px; accent-color: var(--bad); }
@media (min-width: 760px) { .danger-zone .card { grid-template-columns: 1fr auto; align-items: center; } }

/* ===== Статус вопроса в подготовке (по последней попытке) ===== */
.status-badge { margin-left: auto; }
.status-badge:empty { display: none; }
.status-badge .tag { font-size: .78rem; padding: 2px 9px; }
.q.is-known { border-left: 4px solid var(--ok-line); }
.q.is-unknown { border-left: 4px solid var(--bad-line); }
