/* ---------- переменные ---------- */
:root {
  --bg: #eef2f6;
  --card: #ffffff;
  --text: #17222d;
  --muted: #5b6b7b;
  --border: #dbe3ec;
  --primary: #14507a;
  --primary-text: #ffffff;
  --secondary: #e4ebf3;
  --secondary-text: #11405f;
  --danger: #c62828;
  --danger-contrast: #ffffff;
  --danger-bg: #fdecec;
  --success: #1b7a3d;
  --mark: #ffe58f;
  --shadow: 0 1px 2px rgba(16, 38, 58, .06), 0 6px 18px rgba(16, 38, 58, .06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --card: #18222d;
    --text: #e6edf4;
    --muted: #a2b3c4;
    --border: #2a3948;
    --primary: #5aa9de;
    --primary-text: #08131c;
    --secondary: #223243;
    --secondary-text: #cfe4f4;
    --danger: #ff8a80;
    --danger-contrast: #22090a;
    --danger-bg: #3a1f1f;
    --success: #7bd88f;
    --mark: #6b5a1f;
    --shadow: none;
  }
}

/* ---------- база ---------- */
* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(1.25rem, 2.2vw + .85rem, 1.6rem);
  line-height: 1.3;
}

h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  line-height: 1.35;
}

p { margin: 0 0 10px; }

a { color: var(--primary); }

.container {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px;
}

main { padding-top: 20px; padding-bottom: 32px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--muted); }
.lead { color: var(--muted); margin-bottom: 16px; }
.small { font-size: .85rem; }

mark {
  background: var(--mark);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

/* ---------- шапка ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}

.brand {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.nav { display: flex; gap: 4px; }

.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-size: .95rem;
  text-decoration: none;
}

.nav a.active {
  background: var(--primary);
  color: var(--primary-text);
}

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-text);
}

.btn-ghost {
  background: var(--card);
  border-color: var(--border);
}

.btn-wide { width: 100%; }

.btn:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.search-form {
  display: grid;
  gap: 10px;
  margin: 10px 0 6px;
}

.search-form input[type="search"] {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  -webkit-appearance: none;
}

.search-form input[type="search"]:focus {
  border-color: var(--primary);
  outline: none;
}

@media (min-width: 560px) {
  .search-form { grid-template-columns: 1fr auto; }
}

/* ---------- карточки, главная ---------- */
.hero { padding: 4px 0 12px; }

.card {
  margin: 0 0 14px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card h2 { margin-top: 0; }
.card p:last-child { margin-bottom: 0; }
.notice { border-color: var(--primary); }
.empty { color: var(--muted); }

.examples { margin: 12px 0 0; font-size: .9rem; color: var(--muted); }

.found { color: var(--muted); }

/* ---------- результаты поиска ---------- */
.results {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.result a {
  display: block;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s ease;
}

.result a:hover { border-color: var(--primary); }

.result-meta {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.result-text { display: block; }

.result-note {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: .8rem;
}

/* ---------- вопрос и варианты ---------- */
.crumbs { margin-bottom: 10px; }
.crumbs a { font-size: .95rem; text-decoration: none; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--secondary-text);
  font-size: .85rem;
  font-weight: 600;
}

.chip-muted {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
}

.question-title {
  margin: 10px 0 14px;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.45;
}

.options {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.opt-num {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--secondary);
  color: var(--secondary-text);
  font-size: .85rem;
  font-weight: 700;
}

.opt-text { flex: 1 1 auto; }

.badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--danger);
  color: var(--danger-contrast);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .03em;
  line-height: 1.5;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: 1px;
}

/* правильный ответ в режиме подсказки — красный */
.option-correct {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.option-correct .opt-text {
  color: var(--danger);
  font-weight: 600;
}

.option-correct .opt-num {
  background: var(--danger);
  color: var(--danger-contrast);
}

/* ---------- тест ---------- */
.testbar { margin: 4px 0 14px; }

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--secondary);
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width .2s ease;
}

.testbar-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .85rem;
}

.test-form { margin: 0 0 12px; }
.test-form .btn { margin-top: 2px; }

.option-choice {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.option-choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.option-choice:focus-within {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.option-choice input:checked ~ .opt-num {
  background: var(--primary);
  color: var(--primary-text);
}

.option-choice input:checked ~ .opt-text { font-weight: 600; }

.option-choice:has(input:checked) {
  border-color: var(--primary);
  background: var(--secondary);
}

/* ---------- выбор билета ---------- */
.ticket-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ticket {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: 74px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
}

.ticket:hover { border-color: var(--primary); }

.ticket-num { font-weight: 700; }

.ticket-meta {
  color: var(--muted);
  font-size: .82rem;
}

.last-result { font-size: .9rem; }

/* ---------- результат ---------- */
.score-card {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 16px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.score {
  color: var(--primary);
  font-size: 2.6rem;
  font-weight: 800;
  line-height: 1;
}

.score-total {
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 600;
}

.score-info p { margin: 0; }
.score-percent { font-weight: 600; }
.verdict { color: var(--muted); }

.mistakes {
  display: grid;
  gap: 12px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
}

.mistake {
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--danger);
  border-radius: 12px;
}

.mistake-q {
  margin-bottom: 8px;
  font-weight: 600;
}

.answer {
  margin: 4px 0;
  font-size: .95rem;
}

.answer-label {
  color: var(--muted);
  font-weight: 600;
}

.answer-wrong { color: var(--danger); }
.answer-correct { color: var(--success); }

/* ---------- служебное ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.actions form { margin: 0; }
.actions-split { margin-top: 14px; }

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pager .btn { flex: 1 1 auto; }

.flashes {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.flash {
  margin: 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--secondary);
}

.flash-error {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
}

.footer {
  padding-bottom: 28px;
  color: var(--muted);
  font-size: .85rem;
}

@media (max-width: 480px) {
  .actions > .btn,
  .actions form,
  .actions form .btn {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .question-title { font-size: 1rem; }
  .score { font-size: 2.2rem; }
  .brand { font-size: .95rem; }
  .nav a { padding: 8px 10px; font-size: .9rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
