:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-grad: none;
  --card: #ffffff;
  --card-2: #fafbfc;
  --text: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-line: #c7d2fe;
  --green: #067647;
  --green-soft: #ecfdf3;
  --green-line: #a6f4c5;
  --red: #b42318;
  --red-soft: #fef3f2;
  --red-line: #fecdca;
  --amber: #b54708;
  --amber-soft: #fffaeb;
  --amber-line: #fedf89;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 10px 30px -12px rgba(16, 24, 40, .12);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b0c10;
    --bg-grad: radial-gradient(1200px 600px at 15% -10%, #1a1730 0%, transparent 60%),
               radial-gradient(900px 500px at 110% 0%, #0f2420 0%, transparent 55%);
    --card: #14161c;
    --card-2: #191c23;
    --text: #f2f4f7;
    --muted: #98a2b3;
    --line: #262a33;
    --line-strong: #343945;
    --accent: #8b85ff;
    --accent-hover: #a5a0ff;
    --accent-soft: #1d1b36;
    --accent-line: #3b3670;
    --green: #75e0a7;
    --green-soft: #0e2a1e;
    --green-line: #1d4d35;
    --red: #fda29b;
    --red-soft: #2c1513;
    --red-line: #5b2521;
    --amber: #fec84b;
    --amber-soft: #2a2110;
    --amber-line: #55401a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 40px -18px rgba(0, 0, 0, .7);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --bg-grad: none;
  --card: #ffffff;
  --card-2: #fafbfc;
  --text: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-line: #c7d2fe;
  --green: #067647;
  --green-soft: #ecfdf3;
  --green-line: #a6f4c5;
  --red: #b42318;
  --red-soft: #fef3f2;
  --red-line: #fecdca;
  --amber: #b54708;
  --amber-soft: #fffaeb;
  --amber-line: #fedf89;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 10px 30px -12px rgba(16, 24, 40, .12);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c10;
  --bg-grad: radial-gradient(1200px 600px at 15% -10%, #1a1730 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 0%, #0f2420 0%, transparent 55%);
  --card: #14161c;
  --card-2: #191c23;
  --text: #f2f4f7;
  --muted: #98a2b3;
  --line: #262a33;
  --line-strong: #343945;
  --accent: #8b85ff;
  --accent-hover: #a5a0ff;
  --accent-soft: #1d1b36;
  --accent-line: #3b3670;
  --green: #75e0a7;
  --green-soft: #0e2a1e;
  --green-line: #1d4d35;
  --red: #fda29b;
  --red-soft: #2c1513;
  --red-line: #5b2521;
  --amber: #fec84b;
  --amber-soft: #2a2110;
  --amber-line: #55401a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 40px -18px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1180px; margin: 0 auto; padding: 28px 22px 64px; }
.screen { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h1 { font-size: 30px; line-height: 1.2; letter-spacing: -.02em; margin: 18px 0 8px; }
h2 { font-size: 20px; line-height: 1.45; letter-spacing: -.01em; margin: 18px 0 18px; font-weight: 600; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 30px 0 12px; }
.sub { color: var(--muted); margin: 0 0 24px; max-width: 60ch; }

.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row.compact { gap: 10px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 20px;
  box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--accent) 60%, transparent);
}
.logo.small { width: 28px; height: 28px; border-radius: 9px; font-size: 15px; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }
#themeBtn { margin-left: auto; }

.setup .exam-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px; margin: 8px 0 22px;
}

.exam-card {
  text-align: left; cursor: pointer; font: inherit; color: inherit;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 16px; transition: border-color .15s, box-shadow .15s, transform .15s;
  box-shadow: var(--shadow);
}
.exam-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.exam-card.active { border-color: var(--accent); background: var(--accent-soft); }
.exam-card .ec-title { font-weight: 650; letter-spacing: -.01em; display: block; margin-bottom: 4px; }
.exam-card .ec-meta { font-size: 12.5px; color: var(--muted); }
.exam-card .ec-dots { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.exam-card .ec-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .55; }

.settings {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
select, input {
  font: inherit; color: inherit; background: var(--card-2);
  border: 1px solid var(--line-strong); border-radius: 10px; padding: 9px 10px;
  width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
select:focus-visible, input:focus-visible, button:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.setup-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; align-items: center; }
.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent; transition: background .15s, border-color .15s, color .15s, transform .1s, box-shadow .15s; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.primary { background: var(--accent); color: #fff; padding: 10px 18px; font-weight: 600; border-color: var(--accent); }
.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.ghost { background: transparent; color: var(--text); border-color: var(--line-strong); padding: 10px 16px; font-weight: 550; }
.ghost:hover:not(:disabled) { background: var(--card-2); border-color: var(--muted); }
.big { padding: 12px 22px; font-size: 15px; border-radius: 12px; }
.small { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.wide { width: 100%; margin-top: 10px; }
.icon-btn { background: transparent; border: 1px solid var(--line); color: var(--muted); width: 36px; height: 36px; border-radius: 10px; font-size: 16px; }
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.spacer { flex: 1; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.pill {
  font-size: 12.5px; font-weight: 600; padding: 6px 11px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.progress { height: 5px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 16px 0 22px; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #22c55e)); border-radius: 999px; transition: width .25s ease; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 268px; gap: 20px; align-items: start; }

.question-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow);
}
.qmeta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em; padding: 4px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line);
}
.chip.subtle { background: var(--card-2); color: var(--muted); border-color: var(--line); text-transform: capitalize; }

.scenario {
  margin-top: 16px; padding: 12px 14px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line); color: var(--muted); font-size: 13.5px;
}
.scenario strong { color: var(--text); }

.options { display: flex; flex-direction: column; gap: 9px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  background: var(--card); color: var(--text); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font: inherit; line-height: 1.5;
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.option:hover:not(:disabled) { border-color: var(--accent-line); background: var(--accent-soft); }
.option .letter {
  flex: 0 0 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: var(--card-2); border: 1px solid var(--line); font-size: 12.5px; font-weight: 700; color: var(--muted);
}
.option .text { flex: 1; }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.selected .letter { background: var(--accent); border-color: var(--accent); color: #fff; }
.option.correct { border-color: var(--green); background: var(--green-soft); }
.option.correct .letter { background: var(--green); border-color: var(--green); color: #fff; }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option.wrong .letter { background: var(--red); border-color: var(--red); color: #fff; }
.option.dim { opacity: .62; }
.option:disabled { cursor: default; }

.feedback {
  margin-top: 18px; padding: 16px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line); border-left: 3px solid var(--accent);
}
.feedback.ok { border-left-color: var(--green); background: var(--green-soft); }
.feedback.bad { border-left-color: var(--red); background: var(--red-soft); }
.feedback-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.verdict { font-weight: 700; letter-spacing: -.01em; }
.verdict.ok { color: var(--green); }
.verdict.bad { color: var(--red); }
.feedback-answer { color: var(--muted); font-size: 13.5px; }
.feedback-label { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-top: 10px; }
.rationale { margin: 4px 0 0; font-size: 14px; line-height: 1.6; }

.actions { display: flex; align-items: center; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.kbd-hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }

.rail {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); position: sticky; top: 20px;
}
.rail-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 12px; }
.rail-count { font-weight: 600; letter-spacing: 0; text-transform: none; }
.navigator {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
  max-height: 302px; overflow-y: auto; padding-right: 2px;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
.nav-btn {
  aspect-ratio: 1; min-height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--muted); font-size: 12px; font-weight: 600;
  display: grid; place-items: center; position: relative; font-variant-numeric: tabular-nums;
}
.nav-btn:hover { border-color: var(--line-strong); color: var(--text); }
.nav-btn.answered { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.nav-btn.correct { background: var(--green-soft); border-color: var(--green-line); color: var(--green); }
.nav-btn.wrong { background: var(--red-soft); border-color: var(--red-line); color: var(--red); }
.nav-btn.current { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--text); }
.nav-btn.flagged::after {
  content: ""; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--amber);
}
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin: 14px 0 4px; font-size: 11.5px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; border: 1px solid var(--line); }
.dot.correct { background: var(--green-soft); border-color: var(--green-line); }
.dot.wrong { background: var(--red-soft); border-color: var(--red-line); }
.dot.pending { background: var(--accent-soft); border-color: var(--accent-line); }
.dot.flagged { background: var(--amber); border-color: var(--amber); }

.results { max-width: 860px; margin: 20px auto 0; }
.result-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: var(--shadow); }
.result-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.eyebrow { text-transform: uppercase; letter-spacing: .1em; font-size: 11px; font-weight: 700; color: var(--accent); margin: 0 0 4px; }
.result-card h1 { margin-top: 0; }
.score-ring {
  width: 132px; height: 132px; border-radius: 50%; display: grid; place-content: center; text-align: center;
  background:
    radial-gradient(closest-side, var(--card) 78%, transparent 79% 100%),
    conic-gradient(var(--accent) var(--pct, 0%), var(--line) 0);
  flex: 0 0 auto;
}
.score-ring span { font-size: 27px; font-weight: 700; letter-spacing: -.03em; }
.score-ring small { font-size: 12px; color: var(--muted); }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 26px 0 6px; }
.stat { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat-num { display: block; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.stat-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.domain-breakdown { display: flex; flex-direction: column; gap: 10px; }
.domain-row { display: grid; grid-template-columns: minmax(140px, 1.1fr) 3fr auto; gap: 12px; align-items: center; font-size: 13px; }
.domain-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.domain-score { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; white-space: nowrap; }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 30px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .rail { position: static; }
  .navigator { grid-template-columns: repeat(10, 1fr); }
}

@media (max-width: 560px) {
  .app { padding: 20px 14px 48px; }
  .question-card, .result-card { padding: 18px; border-radius: 14px; }
  h1 { font-size: 24px; }
  h2 { font-size: 18px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .navigator { grid-template-columns: repeat(8, 1fr); }
  .score-ring { width: 108px; height: 108px; }
  .score-ring span { font-size: 22px; }
  .kbd-hint { display: none; }
  .domain-row { grid-template-columns: 1fr auto; }
  .domain-row .bar { grid-column: 1 / -1; order: 3; }
}

/* ---------- leaderboard ---------- */
.small-sub { font-size: 13px; margin: 2px 0 0; max-width: none; }
.ok-text { color: var(--green); }

.submit-block {
  margin-top: 28px; padding: 18px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 14px;
}
.submit-block h3 { margin: 0 0 2px; }
.submit-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.submit-row input { flex: 1 1 220px; max-width: 320px; }
.submit-block .hint { margin-top: 10px; }
.submit-block .hint:empty { display: none; }

.lb-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 20px; }
.lb-tab {
  font-size: 13px; font-weight: 600; color: var(--muted);
  background: var(--card-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 7px 14px;
}
.lb-tab:hover { border-color: var(--line-strong); color: var(--text); }
.lb-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.lb-list { display: flex; flex-direction: column; }
.lb-row {
  display: grid; grid-template-columns: 38px minmax(0, 1fr) 78px;
  gap: 12px; align-items: center;
  padding: 11px 12px; border-bottom: 1px solid var(--line);
}
.lb-row:first-child { border-top: 1px solid var(--line); }
.lb-row.me { background: var(--accent-soft); border-radius: 10px; border-color: var(--accent-line); }
.lb-rank {
  height: 30px; min-width: 30px; border-radius: 9px; display: grid; place-items: center;
  font-size: 12.5px; font-weight: 700; color: var(--muted);
  background: var(--card-2); border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.lb-rank.top-1 { color: var(--amber); background: var(--amber-soft); border-color: var(--amber-line); }
.lb-rank.top-2 { color: var(--muted); border-color: var(--line-strong); }
.lb-rank.top-3 { color: #9c4221; border-color: #f5c6a5; background: #fff4ec; }
html[data-theme="dark"] .lb-rank.top-3 { color: #f0a67e; background: #2b1c14; border-color: #55301d; }
@media (prefers-color-scheme: dark) {
  .lb-rank.top-3 { color: #f0a67e; background: #2b1c14; border-color: #55301d; }
}
.lb-person { display: flex; flex-direction: column; min-width: 0; }
.lb-name {
  font-weight: 600; display: flex; align-items: center; gap: 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lb-you {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--accent); background: var(--card); border: 1px solid var(--accent-line);
  border-radius: 999px; padding: 1px 7px; flex: 0 0 auto;
}
.lb-meta { font-size: 11.5px; color: var(--muted); }
.lb-score { text-align: right; display: flex; flex-direction: column; line-height: 1.3; }
.lb-pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-frac { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-empty {
  padding: 34px 20px; text-align: center; color: var(--muted); font-size: 14px;
  border: 1px dashed var(--line-strong); border-radius: 12px;
}
.lb-foot { padding: 12px 2px 0; font-size: 12px; color: var(--muted); }

@media (max-width: 560px) {
  .lb-row { grid-template-columns: 32px minmax(0, 1fr) 64px; gap: 10px; padding: 10px 8px; }
  .submit-row input { max-width: none; }
}

.timer-pill {
  font-size: 12.5px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.timer-pill.warning { color: var(--amber); background: var(--amber-soft); border-color: var(--amber-line); }
.timer-pill.danger { color: var(--red); background: var(--red-soft); border-color: var(--red-line); }
