:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #fbfaf7;
  --ink: #1c2430;
  --muted: #647082;
  --line: #dcd9d1;
  --accent: #1f3a5f;
  --accent-soft: #e7edf5;
  --ok: #1d6b46;
  --ok-soft: #e3f1e8;
  --bad: #a8322a;
  --bad-soft: #f8e6e3;
  --warn: #8a6415;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 36, 48, .05), 0 8px 24px rgba(28, 36, 48, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181e;
    --surface: #1c222b;
    --surface-2: #202730;
    --ink: #e9e7e1;
    --muted: #9aa6b6;
    --line: #333c48;
    --accent: #9dc0ea;
    --accent-soft: #233244;
    --ok: #6ed3a1;
    --ok-soft: #1b3328;
    --bad: #f2938a;
    --bad-soft: #38221f;
    --warn: #e0b866;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 30px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h, 64px) + 88px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(1060px, 100% - 40px); margin-inline: auto; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

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

.brand { display: inline-flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: var(--surface);
  font: 700 20px/1 Georgia, serif;
}
.brand-text { display: grid; line-height: 1.15; }
.brand-text strong { font-size: 15px; letter-spacing: .01em; }
.brand-text small { color: var(--muted); font-size: 12px; }

.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav-link {
  appearance: none; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: 14px; padding: 8px 12px; border-radius: 8px;
  cursor: pointer;
}
.nav-link:hover { color: var(--ink); background: var(--surface-2); }
.nav-link.is-active { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }

.badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 600; vertical-align: 1px;
}

main { padding: 36px 0 64px; outline: none; }

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; letter-spacing: -.01em; color: var(--ink); }
h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.15; margin: 0 0 12px; }
h2 { font-size: 24px; margin: 0 0 14px; }
h3 { font-size: 18px; margin: 0 0 8px; }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.eyebrow {
  text-transform: uppercase; letter-spacing: .12em; font-size: 11px;
  font-weight: 700; color: var(--muted); margin-bottom: 10px;
}

.hero { padding: 8px 0 30px; max-width: 760px; }
.hero p { font-size: 17px; color: var(--muted); max-width: 640px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}

.mode-card { display: flex; flex-direction: column; gap: 10px; cursor: pointer; text-align: left; color: inherit; }
.mode-card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); transform: translateY(-1px); }
.mode-card .num { font: 600 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--accent); letter-spacing: .08em; }
.mode-card p { color: var(--muted); margin: 0; font-size: 14px; flex: 1; }
.mode-card .go { color: var(--accent); font-size: 14px; font-weight: 600; }

.stat { display: grid; gap: 2px; }
.stat b { font: 600 26px/1.1 Georgia, serif; }
.stat span { color: var(--muted); font-size: 13px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 600; font-size: 15px;
  padding: 11px 18px; border-radius: 10px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #14181e; } }
.btn-ghost { background: none; }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); background: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.field { display: grid; gap: 6px; margin-bottom: 18px; }
.field > label { font-size: 13px; font-weight: 600; }
select, input[type="number"], input[type="search"], input[type="text"] {
  font: inherit; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; width: 100%;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
input[type="search"], input[type="number"] {
  -webkit-appearance: none; appearance: none; min-height: 48px;
}
::placeholder { color: var(--muted); opacity: 1; }
select:focus, input:focus {
  outline: none; border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.segmented { display: flex; gap: 8px; flex-wrap: wrap; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 9px 14px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.segmented input:checked + label { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }

.progress-line { height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.progress-line > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s; }
.progress-line.ok > i { background: var(--ok); }
.progress-line.bad > i { background: var(--bad); }

.exam-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.timer {
  font: 600 20px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.timer.is-low { color: var(--bad); border-color: var(--bad); }

/* sticky quiz header (exam / training) */
.quiz-head {
  position: sticky; top: calc(var(--topbar-h, 0px) + 10px); z-index: 15;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; margin: 0 0 14px;
  box-shadow: var(--shadow);
}
.quiz-head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.quiz-head-info { min-width: 0; }
.quiz-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quiz-progress { height: 6px; margin-top: 9px; }

/* sticky action bar (bottom) */
.actionbar {
  position: sticky; bottom: 10px; z-index: 15;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; margin: 16px 0 0;
  box-shadow: 0 -2px 6px rgba(28, 36, 48, .04), 0 10px 28px rgba(28, 36, 48, .12);
}
@supports (bottom: env(safe-area-inset-bottom)) {
  .actionbar { bottom: calc(10px + env(safe-area-inset-bottom)); }
}
.actionbar-inner { display: flex; gap: 10px; align-items: center; }
.actionbar-inner .btn { flex: 0 0 auto; }
.actionbar-wide { flex: 1 1 auto !important; width: 100%; }
.actionbar-end { margin-left: auto; }

/* collapsible question map */
.qmap { margin-top: 16px; padding: 0; overflow: hidden; }
.qmap summary {
  list-style: none; cursor: pointer; user-select: none;
  padding: 14px 18px; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.qmap summary::-webkit-details-marker { display: none; }
.qmap summary::after { content: "▾"; color: var(--muted); transition: transform .15s; }
.qmap[open] summary::after { transform: rotate(180deg); }
.qmap[open] summary { border-bottom: 1px solid var(--line); }
.qmap .navgrid { margin: 14px 18px 16px; }

.btn-sm { font-size: 14px; padding: 8px 14px; }

.qmeta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.chip {
  display: inline-block; padding: 3px 9px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 600;
}
.chip.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

.qtext { font-size: 20px; line-height: 1.45; margin: 6px 0 20px; font-weight: 600; }

.options { display: grid; gap: 10px; margin: 0 0 20px; padding: 0; }
.option {
  display: flex; gap: 12px; align-items: flex-start;
  width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; min-height: 48px; font: inherit; color: inherit; cursor: pointer;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: border-color .12s, background .12s;
}
.option:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.option:active { transform: scale(.995); background: var(--accent-soft); }
.option .mark {
  flex: 0 0 24px; height: 24px; border-radius: 50%;
  border: 1.5px solid var(--line); display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: var(--muted); margin-top: 1px;
}
.option.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.option.is-selected .mark { background: var(--accent); border-color: var(--accent); color: #fff; }
.option.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.option.is-correct .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.is-wrong .mark { background: var(--bad); border-color: var(--bad); color: #fff; }
.option[disabled] { cursor: default; }

.feedback { border-radius: 12px; padding: 16px 18px; margin: 0 0 18px; border: 1px solid var(--line); background: var(--surface-2); }
.feedback.ok { border-color: var(--ok); background: var(--ok-soft); }
.feedback.bad { border-color: var(--bad); background: var(--bad-soft); }
.feedback h3 { margin-bottom: 6px; }
.feedback p:last-child { margin-bottom: 0; }

.exam-footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; padding-top: 16px; border-top: 1px solid var(--line); }

.navgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 7px; margin-top: 12px; }
.navgrid button {
  aspect-ratio: 1; min-width: 44px; min-height: 44px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; font: 600 13px/1 inherit; color: var(--muted); cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.navgrid button.is-answered { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.navgrid button.is-current { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--ink); }

.result-hero { display: flex; gap: 26px; align-items: center; flex-wrap: wrap; }
.score-ring {
  --v: 0;
  width: 132px; height: 132px; border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--ring, var(--accent)) calc(var(--v) * 1%), var(--surface-2) 0);
  position: relative;
}
.score-ring::before {
  content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--surface);
}
.score-ring span { position: relative; font: 600 32px/1 Georgia, serif; }
.score-ring.ok { --ring: var(--ok); }
.score-ring.bad { --ring: var(--bad); }

.verdict { font-size: 15px; font-weight: 700; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }

.review { display: grid; gap: 14px; }
.review-item { border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; background: var(--surface); }
.review-item .q { font-weight: 600; margin-bottom: 10px; }
.answer-line { display: grid; grid-template-columns: 120px 1fr; gap: 10px; font-size: 14px; padding: 3px 0; }
.answer-line dt { color: var(--muted); }
.answer-line dd { margin: 0; }

.topic-list { display: grid; gap: 8px; }
.topic-row {
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 11px; cursor: pointer; text-align: left; font: inherit; color: inherit; width: 100%;
}
.topic-row:hover { border-color: var(--accent); }
.topic-row .t { display: flex; gap: 10px; align-items: baseline; flex: 1 1 auto; min-width: 0; }
.topic-row .t span:last-child { min-width: 0; }
.topic-row .n { font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); min-width: 26px; }
.topic-row .c { color: var(--muted); font-size: 13px; white-space: nowrap; text-align: right; flex: 0 0 auto; }
.topic-row .bar { width: 72px; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.topic-row .bar > i { display: block; height: 100%; background: var(--ok); }
.topic-row .bar.mid > i { background: var(--warn); }
.topic-row .bar.low > i { background: var(--bad); }

.t-ok { color: var(--ok); }
.t-mid { color: var(--warn); }
.t-bad { color: var(--bad); }

/* mistakes list */
.mistake-list { display: grid; gap: 10px; }
.mistake-row {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 11px; padding: 12px 16px;
}
.mistake-row .mr-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 7px; flex-wrap: wrap; }
.mistake-row .mr-q { font-size: 15px; line-height: 1.45; font-weight: 500; }

/* CTA rows stack full-width on mobile */
@media (max-width: 600px) {
  .btn-row.stack-mobile { flex-direction: column; align-items: stretch; }
  .btn-row.stack-mobile .btn { width: 100%; justify-content: center; }
}

.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.pill {
  border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px;
  background: var(--surface); color: var(--muted); font-size: 13px; cursor: pointer;
}
.pill.is-active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.table td.num { font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

.footer { padding: 24px 0 40px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }

@media (max-width: 820px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .wrap { width: min(1060px, 100% - 24px); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat b { font-size: 20px; }
  .topic-row { flex-wrap: wrap; row-gap: 4px; }
  .topic-row .c { margin-left: auto; }
  .topic-row .bar { width: 100%; order: 3; }
  .topic-row .t { flex: 1 1 auto; min-width: 0; }
  .topic-row .t span:last-child { min-width: 0; }
  .qtext { font-size: 18px; }
  .answer-line { grid-template-columns: 1fr; gap: 2px; }
  .brand-text small { display: none; }

  /* compact topbar: one brand row + one scrollable nav row */
  .topbar-inner { min-height: 52px; gap: 6px; padding-block: 6px; }
  .brand { gap: 8px; }
  .brand-mark { width: 30px; height: 30px; border-radius: 8px; font-size: 17px; }
  .brand-text strong { font-size: 14px; }
  .nav {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin-inline: -12px; padding-inline: 12px;
    -webkit-overflow-scrolling: touch;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { white-space: nowrap; padding: 9px 11px; font-size: 13px; }

  /* comfortable touch targets */
  .btn { min-height: 44px; padding: 11px 16px; }
  .segmented label { min-height: 44px; display: inline-flex; align-items: center; }
  .actionbar { padding: 10px 12px; }
  .actionbar-inner { gap: 8px; }
  .actionbar-inner .btn { flex: 1 1 auto; padding-inline: 8px; }
  .actionbar-inner .btn.actionbar-end { flex: 1.2 1 auto; }
  .option { padding: 14px 15px; }
  .option .mark { flex: 0 0 26px; width: 26px; height: 26px; font-size: 13px; margin-top: 0; }
  .quiz-head { padding: 10px 13px; }
  .timer { font-size: 18px; padding: 8px 12px; }
  main { padding: 20px 0 56px; }
  .footer { padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
}
