/* =============================================================================
   styles.css — "The Daily Civics" editorial redesign
   Quiet daily-puzzle aesthetic: paper background, ink text, Instrument Serif
   display type, hairline rules, pill buttons. Light (paper) + warm dark theme.
   ============================================================================ */

:root {
  --paper: #faf7f1;
  --surface: #ffffff;
  --ink: #1e1c18;
  --ink-soft: #494439;
  --muted: #6d675c;
  --faint: #a39c8d;
  --rule: #ddd6c8;
  --rule-light: #e8e2d4;
  --wash: #f2ede2;
  --green: oklch(0.55 0.13 150);
  --green-deep: oklch(0.45 0.11 150);
  --green-wash: oklch(0.95 0.03 150);
  --red: oklch(0.5 0.14 25);
  --red-wash: oklch(0.95 0.03 25);
  --on-ink: #faf7f1;
  --card-shadow: 0 2px 8px rgba(30, 28, 24, 0.08);
  --serif: "Instrument Serif", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --speed: 0.18s;
}

[data-theme="dark"] {
  --paper: #17140f;
  --surface: #201c15;
  --ink: #f2ede2;
  --ink-soft: #cbc4b4;
  --muted: #948c7c;
  --faint: #6d675c;
  --rule: #3b352a;
  --rule-light: #2c2820;
  --wash: #262218;
  --green: oklch(0.68 0.13 150);
  --green-deep: oklch(0.75 0.11 150);
  --green-wash: oklch(0.3 0.045 150);
  --red: oklch(0.62 0.15 25);
  --red-wash: oklch(0.28 0.05 25);
  --on-ink: #17140f;
  --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.serif { font-family: var(--serif); font-weight: 400; }
.serif-it { font-family: var(--serif); font-style: italic; }
.center { text-align: center; }
.muted { color: var(--muted); }

.microlabel {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.microlabel.accent { color: var(--red); }
.microlabel.ok { color: var(--green-deep); }

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 26px 24px 60px;
}

/* ---------------- masthead ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 14px;
}
.brand {
  background: none; border: 0; padding: 0; cursor: pointer; color: inherit;
  display: flex; align-items: baseline; gap: 10px;
}
.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(24px, 4.5vw, 34px);
  letter-spacing: -0.01em;
}
.topbar-actions { display: flex; gap: 14px; align-items: center; }
.streak-chip { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.streak-chip.on { color: var(--ink); }
.icon-btn {
  background: none; border: 0; cursor: pointer; font-size: 17px; padding: 4px;
  color: var(--muted); transition: transform var(--speed);
  font-family: inherit;
}
.icon-btn:hover { transform: scale(1.12); }

.dateline {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding-top: 8px; margin-bottom: 30px;
}

/* ---------------- generic screen scaffold ---------------- */
.screen { animation: fade 0.3s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.screen-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 12px; margin-bottom: 26px;
  max-width: 560px; margin-left: auto; margin-right: auto;
}
.screen-title { font-size: 19px; }
.screen-right { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }

/* quiz/results/flashcards/recall live in a 560px column */
.seg-progress, .q-meta, .q-text, .opt-list, .explain, .quiz-foot, .kbd-hint,
.results-wrap, .flash-stage, .results-actions, .recall-head, .recall-ask,
.recall-reveal, .cat-list, .back-row, .tomorrow {
  max-width: 560px; margin-left: auto; margin-right: auto;
}

/* ---------------- pills (buttons) ---------------- */
.pill {
  display: inline-block;
  padding: 13px 28px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 0;
  transition: transform var(--speed), opacity var(--speed);
}
.pill:hover { transform: translateY(-1px); }
.pill:active { transform: translateY(0); }
.pill-ink { background: var(--ink); color: var(--on-ink); }
.pill-line { background: transparent; color: var(--ink); border: 1.5px solid var(--ink); }
.pill-line.bad { color: var(--red); border-color: var(--red); }
.pill:disabled { opacity: 0.45; cursor: not-allowed; }

.back-link {
  background: none; border: 0; cursor: pointer; font-family: inherit;
  font-size: 13.5px; color: var(--muted); padding: 6px 0;
}
.back-link:hover { color: var(--ink); }
.back-row { margin-top: 26px; }

.kbd-hint { text-align: center; font-size: 12px; color: var(--faint); margin-top: 14px; }

/* ---------------- HOME ---------------- */
.home-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 36px;
}
@media (max-width: 760px) { .home-grid { grid-template-columns: 1fr; } }

.hero-head {
  font-size: clamp(34px, 6vw, 52px);
  line-height: 1.05;
  letter-spacing: -0.01em;
  margin: 0 0 14px;
  font-weight: 400;
}
.hero-head em { font-style: italic; }
.hero-sub {
  font-size: 16px; line-height: 1.6; color: var(--ink-soft);
  max-width: 46ch; margin: 0 0 26px;
}
.hero-cta { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.hero-cta .pill-ink { padding: 16px 34px; font-size: 16px; }
.cta-meta { font-size: 13px; color: var(--muted); }
.cta-meta .serif-it { font-size: 14px; }

/* question of the day */
.qd-block { margin-top: 36px; border-top: 1px solid var(--rule); padding-top: 22px; }
.qd-block .microlabel { margin-bottom: 10px; }
.qd-q { font-size: 26px; line-height: 1.25; margin-bottom: 14px; }
.qd-rows { display: flex; flex-direction: column; }
.qd-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 4px;
  border: 0; border-bottom: 1px solid var(--rule-light);
  background: none; font-family: inherit; font-size: 15.5px; color: var(--ink);
  text-align: left; cursor: pointer; transition: background var(--speed);
}
.qd-row:last-child { border-bottom: 0; }
.qd-row:hover:not(:disabled) { background: var(--wash); }
.qd-row:disabled { cursor: default; }
.qd-explain {
  margin-top: 14px; padding: 13px 15px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 6px;
  font-size: 13.5px; line-height: 1.55; color: var(--ink-soft);
}

/* option rows (quiz + QOTD share these state classes) */
.opt-letter { font-size: 13px; font-weight: 700; color: var(--muted); width: 18px; flex: none; }
.opt-text { flex: 1; }
.opt-tag { font-size: 13px; font-weight: 600; white-space: nowrap; }
.opt-tag.ok { color: var(--green-deep); }
.opt-tag.bad { color: var(--red); }
.is-dim { opacity: 0.45; }
.is-correct {
  background: var(--green-wash) !important;
  border-bottom-color: var(--green) !important;
  font-weight: 600;
}
.is-correct .opt-letter { color: var(--green-deep); }
.is-wrong { background: var(--red-wash) !important; border-bottom-color: var(--red) !important; }
.is-wrong .opt-letter { color: var(--red); }

/* right rail */
.home-rail { display: flex; flex-direction: column; gap: 22px; }
.rail-card {
  border: 1px solid var(--rule); border-radius: 6px;
  background: var(--surface); padding: 20px 22px;
}
.rail-card .microlabel { margin-bottom: 12px; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; align-items: center; justify-items: center; }
.cal-dow { font-size: 10px; color: var(--faint); }
.cal-pad { width: 24px; height: 24px; }
.cal-day { width: 24px; height: 24px; border-radius: 50%; background: var(--rule-light); }
.cal-day.future { background: var(--wash); }
.cal-day.done { background: var(--green); }
.cal-day.today { background: transparent; border: 2px solid var(--ink); }
.cal-day.today-done { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
.cal-caption { font-size: 13px; color: var(--ink-soft); margin-top: 14px; line-height: 1.5; }

.prog-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.prog-num { font-size: 30px; }
.prog-of { font-size: 18px; color: var(--muted); }
.prog-lbl { font-size: 12px; color: var(--muted); }
.prog-bar { height: 6px; border-radius: 999px; background: var(--rule-light); overflow: hidden; margin-bottom: 16px; }
.prog-bar i { display: block; height: 100%; background: var(--ink); border-radius: 999px; transition: width 0.6s ease; }

.rail-links { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.rail-link {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: none; border: 0; border-bottom: 1px solid var(--wash);
  padding: 0 0 8px; font-family: inherit; font-size: 14px; color: var(--ink);
  cursor: pointer; text-align: left; transition: color var(--speed);
}
.rail-link:last-child { border-bottom: 0; padding-bottom: 0; }
.rail-link:hover .rail-arrow { transform: translateX(3px); }
.rail-link.accent, .rail-link.accent .rail-arrow { color: var(--red); font-weight: 600; }
.rail-link.muted { color: var(--faint); cursor: default; }
.rail-arrow { color: var(--muted); transition: transform var(--speed); }

/* ---------------- QUIZ ---------------- */
.seg-progress { display: flex; gap: 5px; margin-bottom: 30px; }
.seg { flex: 1; height: 3px; background: var(--rule-light); }
.seg.cur { background: var(--ink); }
.seg.ok { background: var(--green); }
.seg.bad { background: var(--red); }

.q-meta { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.q-text {
  font-size: clamp(24px, 4.4vw, 32px);
  line-height: 1.2; margin: 0 auto 28px; font-weight: 400;
}

.opt-list { display: flex; flex-direction: column; }
.opt-row {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 6px;
  border: 0; border-bottom: 1px solid var(--rule-light);
  background: none; font-family: inherit; font-size: 16px; color: var(--ink);
  text-align: left; cursor: pointer; transition: background var(--speed);
}
.opt-row:hover:not(:disabled) { background: var(--wash); }
.opt-row:disabled { cursor: default; }
.opt-row.is-correct, .opt-row.is-wrong { padding-left: 10px; padding-right: 10px; margin: 0 -10px; }

.explain {
  display: none;
  margin-top: 22px; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 6px;
  font-size: 14px; line-height: 1.6; color: var(--ink-soft);
  animation: fade 0.25s ease both;
}
.explain.show { display: block; }
.explain .serif-it { font-size: 15px; }
.explain .accept { margin-top: 6px; font-size: 12.5px; color: var(--faint); }

.quiz-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; gap: 10px; }

/* ---------------- RESULTS (share card) ---------------- */
.results-wrap { padding-top: 4px; }
.results-wrap .microlabel.center { display: block; text-align: center; margin-bottom: 18px; }

.share-card {
  border: 2px solid var(--ink); border-radius: 8px;
  background: var(--surface); padding: 36px 30px;
  text-align: center;
  box-shadow: 6px 6px 0 var(--rule-light);
}
.sc-brand { font-size: 20px; margin-bottom: 4px; }
.sc-score { font-size: clamp(60px, 14vw, 84px); line-height: 1; letter-spacing: -0.02em; margin: 10px 0 2px; }
.sc-of { color: var(--faint); }
.sc-badge {
  display: inline-block;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.14em;
  border-radius: 999px; padding: 6px 16px; margin: 10px 0 16px;
  transform: rotate(-2deg);
}
.sc-badge.ok { color: var(--green-deep); border: 1.5px solid var(--green); }
.sc-badge.bad { color: var(--red); border: 1.5px solid var(--red); }
.sc-caption { font-size: 13.5px; color: var(--ink-soft); line-height: 1.55; }

.strip { display: flex; flex-direction: column; gap: 4px; align-items: center; margin-bottom: 16px; }
.strip-row { display: flex; gap: 4px; justify-content: center; }
.strip-sq { width: 14px; height: 14px; border-radius: 3px; }
.strip-sq.ok { background: var(--green); }
.strip-sq.bad { background: var(--red); }

.results-actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.tomorrow { text-align: center; margin-top: 18px; font-size: 13px; color: var(--muted); }

/* ---------------- FLASHCARDS ---------------- */
.flash-stage { position: relative; perspective: 1400px; margin-bottom: 28px; }
.flash-backing {
  position: absolute; inset: 10px -8px -8px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 8px;
  transform: rotate(1.2deg);
}
.flash {
  position: relative;
  min-height: 220px;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
  cursor: pointer;
}
.flash.flipped { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border: 1px solid var(--rule); border-radius: 8px;
  padding: 34px 30px;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center;
  box-shadow: var(--card-shadow);
  background: var(--surface);
}
.flash-front {
  background: repeating-linear-gradient(180deg, var(--surface) 0 27px, var(--wash) 27px 28px);
}
.flash-face .microlabel { margin-bottom: 14px; }
.flash-q { font-size: 28px; line-height: 1.3; }
.flash-a { font-size: 30px; line-height: 1.25; }
.flash-tap { margin-top: 18px; font-size: 12px; color: var(--faint); }
.flash-back { transform: rotateY(180deg); }
.flash-note { margin-top: 14px; font-size: 13px; color: var(--ink-soft); max-width: 46ch; line-height: 1.5; }

/* ---------------- RECALL ---------------- */
.recall-head { text-align: center; margin-bottom: 26px; }
.recall-head .microlabel { margin-bottom: 12px; display: block; }
.recall-q { font-size: clamp(24px, 4.4vw, 32px); line-height: 1.25; max-width: 24ch; margin: 0 auto; font-weight: 400; }

.recall-input {
  display: block;
  width: 100%; max-width: 420px;
  margin: 0 auto 24px;
  padding: 12px 4px;
  border: 0; border-bottom: 2px solid var(--ink);
  background: transparent;
  font-family: inherit; font-size: 17px; color: var(--ink);
  text-align: center;
}
.recall-input::placeholder { color: var(--faint); font-style: italic; }
.recall-input:focus { outline: none; border-bottom-color: var(--green-deep); }
.recall-cta { display: flex; justify-content: center; }

.recall-reveal { animation: fade 0.25s ease both; }
.reveal-answer {
  padding: 18px; border-radius: 6px;
  background: var(--green-wash); border: 1px solid var(--green);
  text-align: center; margin-bottom: 12px;
}
.ra-text { font-size: 26px; line-height: 1.25; margin-top: 4px; }
.ra-accept { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.your-answer {
  padding: 14px 18px; border-radius: 6px;
  background: var(--surface); border: 1px solid var(--rule);
  text-align: center;
}
.ya-text { font-size: 16px; margin-top: 3px; }
.auto-verdict { margin-top: 14px; text-align: center; font-size: 14px; font-weight: 600; }
.auto-verdict.good { color: var(--green-deep); }
.auto-verdict.bad { color: var(--red); }

/* ---------------- CATEGORY LIST ---------------- */
.cat-list { display: flex; flex-direction: column; }
.cat-item {
  display: flex; justify-content: space-between; align-items: center; gap: 14px;
  padding: 16px 6px;
  background: none; border: 0; border-bottom: 1px solid var(--rule-light);
  font-family: inherit; color: var(--ink); text-align: left; cursor: pointer;
  transition: background var(--speed);
}
.cat-item:hover { background: var(--wash); }
.ci-main { display: flex; flex-direction: column; gap: 2px; }
.ci-name { font-size: 20px; }
.ci-sub { font-size: 12.5px; color: var(--muted); }
.ci-prog { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ---------------- MODALS (settings / disclaimer) ---------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(30, 28, 24, 0.45);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
  animation: fade 0.18s ease both; backdrop-filter: blur(2px);
}
.modal-back.show { display: flex; }
.modal {
  width: 100%; max-width: 440px;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 8px;
  box-shadow: 6px 6px 0 var(--rule-light);
  padding: 24px;
}
.modal h3 { margin: 0 0 4px; font-family: var(--serif); font-weight: 400; font-size: 24px; }
.modal .muted { font-size: 13px; margin: 0 0 14px; }
.modal.modal-scroll { max-width: 560px; max-height: 82vh; overflow-y: auto; }
.disc-intro { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 8px; }
.disc-block { padding: 12px 0; border-top: 1px solid var(--rule-light); }
.disc-block:first-of-type { border-top: 0; }
.disc-block h4 { margin: 0 0 4px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.disc-block p { margin: 0; font-size: 13px; color: var(--ink-soft); line-height: 1.55; }
.disc-block p a, .disc-intro a { color: var(--ink); }

.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--rule-light);
}
.setting-row:first-of-type { border-top: 0; }
.s-label { font-size: 14.5px; }
.s-desc { font-size: 12px; color: var(--muted); }

.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--rule-light);
  border: 1px solid var(--rule); border-radius: 999px; cursor: pointer; transition: var(--speed);
}
.switch .slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  background: var(--surface); border-radius: 50%; transition: var(--speed);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider { background: var(--ink); border-color: var(--ink); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.seg-theme, .seg { font-family: inherit; }
.modal .seg { display: inline-flex; background: var(--wash); border: 1px solid var(--rule); border-radius: 999px; padding: 3px; gap: 3px; height: auto; }
.modal .seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 999px;
  cursor: pointer; font-size: 12.5px; color: var(--muted); font-family: inherit;
}
.modal .seg button.active { background: var(--ink); color: var(--on-ink); font-weight: 600; }

/* legacy .btn classes used inside modals */
.btn {
  appearance: none; border: 0; border-radius: 999px;
  padding: 11px 20px; font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: transform var(--speed);
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--ink); }
.btn-danger { background: transparent; color: var(--red); border: 1.5px solid var(--red); }
.btn-block { display: block; width: 100%; }
.mt { margin-top: 12px; }

.link-btn {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font: inherit; font-size: 12px; text-decoration: underline; padding: 2px;
}
.link-btn:hover { color: var(--ink); }

/* ---------------- footer ---------------- */
footer.foot {
  margin-top: 52px; border-top: 1px solid var(--rule); padding-top: 16px;
  text-align: center; font-size: 11.5px; color: var(--faint); line-height: 1.6;
}
.foot-disclaimer { max-width: 76ch; margin: 0 auto 4px; }
.foot-disclaimer strong { color: var(--muted); }
footer.foot a { color: var(--muted); }

/* confetti canvas */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; display: none; }

@media (max-width: 560px) {
  .wrap { padding: 18px 16px 48px; }
  .hero-cta .pill-ink { padding: 14px 26px; }
  .share-card { padding: 28px 18px; }
}

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