/* Citizenship Quiz - mobile first. ASCII only. */
:root {
  --navy: #1d3a6e;
  --navy-dark: #142a52;
  --red: #b0132b;
  --ink: #1a1d24;
  --muted: #4a5163;
  --line: #d5d9e3;
  --bg: #f4f6fa;
  --card: #ffffff;
  --ok: #17663a;
  --ok-bg: #e7f5ec;
  --bad: #a3141f;
  --bad-bg: #fdecee;
  --focus: #f2a900;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
img, svg, canvas { max-width: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--navy); }
a:hover { color: var(--red); }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); }
.skip { position: absolute; left: -9999px; top: 0; background: #fff; color: var(--navy); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }

/* Header */
.site-header { background: var(--navy); color: #fff; padding-top: env(safe-area-inset-top); }
.header-row { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; background: #fff url("../favicon.svg") center/100% no-repeat; flex: none; }
.brand-name { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: .2px; }
.brand-tag { margin: 0; font-size: .9rem; color: #dfe6f5; }
.scorebar { background: var(--navy-dark); position: sticky; top: 0; z-index: 5; }
.site-header { position: relative; }
.scorebar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 8px; padding-bottom: 8px; }
.score { margin: 0; font-weight: 700; color: #fff; font-size: 1rem; }
.score small { font-weight: 400; color: #dfe6f5; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 2px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-small { min-height: 44px; padding: 6px 12px; font-size: .9rem; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); color: #fff; }
.btn-secondary { background: #fff; color: var(--navy); border-color: var(--navy); }
.btn-secondary:hover { background: #eef2fa; }
.btn-ghost-light { background: transparent; color: #fff; border-color: #c9d3ea; }
.btn-ghost-light:hover { background: rgba(255,255,255,.12); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-bad { background: var(--bad); color: #fff; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* Controls */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; margin: 14px 0 4px; }
.controls .field-btn { grid-column: 1 / -1; flex-direction: column; align-items: stretch; gap: 4px; }
.controls .field-btn .btn { min-height: 44px; padding: 6px 12px; }
.score small { display: none; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.field label, legend { font-weight: 600; font-size: .95rem; }
.field-btn { justify-content: flex-end; }
select, input {
  font: inherit; min-height: 44px; padding: 8px 10px; border: 1px solid #8a92a6; border-radius: 8px;
  background: #fff; color: var(--ink); width: 100%;
}
.help { margin: 0; font-size: .85rem; color: var(--muted); }
.small { font-size: .85rem; }

/* Mode tabs */
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 14px; }
.mode {
  font: inherit; font-weight: 600; font-size: .95rem; min-height: 48px; padding: 8px 6px;
  border: 2px solid var(--navy); background: #fff; color: var(--navy); border-radius: 10px; cursor: pointer;
}
.mode[aria-pressed="true"] { background: var(--navy); color: #fff; }
.badge { display: inline-block; min-width: 1.6em; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font-size: .8rem; line-height: 1.6; }
.mode[aria-pressed="true"] .badge { background: #fff; color: var(--red); }

/* Card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 16px 20px; box-shadow: 0 2px 8px rgba(20,42,82,.06); }
.meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin: 0 0 8px; font-size: .85rem; color: var(--muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: #eef2fa; color: var(--navy); font-weight: 600; }
.pill-star { background: #fff4d6; color: #6b4a00; }
.question { font-size: 1.3rem; line-height: 1.35; margin: 4px 0 6px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: .95rem; }
.options { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.opt {
  width: 100%; text-align: left; display: flex; gap: 12px; align-items: flex-start;
  font: inherit; padding: 12px 14px; min-height: 52px; border: 2px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); cursor: pointer;
}
.opt:hover:not([disabled]) { border-color: var(--navy); background: #f6f8fd; }
.opt .key { flex: none; width: 28px; height: 28px; border-radius: 50%; background: #eef2fa; color: var(--navy); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; font-size: .9rem; }
.opt[disabled] { cursor: default; }
.opt.is-correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.is-correct .key { background: var(--ok); color: #fff; }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.is-wrong .key { background: var(--bad); color: #fff; }
.opt .tag { margin-left: auto; font-weight: 700; font-size: .85rem; white-space: nowrap; }
.opt.is-correct .tag { color: var(--ok); }
.opt.is-wrong .tag { color: var(--bad); }

.feedback { margin-top: 16px; padding: 14px; border-radius: 10px; border: 2px solid var(--line); }
.feedback:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
.feedback.ok { border-color: var(--ok); background: var(--ok-bg); }
.feedback.bad { border-color: var(--bad); background: var(--bad-bg); }
.feedback.info { border-color: var(--navy); background: #eef2fa; }
.feedback h3 { margin: 0 0 6px; font-size: 1.1rem; }
.feedback.ok h3 { color: var(--ok); }
.feedback.bad h3 { color: var(--bad); }
.feedback ul { margin: 6px 0 0; padding-left: 22px; }
.feedback li { margin: 2px 0; }
.note { margin: 8px 0 0; font-size: .92rem; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.selfcheck { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.myanswer { margin: 8px 0 0; padding: 10px 12px; border-left: 4px solid var(--navy); background: #f6f8fd; }
.progress { height: 8px; background: #e3e7f0; border-radius: 999px; overflow: hidden; margin: 6px 0 12px; }
.progress > span { display: block; height: 100%; background: var(--navy); }
.tally { display: flex; gap: 14px; flex-wrap: wrap; font-weight: 600; margin: 0 0 4px; }
.tally .r { color: var(--ok); }
.tally .w { color: var(--bad); }
.result-list { padding-left: 20px; }
.result-list li { margin: 4px 0; }
.result-list .r { color: var(--ok); font-weight: 700; }
.result-list .w { color: var(--bad); font-weight: 700; }
.empty { text-align: center; padding: 10px 0; }
.kbd-hint { color: var(--muted); font-size: .85rem; margin: 10px 2px 24px; display: none; }
.notice { margin: 14px 0 0; padding: 10px 14px; border-radius: 10px; background: #fff4d6; color: #4d3500; border: 1px solid #e8c766; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Dialog */
dialog { border: none; border-radius: var(--radius); padding: 0; width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px); color: var(--ink); }
dialog::backdrop { background: rgba(10, 20, 40, .55); }
.dialog-body { padding: 18px 18px 20px; }
.dialog-body h2 { margin-top: 0; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 4px; margin: 10px 0; }
.loc-links { margin: 4px 0 8px; font-size: .95rem; }
.loc-links ul { margin: 4px 0; padding-left: 20px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 12px; }

/* Footer */
.site-footer { border-top: 1px solid var(--line); background: #fff; color: var(--muted); padding: 18px 0 calc(28px + env(safe-area-inset-bottom)); margin-top: 10px; font-size: .92rem; }
.site-footer p { margin: 6px 0; }

@media (min-width: 640px) {
  .controls { grid-template-columns: 1fr 1fr 1fr; gap: 12px; align-items: start; }
  .controls .field-btn { grid-column: auto; flex-direction: column; align-items: stretch; gap: 4px; padding-top: 27px; }
  .controls .field-btn .btn { min-height: 44px; }
  .card { padding: 26px 28px 28px; }
  .question { font-size: 1.5rem; }
  .kbd-hint { display: block; }
  .score small { display: inline; }
  .mode { font-size: 1rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .opt, .btn, .mode { transition: background-color .12s, border-color .12s; }
}

/* ---------- flash cards ---------- */
.deck { overflow-x: hidden; overflow-x: clip; padding: 4px 2px 8px; margin: 0 -2px; }
.flashcard { touch-action: pan-y; user-select: none; -webkit-user-select: none; will-change: transform; position: relative; }
.flashcard a, .flashcard .feedback li, .flashcard .feedback p { user-select: text; -webkit-user-select: text; }
.flashcard.dragging { cursor: grabbing; }
.flashcard.anim { transition: transform .2s ease-out, opacity .2s ease-out; }
.swipe-hint { margin: 12px 0 0; font-size: .85rem; color: var(--muted); text-align: center; }
.actions .btn { flex: 1 1 auto; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row { flex-wrap: nowrap; }
.btn-row .btn { flex: 1 1 0; white-space: nowrap; }
.btn-row .btn-toggle { flex: 0 0 auto; }
.btn-toggle[aria-pressed="true"] { background: var(--navy); color: #fff; }

/* score bar: streak */
.score-wrap { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.streak { margin: 0; display: flex; gap: 10px; font-size: .85rem; color: #dfe6f5; }
.streak-now { font-weight: 700; color: #ffd166; }
.skipped { font-weight: 400; color: #dfe6f5; }

/* results and celebrations */
.result-head { position: relative; }
.result-head .check {
  float: left; width: 34px; height: 34px; margin: 0 10px 0 0; border-radius: 50%; background: var(--ok); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.2rem;
}
.milestone { margin: 4px 0 0; font-weight: 700; color: #6b4a00; background: #fff4d6; border-radius: 8px; padding: 6px 10px; clear: both; }
.encourage { color: var(--ink); }
.pass-badge { width: 72px; height: 72px; margin: 4px auto 6px; border-radius: 50%; background: #f2a900; color: #fff; font-size: 2.6rem; line-height: 72px; text-align: center; }
.pass-title { text-align: center; color: var(--ok); }
.fx-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 50; display: none; }
@media (prefers-reduced-motion: no-preference) {
  .flashcard.celebrate { animation: cq-pulse .7s ease-out; }
  .flashcard.celebrate-big { animation: cq-pulse-big 1s ease-out; }
  .result-head .check { animation: cq-pop .35s ease-out; }
}
@keyframes cq-pulse { 0% { box-shadow: 0 0 0 0 rgba(23,102,58,.45); } 40% { box-shadow: 0 0 0 10px rgba(23,102,58,.18); transform: scale(1.01); } 100% { box-shadow: 0 2px 8px rgba(20,42,82,.06); transform: none; } }
@keyframes cq-pulse-big { 0% { box-shadow: 0 0 0 0 rgba(242,169,0,.6); } 35% { box-shadow: 0 0 0 16px rgba(242,169,0,.25); transform: scale(1.02); } 100% { box-shadow: 0 2px 8px rgba(20,42,82,.06); transform: none; } }
@keyframes cq-pop { 0% { transform: scale(.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* about / help */
.about { margin: 0 0 20px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.about summary { cursor: pointer; padding: 12px 16px; min-height: 48px; display: flex; align-items: center; font-weight: 700; color: var(--navy); }
.about-body { padding: 0 16px 12px; }
.about-body h2 { font-size: 1.05rem; margin: 12px 0 4px; }
.notice .btn { margin-left: 6px; }
@media (prefers-reduced-motion: reduce) {
  .flashcard.anim { transition: none; }
}
