:root {
  --bg: #14161a;
  --surface: #1c1f26;
  --surface-2: #23272f;
  --border: #333a45;
  --text: #e8eaed;
  --text-dim: #9aa3b0;
  --accent: #6aa6ff;
  --ok: #4ec98a;
  --bad: #ff7b72;
  --warn: #e3b341;
  --flag: #c08bef;
  --radius: 8px;
  --gap: 1rem;
}

:root[data-theme='light'] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #d3d8e0;
  --text: #1b1f27;
  --text-dim: #5b6472;
  --accent: #2b6cd4;
  --ok: #1a7f4b;
  --bad: #c03530;
  --warn: #8a6100;
  --flag: #7a3fb0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem var(--gap);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: var(--gap); flex-wrap: wrap; }
.topbar a { color: var(--text-dim); text-decoration: none; }
.topbar a:hover { color: var(--text); }

#view, #notices { max-width: 60rem; margin: 0 auto; padding: var(--gap); }
h1, h2, h3 { line-height: 1.25; }

.banner { padding: 0.75rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.banner--warn { border-color: var(--warn); }
.banner--error { border-color: var(--bad); }

.btn {
  display: inline-block;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover:not([disabled]) { border-color: var(--accent); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #0d1117; font-weight: 600; }
.btn--warn { border-color: var(--warn); }
.btn--danger { border-color: var(--bad); color: var(--bad); }

.tiles, .cards { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.tile, .card, .resume, .danger, .notes__item {
  padding: var(--gap);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.tile__value { font-size: 2rem; font-weight: 700; margin: 0; }
.tile__label { margin: 0.2rem 0 0; font-weight: 600; }
.tile__hint, .card__meta, .setting__hint { color: var(--text-dim); font-size: 0.875rem; margin: 0.2rem 0 0; }
.quick, .card__actions, .practice__nav, .exam__nav, .results__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.question__meta { color: var(--text-dim); font-size: 0.875rem; }
.question__stem { font-size: 1.15rem; }
.options { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
.option { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.option label { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.75rem; cursor: pointer; }
.option--correct-picked { border-color: var(--ok); }
.option--correct-missed { border-color: var(--ok); border-style: dashed; }
.option--wrong-picked { border-color: var(--bad); }
.option__mark { margin-left: auto; font-weight: 700; }

.feedback { border-left: 4px solid var(--border); padding-left: var(--gap); margin-top: var(--gap); }
.feedback--right { border-left-color: var(--ok); }
.feedback--wrong { border-left-color: var(--bad); }
.explanation { margin-bottom: 0.75rem; }
.explanation__option { font-weight: 600; margin: 0; }
.explanation__body { margin: 0.2rem 0 0; white-space: pre-wrap; }
.references a { color: var(--accent); word-break: break-all; }

.domain-list { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
.domain-row { display: grid; grid-template-columns: minmax(8rem, 1fr) 2fr auto; gap: 0.75rem; align-items: center; }
.domain-row--actionable { grid-template-columns: minmax(8rem, 1fr) 2fr auto auto; }
.domain-row--weakest .domain-row__fill { background: var(--warn); }
.domain-row__bar { background: var(--surface-2); border-radius: var(--radius); height: 0.75rem; overflow: hidden; }
.domain-row__fill { display: block; height: 100%; background: var(--accent); }
.domain-row__value { color: var(--text-dim); font-size: 0.875rem; white-space: nowrap; }

.navigator { display: grid; gap: 0.35rem; grid-template-columns: repeat(auto-fill, minmax(2.5rem, 1fr)); margin-top: var(--gap); }
.navigator__cell { padding: 0.45rem 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.navigator__cell--answered { background: var(--surface-2); border-color: var(--accent); }
.navigator__cell--flagged { border-color: var(--flag); }
.navigator__cell.is-current { outline: 2px solid var(--accent); }

.practice__bar, .exam__bar { display: flex; flex-wrap: wrap; gap: var(--gap); align-items: baseline; justify-content: space-between; }
.exam__clock { font-variant-numeric: tabular-nums; font-size: 1.5rem; font-weight: 700; }
.exam__clock.is-warning { color: var(--warn); }
.note { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; }
.flag { display: flex; gap: 0.5rem; align-items: center; }

.results__headline { padding: var(--gap); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.results__headline.is-pass { border-color: var(--ok); }
.results__headline.is-fail { border-color: var(--bad); }
.results__score { font-size: 2.5rem; font-weight: 700; margin: 0; }
.result-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem var(--gap); margin-bottom: 0.5rem; }
.result-item--wrong { border-left: 4px solid var(--bad); }
.result-item--right { border-left: 4px solid var(--ok); }

.setting { display: flex; gap: 0.6rem; align-items: flex-start; margin-bottom: 0.75rem; }
.history, .notes { list-style: none; padding: 0; display: grid; gap: 0.5rem; }
.history a { color: var(--accent); }
.history__meta, .notes__meta { color: var(--text-dim); font-size: 0.875rem; }
.dropzone-hint { color: var(--text-dim); font-size: 0.875rem; }
.is-dropping { outline: 2px dashed var(--accent); outline-offset: 0.5rem; }
.fatal { padding: var(--gap); border: 1px solid var(--bad); border-radius: var(--radius); }

@media (max-width: 40rem) {
  #view, #notices { padding: 0.75rem; }
  .domain-row, .domain-row--actionable { grid-template-columns: 1fr; gap: 0.25rem; }
  .practice__nav .btn, .exam__nav .btn, .card__actions .btn { flex: 1 1 8rem; }
  .results__score { font-size: 2rem; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
