/* ============================================================
   Civics 100 — design tokens
   Palette: federal ink navy on cool security paper, stamp inks
   in red and green, gold foil reserved for mastery.
   Type: Besley (display) / Public Sans (body — the U.S. federal
   web typeface) / Spline Sans Mono (form numbering).
   ============================================================ */

:root {
  --ink: #16233B;          /* federal ink navy */
  --ink-soft: #3D4A63;
  --paper: #EDEFF1;        /* security paper */
  --card: #FDFDFB;
  --line: #C9CFD8;
  --stamp-red: #A3212B;    /* stamp ink */
  --stamp-green: #1F6E43;  /* approval ink */
  --foil: #8A6D1F;         /* gold foil (text-safe) */
  --foil-bright: #C9A84C;
  --focus: #2456C4;

  --font-display: "Besley", "Georgia", serif;
  --font-body: "Public Sans", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Spline Sans Mono", "SF Mono", monospace;

  --radius: 10px;
  --shadow-card: 0 1px 2px rgba(22, 35, 59, 0.08), 0 8px 24px rgba(22, 35, 59, 0.10);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100dvh;
}

/* ---------- masthead with engraved guilloche band ---------- */

.masthead {
  background:
    repeating-linear-gradient(105deg, rgba(255,255,255,0.055) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(75deg, rgba(255,255,255,0.055) 0 1px, transparent 1px 7px),
    var(--ink);
  border-bottom: 3px solid var(--foil-bright);
  color: #F4F1E6;
}

.masthead-inner {
  max-width: 920px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  color: var(--foil-bright);
  font-size: 22px;
  line-height: 1;
}

.brand-text { display: flex; flex-direction: column; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #B9C0CE;
}

.topnav { display: none; gap: 4px; }

.topnav a {
  color: #D5DAE3;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 6px;
}

.topnav a:hover { background: rgba(255,255,255,0.09); color: #fff; }

.topnav a[aria-current="page"] {
  background: rgba(255,255,255,0.12);
  color: #fff;
  box-shadow: inset 0 -2px 0 var(--foil-bright);
}

/* ---------- layout ---------- */

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 28px 20px 110px; /* bottom room for tabbar */
}

.view-head h1, .doc-head h1 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.15;
  margin: 6px 0 10px;
  font-size: clamp(26px, 5.5vw, 38px);
  text-wrap: balance;
}

.eyebrow, .back-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0;
}

.lede, .view-sub {
  color: var(--ink-soft);
  margin: 0 0 8px;
  max-width: 60ch;
}

.mono { font-family: var(--font-mono); }

.section-title {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0 0 10px;
}

/* ---------- home ---------- */

.progress-doc {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 22px 0;
  box-shadow: var(--shadow-card);
}

.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.progress-label { font-weight: 600; font-size: 14px; }

.progress-count { font-size: 14px; color: var(--ink-soft); }

.progress-track {
  height: 12px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--foil), var(--foil-bright));
  border-radius: 999px;
  transition: width 0.6s ease;
}

.cat-bars { margin-top: 14px; display: grid; gap: 8px; }

.cat-bar {
  display: grid;
  grid-template-columns: 150px 1fr 52px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.cat-bar .progress-track { height: 8px; }

.cat-bar .num { text-align: right; color: var(--ink-soft); font-size: 12px; }

.home-actions { display: grid; gap: 12px; margin: 22px 0; }

.action-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.action-card:hover { transform: translateY(-2px); border-color: var(--ink-soft); }

.action-num {
  font-size: 13px;
  color: var(--foil);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}

.action-body { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.action-body strong { font-family: var(--font-display); font-size: 17px; }

.action-body span { color: var(--ink-soft); font-size: 14px; }

.action-arrow { color: var(--ink-soft); font-size: 18px; }

.test-history {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 22px 0;
}

.test-history ul { list-style: none; margin: 0; padding: 0; }

.test-history li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px dashed var(--line);
  font-size: 14px;
}

.test-history li:first-child { border-top: 0; }

.hist-result { font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }

.hist-pass { color: var(--stamp-green); }
.hist-fail { color: var(--stamp-red); }

.note-65 {
  border-left: 3px solid var(--foil-bright);
  background: var(--card);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 16px;
  font-size: 14px;
  color: var(--ink-soft);
  margin: 22px 0;
}

.star-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--foil);
  border: 1px solid var(--foil-bright);
  border-radius: 4px;
  padding: 1px 5px;
  white-space: nowrap;
}

/* ---------- chips ---------- */

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0 20px;
}

.chip {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* ---------- flashcard ---------- */

.deck-counter {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

.flip-scene { perspective: 1400px; }

.flip-card {
  position: relative;
  display: block;
  width: 100%;
  min-height: 320px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.flip-inner {
  position: relative;
  display: block;
  width: 100%;
  min-height: 320px;
  transition: transform 0.55s cubic-bezier(0.3, 0.8, 0.3, 1);
  transform-style: preserve-3d;
}

.flip-card.flipped .flip-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 28px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow-y: auto;
}

.card-front {
  background:
    linear-gradient(var(--card), var(--card)) padding-box,
    var(--card);
  border-top: 4px solid var(--ink);
}

.card-back {
  transform: rotateY(180deg);
  border-top: 4px solid var(--foil-bright);
  justify-content: flex-start;
}

.qnum {
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--stamp-red);
  border: 1.5px solid currentColor;
  border-radius: 4px;
  padding: 3px 8px;
  width: fit-content;
  transform: rotate(-2deg);
}

.card-q {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(20px, 4.5vw, 26px);
  line-height: 1.3;
  margin: 0;
  text-wrap: balance;
}

.card-hint {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: auto;
}

.card-answers { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }

.card-answers .ans {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  line-height: 1.35;
}

.card-answers .ans + .ans {
  border-top: 1px dashed var(--line);
  padding-top: 6px;
}

.card-answers.many .ans { font-size: 15px; }

.card-note {
  font-size: 13px;
  color: var(--ink-soft);
  border-left: 3px solid var(--foil-bright);
  padding-left: 10px;
  margin-top: 10px;
}

.card-note:empty { display: none; }

/* signature: the grading stamp */

.stamp, .grade-stamp {
  font-family: var(--font-display);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  border: 3px double currentColor;
  border-radius: 6px;
  padding: 0.25em 0.6em;
  transform: rotate(-7deg);
  mix-blend-mode: multiply;
}

.grade-stamp {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 15px;
  pointer-events: none;
  opacity: 0;
  z-index: 2;
}

.grade-stamp.show-know { color: var(--stamp-green); animation: stamp-in 0.45s ease forwards; }
.grade-stamp.show-miss { color: var(--stamp-red); animation: stamp-in 0.45s ease forwards; }

.stamp { display: inline-block; font-size: clamp(22px, 5vw, 32px); }
.stamp-pass { color: var(--stamp-green); }
.stamp-fail { color: var(--stamp-red); }
.stamp.animate { animation: stamp-in 0.5s ease both; }

@keyframes stamp-in {
  0%   { opacity: 0; transform: rotate(-7deg) scale(2.1); }
  60%  { opacity: 1; transform: rotate(-7deg) scale(0.94); }
  100% { opacity: 1; transform: rotate(-7deg) scale(1); }
}

/* ---------- buttons ---------- */

.grade-row {
  display: flex;
  gap: 12px;
  margin: 18px 0 6px;
}

.btn {
  flex: 1;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  color: #fff;
  min-height: 48px;
}

.btn-know { background: var(--ink); }
.btn-know:hover { background: #1F3152; }

.btn-miss {
  background: var(--card);
  color: var(--stamp-red);
  border-color: var(--stamp-red);
}
.btn-miss:hover { background: #F7ECEC; }

.btn-secondary {
  background: var(--card);
  color: var(--ink);
  border-color: var(--line);
}
.btn-secondary:hover { border-color: var(--ink-soft); }

.btn-wide { width: 100%; flex: none; margin-top: 16px; }

.kbd-hint {
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
  margin: 10px 0 0;
}

@media (hover: none) { .kbd-hint { display: none; } }

.done-panel, .results-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 32px 24px;
  text-align: center;
  margin: 20px 0;
}

.done-stamp { margin: 0 0 12px; }

/* ---------- practice test ---------- */

.test-setup {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-top: 16px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.toggle-row input { width: 18px; height: 18px; accent-color: var(--ink); }

.fine-print {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 12px 0 0;
}

.test-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.choices { display: grid; gap: 10px; margin-top: 6px; }

.choice {
  font: inherit;
  font-size: 15px;
  text-align: left;
  background: var(--paper);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px 13px 44px;
  cursor: pointer;
  position: relative;
  min-height: 48px;
}

.choice::before {
  content: attr(data-key);
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 4px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  background: var(--card);
}

.choice:hover:not(:disabled) { border-color: var(--ink-soft); background: #fff; }

.choice:disabled { cursor: default; }

.choice.correct {
  border-color: var(--stamp-green);
  background: #EAF3EC;
  color: var(--stamp-green);
  font-weight: 700;
}

.choice.wrong {
  border-color: var(--stamp-red);
  background: #F7ECEC;
  color: var(--stamp-red);
}

.choice.dim { opacity: 0.55; }

.test-next-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  min-height: 48px;
}

.test-next-row .btn { flex: 0 0 auto; padding-inline: 28px; }

.test-score {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0;
}

.result-score {
  font-family: var(--font-display);
  font-size: 42px;
  font-weight: 800;
  margin: 14px 0 4px;
}

.result-msg { color: var(--ink-soft); margin: 0; }

.missed-list { margin: 18px 0; display: grid; gap: 10px; }

.missed-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--stamp-red);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
}

.missed-item .mq { font-weight: 700; display: block; }

.missed-item .ma { color: var(--stamp-green); font-weight: 600; }

/* ---------- browse ---------- */

.browse-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin: 16px 0 20px;
}

#browse-search {
  flex: 1 1 240px;
  font: inherit;
  font-size: 15px;
  padding: 11px 14px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}

#browse-search:focus { border-color: var(--focus); outline: none; }

.browse-sec {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 26px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.browse-cat {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  margin: 34px 0 4px;
}

.q-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
}

.q-item summary {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 13px 14px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  font-size: 15px;
}

.q-item summary::-webkit-details-marker { display: none; }

.q-item summary .n {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  flex: 0 0 26px;
  text-align: right;
}

.q-item summary .star { color: var(--foil); font-size: 13px; }

.q-item[open] summary { border-bottom: 1px dashed var(--line); }

.q-item .a {
  padding: 12px 14px 14px 52px;
  font-size: 14px;
}

.q-item .a ul { margin: 0; padding-left: 18px; }

.q-item .a li { margin: 3px 0; }

.q-item .known-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--foil);
  margin-left: auto;
  white-space: nowrap;
}

.browse-empty { color: var(--ink-soft); padding: 24px 0; text-align: center; }

/* ---------- footer ---------- */

.app-footer {
  max-width: 920px;
  margin: 0 auto;
  padding: 0 20px 120px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.app-footer a { color: inherit; }

.link-btn {
  background: none;
  border: none;
  font: inherit;
  font-size: 12.5px;
  color: var(--stamp-red);
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

/* ---------- bottom tab bar (mobile) ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--ink);
  border-top: 2px solid var(--foil-bright);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px 8px;
  color: #9AA5B8;
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.tabbar svg { width: 22px; height: 22px; fill: currentColor; }

.tabbar a[aria-current="page"] { color: #fff; }

.tabbar a[aria-current="page"] svg { fill: var(--foil-bright); }

/* ---------- desktop ---------- */

@media (min-width: 760px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  main { padding-bottom: 40px; }
  .app-footer { padding-bottom: 40px; }
  .flip-card, .flip-inner { min-height: 360px; }
  .grade-row { max-width: 520px; margin-left: auto; margin-right: auto; }
  #study-area, #study-done, #test-question, #test-intro, #test-results { max-width: 640px; margin-left: auto; margin-right: auto; }
}

/* ---------- a11y ---------- */

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

@media (prefers-reduced-motion: reduce) {
  .flip-inner { transition: none; }
  .progress-fill { transition: none; }
  .grade-stamp.show-know, .grade-stamp.show-miss, .stamp.animate { animation: none; opacity: 1; }
  .action-card:hover { transform: none; }
}
