:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #1f232d;
  --border: #2c313d;
  --text: #e8eaf0;
  --text-dim: #9aa1b0;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, 0.15);
  --green: #4caf7d;
  --green-soft: rgba(76, 175, 125, 0.15);
  --red: #e05c5c;
  --red-soft: rgba(224, 92, 92, 0.15);
  --amber: #d9a441;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.logo { font-weight: 700; color: var(--accent); cursor: pointer; }
.topbar-right { color: var(--text-dim); font-size: 0.85rem; }

/* ---------- Layout ---------- */
#app { flex: 1; max-width: 900px; width: 100%; margin: 0 auto; padding: 32px 20px 64px; }
.screen.hidden, .hidden { display: none !important; }

h1 { font-size: 2rem; line-height: 1.25; margin-bottom: 12px; text-align: center; }
.accent { color: var(--accent); }
.subtitle { color: var(--text-dim); text-align: center; max-width: 620px; margin: 0 auto 28px; }

/* ---------- Stats ---------- */
.stats-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 22px;
  text-align: center;
  min-width: 130px;
}
.stat .num { font-size: 1.5rem; font-weight: 700; color: var(--accent); display: block; }
.stat .lbl { font-size: 0.78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; margin-bottom: 32px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card h2 { font-size: 1.15rem; }
.card p { color: var(--text-dim); font-size: 0.9rem; flex-grow: 0; }
.card label { font-size: 0.78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 4px; }
.card select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.9rem;
}
.missed-count { font-weight: 600; color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 7px 12px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.danger-link { background: none; border: none; color: var(--red); font-size: 0.8rem; padding: 4px; }
.btn.danger-link:hover { text-decoration: underline; }

/* ---------- Domain breakdown ---------- */
.domain-breakdown { display: flex; flex-direction: column; gap: 8px; }
.domain-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
}
.domain-row .name { flex: 1; display: flex; align-items: center; gap: 8px; }
.domain-row .weight {
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 20px;
  padding: 1px 8px;
  flex-shrink: 0;
}
.domain-row .bar { flex: 2; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.domain-row .bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.domain-row .bar-fill.good { background: var(--green); }
.domain-row .bar-fill.bad { background: var(--red); }
.domain-row .pct { width: 110px; text-align: right; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---------- Quiz ---------- */
.quiz-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.quiz-progress { flex: 1; display: flex; flex-direction: column; gap: 5px; }
#quiz-position { font-size: 0.82rem; color: var(--text-dim); }
.progress-track { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.25s; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); font-size: 1.05rem; }
.timer.warning { color: var(--red); }

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 18px;
}
.domain-tag {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.official-tag, .official-inline {
  display: inline-block;
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid var(--green);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  margin-left: 8px;
  vertical-align: middle;
  letter-spacing: 0.03em;
}
.official-inline { margin: 0 2px; font-size: 0.68rem; padding: 1px 7px; }

.question-text { font-size: 1.15rem; font-weight: 600; margin-bottom: 20px; line-height: 1.5; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 16px;
  cursor: pointer;
  text-align: left;
  font-size: 0.95rem;
  color: var(--text);
  width: 100%;
  transition: border-color 0.12s, background 0.12s;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option .key {
  flex-shrink: 0;
  width: 24px; height: 24px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; color: var(--text-dim);
}
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.correct { border-color: var(--green); background: var(--green-soft); }
.option.correct .key { border-color: var(--green); color: var(--green); }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option.wrong .key { border-color: var(--red); color: var(--red); }
.option:disabled { cursor: default; }

.explanation {
  margin-top: 18px;
  padding: 14px 16px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
  font-size: 0.92rem;
  color: var(--text-dim);
}
.explanation strong { color: var(--text); }

.quiz-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.footer-center { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.hint { color: var(--text-dim); font-size: 0.78rem; text-align: center; }

.btn.grade {
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  padding: 7px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
}
.btn.grade:hover { border-color: var(--green); border-style: solid; color: var(--green); }

/* ---------- Results ---------- */
.score-circle {
  width: 170px; height: 170px;
  border-radius: 50%;
  border: 6px solid var(--accent);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  margin: 20px auto;
}
.score-circle.pass { border-color: var(--green); }
.score-circle.fail { border-color: var(--red); }
.score-value { font-size: 2.4rem; font-weight: 800; }
.score-label { font-size: 0.85rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.score-detail { text-align: center; color: var(--text-dim); margin-bottom: 24px; }
.score-detail .caveat {
  display: inline-block;
  max-width: 620px;
  margin-top: 10px;
  font-size: 0.8rem;
  line-height: 1.5;
  opacity: 0.85;
}
.results-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 24px 0; }

.review-list { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.review-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.review-item .rq { font-weight: 600; margin-bottom: 10px; }
.review-item .ra { font-size: 0.9rem; margin-bottom: 4px; }
.review-item .ra.user { color: var(--red); }
.review-item .ra.skipped { color: var(--amber); }
.review-item .ra.correct { color: var(--green); }

.review-section {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 18px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.review-section:first-child { margin-top: 0; }
.review-section span {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
}
.review-item .rex { font-size: 0.88rem; color: var(--text-dim); margin-top: 8px; }

.footer { text-align: center; color: var(--text-dim); font-size: 0.78rem; padding: 18px; border-top: 1px solid var(--border); }

@media (max-width: 600px) {
  h1 { font-size: 1.5rem; }
  .question-text { font-size: 1.02rem; }
  .quiz-footer { flex-wrap: wrap; }
  .hint { display: none; }
}

/* ============================================================
   DASHBOARD
   Charts use a single accent hue for magnitude; state is always
   carried by an icon + text tag, never colour alone (the green/red
   pair is not separable under deuteranopia).
   ============================================================ */

.topbar-right { display: flex; align-items: center; gap: 12px; }

.dash-top { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.dash-top h1 { text-align: left; margin: 0; font-size: 1.6rem; }
.dash-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.dash-actions label.btn { cursor: pointer; }

.dash-privacy {
  font-size: 0.82rem; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 22px;
}

/* ---- Hero ---- */
.hero-card { text-align: center; align-items: center; margin-bottom: 16px; }
.hero-figure {
  font-size: 4rem; font-weight: 800; line-height: 1;
  color: var(--accent); letter-spacing: -0.02em;
}
.hero-figure.good { color: var(--green); }
.hero-figure.warn { color: var(--amber); }
.hero-figure.bad  { color: var(--red); }
.hero-unit { font-size: 1.6rem; font-weight: 600; margin-left: 2px; }
.hero-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.hero-verdict { font-weight: 600; color: var(--text); font-size: 1rem; }
.hero-note { font-size: 0.82rem; color: var(--text-dim); max-width: 620px; line-height: 1.5; }
.hero-caveat { font-size: 0.82rem; color: var(--amber); max-width: 620px; }

/* ---- KPI row ---- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 32px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 2px;
}
.kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.kpi-sub { font-size: 0.9rem; font-weight: 500; color: var(--text-dim); margin-left: 1px; }
.kpi-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); }
.kpi-foot { font-size: 0.74rem; margin-top: 4px; }
.kpi-foot.good { color: var(--green); }
.kpi-foot.warn { color: var(--amber); }

/* ---- Blocks ---- */
.dash-block { margin-bottom: 34px; }
.dash-block h2 { font-size: 1.05rem; margin-bottom: 6px; }
.block-note { font-size: 0.83rem; color: var(--text-dim); margin-bottom: 14px; line-height: 1.5; max-width: 680px; }
.dash-block > .btn { margin-top: 14px; }

/* ---- Domain bars ---- */
.dom-row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.dom-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.dom-name { font-weight: 600; font-size: 0.95rem; }
.dom-weight { font-size: 0.72rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 20px; padding: 2px 9px; }
.dom-tag { font-size: 0.72rem; font-weight: 700; border-radius: 20px; padding: 2px 9px; margin-left: auto; }
.dom-tag.good { color: var(--green); background: var(--green-soft); }
.dom-tag.warn { color: var(--amber); background: rgba(217, 164, 65, 0.15); }
.dom-tag.bad  { color: var(--red); background: var(--red-soft); }
.dom-tag.idle { color: var(--text-dim); background: var(--surface-2); }
.dom-barwrap { display: flex; align-items: center; gap: 12px; }
.dom-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.dom-fill { height: 100%; background: var(--accent); border-radius: 5px; transition: width 0.3s; }
.dom-value { width: 46px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.dom-meta { font-size: 0.74rem; color: var(--text-dim); margin-top: 8px; }

/* ---- Charts ---- */
.chart-host { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.crosshair { pointer-events: none; }
.tooltip {
  position: absolute; top: 12px; transform: translateX(-50%);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 11px; font-size: 0.78rem; color: var(--text-dim);
  pointer-events: none; white-space: nowrap; z-index: 5;
}
.tooltip strong { color: var(--text); font-size: 0.95rem; }

/* ---- Spaced repetition ---- */
.review-lead { font-size: 0.95rem; margin-bottom: 14px; }
.review-lead strong { color: var(--accent); font-size: 1.2rem; }
.box-row { display: flex; gap: 10px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.box-cell { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.box-n { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.box-bar { width: 100%; max-width: 70px; background: var(--accent); border-radius: 3px; }
.box-label { font-size: 0.7rem; color: var(--text-dim); text-align: center; }
.review-note { font-size: 0.78rem; color: var(--text-dim); margin-top: 12px; line-height: 1.5; }

/* ---- Tables ---- */
.scroll-x { overflow-x: auto; }
.dash-block table, .data-table table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.dash-block th, .data-table th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.dash-block td, .data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.dash-block td.dim, .data-table td.dim { color: var(--text-dim); }
.q-cell { max-width: 420px; }
td .ok { color: var(--green); }
td .no { color: var(--red); }
caption { text-align: left; font-size: 0.78rem; color: var(--text-dim); padding-bottom: 8px; }

.data-table { display: none; margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; }
body.show-tables .data-table { display: block; }

.empty { font-size: 0.85rem; color: var(--text-dim); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 18px; text-align: center; }

.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; }

@media (max-width: 600px) {
  .hero-figure { font-size: 3rem; }
  .dash-top h1 { font-size: 1.3rem; }
  .box-label { font-size: 0.62rem; }
  .q-cell { max-width: 200px; }
}

/* ============================================================
   DONATIONS
   Opens only on click — never on arrival. Nothing is gated.
   ============================================================ */

/* Restrained on purpose: an outlined pill, not a filled call-to-action.
   Bigger than the surrounding footer text, but it should not compete with it. */
.donate-link {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.2;
  padding: 9px 20px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 22px;
  transition: border-color 0.15s, background 0.15s;
}
.donate-link:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

/* ---- Contextual card on the results screen ---- */
.donate-inline {
  background: var(--surface); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 18px 20px; margin: 24px 0;
}
.dn-inline { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; justify-content: space-between; }
.dn-inline strong { display: block; margin-bottom: 4px; }
.dn-inline p { font-size: 0.86rem; color: var(--text-dim); max-width: 460px; margin: 0; }
.dn-inline-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ---- Overlay ---- */
.dn-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.7);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
}
body.dn-open { overflow: hidden; }

.dn-panel {
  position: relative;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
  max-width: 560px; width: 100%; outline: none;
}
.dn-panel h2 { font-size: 1.35rem; text-align: left; margin-bottom: 10px; }
.dn-lead { font-size: 0.88rem; color: var(--text-dim); line-height: 1.6; margin-bottom: 22px; }
.dn-close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none; color: var(--text-dim);
  font-size: 1.1rem; cursor: pointer; padding: 6px 10px; border-radius: 6px;
}
.dn-close:hover { color: var(--text); background: var(--surface-2); }

.dn-methods { display: flex; flex-direction: column; gap: 20px; }
.dn-method { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.dn-method h3 { font-size: 1rem; margin-bottom: 4px; }
.dn-sub { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 14px; }

.dn-amounts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.dn-chip {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 20px; padding: 6px 14px; font-size: 0.85rem; cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.dn-chip:hover { border-color: var(--accent); }
.dn-chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.dn-qr { display: flex; justify-content: center; margin-bottom: 16px; }
.dn-qr svg { width: 190px; height: 190px; border-radius: 8px; display: block; }

.dn-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); margin-bottom: 6px; }
.dn-copyrow { display: flex; gap: 8px; }
.dn-code {
  flex: 1; min-width: 0;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 8px; padding: 9px 11px; font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-overflow: ellipsis;
}
.dn-bmc { display: inline-block; text-decoration: none; }
.dn-err { font-size: 0.82rem; color: var(--amber); }
.dn-foot { font-size: 0.74rem; color: var(--text-dim); margin-top: 18px; text-align: center; }

@media (max-width: 600px) {
  .dn-panel { padding: 20px; }
  .dn-overlay { padding: 16px 10px; }
  .dn-inline { flex-direction: column; align-items: stretch; }
  .dn-inline-actions { justify-content: stretch; }
  .dn-inline-actions .btn { flex: 1; }
}
