/* Quiz — базовая дизайн-система (§7).
   Темы: <body data-theme="dark"> (экран, телефон) и "light" (админка, async).
   Треки добавляют свои файлы: live.css, admin.css, async.css — поверх этого.
   Никаких внешних ресурсов и шрифтов: system-ui. */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --radius-sm: 8px;
  --gap: 12px;
  --gap-lg: 24px;
  --btn-h: 64px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .18);
  --dur: 180ms;

  /* варианты A–F: цвет + фигура + буква (дальтоники, 10 м) */
  --opt-a: #e5484d;  /* красный ▲ */
  --opt-b: #2f6fed;  /* синий ◆ */
  --opt-c: #f5c518;  /* жёлтый ● */
  --opt-d: #1fa860;  /* зелёный ■ */
  --opt-e: #f2801e;  /* оранжевый ⬟ */
  --opt-f: #8b4de0;  /* фиолетовый ★ */
  --opt-c-fg: #1a1500;
  --opt-fg: #ffffff;

  --ok: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;
}

[data-theme="dark"] {
  --bg: #0f1220;
  --bg-2: #171b30;
  --card: #1c2140;
  --fg: #f4f5fb;
  --fg-2: #c7cae0;
  --muted: #9a9ebd;
  --line: #2b3157;
  --accent: #7c5cff;
  --accent-fg: #ffffff;
  --accent-2: #a58bff;
  --input-bg: #121631;
  --focus: #c9b9ff;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-2: #ffffff;
  --card: #ffffff;
  --fg: #14172b;
  --fg-2: #3a3f5c;
  --muted: #5c6280;
  --line: #d9dcea;
  --accent: #5b3fe0;
  --accent-fg: #ffffff;
  --accent-2: #7c5cff;
  --input-bg: #ffffff;
  --focus: #5b3fe0;
  color-scheme: light;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 500 17px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
[hidden] { display: none !important; }

/* ---------- типографика ---------- */
.h1 { font-size: clamp(28px, 6vw, 40px); font-weight: 800; letter-spacing: -.01em; line-height: 1.1; }
.h2 { font-size: clamp(20px, 4vw, 26px); font-weight: 700; line-height: 1.2; }
.h3 { font-size: 18px; font-weight: 700; }
.lead { font-size: 18px; color: var(--fg-2); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.big { font-size: clamp(40px, 12vw, 96px); font-weight: 800; letter-spacing: .04em; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .06em; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.err { color: var(--bad); font-weight: 600; }
.center { text-align: center; align-items: center; }

/* ---------- раскладка ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.page-narrow { max-width: 480px; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.stack-lg { display: flex; flex-direction: column; gap: var(--gap-lg); }
.row { display: flex; flex-wrap: wrap; gap: var(--gap); align-items: center; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
[data-theme="light"] .card { box-shadow: 0 1px 3px rgba(20, 23, 43, .08); }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; justify-content: space-between; gap: var(--gap); padding: 12px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.link { color: var(--accent-2); font-weight: 600; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ---------- кнопки (≥ 64 px, зона большого пальца) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--btn-h); padding: 12px 22px;
  border: 2px solid transparent; border-radius: var(--radius);
  background: var(--bg-2); color: var(--fg);
  font-weight: 700; font-size: 18px; line-height: 1.2;
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: transform var(--dur), opacity var(--dur), background-color var(--dur);
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-secondary { border-color: var(--line); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-ghost { background: transparent; color: var(--fg-2); }
.btn-lg { font-size: 22px; min-height: 72px; width: 100%; }
.btn-sm { min-height: 44px; padding: 8px 14px; font-size: 15px; border-radius: var(--radius-sm); }
.btn-block { width: 100%; }

/* ---------- формы ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 14px; font-weight: 700; color: var(--fg-2); text-transform: uppercase; letter-spacing: .04em; }
.help { font-size: 14px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 56px; padding: 12px 16px;
  background: var(--input-bg); color: var(--fg);
  border: 2px solid var(--line); border-radius: var(--radius-sm);
  font-size: 20px; outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--focus); }
.input[readonly] { opacity: .7; }
.textarea { min-height: 120px; resize: vertical; }
.pin-input { font-size: 34px; font-weight: 800; text-align: center; letter-spacing: .5em; font-variant-numeric: tabular-nums; padding-left: calc(16px + .5em); }
.input-prefix { display: flex; align-items: stretch; }
.input-prefix .prefix { display: flex; align-items: center; padding: 0 12px; border: 2px solid var(--line); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--bg-2); color: var(--muted); font-size: 22px; font-weight: 700; }
.input-prefix .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 16px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.me { background: color-mix(in srgb, var(--accent) 18%, transparent); }

/* ---------- плитки вариантов A–F ---------- */
.opts { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap); }
.opts.cols-3 { grid-template-columns: repeat(3, 1fr); }
.opt {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: var(--btn-h); padding: 14px 16px;
  border: 0; border-radius: var(--radius);
  color: var(--opt-fg); background: var(--opt-bg, var(--accent));
  font-weight: 700; font-size: 18px; text-align: left; line-height: 1.25;
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: transform var(--dur), opacity var(--dur), filter var(--dur);
}
.opt:active, .opt.pressed { transform: scale(.96); }
.opt:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.opt:disabled { cursor: default; }
.opt.dim { opacity: .4; }
.opt.correct { outline: 4px solid var(--ok); outline-offset: 2px; }
.opt.selected::after { content: "✓"; position: absolute; top: 8px; right: 12px; font-size: 22px; }
.opt-a { --opt-bg: var(--opt-a); }
.opt-b { --opt-bg: var(--opt-b); }
.opt-c { --opt-bg: var(--opt-c); color: var(--opt-c-fg); }
.opt-d { --opt-bg: var(--opt-d); }
.opt-e { --opt-bg: var(--opt-e); }
.opt-f { --opt-bg: var(--opt-f); }
.opt__badge { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.shapes-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.opt__shape { width: clamp(28px, 12vw, 44px); height: clamp(28px, 12vw, 44px); fill: currentColor; }
.opt__letter { font-size: 22px; font-weight: 800; }
.opt__text { flex: 1 1 auto; word-break: break-word; }
.opt__img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); }
.opt.has-img { flex-direction: column; align-items: stretch; }

/* маленькие бейджи фигур (лидерборд, результаты) */
.shape { width: 1.1em; height: 1.1em; fill: currentColor; vertical-align: -0.15em; display: inline-block; }
.shape-a { color: var(--opt-a); } .shape-b { color: var(--opt-b); } .shape-c { color: var(--opt-c); }
.shape-d { color: var(--opt-d); } .shape-e { color: var(--opt-e); } .shape-f { color: var(--opt-f); }

/* ---------- состояния / бейджи ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; background: var(--bg-2); color: var(--fg-2); border: 1px solid var(--line); }
.badge-ok { background: var(--ok); color: #06210f; border-color: transparent; }
.badge-bad { background: var(--bad); color: #fff; border-color: transparent; }
.badge-warn { background: var(--warn); color: #221600; border-color: transparent; }
.badge-accent { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }

.bar { position: relative; height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; width: var(--w, 0%); background: var(--accent); border-radius: 999px; transition: width 250ms linear; }
.bar.danger > i { background: var(--bad); }

.banner { padding: 12px 16px; border-radius: var(--radius-sm); font-weight: 600; }
.banner-warn { background: color-mix(in srgb, var(--warn) 22%, var(--card)); color: var(--fg); }
.banner-bad { background: color-mix(in srgb, var(--bad) 22%, var(--card)); color: var(--fg); }
.banner-ok { background: color-mix(in srgb, var(--ok) 22%, var(--card)); color: var(--fg); }
.topline { position: fixed; top: 0; left: 0; right: 0; height: 6px; z-index: 50; }
.topline.warn { background: var(--warn); }
.topline.bad { background: var(--bad); }

/* ---------- диалоги / оверлеи ---------- */
.dialog { border: 0; border-radius: var(--radius); background: var(--card); color: var(--fg); padding: 24px; max-width: min(92vw, 460px); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(15, 18, 32, .82); z-index: 100; font-size: clamp(32px, 8vw, 96px); font-weight: 800; }

/* ---------- утилиты ---------- */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.w-full { width: 100%; }
.grow { flex: 1 1 auto; }
.nowrap { white-space: nowrap; }
.mt { margin-top: var(--gap); }
.mt-lg { margin-top: var(--gap-lg); }
.thumb-zone { padding-bottom: 20dvh; }
.sticky-bottom { position: sticky; bottom: 0; padding: 12px 0 max(12px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.no-select { user-select: none; -webkit-user-select: none; }

/* ---------- motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; animation-iteration-count: 1 !important; }
}
@media (min-width: 720px) {
  body { font-size: 18px; }
  .opts { gap: 16px; }
}
