:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #15171c;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2f6fec;
  --accent-soft: #e6eeff;
  --ok: #1f9d55;
  --ok-soft: #e3f6ea;
  --bad: #d64545;
  --bad-soft: #fde8e8;
  --warn: #c98400;
  --warn-soft: #fff4dc;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 16px;
  --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --card: #1b1e25;
    --text: #eef0f4;
    --muted: #9aa1ad;
    --line: #2b2f38;
    --accent: #6b9bff;
    --accent-soft: #1f2b45;
    --ok: #3cc47c;
    --ok-soft: #173326;
    --bad: #ff6b6b;
    --bad-soft: #3a1d1f;
    --warn: #f0b23e;
    --warn-soft: #3a2f17;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--tabs-h) + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
body.quiz-mode { padding-bottom: env(safe-area-inset-bottom); }
#app { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; }
h1 { font-size: 28px; margin: 8px 0 16px; letter-spacing: -.02em; }
h2 { font-size: 20px; margin: 24px 0 10px; letter-spacing: -.01em; }
h3 { font-size: 16px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 12px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 .card { margin: 0; }
.big { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.label { font-size: 13px; color: var(--muted); }

.btn {
  display: block; width: 100%; border: 0; border-radius: 14px; padding: 15px 16px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 17px; cursor: pointer;
}
.btn:active { opacity: .85; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn[disabled] { opacity: .45; }

.mode {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--card); border: 0; border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); margin-bottom: 10px; cursor: pointer;
}
.mode:active { transform: scale(.99); }
.mode .ic { font-size: 26px; width: 40px; height: 40px; display: grid; place-items: center;
  background: var(--accent-soft); border-radius: 12px; flex: none; }
.mode .t { font-weight: 600; }
.mode .d { font-size: 13px; color: var(--muted); }
.mode .badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 999px;
  padding: 2px 9px; font-size: 13px; font-weight: 600; flex: none; }
.mode.primary { background: var(--accent-strong, var(--accent)); color: #fff; }
@media (prefers-color-scheme: dark) { :root { --accent-strong: #3466d6; } .btn:not(.secondary):not(.ghost):not(.danger) { background: #3466d6; } }
.mode.primary .ic { background: rgba(255,255,255,.18); }
.mode.primary .d { color: rgba(255,255,255,.85); }
.mode.primary .badge { background: #fff; color: var(--accent); }

.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; }
.bar .ok { background: var(--ok); } .bar .warn { background: var(--warn); } .bar .acc { background: var(--accent); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }

/* Quiz */
.qtop { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.qtop .x { border: 0; background: var(--card); width: 38px; height: 38px; border-radius: 12px;
  font-size: 20px; box-shadow: var(--shadow); cursor: pointer; flex: none; }
.qtop .prog { flex: 1; }
.qtop .lang { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 700;
  border-radius: 10px; padding: 8px 10px; font-size: 14px; cursor: pointer; flex: none; }
.qmeta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; gap: 8px; }
.tag { background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.tag.dmv { background: var(--ok-soft); color: var(--ok); }
.qtext { font-size: 19px; font-weight: 600; line-height: 1.35; margin: 4px 0 6px; }
.qalt { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.qimg { display: flex; justify-content: center; margin: 12px 0; }
.qimg img { max-width: 170px; max-height: 170px; width: auto; height: auto; }
.opts { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.opt {
  text-align: left; border: 2px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 13px 14px; cursor: pointer; display: flex; gap: 12px; align-items: flex-start;
}
.opt .k { flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--bg);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: var(--muted); }
.opt .o-alt { display: block; font-size: 13px; color: var(--muted); margin-top: 3px; }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .k { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .k { background: var(--bad); color: #fff; }
.opt[disabled] { cursor: default; }
.explain { margin-top: 14px; border-radius: 14px; padding: 14px; background: var(--card); box-shadow: var(--shadow); }
.explain .verdict { font-weight: 700; margin-bottom: 6px; }
.explain .verdict.ok { color: var(--ok); } .explain .verdict.bad { color: var(--bad); }
.ex-body p { margin: 0 0 8px; }
.ex-body p:last-child { margin-bottom: 0; }
.explain .alt p { margin: 0 0 6px; }
.explain .ref { font-size: 12px; color: var(--muted); margin-top: 8px; }
.explain .alt { font-size: 14px; color: var(--muted); margin-top: 6px; }
.qfoot { position: sticky; bottom: 0; padding: 12px 0 calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent); margin-top: 8px; }

/* Lists */
.row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.row.click { cursor: pointer; }
.pill { font-size: 12px; font-weight: 700; border-radius: 8px; padding: 2px 8px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.chart { display: flex; align-items: flex-end; gap: 3px; height: 130px; padding-top: 16px; }
.chart .colw { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; }
.chart .cn { font-size: 9px; line-height: 12px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: visible; }
.chart .col { display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; min-height: 2px; background: var(--line); }
.chart .col .c { background: var(--ok); } .chart .col .w { background: var(--bad); }
.chart-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }

.ring { --p: 0; width: 120px; height: 120px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--ring-c, var(--accent)) calc(var(--p) * 1%), var(--line) 0);
  display: grid; place-items: center; }
.ring > div { width: 94px; height: 94px; border-radius: 50%; background: var(--card); display: grid; place-items: center; text-align: center; }
.ring b { font-size: 26px; letter-spacing: -.02em; display: block; }
.ready { display: flex; gap: 16px; align-items: center; }

input[type=password], input[type=number], select {
  font: inherit; width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text);
}
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting select, .setting input { width: auto; min-width: 90px; }
.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); z-index: 10;
}
.tabs button { border: 0; background: none; display: flex; flex-direction: column; align-items: center;
  font-size: 11px; color: var(--muted); gap: 2px; padding: 4px 16px; cursor: pointer; }
.tabs button .ti { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); }
.tabs button.active .ti { filter: none; opacity: 1; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; }
.center { text-align: center; }
.result-big { font-size: 56px; font-weight: 800; letter-spacing: -.03em; }
.offline { background: var(--warn-soft); color: var(--warn); font-size: 13px; padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; }
