:root,
[data-theme='light'] {
  --hero-bg: url('hero-bg-light.png');

  --hero-filter: none;
  --color-bg: #fbf5f4;
  --color-surface: #ffffff;
  --color-surface-2: #f6efee;
  --color-surface-offset: #efe3e1;
  --color-text: #1c1214;
  --color-text-muted: #6b5559;
  --color-text-faint: #9c8387;
  --color-primary: #c2410c;
  --color-primary-2: #b02e05;
  --color-border: #ecdcd9;
  --color-divider: #f1e6e3;
  --color-success: #15803d;
  --color-warning: #b45309;
  --color-error: #dc2626;
  --color-moderate: #2563eb;
  --color-opinion: #9333ea;
  --chart-1: #c2410c;
  --chart-2: #dc2626;
  --chart-3: #15803d;
  --chart-4: #2563eb;
  --chart-5: #9333ea;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow: 0 1px 3px rgba(28, 18, 20, 0.08), 0 1px 2px rgba(28, 18, 20, 0.04);
  --shadow-sm: 0 1px 2px rgba(28, 18, 20, 0.06);
  --shadow-md: 0 4px 12px rgba(28, 18, 20, 0.08);
}

[data-theme='dark'] {
  --hero-bg: url('hero-bg-dark.png');
  --hero-filter: none;
  --color-bg: #0f0a0d;
  --color-surface: #1a1115;
  --color-surface-2: #24171c;
  --color-surface-offset: #2d1d23;
  --color-text: #f5edef;
  --color-text-muted: #b89aa1;
  --color-text-faint: #8a6b72;
  --color-primary: #fb7185;
  --color-primary-2: #fda4af;
  --color-border: #321f26;
  --color-divider: #39242c;
  --color-success: #4ade80;
  --color-warning: #fbbf24;
  --color-error: #f87171;
  --color-moderate: #60a5fa;
  --color-opinion: #a78bfa;
  --chart-1: #fb7185;
  --chart-2: #f87171;
  --chart-3: #4ade80;
  --chart-4: #60a5fa;
  --chart-5: #a78bfa;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  transition: background 0.25s ease, color 0.25s ease;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: var(--hero-bg);
  background-size: cover;
  background-position: top center;
  background-repeat: no-repeat;
  background-attachment: scroll;
  filter: var(--hero-filter, none);
  opacity: 0.32;
  transition: filter 0.25s ease, opacity 0.25s ease;
}

code { font-family: var(--font-mono); font-size: 0.9em; background: var(--color-surface-2); padding: 0.1em 0.3em; border-radius: 3px; }

.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: static;
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 36px; height: 36px; color: var(--color-primary); flex-shrink: 0; }
.brand h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { font-size: 0.82rem; color: var(--color-text-muted); }
.last-updated { font-size: 0.74rem; color: var(--color-text-faint); font-family: var(--font-mono); white-space: nowrap; }

.container {
  max-width: 1240px; margin: 0 auto; padding: 24px 20px 60px;
  display: flex; flex-direction: column; gap: 24px;
}

/* --- navbar --- */
.navbar {
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 60;
}
.navbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 46px;
}
.nav-menu { display: flex; align-items: center; flex: 1; justify-content: space-between; }
.nav-links { display: flex; list-style: none; gap: 4px; margin: 0; padding: 0; flex-shrink: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar-actions .refresh-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 6px; border: 1px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text);
  font-size: 0.78rem; cursor: pointer; transition: background 0.15s;
}
.topbar-actions .refresh-btn:hover { background: var(--color-primary); color: #fff; }
.topbar-actions [data-theme-toggle] { background: none; border: none; color: var(--color-text-muted); cursor: pointer; padding: 4px; }
.topbar-actions [data-theme-toggle]:hover { color: var(--color-primary); }
.nav-links a {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 12px; border-radius: 6px;
  font-size: 0.85rem; font-weight: 500; color: var(--color-text-muted);
  text-decoration: none; transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.nav-links a svg { flex-shrink: 0; display: block; }
.nav-links a:hover { color: var(--color-primary); background: var(--color-surface); }
.nav-links a.active { color: var(--color-primary); font-weight: 600; }

.hamburger {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 38px; height: 38px; padding: 8px; background: none; border: none; cursor: pointer;
}
.hamburger span { display: block; height: 2px; width: 100%; background: var(--color-text); border-radius: 2px; transition: transform 0.2s, opacity 0.2s; }
.hamburger.open span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

section.question-card, section.kpi-grid, section.lead-card { scroll-margin-top: 70px; }

@media (max-width: 1100px) {
  .hamburger { display: flex; }
  .nav-menu {
    position: absolute; top: 46px; left: 0; right: 0;
    flex-direction: column; background: var(--color-surface);
    border-bottom: 1px solid var(--color-border); padding: 8px 12px;
    transform: translateY(-200%); transition: transform 300ms ease;
    z-index: 99;
  }
  .nav-menu.open { transform: translateY(0); }
  .nav-links { flex-direction: column; gap: 2px; }
  .nav-links a { padding: 10px 12px; }
  .navbar-inner { position: relative; }
}

.lead-card, .question-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.lead-card { border-left: 4px solid var(--color-primary); }
.lead-card h2 { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; margin: 10px 0 8px; }
.lead-subhead { color: var(--color-text-muted); font-size: 1.02rem; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.03em; }
.badge-high { background: rgba(74, 222, 128, 0.12); color: var(--color-success); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.kpi-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 10px; padding: 18px 20px; box-shadow: var(--shadow);
}
.kpi-label { display: block; font-size: 0.74rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.kpi-value { display: block; font-size: 1.9rem; font-weight: 700; letter-spacing: -0.03em; }
.kpi-delta { display: block; font-size: 0.78rem; color: var(--color-text-muted); margin-top: 2px; }

.section-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.q-num {
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  background: color-mix(in srgb, var(--color-primary) 50%, #0b0f14); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.q-num svg { width: 18px; height: 18px; display: block; }
.section-head h2 { font-size: 1.15rem; font-weight: 700; }
.conf-badge { display: inline-block; margin-top: 3px; padding: 1px 8px; border-radius: 4px; font-size: 0.68rem; font-weight: 600; background: rgba(74, 222, 128, 0.12); color: var(--color-success); }

.answer-text { color: var(--color-text); margin-bottom: 16px; font-size: 0.98rem; }

/* --- grade legend --- */
.grade-list { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.grade-legend {
  flex: 1; min-width: 200px; padding: 12px 14px;
  background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: 8px;
}
.grade-legend .g-head { font-weight: 700; font-size: 0.88rem; margin-bottom: 2px; }
.grade-legend p { font-size: 0.78rem; color: var(--color-text-muted); }

/* --- grade badges --- */
.grade-badge { padding: 2px 8px; border-radius: 4px; font-size: 0.66rem; font-weight: 700; font-family: var(--font-mono); }
.grade-S { background: rgba(74, 222, 128, 0.14); color: var(--color-success); }
.grade-M { background: rgba(96, 165, 250, 0.14); color: var(--color-moderate); }
.grade-W { background: rgba(251, 191, 36, 0.14); color: var(--color-warning); }
.grade-OPINION { background: rgba(167, 139, 250, 0.14); color: var(--color-opinion); }

/* --- claims --- */
.claim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.claim-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.claim-head { display: flex; flex-direction: column; gap: 6px; }
.claim-card h3 { font-size: 0.96rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.4; }
.verdict-badge {
  align-self: flex-start; padding: 2px 10px; border-radius: 999px; font-size: 0.68rem; font-weight: 600;
  background: color-mix(in srgb, var(--color-primary) 12%, transparent); color: var(--color-primary);
}
.claim-card .grade-badge { align-self: flex-start; }
.claim-evidence { font-size: 0.84rem; color: var(--color-text-muted); }
.src-file { font-size: 0.72rem; color: var(--color-text-faint); font-family: var(--font-mono); word-break: break-word; }
.src-file .src-wiki { color: var(--color-primary); text-decoration: none; font-family: var(--font-base); }
.src-file .src-wiki:hover { text-decoration: underline; }

/* --- proof table --- */
.evidence-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; background: color-mix(in srgb, var(--color-surface) 80%, transparent); backdrop-filter: blur(4px); border: 1px solid var(--color-border); border-radius: 8px; }
.evidence-table th, .evidence-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); vertical-align: top; }
.evidence-table th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); }
.evidence-table td:nth-child(1) { font-weight: 600; }
.evidence-table td .g-note { display: block; font-size: 0.76rem; color: var(--color-text-faint); margin-top: 2px; }

/* --- mitigations --- */
.mitigation-list { display: flex; flex-direction: column; gap: 14px; }
.mitigation-card {
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: 10px; padding: 18px 20px;
}
.mitigation-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.mitigation-card h3 { font-size: 1.02rem; font-weight: 700; letter-spacing: -0.01em; }
.ev-badge { padding: 2px 10px; border-radius: 999px; font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.ev-strong { background: rgba(74, 222, 128, 0.14); color: var(--color-success); }
.ev-moderate { background: rgba(96, 165, 250, 0.14); color: var(--color-moderate); }
.ev-weak { background: rgba(251, 191, 36, 0.14); color: var(--color-warning); }
.mitigation-summary { font-size: 0.9rem; color: var(--color-text); margin-bottom: 10px; }
.mitigation-row { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 10px; }
.mitigation-support, .mitigation-risk { flex: 1; min-width: 240px; }
.mini-label { display: block; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-faint); margin-bottom: 4px; }
.mitigation-support ul { margin: 0; padding-left: 18px; font-size: 0.82rem; color: var(--color-text-muted); }
.mitigation-support li { margin-bottom: 3px; }
.mitigation-risk p { margin: 0; font-size: 0.82rem; color: var(--color-text-muted); }

/* --- methodology --- */
.mini-head { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-faint); margin: 18px 0 8px; }
.uncertainty-list { margin: 0 0 12px 0; padding: 14px 16px 14px 42px; font-size: 0.86rem; color: var(--color-text-muted); background: color-mix(in srgb, var(--color-surface) 80%, transparent); backdrop-filter: blur(4px); border: 1px solid var(--color-border); border-radius: 8px; }
.uncertainty-list li { margin-bottom: 5px; }
.uncertainty-list .u-item { font-weight: 600; color: var(--color-text); }
.method-list { margin: 0 0 12px 0; padding: 14px 16px 14px 42px; font-size: 0.88rem; color: var(--color-text-muted); background: color-mix(in srgb, var(--color-surface) 80%, transparent); backdrop-filter: blur(4px); border: 1px solid var(--color-border); border-radius: 8px; }
.method-list li { margin-bottom: 5px; }
.note-list { margin: 0 0 12px 0; padding: 14px 16px 14px 42px; font-size: 0.82rem; color: var(--color-text-muted); background: color-mix(in srgb, var(--color-surface) 80%, transparent); backdrop-filter: blur(4px); border: 1px solid var(--color-border); border-radius: 8px; }
.note-list li { margin-bottom: 4px; }

.sources-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.sources-row a {
  font-size: 0.74rem; color: var(--color-primary-2); text-decoration: none;
  border: 1px solid var(--color-border); padding: 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  transition: background 0.15s;
}
.sources-row a:hover { background: var(--color-primary); color: #fff; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border); border-left: 4px solid var(--color-success);
  padding: 12px 20px; border-radius: 8px; font-size: 0.88rem;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-left-color: var(--color-error); }

@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .evidence-table { font-size: 0.76rem; }
  .evidence-table th, .evidence-table td { padding: 8px 6px; }
}

/* --- Hero Background Transparency Overrides --- */
body {
  background-color: color-mix(in srgb, var(--color-bg) 85%, transparent);
}

.topbar,
.kpi-card {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  backdrop-filter: blur(8px);
}

.navbar {
  background: color-mix(in srgb, var(--color-surface-2) 80%, transparent);
  backdrop-filter: blur(24px);
}

.lead-card,
.question-card {
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  backdrop-filter: blur(4px);
}

.claim-card,
.mitigation-card,
.grade-legend {
  background: color-mix(in srgb, var(--color-surface-2) 80%, transparent);
  backdrop-filter: blur(4px);
}

.evidence-table th {
  background: color-mix(in srgb, var(--color-surface-2) 80%, transparent);
  backdrop-filter: blur(4px);
}

.evidence-table tr:hover td {
  background: color-mix(in srgb, var(--color-surface-2) 70%, transparent);
  backdrop-filter: blur(4px);
}

.nav-menu {
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
  backdrop-filter: blur(32px);
}

.toast {
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
  backdrop-filter: blur(16px);
}

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

/* --- Nav / subnav horizontal overflow guard --- */
.nav-links { flex-wrap: nowrap; flex-shrink: 0; }
.nav-menu { min-width: 0; }
.navbar-inner { height: auto; }
#refresh-btn { display: none; }
html.nav-collapsed .hamburger { display: flex; }
html.nav-collapsed .nav-menu { position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; background: var(--color-surface); border-bottom: 1px solid var(--color-border); padding: 8px 12px; transform: translateY(-200%); transition: transform 300ms ease; z-index: 99; }
html.nav-collapsed .nav-menu.open { transform: translateY(0); }
html.nav-collapsed .nav-links { flex-direction: column; gap: 2px; }
html.nav-collapsed .nav-links a { padding: 10px 12px; }

/* --- Subnav dropdown (buildSubnav) --- */
.nav-item { position: relative; }
.subnav {
  position: absolute; top: 100%; left: 0; min-width: 240px; max-height: 70vh; overflow-y: auto;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 8px; box-shadow: var(--shadow-md);
  display: none; flex-direction: column; padding: 6px; z-index: 300;
}
.nav-item:hover > .subnav,
.nav-item:focus-within > .subnav,
.nav-item.subnav-open > .subnav { display: flex; }
.subnav.subnav-has-children { overflow: visible; max-height: none; }
.subnav a {
  padding: 7px 12px; font-size: 0.76rem; border-radius: 6px;
  color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.subnav a:hover { background: var(--color-surface-offset); color: var(--color-primary); }
@media (max-width: 1100px) {
  .subnav { position: static; min-width: 0; max-height: none; box-shadow: none; border: none; border-left: 1px solid var(--color-border); margin: 0 0 4px 14px; padding: 2px 0 2px 8px; }
  .nav-item.subnav-open .subnav { display: flex; }
}

.nav-item.subnav-right .subnav { left: auto !important; right: 0 !important; }
.subnav-right .subnav-nested { left: auto !important; right: 100% !important; }

/* md2wiki:footer — minimal footer where the dashboard has no .footer rule */
.footer { border-top: 1px solid var(--color-border); padding: 18px 20px; text-align: center; font-size: 0.8rem; color: var(--color-text-muted); }
.footer a { color: var(--color-primary); }

/* research corpus (md2wiki researchFiles) */
.research-list { display: flex; flex-wrap: wrap; gap: 8px; }
.research-link { font-size: 0.82rem; color: var(--color-primary); text-decoration: none; background: var(--color-surface-2, rgba(0,0,0,0.04)); border: 1px solid var(--color-border); padding: 5px 10px; border-radius: 999px; }
.research-link:hover { text-decoration: underline; }
