/* Carbon Correction - NYT-Style Data Journalism */

/* ============================================
   CSS Custom Properties
   ============================================ */
:root {
  /* Colors */
  --bg-dark: #1a1a2e;
  --bg-light: #f8f9fa;
  --bg-cream: #fffef9;
  --text-primary: #121212;
  --text-secondary: #666666;
  --text-light: #999999;
  --accent-red: #d64045;
  --accent-blue: #1d4e89;
  --accent-gold: #f0c808;
  --line-gray: #e0e0e0;
  --line-dark: #333;

  /* Typography */
  --font-headline: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-data: 'IBM Plex Mono', 'SF Mono', Monaco, monospace;

  /* Spacing */
  --section-padding: 100vh;
  --content-max-width: 680px;
  --wide-max-width: 1100px;
}

/* ============================================
   Base Styles
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 18px;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg-cream);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Typography
   ============================================ */
h1, h2, h3, h4 {
  font-family: var(--font-headline);
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}

h1 {
  font-size: clamp(2.5rem, 6vw, 4rem);
  letter-spacing: -0.02em;
}

h2 {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1.5rem;
}

p {
  margin: 0 0 1.5rem 0;
}

a {
  color: var(--accent-blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.lead {
  font-size: 1.35rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.byline {
  font-size: 0.9rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.dateline {
  font-size: 0.85rem;
  color: var(--text-light);
}

/* ============================================
   Layout
   ============================================ */
.container {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.container--wide {
  max-width: var(--wide-max-width);
}

/* ============================================
   Header / Navigation
   ============================================ */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(255, 254, 249, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-gray);
  padding: 0.75rem 0;
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.site-header.hidden {
  transform: translateY(-100%);
}

.site-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: var(--wide-max-width);
}

.site-logo {
  font-family: var(--font-headline);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.site-nav {
  display: flex;
  gap: 2rem;
}

.site-nav a {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.site-nav a:hover {
  color: var(--text-primary);
  text-decoration: none;
}

/* ============================================
   Hero Section
   ============================================ */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6rem 0 4rem;
  background: linear-gradient(180deg, var(--bg-cream) 0%, #fff 100%);
}

.hero__label {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-red);
  margin-bottom: 1.5rem;
  padding: 0.5rem 1rem;
  background: rgba(214, 64, 69, 0.1);
  border-radius: 2px;
}

.hero__title {
  margin-bottom: 1.5rem;
  max-width: 900px;
}

.hero__subtitle {
  font-size: 1.5rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin-bottom: 2rem;
  line-height: 1.5;
}

.hero__meta {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line-gray);
}

.hero__stat {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-top: 2rem;
}

.hero__stat-number {
  font-family: var(--font-data);
  font-size: 4rem;
  font-weight: 700;
  color: var(--accent-red);
  line-height: 1;
}

.hero__stat-label {
  font-size: 1.1rem;
  color: var(--text-secondary);
}

/* ============================================
   Scrollytelling Sections
   ============================================ */
.scrolly {
  position: relative;
}

.scrolly__graphic {
  position: sticky;
  top: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-cream);
  z-index: 1;
}

.scrolly__graphic--dark {
  background: var(--bg-dark);
}

.scrolly__chart {
  width: 100%;
  max-width: 800px;
  height: 500px;
  padding: 2rem;
}

.scrolly__steps {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

.scrolly__step {
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding: 2rem;
  pointer-events: auto;
}

.scrolly__step:first-child {
  padding-top: 60vh;
}

.scrolly__step:last-child {
  padding-bottom: 60vh;
}

.step__content {
  background: rgba(255, 254, 249, 0.95);
  backdrop-filter: blur(5px);
  padding: 2rem 2.5rem;
  max-width: 400px;
  border-radius: 4px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  border-left: 4px solid var(--accent-red);
}

.step__content h3 {
  margin-bottom: 1rem;
  font-size: 1.3rem;
}

.step__content p {
  margin-bottom: 0;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.6;
}

.step__content .highlight {
  color: var(--accent-red);
  font-weight: 600;
}

.step__content .highlight--blue {
  color: var(--accent-blue);
}

/* ============================================
   Big Number Display
   ============================================ */
.big-number {
  text-align: center;
  padding: 4rem 2rem;
}

.big-number__value {
  font-family: var(--font-data);
  font-size: clamp(4rem, 15vw, 10rem);
  font-weight: 700;
  line-height: 1;
  color: var(--accent-red);
  margin-bottom: 1rem;
}

.big-number__value--blue {
  color: var(--accent-blue);
}

.big-number__unit {
  font-size: 0.4em;
  color: var(--text-secondary);
  vertical-align: middle;
}

.big-number__label {
  font-size: 1.2rem;
  color: var(--text-secondary);
  max-width: 400px;
  margin: 0 auto;
}

.big-number__context {
  font-size: 0.95rem;
  color: var(--text-light);
  margin-top: 1rem;
  font-style: italic;
}

/* ============================================
   Charts
   ============================================ */
.chart-container {
  width: 100%;
  height: 100%;
  position: relative;
}

.chart-title {
  font-family: var(--font-headline);
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-align: center;
}

.chart-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 1.5rem;
}

/* D3 Chart Styles */
.axis text {
  font-family: var(--font-body);
  font-size: 12px;
  fill: var(--text-secondary);
}

.axis path,
.axis line {
  stroke: var(--line-gray);
}

.grid line {
  stroke: var(--line-gray);
  stroke-opacity: 0.5;
  stroke-dasharray: 2, 2;
}

.line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.line--understated {
  stroke: var(--accent-red);
}

.line--overstated {
  stroke: var(--accent-blue);
}

.area--understated {
  fill: var(--accent-red);
  fill-opacity: 0.15;
}

.area--overstated {
  fill: var(--accent-blue);
  fill-opacity: 0.15;
}

.dot {
  fill: #fff;
  stroke-width: 2;
}

.dot--understated {
  stroke: var(--accent-red);
}

.dot--overstated {
  stroke: var(--accent-blue);
}

.reference-line {
  stroke: var(--text-light);
  stroke-width: 1;
  stroke-dasharray: 5, 5;
}

.reference-label {
  font-family: var(--font-data);
  font-size: 11px;
  fill: var(--text-light);
}

.bar--positive {
  fill: var(--accent-red);
}

.bar--negative {
  fill: var(--accent-blue);
}

.tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: var(--font-data);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 100;
}

.tooltip.visible {
  opacity: 1;
}

/* Legend */
.legend {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1rem;
  font-size: 0.85rem;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend__color {
  width: 16px;
  height: 3px;
  border-radius: 2px;
}

.legend__color--understated {
  background: var(--accent-red);
}

.legend__color--overstated {
  background: var(--accent-blue);
}

/* ============================================
   Donut Chart
   ============================================ */
.donut-center {
  text-anchor: middle;
}

.donut-center__value {
  font-family: var(--font-data);
  font-size: 2.5rem;
  font-weight: 700;
  fill: var(--text-primary);
}

.donut-center__label {
  font-size: 0.9rem;
  fill: var(--text-secondary);
}

.donut-label {
  font-size: 0.8rem;
  fill: var(--text-secondary);
}

/* ============================================
   Narrative Sections
   ============================================ */
.narrative {
  padding: 6rem 0;
  background: #fff;
}

.narrative__content {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.narrative h2 {
  margin-bottom: 1.5rem;
}

.narrative p {
  font-size: 1.1rem;
}

.narrative__pullquote {
  font-family: var(--font-headline);
  font-size: 1.8rem;
  font-style: italic;
  color: var(--text-secondary);
  border-left: 4px solid var(--accent-gold);
  padding-left: 1.5rem;
  margin: 3rem 0;
}

/* ============================================
   Data Explorer
   ============================================ */
.explorer {
  padding: 6rem 0;
  background: var(--bg-light);
}

.explorer__header {
  text-align: center;
  margin-bottom: 3rem;
}

.explorer__controls {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.explorer__search {
  flex: 1;
  min-width: 200px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: var(--font-body);
  border: 1px solid var(--line-gray);
  border-radius: 4px;
  background: #fff;
}

.explorer__search:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(29, 78, 137, 0.1);
}

.explorer__filter {
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-family: var(--font-body);
  border: 1px solid var(--line-gray);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.data-table th,
.data-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--line-gray);
}

.data-table th {
  background: var(--bg-dark);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  user-select: none;
}

.data-table th:hover {
  background: #252542;
}

.data-table th.sorted-asc::after {
  content: ' ↑';
}

.data-table th.sorted-desc::after {
  content: ' ↓';
}

.data-table td {
  font-family: var(--font-data);
  font-size: 0.9rem;
}

.data-table tr:hover {
  background: rgba(29, 78, 137, 0.05);
}

.data-table .positive {
  color: var(--accent-red);
}

.data-table .negative {
  color: var(--accent-blue);
}

.table-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
}

.table-pagination button {
  padding: 0.5rem 1rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  border: 1px solid var(--line-gray);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.table-pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.table-pagination button:hover:not(:disabled) {
  background: var(--bg-light);
}

/* ============================================
   Download Section
   ============================================ */
.download {
  padding: 6rem 0;
  background: var(--bg-dark);
  color: #fff;
  text-align: center;
}

.download h2 {
  color: #fff;
  margin-bottom: 1rem;
}

.download__subtitle {
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.1rem;
  margin-bottom: 2rem;
}

.download__buttons {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 3rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 2rem;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn--primary {
  background: var(--accent-gold);
  color: var(--text-primary);
}

.btn--primary:hover {
  background: #d4af07;
  text-decoration: none;
}

.btn--secondary {
  background: transparent;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.btn--secondary:hover {
  border-color: #fff;
  text-decoration: none;
}

.download__citation {
  max-width: 600px;
  margin: 0 auto;
  padding: 2rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  text-align: left;
}

.download__citation h4 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 1rem;
}

.download__citation p {
  font-family: var(--font-data);
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.8;
  margin: 0;
}

/* ============================================
   Video Embed
   ============================================ */
.video-embed {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  margin-bottom: 2.5rem;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.video-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ============================================
   Media List
   ============================================ */
.media-list {
  list-style: none;
  padding: 0;
  margin: 2rem 0 0 0;
}

.media-list li {
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--line-gray);
}

.media-list li:first-child {
  border-top: 1px solid var(--line-gray);
}

.media-list a {
  display: block;
  color: var(--text-primary);
  transition: color 0.2s ease;
}

.media-list a:hover {
  color: var(--accent-blue);
  text-decoration: none;
}

.media-list strong {
  color: var(--accent-blue);
  font-weight: 600;
}

/* Author Links in Byline */
.byline a {
  color: var(--text-light);
  text-decoration: none;
  border-bottom: 1px dotted rgba(255, 255, 255, 0.4);
  transition: color 0.2s ease, border-color 0.2s ease;
}

.byline a:hover {
  color: #fff;
  border-color: #fff;
  text-decoration: none;
}

/* ============================================
   Footer
   ============================================ */
.site-footer {
  background: #111;
  color: rgba(255, 255, 255, 0.6);
  padding: 3rem 0;
  font-size: 0.85rem;
}

.site-footer .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  max-width: var(--wide-max-width);
}

.site-footer a {
  color: rgba(255, 255, 255, 0.6);
}

.site-footer a:hover {
  color: #fff;
}

.footer__links {
  display: flex;
  gap: 2rem;
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes countUp {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.animate-in {
  animation: fadeInUp 0.8s ease forwards;
}

.animate-delay-1 { animation-delay: 0.1s; }
.animate-delay-2 { animation-delay: 0.2s; }
.animate-delay-3 { animation-delay: 0.3s; }
.animate-delay-4 { animation-delay: 0.4s; }

/* Step visibility */
.scrolly__step.is-active .step__content {
  opacity: 1;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  .site-nav {
    display: none;
  }

  .hero {
    min-height: auto;
    padding: 5rem 0 3rem;
  }

  .hero__stat-number {
    font-size: 3rem;
  }

  .scrolly__graphic {
    height: 50vh;
    position: relative;
  }

  .scrolly__step {
    min-height: auto;
    padding: 2rem 1rem;
  }

  .scrolly__step:first-child {
    padding-top: 2rem;
  }

  .scrolly__step:last-child {
    padding-bottom: 2rem;
  }

  .step__content {
    max-width: 100%;
    padding: 1.5rem;
  }

  .big-number__value {
    font-size: 3rem;
  }

  .explorer__controls {
    flex-direction: column;
  }

  .data-table {
    display: block;
    overflow-x: auto;
  }

  .download__buttons {
    flex-direction: column;
    align-items: center;
  }

  .site-footer .container {
    flex-direction: column;
    text-align: center;
  }

  .footer__links {
    flex-direction: column;
    gap: 1rem;
  }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  .site-header,
  .site-footer,
  .scrolly__graphic {
    display: none;
  }

  .scrolly__step {
    min-height: auto;
    page-break-inside: avoid;
  }
}
