/* ── KB Theme Variables ────────────────────────────────────────────────────────
   Dark is the default; light is applied via html.light class (set by JS) or
   prefers-color-scheme for users without a saved preference.
   ──────────────────────────────────────────────────────────────────────────── */

:root {
  --bg: #070b14;
  --background: #070b14;
  --surface: #0d1420;
  --surface-2: #111c2d;
  --surface-3: #162035;
  --border: #1e2d45;
  --border-subtle: #152030;
  --text: #e8edf5;
  --text-muted: #6b7fa0;
  --text-dim: #3d5070;
  --blue: #3b82f6;
  --blue-dim: rgba(59, 130, 246, 0.12);
  --blue-glow: rgba(59, 130, 246, 0.25);
  --purple: #8b5cf6;
  --purple-dim: rgba(139, 92, 246, 0.12);
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.12);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.12);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.6);
  --sidebar-width: 280px;
  --content-max: 780px;
  --header-h: 56px;
  --header-bg: rgba(13, 20, 32, 0.92);
}

/* System prefers light — applied before JS runs (no class on html yet) */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fc;
    --background: #f6f8fc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --surface-3: #e8eef8;
    --border: #dde4f0;
    --border-subtle: #e8eef8;
    --text: #0f172a;
    --text-muted: #4b6080;
    --text-dim: #94a3b8;
    --blue: #2563eb;
    --blue-dim: rgba(37, 99, 235, 0.08);
    --blue-glow: rgba(37, 99, 235, 0.2);
    --purple: #7c3aed;
    --purple-dim: rgba(124, 58, 237, 0.08);
    --green: #059669;
    --green-dim: rgba(5, 150, 105, 0.08);
    --amber: #d97706;
    --amber-dim: rgba(217, 119, 6, 0.08);
    --red: #dc2626;
    --red-dim: rgba(220, 38, 38, 0.08);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.10);
    --header-bg: rgba(246, 248, 252, 0.92);
  }
}

/* Explicit dark class — overrides media query */
html.dark {
  --bg: #070b14;
  --background: #070b14;
  --surface: #0d1420;
  --surface-2: #111c2d;
  --surface-3: #162035;
  --border: #1e2d45;
  --border-subtle: #152030;
  --text: #e8edf5;
  --text-muted: #6b7fa0;
  --text-dim: #3d5070;
  --blue: #3b82f6;
  --blue-dim: rgba(59, 130, 246, 0.12);
  --blue-glow: rgba(59, 130, 246, 0.25);
  --purple: #8b5cf6;
  --purple-dim: rgba(139, 92, 246, 0.12);
  --green: #10b981;
  --green-dim: rgba(16, 185, 129, 0.12);
  --amber: #f59e0b;
  --amber-dim: rgba(245, 158, 11, 0.12);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.12);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.6);
  --header-bg: rgba(13, 20, 32, 0.92);
}

/* Explicit light class — overrides media query */
html.light {
  --bg: #f6f8fc;
  --background: #f6f8fc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e8eef8;
  --border: #dde4f0;
  --border-subtle: #e8eef8;
  --text: #0f172a;
  --text-muted: #4b6080;
  --text-dim: #94a3b8;
  --blue: #2563eb;
  --blue-dim: rgba(37, 99, 235, 0.08);
  --blue-glow: rgba(37, 99, 235, 0.2);
  --purple: #7c3aed;
  --purple-dim: rgba(124, 58, 237, 0.08);
  --green: #059669;
  --green-dim: rgba(5, 150, 105, 0.08);
  --amber: #d97706;
  --amber-dim: rgba(217, 119, 6, 0.08);
  --red: #dc2626;
  --red-dim: rgba(220, 38, 38, 0.08);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.10);
  --header-bg: rgba(246, 248, 252, 0.92);
}

/* ── Reset & Base ─────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::selection { background: var(--blue-glow); color: var(--text); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 35;
  height: var(--header-h);
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
}
.hamburger {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  align-items: center; justify-content: center;
  cursor: pointer;
}
.hamburger:hover { background: var(--surface-3); }
.crumbs { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.crumbs a { color: var(--text-muted); }
.crumbs a:hover { color: var(--blue); text-decoration: none; }
.crumbs .sep { color: var(--text-dim); }
.crumbs .here { color: var(--text); font-weight: 500; }
.brand {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 13px; color: var(--text);
}
.brand .icon-circle {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: white;
  box-shadow: 0 2px 8px var(--blue-glow);
}

/* ── Theme Toggle ─────────────────────────────────────────────────────────── */
.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  padding: 0;
}
.theme-toggle:hover { background: var(--surface-3); color: var(--text); }
/* In dark mode: show sun (click → go light). In light mode: show moon (click → go dark). */
html.dark .theme-toggle .moon-icon,
html.light .theme-toggle .sun-icon { display: none; }
html.dark .theme-toggle .sun-icon,
html.light .theme-toggle .moon-icon { display: block; }
/* Default (before JS class is set): defer to prefers-color-scheme */
@media (prefers-color-scheme: dark) {
  :root:not(.light) .moon-icon { display: none; }
}
@media (prefers-color-scheme: light) {
  :root:not(.dark) .sun-icon { display: none; }
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--header-h); left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0 40px 0;
  z-index: 30;
  transition: transform 0.25s ease;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

.nav-section { margin-bottom: 12px; }
.nav-section-title {
  padding: 8px 20px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.nav-link {
  display: block;
  padding: 6px 20px 6px 24px;
  font-size: 13px;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  transition: all 0.12s;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav-link.active {
  color: var(--blue);
  border-left-color: var(--blue);
  background: var(--blue-dim);
  font-weight: 500;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  z-index: 25;
}
.sidebar-overlay.visible { display: block; }

/* ── Main content ────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-width);
  padding: 32px 48px 80px 48px;
  min-height: calc(100vh - var(--header-h));
}
.content { max-width: var(--content-max); margin: 0 auto; }

h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 12px 0;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
h2 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 36px 0 14px 0;
  color: var(--text);
}
h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 28px 0 6px 0;
  color: var(--text);
}
h3::before {
  content: "";
  display: inline-block;
  width: 4px; height: 14px;
  background: var(--blue);
  border-radius: 2px;
  margin-right: 10px;
  vertical-align: -2px;
}
p { color: var(--text); margin: 10px 0; }
p.lead { font-size: 17px; color: var(--text-muted); line-height: 1.6; }
ul, ol { color: var(--text); padding-left: 22px; }
li { margin: 4px 0; }
code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--purple);
}
strong { color: var(--text); font-weight: 600; }
em { color: var(--text-muted); font-style: italic; }

/* ── Callouts ────────────────────────────────────────────────────────────── */
.callout {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 18px 0;
  display: flex; gap: 12px;
  align-items: flex-start;
  font-size: 14px;
}
.callout.warn { border-color: rgba(245,158,11,0.3); background: var(--amber-dim); }
.callout.warn .callout-icon { color: var(--amber); }
.callout.info { border-color: rgba(59,130,246,0.3); background: var(--blue-dim); }
.callout.info .callout-icon { color: var(--blue); }
.callout.danger { border-color: rgba(239,68,68,0.3); background: var(--red-dim); }
.callout.danger .callout-icon { color: var(--red); }
.callout-icon { flex-shrink: 0; margin-top: 2px; }
.callout-body { flex: 1; }
.callout-body strong { display: block; margin-bottom: 2px; }

/* ── State footer, tags ──────────────────────────────────────────────────── */
.state-footer {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-subtle);
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  vertical-align: 4px;
  margin-left: 8px;
}
.tag.two-party { background: var(--red-dim); color: var(--red); border: 1px solid rgba(239,68,68,0.25); }
.tag.one-party { background: var(--green-dim); color: var(--green); border: 1px solid rgba(16,185,129,0.25); }
.tag.mixed { background: var(--amber-dim); color: var(--amber); border: 1px solid rgba(245,158,11,0.25); }

/* ── Prev/Next nav ───────────────────────────────────────────────────────── */
.pn-nav {
  margin-top: 56px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.pn-card {
  display: block;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: all 0.15s;
  color: var(--text);
}
.pn-card:hover { border-color: var(--blue); transform: translateY(-1px); text-decoration: none; }
.pn-card .pn-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; }
.pn-card .pn-title { font-size: 15px; font-weight: 600; color: var(--text); }
.pn-card.next { text-align: right; }
.pn-card.disabled { opacity: 0.35; pointer-events: none; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
  margin-left: var(--sidebar-width);
  padding: 24px 48px 40px 48px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.6;
}
.site-footer strong { color: var(--text-muted); }

/* ── Index page: hero, feature grid, state grid ──────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 36px 32px 36px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  top: -60px; right: -60px;
  width: 220px; height: 220px;
  background: radial-gradient(circle, var(--blue-glow), transparent 70%);
  pointer-events: none;
}
.hero .kicker {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--blue);
  background: var(--blue-dim);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.hero h1 { margin: 0 0 8px 0; border: none; padding: 0; font-size: 36px; }
.hero p.lead { margin-top: 6px; }
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 40px 0 12px 0;
}
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: all 0.15s;
}
.feature-card:hover { border-color: var(--blue); transform: translateY(-1px); }
.feature-card .feature-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  background: var(--blue-dim);
  color: var(--blue);
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
.feature-card h3 { margin: 0 0 6px 0; font-size: 15px; font-weight: 600; }
.feature-card h3::before { content: none; }
.feature-card p { font-size: 13px; color: var(--text-muted); margin: 0; line-height: 1.5; }

.state-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 30px;
}
.state-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  transition: all 0.12s;
}
.state-card:hover {
  border-color: var(--blue);
  background: var(--surface-2);
  transform: translateY(-1px);
  text-decoration: none;
}
.state-card .state-name { font-size: 14px; font-weight: 500; }
.state-card .tag { margin-left: 0; }
.state-card.federal { border-color: rgba(139, 92, 246, 0.35); }
.state-card.federal:hover { border-color: var(--purple); }
.state-card.federal .tag.mixed { background: var(--purple-dim); color: var(--purple); border-color: rgba(139,92,246,0.3); }

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .site-header, .sidebar-overlay, .pn-nav, .theme-toggle { display: none !important; }
  .main, .site-footer { margin-left: 0; padding: 20px; }
  body { background: white; color: black; font-size: 11pt; }
  h1, h2, h3 { color: black; page-break-after: avoid; }
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 880px) {
  .hamburger { display: inline-flex; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 20px 18px 60px 18px; }
  .site-footer { margin-left: 0; padding: 20px 18px 36px 18px; }
  h1 { font-size: 24px; }
  h2 { font-size: 20px; }
  .brand { display: none; }
  .pn-nav { grid-template-columns: 1fr; }
}
