:root {
  --bg: #F6F7FB;
  --card: #FFFFFF;
  --ink: #15172B;
  --ink-2: #2A2D45;
  --muted: #555A75;
  --line: #E3E5EF;
  --line-2: #D8DBE8;
  --soft: #EEF0F7;
  --accent: #3036C9;
  --accent-ink: #2A2E9E;
  --accent-soft: #EEF0FF;
  --ok: #15803D;
  --ok-ink: #14532D;
  --ok-soft: #E9F7EF;
  --bad: #C2410C;
  --bad-ink: #7C2D12;
  --bad-soft: #FDF0E7;
  --warn-soft: #FFF7E6;
  --warn-line: #F3D9A4;
  --warn-ink: #5C3A00;
  --radius: 14px;
  --font: Manrope, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.noscript { padding: 24px; text-align: center; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.app.locked { overflow: hidden; }

/* ---------- шапка ---------- */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; border-radius: 12px;
  margin-left: -8px; color: var(--ink);
}
.icon-btn:hover { background: var(--soft); }
.icon-btn svg { width: 24px; height: 24px; }
.logo {
  width: 40px; height: 40px; flex: none; border-radius: 12px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.logo svg { width: 22px; height: 22px; }
.brand { font-size: 16px; font-weight: 700; line-height: 1.25; }

h1 { margin: 0; font-size: 26px; line-height: 1.18; font-weight: 800; letter-spacing: -0.4px; }
h2 { margin: 0; font-size: 20px; font-weight: 800; }
.lead { margin: 8px 0 0; color: #4A4E68; }

.notice {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--warn-soft); border: 1px solid var(--warn-line); border-radius: var(--radius);
  padding: 14px; color: var(--warn-ink); font-size: 14px; line-height: 1.45;
}
.notice svg { width: 22px; height: 22px; flex: none; margin-top: 1px; }
.notice p { margin: 0; }

/* ---------- форма ---------- */
.form { display: flex; flex-direction: column; gap: 14px; margin-top: auto; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; color: var(--ink-2); display: flex; justify-content: space-between; }
.field .counter { font-weight: 500; color: var(--muted); }
.input, .select {
  width: 100%; height: 52px; border: 1px solid var(--line-2); border-radius: var(--radius);
  background: var(--card); padding: 0 16px; font-size: 17px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(48, 54, 201, .15); }
.input.invalid { border-color: var(--bad); }
.select-wrap { position: relative; }
.select { appearance: none; -webkit-appearance: none; padding-right: 44px; font-size: 16px; }
.select-wrap svg { position: absolute; right: 16px; top: 16px; width: 20px; height: 20px; pointer-events: none; color: var(--muted); }
.field-error { margin: 0; color: var(--bad); font-size: 13px; font-weight: 600; }
.form-error {
  margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--bad-soft);
  color: var(--bad-ink); font-size: 14px; font-weight: 600;
}

/* ---------- кнопки ---------- */
.btn {
  height: 56px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--card);
  font-size: 16px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 18px; text-decoration: none; color: var(--ink); width: 100%;
  transition: transform .05s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.99); }
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-size: 17px; }
.btn.primary:hover { background: #262BB0; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 12px; }
.btn-row .btn { flex: 1; }
.btn-row .btn.grow { flex: 2; }
.btn-col { display: flex; flex-direction: column; gap: 12px; margin-top: auto; }

/* ---------- тест ---------- */
.test-head { display: flex; align-items: center; gap: 8px; }
.test-head .who { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; color: #4A4E68; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.timer svg { width: 16px; height: 16px; color: var(--accent); }
.progress-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; color: var(--muted); }
.progress-row b { color: var(--ink); font-size: 15px; }
.progress { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; border-radius: 4px; background: var(--accent); transition: width .25s; }

.q-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.q-label { font-size: 12px; font-weight: 800; color: var(--accent); letter-spacing: .5px; text-transform: uppercase; }
.q-text { margin: 0; font-size: 19px; line-height: 1.4; font-weight: 700; white-space: pre-line; }
.q-hint { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  min-height: 58px; display: flex; align-items: center; gap: 14px; padding: 12px 14px;
  border: 1px solid var(--line-2); border-radius: 16px; background: var(--card); text-align: left; font-size: 16px; line-height: 1.35;
  transition: border-color .12s, background .12s;
}
.option:hover { border-color: #B9BDD3; }
.option .letter {
  width: 32px; height: 32px; flex: none; border-radius: 10px; background: var(--soft);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px;
}
.option.multi .letter { border-radius: 8px; }
.option[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--accent-soft); padding: 11px 13px; font-weight: 600; }
.option[aria-pressed="true"] .letter { background: var(--accent); color: #fff; }
.test-nav { margin-top: auto; position: sticky; bottom: 0; padding-top: 8px; background: linear-gradient(transparent, var(--bg) 30%); }

/* ---------- итог ---------- */
.center { text-align: center; }
.kicker { font-size: 15px; font-weight: 600; color: var(--muted); }
.ring { position: relative; width: 190px; height: 190px; align-self: center; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .value { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .pct { font-size: 46px; font-weight: 800; line-height: 1; }
.ring .of { font-size: 14px; color: var(--muted); margin-top: 6px; }
.verdict { margin: 0; text-align: center; font-weight: 700; }
.tiles { display: flex; gap: 12px; }
.tile { flex: 1; border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.tile svg { width: 24px; height: 24px; }
.tile .num { font-size: 30px; font-weight: 800; line-height: 1.1; }
.tile .cap { font-size: 14px; font-weight: 700; }
.tile.ok { background: var(--ok-soft); color: var(--ok-ink); }
.tile.ok svg { color: var(--ok); }
.tile.bad { background: var(--bad-soft); color: var(--bad-ink); }
.tile.bad svg { color: var(--bad); }
.facts { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 4px 16px; font-size: 14px; }
.facts > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #EEF0F5; }
.facts > div:last-child { border-bottom: 0; }
.facts span:first-child { color: var(--muted); }
.facts span:last-child { font-weight: 700; text-align: right; }

.mistakes { display: flex; flex-direction: column; gap: 10px; }
.mistake { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.mistake .mq { margin: 0; font-weight: 700; }
.mistake .line { margin: 0; display: flex; gap: 8px; align-items: flex-start; }
.mistake .line svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.mistake .yours { color: var(--bad-ink); }
.mistake .yours svg { color: var(--bad); }
.mistake .right { color: var(--ok-ink); }
.mistake .right svg { color: var(--ok); }

/* ---------- статистика ---------- */
.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.chip {
  height: 38px; padding: 0 4px; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--card); font-size: 13px; font-weight: 700; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.segmented { display: flex; background: var(--soft); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; height: 38px; border: 0; border-radius: 9px; background: transparent; font-size: 14px; font-weight: 700; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(21, 23, 43, .12); }
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.summary div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.summary b { font-size: 20px; font-weight: 800; }
.summary span { font-size: 12px; color: var(--muted); line-height: 1.3; }
.explain { margin: -6px 0 0; font-size: 13px; color: var(--muted); }
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 15px; width: 18px; height: 18px; color: var(--muted); }
.search .input { padding-left: 42px; height: 48px; font-size: 15px; }

.board { background: var(--card); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.person { border-bottom: 1px solid #EEF0F5; }
.person:last-child { border-bottom: 0; }
.person-row {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0; background: transparent; text-align: left;
}
.person-row:hover { background: #FAFBFD; }
.rank {
  width: 34px; height: 34px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; background: var(--soft); color: var(--ink-2);
}
.rank.top { background: var(--accent); color: #fff; }
.rank.r1 { background: #B7791F; }
.person .who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.person .nm { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 700; min-width: 0; }
.person .nm span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.times {
  flex: none; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink);
  font-size: 12px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center;
}
.person .sub { font-size: 12px; color: var(--muted); }
.person .score { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.person .score b { font-size: 16px; font-weight: 800; }
.person .score span { font-size: 12px; color: var(--muted); }
.history { padding: 0 14px 12px 60px; display: flex; flex-direction: column; gap: 6px; }
.history div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 13px; color: var(--muted); }
.history .src { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .res { flex: none; white-space: nowrap; }
.history b { color: var(--ink); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------- меню ---------- */
.overlay { position: fixed; inset: 0; background: rgba(21, 23, 43, .55); z-index: 50; display: flex; animation: fade .15s; }
.drawer {
  width: min(300px, 82vw); height: 100%; background: var(--card); padding: max(20px, env(safe-area-inset-top)) 14px 24px;
  display: flex; flex-direction: column; gap: 6px; animation: slide .2s ease-out;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 18px; gap: 8px; }
.drawer-head .brand { font-size: 15px; }
.nav-link {
  height: 52px; display: flex; align-items: center; gap: 14px; padding: 0 12px; border-radius: 12px; border: 0;
  background: transparent; font-size: 16px; font-weight: 600; text-align: left; color: var(--ink); width: 100%;
}
.nav-link svg { width: 22px; height: 22px; }
.nav-link.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }
.drawer .foot { margin-top: auto; padding: 0 8px; font-size: 13px; color: var(--muted); }

/* ---------- окно подтверждения ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(21, 23, 43, .55); display: flex; align-items: flex-end; justify-content: center; padding: 16px; animation: fade .15s; }
.modal {
  width: 100%; max-width: 420px; background: var(--card); border-radius: 22px; padding: 24px 20px 20px;
  display: flex; flex-direction: column; gap: 10px; animation: rise .2s ease-out;
}
.modal .m-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--bad-soft); color: var(--bad); display: flex; align-items: center; justify-content: center; }
.modal .m-icon svg { width: 26px; height: 26px; }
.modal p { margin: 0 0 8px; color: #4A4E68; }
.modal .btn-col { margin-top: 4px; }
@media (min-width: 600px) { .modal-wrap { align-items: center; } }

.loading { display: flex; justify-content: center; padding: 40px 0; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(-100%); } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

:focus-visible { outline: 3px solid rgba(48, 54, 201, .45); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
