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

:root {
  /* Warm editorial palette */
  --ink:        #1a1814;
  --ink-soft:   #4a4540;
  --ink-muted:  #857e75;
  --rule:       #d8d1c4;
  --bg:         #f0ebe2;
  --bg-warm:    #e8e1d6;
  --bg-card:    #f7f3ed;

  /* Accent colours */
  --burgundy:   #7a1a22;
  --burgundy-light: #a84050;
  --navy:       #1a2744;
  --teal:       #1a6a5e;

  /* Pairing colours (consistent throughout) */
  --mf-color: #1a2744;  /* navy */
  --mm-color: #7a1a22;  /* burgundy */
  --ff-color: #1a6a5e;  /* teal */

  /* Type scale */
  --font-head: 'Playfair Display', 'Georgia', serif;
  --font-body: 'Source Serif 4', 'Georgia', serif;
  --font-sans: 'Inter', 'Helvetica Neue', Arial, sans-serif;

  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --text-4xl:  2.25rem;
  --text-5xl:  3rem;

  --max-prose: 680px;
  --max-wide:  900px;
  --max-full:  1100px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-lg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* ── Background grid ──────────────────────────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(122,26,34,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(122,26,34,0.03) 1px, transparent 1px);
  background-size: 52px 52px;
  pointer-events: none;
  z-index: 0;
  animation: grid-drift 50s linear infinite;
}

@keyframes grid-drift {
  0%   { background-position: 0 0; }
  100% { background-position: 52px 52px; }
}

/* ── Nav ──────────────────────────────────────────────────────────────────── */
#nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(250, 249, 247, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
}

#nav .nav-brand {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
}

#nav-links {
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
#nav-links::-webkit-scrollbar { display: none; }

#nav-links a {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 0 0.75rem;
  height: 52px;
  display: flex;
  align-items: center;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
#nav-links a:hover { color: var(--ink); }
#nav-links a.active {
  color: var(--burgundy);
  border-bottom-color: var(--burgundy);
}

/* ── Main layout ──────────────────────────────────────────────────────────── */
main {
  position: relative;
  z-index: 1;
  padding-top: 52px;
}

/* ── Sections ─────────────────────────────────────────────────────────────── */
.chapter {
  padding: 4rem 1.5rem 2.5rem;
  max-width: var(--max-full);
  margin: 0 auto;
}

.chapter + .chapter {
  border-top: 1px solid var(--rule);
}

.chapter-inner {
  max-width: var(--max-wide);
  margin: 0 auto;
}

/* Chapter label */
.chapter-label {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.chapter-label .chapter-num {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--burgundy);
}

.chapter-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* Chapter heading */
.chapter h2 {
  font-family: var(--font-head);
  font-size: var(--text-4xl);
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink);
  margin-bottom: 1.5rem;
  max-width: var(--max-prose);
}

/* Editorial paragraph */
.editorial {
  font-size: var(--text-lg);
  line-height: 1.75;
  color: var(--ink-soft);
  max-width: var(--max-prose);
  margin-bottom: 2.5rem;
}

.editorial strong {
  color: var(--ink);
  font-weight: 600;
}

/* Callout stat */
.callout {
  background: var(--bg-warm);
  border-left: 3px solid var(--burgundy);
  padding: 1rem 1.5rem;
  margin: 2rem 0;
  max-width: var(--max-prose);
  border-radius: 0 4px 4px 0;
}

.callout p {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--ink-soft);
}

.callout strong {
  color: var(--ink);
}

.chart-note {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

/* Chart container */
.chart-wrap {
  margin: 2rem 0;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.chart-title {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.chart-wrap svg {
  display: block;
  width: 100%;
  overflow: visible;
  margin-top: auto;
  margin-bottom: auto;
}

/* Two-column chart layout */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 2rem 0;
}


/* ── Hero section ─────────────────────────────────────────────────────────── */
#hero {
  padding: 4rem 3rem 0;
  max-width: var(--max-full);
  margin: 0 auto;
  border-bottom: 1px solid var(--rule);
}

.hero-eyebrow {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 1.75rem;
}

.hero-eyebrow::before {
  content: '———';
  letter-spacing: -0.05em;
  color: var(--rule);
}

#hero h1 {
  font-family: var(--font-head);
  font-size: clamp(2.8rem, 6.5vw, 5.5rem);
  font-weight: 700;
  line-height: 1.08;
  color: var(--ink);
  max-width: 820px;
  margin-bottom: 2rem;
}

#hero h1 em {
  font-style: italic;
  color: var(--burgundy);
}

#hero .hero-intro {
  font-size: var(--text-lg);
  line-height: 1.75;
  color: var(--ink-soft);
  max-width: 660px;
  margin-bottom: 3.5rem;
}

#hero .hero-intro strong {
  color: var(--ink);
  font-weight: 600;
}

#hero .hero-intro a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--burgundy);
  text-underline-offset: 2px;
}

#hero .hero-intro a:hover {
  color: var(--burgundy);
}

/* ── Hero stat rows ────────────────────────────────────────────────────────── */
.hero-stats-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
  border-top: 1px solid var(--rule);
  padding: 2rem 0;
}

.hero-stats-row + .hero-stats-row {
  border-top: 1px solid var(--rule);
  padding-bottom: 3rem;
}

.hero-stat {
  padding: 0 1rem;
  border-right: 1px solid var(--rule);
}

.hero-stat:first-child {
  padding-left: 0;
}

.hero-stat:last-child {
  border-right: none;
  padding-right: 0;
}

.hero-stat .stat-label {
  font-family: var(--font-sans);
  font-size: clamp(9px, 1.5vw, 10px);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.4rem;
  display: block;
}

.hero-stat .stat-num {
  font-family: var(--font-head);
  font-size: clamp(1.8rem, 3.5vw, 2.75rem);
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.01em;
  display: block;
  margin-bottom: 0.35rem;
}

.hero-stat .stat-num .unit {
  font-size: 0.38em;
  font-weight: 400;
  color: var(--ink-muted);
  letter-spacing: 0;
  vertical-align: baseline;
  position: relative;
  top: -0.15em;
}

.hero-stat .stat-caption {
  display: block;
  font-family: var(--font-sans);
  font-size: clamp(10px, 1.5vw, 11px);
  line-height: 1.35;
  color: var(--ink-muted);
  max-width: 160px;
  margin-top: 1rem;
}

/* Big primary stats (first row) */
.hero-stats-row.primary {
  grid-template-columns: repeat(4, 1fr);
}

.hero-stats-row.primary .stat-num {
  font-size: clamp(2.2rem, 4.5vw, 3.5rem);
  color: var(--ink);
}

/* ── D3 axis styles ───────────────────────────────────────────────────────── */
.axis text {
  font-family: var(--font-sans);
  font-size: clamp(9px, 1.5vw, 11px);
  fill: var(--ink-muted);
}

.axis path, .axis line {
  stroke: var(--rule);
  stroke-width: 1;
}

.axis .domain { display: none; }

.grid line {
  stroke: var(--rule);
  stroke-dasharray: 3,3;
}

.grid .domain { display: none; }

/* ── Legend ───────────────────────────────────────────────────────────────── */
.legend {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--ink-soft);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-rect {
  width: 14px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Donut chart ──────────────────────────────────────────────────────────── */
.donut-center-text {
  font-family: var(--font-head);
}

/* ── Scatter plot ─────────────────────────────────────────────────────────── */
.scatter-dot {
  opacity: 0.55;
  transition: opacity 0.15s;
}
.scatter-dot:hover { opacity: 1; }

/* ── Tooltip ──────────────────────────────────────────────────────────────── */
.chart-tooltip {
  position: fixed;
  background: var(--ink);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 200;
  max-width: 200px;
}

/* ── Word cloud ───────────────────────────────────────────────────────────── */

/* ── Timeline chart label ─────────────────────────────────────────────────── */
.line-label {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
}

/* ── Heatmap ──────────────────────────────────────────────────────────────── */
.heatmap-cell {
  stroke: var(--bg);
  stroke-width: 2;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--rule);
  padding: 3rem 1.5rem;
  text-align: center;
}

footer p {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--ink-muted);
  line-height: 1.6;
}

footer a {
  color: var(--burgundy);
  text-decoration: underline;
}

/* ── Utility ──────────────────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Fade-in on scroll */
.fade-in {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.fade-in.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Tablet ───────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  /* Nav: shrink brand, let links scroll horizontally */
  #nav { padding: 0 1rem; }
  #nav .nav-brand { font-size: 10px; }
  #nav-links a { padding: 0 0.5rem; font-size: 9px; }
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .chapter { padding: 3rem 1rem; }
  #hero { padding: 2.5rem 1rem 0; }
  .chapter h2 { font-size: var(--text-3xl); }

  /* Nav: hide brand text, keep links scrollable so chapters stay reachable */
  #nav .nav-brand { display: none; }
  #nav-links {
    display: flex;
    width: 100%;
  }
  #nav-links a { padding: 0 0.6rem; }

  .hero-stats-row,
  .hero-stats-row.primary {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem 0;
  }

  .hero-stat {
    border-right: none;
    border-bottom: 1px solid var(--rule);
    padding: 0 0 1rem 0;
  }

  .hero-stat:nth-child(even) { padding-left: 1rem; }

  .chart-row { grid-template-columns: 1fr; }

  .hero-stat .stat-caption {
    max-width: 100%;
    font-size: 10px;
  }
}

/* ── Small phones ─────────────────────────────────────────────────────────── */
@media (max-width: 400px) {
  #nav-links a { padding: 0 0.4rem; font-size: 8px; }
  .hero-stats-row { grid-template-columns: 1fr 1fr; gap: 0.75rem 0; }
}

/* ── About page ───────────────────────────────────────────────────────────── */
.about-hero {
  max-width: var(--max-prose);
  margin: 0 auto;
  padding: 5rem 1.5rem 3rem;
}

.about-hero .eyebrow {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 1.25rem;
}

.about-hero h1 {
  font-family: var(--font-head);
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1.1;
  color: var(--ink);
  margin-bottom: 2rem;
}

.about-section {
  max-width: var(--max-prose);
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

.about-section h2 {
  font-family: var(--font-head);
  font-size: clamp(1.4rem, 3vw, 2rem);
  color: var(--ink);
  margin-bottom: 1.25rem;
  padding-top: 3rem;
  border-top: 1px solid var(--rule);
}

.about-section p {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  line-height: 1.75;
  color: var(--ink-soft);
  margin-bottom: 1.25rem;
}

.about-section a {
  color: var(--burgundy);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.about-section ol, .about-section ul {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  line-height: 1.75;
  color: var(--ink-soft);
  padding-left: 1.5rem;
  margin-bottom: 1.25rem;
}

.about-section li {
  margin-bottom: 0.5rem;
}

.about-section strong {
  font-weight: 600;
  color: var(--ink);
}

.about-section .tech-note {
  background: var(--bg-warm);
  border-left: 3px solid var(--rule);
  padding: 1rem 1.5rem;
  margin: 2rem 0;
  border-radius: 0 4px 4px 0;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--ink-muted);
  line-height: 1.6;
}

@media (max-width: 680px) {
  .about-hero { padding: 4rem 1rem 2rem; }
  .about-section { padding: 0 1rem 3rem; }
}
