:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --text: #1c1f26;
  --muted: #6b7280;
  --border: #e3e5ea;
  --accent: #3b6ef5;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --ok-bg: #e3f6ea;
  --bad: #d83a3a;
  --bad-bg: #fce8e8;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --surface: #1e2129;
    --text: #eceef3;
    --muted: #9097a5;
    --border: #2e323d;
    --accent: #5b87ff;
    --ok: #3ccf7a;
    --ok-bg: #173826;
    --bad: #ff6b6b;
    --bad-bg: #3d1d1f;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.screen {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 { font-size: 26px; margin: 8px 0 0; }
h2 { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 4px; }

.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- Настройки ---------- */

.group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.group-head { display: flex; justify-content: space-between; align-items: baseline; }

.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 0;
  cursor: pointer;
}
.opt + .opt, #regions + .opt { border-top: 1px solid var(--border); }
#regions .opt:first-child { border-top: 0; }
.opt span { flex: 1; }
.opt small { display: block; color: var(--muted); font-size: 14px; }
.opt input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex-shrink: 0; }

.switch input {
  appearance: none;
  width: 46px; height: 28px;
  border-radius: 14px;
  background: var(--border);
  position: relative;
  transition: background .2s;
}
.switch input::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

.link {
  background: none; border: 0; padding: 4px 0;
  color: var(--accent); font: inherit; font-size: 15px; cursor: pointer;
}

/* ---------- Кнопки ---------- */

.bottom { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

.btn {
  display: block;
  width: 100%;
  min-height: 54px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.ok { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.btn.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.btn.ok:disabled, .btn.bad:disabled { opacity: 1; }

.icon-btn {
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ---------- Карточка ---------- */

.quiz-head { display: flex; align-items: center; gap: 12px; }
.progress { flex: 1; height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
#progress-text { font-size: 15px; min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
}
.flag {
  width: 120px; height: 90px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
  margin: 0 auto 12px;
}
.flag.placeholder { visibility: hidden; }
#q-label { margin: 0; font-size: 15px; }
.q-text { font-size: 28px; font-weight: 700; margin: 4px 0 0; overflow-wrap: anywhere; }
.feedback { min-height: 1.4em; margin: 12px 0 0; font-weight: 600; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

.answers { display: flex; flex-direction: column; gap: 10px; }

#answer {
  width: 100%;
  min-height: 54px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 18px;
}
#answer:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#answer.ok { border-color: var(--ok); background: var(--ok-bg); }
#answer.bad { border-color: var(--bad); background: var(--bad-bg); }

/* ---------- Результат ---------- */

.score { text-align: center; padding: 16px 0; }
.score-num { font-size: 44px; font-weight: 800; margin: 0; }
.score p { margin: 0; }

.mistakes { list-style: none; margin: 0; padding: 0; }
.mistakes li {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.mistakes li:first-child { border-top: 0; }
.mistakes img { width: 32px; height: 24px; object-fit: cover; border-radius: 3px; border: 1px solid var(--border); }
.mistakes b { font-weight: 600; }
