:root {
  color-scheme: light dark;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --ink: #141a26;
  --muted: #5a6478;
  --line: #e1e5ec;
  --track: #e6e9f0;
  --primary: #2451d6;
  --on-primary: #ffffff;
  --primary-tint: #e9eefc;
  --good: #12805c;
  --good-tint: #e3f5ee;
  --bad: #c7332f;
  --bad-tint: #fdebea;
  --flag: #a85800;
  --flag-tint: #fff2e0;
  --on-status: #ffffff;
  --shadow: 0 1px 2px rgb(20 26 38 / 0.05), 0 6px 20px rgb(20 26 38 / 0.05);
  --radius: 14px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --surface: #181d26;
    --surface-2: #1f2530;
    --ink: #eef1f6;
    --muted: #9aa4b5;
    --line: #2b3340;
    --track: #2a313d;
    --primary: #8aa6ff;
    --on-primary: #0b1226;
    --primary-tint: #1d2744;
    --good: #46c79a;
    --good-tint: #11312a;
    --bad: #ff8a80;
    --bad-tint: #3a1c1c;
    --flag: #f2b056;
    --flag-tint: #33250f;
    --on-status: #0f1319;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

#app {
  max-width: 1080px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

h1, h2, h3, p, dl, dd { margin: 0; }
h1 { font-size: 1.6rem; line-height: 1.2; letter-spacing: -0.015em; }
h2 { font-size: 1.1rem; line-height: 1.3; font-weight: 700; letter-spacing: -0.005em; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[tabindex="-1"]:focus-visible { outline: none; }

.loading { padding: 64px 16px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.num { font-variant-numeric: tabular-nums; }
.narrow { max-width: 640px; margin-inline: auto; }
.icon { flex: none; width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.stack { display: grid; gap: 14px; }
.stack > * { min-width: 0; }

.notice {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--flag-tint);
  font-size: 0.9rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: var(--on-status); }
.btn-wide { display: flex; width: 100%; }
.btn-quiet { min-height: 44px; padding: 8px 10px; border-color: transparent; background: transparent; color: var(--muted); font-weight: 550; font-size: 0.95rem; }
.btn-flagged { color: var(--flag); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
@media (hover: hover) {
  .btn:not(:disabled):hover { background: var(--surface-2); }
  .btn-primary:not(:disabled):hover { background: var(--primary); filter: brightness(1.08); }
  .btn-danger:not(:disabled):hover { background: var(--bad); filter: brightness(1.08); }
  .btn-quiet:not(:disabled):hover { background: var(--track); color: var(--ink); }
}

/* Bars and legend */
.bar { display: flex; height: 8px; overflow: hidden; border-radius: 4px; background: var(--track); }
.bar i { display: block; }
.bar .good { background: var(--good); }
.bar .bad { background: var(--bad); }
.bar .primary { background: var(--primary); }

.dot { display: inline-block; flex: none; width: 10px; height: 10px; border: 2px solid var(--muted); border-radius: 50%; }
.dot.good { border-color: var(--good); background: var(--good); }
.dot.bad { border-color: var(--bad); background: var(--bad); }

/* Home */
.brand { display: flex; align-items: center; gap: 12px; margin: 4px 0 18px; }
.brand-mark { display: flex; align-items: center; justify-content: center; flex: none; width: 42px; height: 42px; border-radius: 11px; background: var(--primary); color: var(--on-primary); }
.brand-mark .icon { width: 24px; height: 24px; stroke-width: 2.6; }
.brand h1 { font-size: 1.3rem; }
.brand p { font-size: 0.875rem; color: var(--muted); line-height: 1.3; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head .btn-quiet { margin: -8px -8px -8px 0; min-height: 40px; }

.progress-row { display: flex; align-items: center; gap: 18px; }
.ring-wrap { position: relative; flex: none; width: 104px; height: 104px; }
.ring { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 11; }
.ring-track { stroke: var(--track); }
.ring-good { stroke: var(--good); }
.ring-bad { stroke: var(--bad); }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.ring-label b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.ring-label span { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.legend { flex: 1 1 auto; display: grid; gap: 7px; min-width: 0; }
.legend div { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; }
.legend dt { color: var(--muted); }
.legend dd { margin-left: auto; font-weight: 650; font-variant-numeric: tabular-nums; }

.progress-sentence { margin-top: 14px; color: var(--muted); font-size: 0.95rem; }
.continue { margin-top: 14px; }
.continue .btn { flex-direction: column; gap: 0; min-height: 62px; line-height: 1.25; }
.continue small { font-size: 0.85rem; font-weight: 450; opacity: 0.88; }

.action-list { padding: 4px 0; }
.action-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 68px;
  padding: 10px 16px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.action-row + .action-row { border-top: 1px solid var(--line); }
.action-icon { display: flex; align-items: center; justify-content: center; flex: none; width: 38px; height: 38px; border-radius: 10px; background: var(--primary-tint); color: var(--primary); }
.action-text { flex: 1 1 auto; min-width: 0; }
.action-text b { display: block; font-weight: 620; line-height: 1.3; }
.action-text small { display: block; color: var(--muted); font-size: 0.86rem; line-height: 1.3; margin-top: 1px; }
.action-count { flex: none; min-width: 26px; padding: 1px 8px; border-radius: 999px; background: var(--track); font-size: 0.85rem; font-weight: 650; text-align: center; font-variant-numeric: tabular-nums; }
.chev { flex: none; color: var(--muted); }
@media (hover: hover) { .action-row:hover { background: var(--surface-2); } }

.topics-card { padding: 18px 0 6px; }
.topics-intro { padding: 0 18px 12px; }
.topics-intro p { margin-top: 2px; color: var(--muted); font-size: 0.9rem; }
.topic { border-top: 1px solid var(--line); }
.topic summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}
.topic summary::-webkit-details-marker { display: none; }
.topic-main { flex: 1 1 auto; min-width: 0; }
.topic-title { display: block; font-weight: 620; line-height: 1.3; }
.topic-meta { display: block; margin: 2px 0 8px; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.topic .chev { transition: transform 0.15s ease; }
.topic[open] > summary .chev { transform: rotate(90deg); }
.topic-body { padding: 0 18px 16px; }
@media (hover: hover) { .topic summary:hover { background: var(--surface-2); } }

.part-list { margin: 10px 0 0; padding: 0; list-style: none; }
.part-list li + li { border-top: 1px solid var(--line); }
.part-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 8px 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.part-name { flex: 1 1 auto; min-width: 0; }
.part-name b { display: block; font-weight: 600; line-height: 1.25; }
.part-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; }
.part-sub small { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block;
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--track);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pill.good { background: var(--good-tint); color: var(--good); }
.pill.bad { background: var(--bad-tint); color: var(--bad); }
.pill.primary { background: var(--primary-tint); color: var(--primary); }

.history { margin: 8px 0 0; padding: 0; list-style: none; }
.history li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 0.95rem; }
.history li:first-child { border-top: 0; }
.history b { display: block; font-weight: 600; line-height: 1.3; }
.history small { color: var(--muted); font-size: 0.84rem; }

/* Sub-pages */
.topbar { display: flex; align-items: center; margin: -4px 0 8px -10px; }
.page-title { margin-bottom: 18px; }
.page-title p { margin-top: 4px; color: var(--muted); font-size: 0.95rem; }

/* Setup */
.step { margin: 0 0 14px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); min-width: 0; }
.step legend { float: left; width: 100%; margin-bottom: 12px; padding: 0; font-size: 1.05rem; font-weight: 700; line-height: 1.3; }
.step legend + * { clear: both; }
.step .hint { margin-top: 10px; color: var(--muted); font-size: 0.875rem; }
.field-label { display: block; margin-top: 14px; font-size: 0.9rem; font-weight: 600; }

.options { display: grid; gap: 8px; }
.options-2 { grid-template-columns: 1fr 1fr; }
.opt { position: relative; display: block; min-width: 0; }
.opt input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.opt-body {
  display: block;
  height: 100%;
  padding: 11px 14px 11px 42px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  position: relative;
}
.opt-body::before {
  content: "";
  position: absolute;
  top: 14px;
  left: 14px;
  width: 18px;
  height: 18px;
  border: 2px solid var(--muted);
  border-radius: 50%;
}
.opt-body b { display: block; font-weight: 620; line-height: 1.3; }
.opt-body small { display: block; margin-top: 2px; color: var(--muted); font-size: 0.86rem; line-height: 1.3; }
.opt input:checked + .opt-body { border-color: var(--primary); background: var(--primary-tint); }
.opt input:checked + .opt-body::before { border: 5px solid var(--primary); background: var(--surface); }
.opt input:focus-visible + .opt-body { outline: 2px solid var(--primary); outline-offset: 2px; }

.seg { display: flex; padding: 3px; gap: 3px; border-radius: var(--radius-sm); background: var(--track); }
.seg label { flex: 1 1 0; position: relative; min-width: 0; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}
.seg input:checked + span { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgb(0 0 0 / 0.14); }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }
.seg input:disabled { cursor: default; }
.seg input:disabled + span { opacity: 0.4; }

select {
  width: 100%;
  min-height: 50px;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.check-list { margin-top: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.check-list label { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 8px 12px; cursor: pointer; line-height: 1.25; }
.check-list label + label { border-top: 1px solid var(--line); }
.check-list input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--primary); }
.check-list .num { margin-left: auto; color: var(--muted); font-size: 0.875rem; }

/* Bottom action bar: fixed under the thumb on phones, in the page flow on wide screens */
.action-spacer { height: 100px; }
.action-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.action-bar-inner { max-width: 640px; margin: 0 auto; }
.start-note { margin-bottom: 8px; font-size: 0.925rem; font-weight: 550; text-align: center; }
.start-note.warn { color: var(--bad); }

/* Question */
.q-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px; margin: -6px -8px 8px; }
.q-top > :first-child { justify-self: start; }
.q-top > :last-child { justify-self: end; }
.q-count { font-weight: 650; font-size: 0.95rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.q-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; margin: 16px 0 8px; color: var(--muted); font-size: 0.85rem; }
.q-tally { font-weight: 600; font-variant-numeric: tabular-nums; }
.q-text { font-size: 1.3rem; font-weight: 650; line-height: 1.32; letter-spacing: -0.01em; }

.choices { display: grid; gap: 10px; margin: 18px 0 0; padding: 0; list-style: none; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 13px 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.choice-key {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--track);
  font-size: 0.9rem;
  font-weight: 700;
}
.choice-text { flex: 1 1 auto; min-width: 0; padding-top: 2px; }
.choice-mark { flex: none; padding-top: 4px; }
.choice[aria-disabled="true"] { cursor: default; }
.choice.is-picked { border-color: var(--primary); background: var(--primary-tint); }
.choice.is-picked .choice-key { background: var(--primary); color: var(--on-primary); }
.choice.is-correct { border-color: var(--good); background: var(--good-tint); }
.choice.is-correct .choice-key { background: var(--good); color: var(--on-status); }
.choice.is-correct .choice-mark { color: var(--good); }
.choice.is-wrong { border-color: var(--bad); background: var(--bad-tint); }
.choice.is-wrong .choice-key { background: var(--bad); color: var(--on-status); }
.choice.is-wrong .choice-mark { color: var(--bad); }
@media (hover: hover) { .choice:not([aria-disabled="true"]):not(.is-picked):hover { border-color: var(--primary); } }

.feedback { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding: 9px 12px; border-radius: var(--radius-sm); font-weight: 620; font-size: 0.95rem; line-height: 1.3; }
.feedback.good { background: var(--good-tint); color: var(--good); }
.feedback.bad { background: var(--bad-tint); color: var(--bad); }
.q-actions { display: flex; gap: 10px; }
.q-actions .btn { flex: 1 1 0; }
.q-keys { display: none; margin-top: 10px; color: var(--muted); font-size: 0.8rem; text-align: center; }
@media (hover: hover) and (pointer: fine) { .q-keys { display: block; } .action-spacer.has-keys { height: 130px; } }

/* Results */
.score-card { text-align: center; }
.score-kicker { color: var(--muted); font-size: 0.95rem; }
.score-value { font-size: 3.5rem; font-weight: 760; line-height: 1.1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.score-card .pill { margin-top: 4px; padding: 4px 12px; font-size: 0.9rem; }
.meter { position: relative; margin: 26px 0 8px; }
.meter .bar { height: 10px; border-radius: 5px; }
.meter-tick { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--ink); }
.meter-label { position: absolute; top: -24px; transform: translateX(-50%); color: var(--muted); font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.score-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.score-stats b { display: block; font-size: 1.25rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.score-stats span { color: var(--muted); font-size: 0.84rem; }
.score-note { margin-top: 14px; color: var(--muted); font-size: 0.9rem; }

.breakdown { margin: 12px 0 0; padding: 0; list-style: none; }
.breakdown li { padding: 10px 0; border-top: 1px solid var(--line); }
.breakdown li:first-child { border-top: 0; }
.breakdown-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-size: 0.925rem; }

.section-title { margin: 8px 0 -2px; }
.review-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.review-q { font-weight: 620; line-height: 1.35; }
.answer { margin-top: 10px; padding: 9px 12px; border-radius: var(--radius-sm); font-size: 0.95rem; line-height: 1.35; }
.answer small { display: block; font-size: 0.76rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; }
.answer.good { background: var(--good-tint); }
.answer.good small { color: var(--good); }
.answer.bad { background: var(--bad-tint); }
.answer.bad small { color: var(--bad); }
.answer-plain { margin-top: 8px; padding: 0 12px; color: var(--muted); font-size: 0.95rem; }
.review-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px -8px -8px 0; color: var(--muted); font-size: 0.84rem; }
.review-foot .btn { font-size: 0.875rem; }

.empty { padding: 28px 12px; color: var(--muted); text-align: center; }
.list-note { color: var(--muted); font-size: 0.875rem; text-align: center; }

/* Dialog */
dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgb(8 12 20 / 0.55); }
dialog h2 { font-size: 1.2rem; margin-bottom: 6px; }
dialog p { color: var(--muted); font-size: 0.97rem; }
.dialog-actions { display: grid; gap: 8px; margin-top: 18px; }

/* Wider screens */
@media (min-width: 768px) {
  #app { padding-top: 32px; padding-inline: 24px; }
  .action-spacer { display: none; }
  .action-bar {
    position: static;
    margin-top: 16px;
    padding: 0;
    border: 0;
    background: none;
  }
  .start-note { text-align: left; }
  .q-page { max-width: 720px; margin: 8px auto 0; padding: 22px 28px 26px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
  .q-page .action-bar-inner { max-width: none; }
  .q-page .action-bar { margin-top: 22px; }
  .q-text { font-size: 1.45rem; }
  .choice { background: var(--surface); }
}

@media (min-width: 960px) {
  .home-grid { display: grid; grid-template-columns: 380px minmax(0, 1fr); align-items: start; gap: 20px; }
  .home-side { position: sticky; top: 20px; }
  .brand { margin-bottom: 24px; }
}
.home-main { margin-top: 14px; }
@media (min-width: 960px) { .home-main { margin-top: 0; } }
