/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8f9fa;
  --bg-alt: #ffffff;
  --text: #1a1a2e;
  --text-muted: #4a5568;
  --accent: #2c5282;
  --accent-light: #ebf4ff;
  --border: #e2e8f0;
  --table-stripe: #f1f5f9;
  --card-bg: #ffffff;
  --callout-bg: #fffbeb;
  --callout-border: #d69e2e;
  --badge-headline: #276749;
  --badge-headline-bg: #c6f6d5;
  --badge-supporting: #2b6cb0;
  --badge-supporting-bg: #bee3f8;
  --badge-provisional: #975a16;
  --badge-provisional-bg: #fefcbf;
  --badge-method: #744210;
  --badge-method-bg: #feebc8;
  --badge-qa: #718096;
  --badge-qa-bg: #edf2f7;
  --nav-bg: #ffffff;
  --nav-shadow: 0 1px 3px rgba(0,0,0,0.08);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-alt: #16213e;
  --text: #e2e8f0;
  --text-muted: #a0aec0;
  --accent: #63b3ed;
  --accent-light: #1a365d;
  --border: #2d3748;
  --table-stripe: #1e293b;
  --card-bg: #1e293b;
  --callout-bg: #44337a1a;
  --callout-border: #ecc94b;
  --badge-headline: #9ae6b4;
  --badge-headline-bg: #22543d;
  --badge-supporting: #90cdf4;
  --badge-supporting-bg: #2a4365;
  --badge-provisional: #fefcbf;
  --badge-provisional-bg: #744210;
  --badge-method: #feebc8;
  --badge-method-bg: #7b341e;
  --badge-qa: #cbd5e0;
  --badge-qa-bg: #4a5568;
  --nav-bg: #16213e;
  --nav-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  transition: background 0.2s ease, color 0.2s ease;
}

/* === Typography === */
h1 { font-size: 2.25rem; font-weight: 700; line-height: 1.2; margin-bottom: 1rem; letter-spacing: -0.02em; }
h2 { font-size: 1.75rem; font-weight: 600; line-height: 1.3; margin: 2.5rem 0 1rem; letter-spacing: -0.01em; }
h3 { font-size: 1.35rem; font-weight: 600; line-height: 1.4; margin: 2rem 0 0.75rem; }
p { margin-bottom: 1rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--table-stripe); padding: 0.15em 0.35em; border-radius: 3px; }

/* === Layout === */
.container { max-width: 860px; margin: 0 auto; padding: 0 1.5rem; }
.container--wide { max-width: 1100px; }

/* === Navigation === */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  box-shadow: var(--nav-shadow);
  transition: background 0.2s ease;
}

.nav__inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.nav__brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.nav__links {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  list-style: none;
}

.nav__links a {
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s;
}

.nav__links a:hover,
.nav__links a.active {
  color: var(--accent);
}

.nav__toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: border-color 0.15s;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.theme-toggle svg { display: block; }
.theme-toggle:hover { border-color: var(--accent); }

/* === Hero === */
.hero {
  padding: 4rem 0 3rem;
  border-bottom: 1px solid var(--border);
}

.hero__subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 640px;
  margin-top: 0.5rem;
}

/* === Stats row === */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
  margin: 2rem 0;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.stat-card__value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.stat-card__label {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* === Callout === */
.callout {
  background: var(--callout-bg);
  border-left: 4px solid var(--callout-border);
  border-radius: 0 6px 6px 0;
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
  transition: background 0.2s ease;
}

.callout__title {
  font-weight: 600;
  margin-bottom: 0.35rem;
}

details.callout summary {
  list-style: none;
}

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

/* === Figures === */
.figure {
  margin: 2rem 0;
  text-align: center;
}

.figure__img-wrap {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: inline-block;
  max-width: 100%;
}

.figure img {
  max-width: 100%;
  height: auto;
  display: block;
}

.figure figcaption {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

/* === Tables === */
.table-wrap {
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  white-space: nowrap;
}

.data-table th {
  background: var(--bg-alt);
  font-weight: 600;
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr:nth-child(even) { background: var(--table-stripe); }
.data-table tbody tr:hover { background: var(--accent-light); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* === Evidence badges === */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2em 0.55em;
  border-radius: 4px;
  white-space: nowrap;
}

.badge--headline { color: var(--badge-headline); background: var(--badge-headline-bg); }
.badge--supporting { color: var(--badge-supporting); background: var(--badge-supporting-bg); }
.badge--provisional { color: var(--badge-provisional); background: var(--badge-provisional-bg); }
.badge--method { color: var(--badge-method); background: var(--badge-method-bg); }
.badge--qa { color: var(--badge-qa); background: var(--badge-qa-bg); }

/* === Compact prose (explanations page) === */
.prose-tight .section { padding: 1.5rem 0; }
.prose-tight .section + .section { border-top: none; }
.prose-tight p { margin-bottom: 0.6rem; }
.prose-tight h2 { margin-top: 1.5rem; }

/* === Section spacing === */
.section { padding: 3rem 0; }
.section + .section { border-top: 1px solid var(--border); }

/* === Page header === */
.page-header {
  padding: 3rem 0 2rem;
  border-bottom: 1px solid var(--border);
}

.page-header p {
  color: var(--text-muted);
  max-width: 640px;
}

/* === Evidence tier list (methods page) === */
.tier-list {
  list-style: none;
  margin: 1.5rem 0;
}

.tier-list li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.tier-list li:last-child { border-bottom: none; }

/* === Dataset cards === */
.dataset-group { margin: 2rem 0; }

.dataset-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  transition: background 0.2s ease;
}

.dataset-card__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.dataset-card__name {
  font-weight: 600;
  font-size: 1.05rem;
}

.dataset-card p {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 0;
}

/* === Formula === */
.formula {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  font-size: 1.15rem;
  font-family: var(--mono);
  margin: 1.5rem 0;
}

/* === Footer === */
.footer {
  padding: 2rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text-muted);
  text-align: center;
}

/* === Responsive === */
@media (max-width: 768px) {
  body { font-size: 16px; }
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.4rem; }
  .hero { padding: 2.5rem 0 2rem; }
  .stats { grid-template-columns: 1fr; }

  .nav__toggle { display: block; }

  .nav__links {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--nav-bg);
    flex-direction: column;
    padding: 1rem 1.5rem;
    gap: 0.5rem;
    box-shadow: var(--nav-shadow);
  }

  .nav__links.open { display: flex; }

  .section { padding: 2rem 0; }
}

@media (max-width: 480px) {
  .container { padding: 0 1rem; }
  .stat-card__value { font-size: 1.6rem; }
}
