/* ==========================================================================
   The Carbon Ledger — design tokens
   Palette: deep atmosphere navy + ember amber (data/heat), cool teal (relief)
   Type: Fraunces (display, editorial serif) / Inter (body) / IBM Plex Mono (data)
   ========================================================================== */

:root {
  --ink:        #0B1220;   /* base background — deep night atmosphere */
  --ink-2:      #101A2E;   /* panel background */
  --ink-3:      #17233B;   /* raised panel / hover */
  --line:       #263252;   /* hairline borders */
  --paper:      #E9EDF6;   /* primary text */
  --paper-dim:  #96A2C0;   /* secondary text */
  --paper-faint:#5C6889;   /* tertiary / captions */

  --ember:      #E8923D;   /* primary accent — carbon / heat */
  --ember-dim:  #B9752F;
  --teal:       #4FB8A6;   /* relief accent — decoupling / positive signal */
  --teal-dim:   #2E7A6E;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;

  --container: 1100px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--ember); color: var(--ink); }

a { color: var(--ember); }

.sub { font-size: 0.7em; vertical-align: sub; }

/* Subtle film-grain texture over the whole page — keeps flat dark bg from feeling flat */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 999;
  opacity: 0.035; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------------------------- Masthead ---------------------------- */
.masthead {
  position: sticky; top: 0; z-index: 100;
  background: rgba(11, 18, 32, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.masthead__inner {
  max-width: var(--container); margin: 0 auto; padding: 18px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.masthead__mark { display: flex; align-items: center; gap: 8px; }
.mark__dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ember);
  box-shadow: 0 0 8px var(--ember);
}
.mark__label {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em;
  color: var(--paper-dim);
}
.masthead__nav { display: flex; gap: 28px; }
.masthead__nav a {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.04em;
  color: var(--paper-dim); text-decoration: none; text-transform: lowercase;
  transition: color 0.15s ease;
}
.masthead__nav a:hover { color: var(--ember); }

/* ---------------------------- Hero ---------------------------- */
.hero {
  max-width: var(--container); margin: 0 auto;
  padding: 88px 24px 40px;
}
.hero__inner { max-width: 720px; }
.eyebrow {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.08em;
  color: var(--ember); text-transform: uppercase; margin: 0 0 20px;
}
.hero__title {
  font-family: var(--font-display); font-weight: 500; font-style: italic;
  font-size: clamp(56px, 9vw, 104px); line-height: 0.94; letter-spacing: -0.01em;
  margin: 0 0 28px; color: var(--paper);
}
.hero__dek {
  font-size: 19px; color: var(--paper-dim); max-width: 560px; margin: 0 0 56px;
  font-weight: 400;
}

.hero__stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 4px;
  overflow: hidden;
}
.stat {
  background: var(--ink-2); padding: 22px 20px;
}
.stat__value {
  font-family: var(--font-mono); font-size: 28px; color: var(--ember);
  display: block; margin-bottom: 6px; font-weight: 500;
}
.stat__value--teal { color: var(--teal); }
.stat__label {
  font-size: 12.5px; color: var(--paper-faint); line-height: 1.4;
}

/* Signature element: the atmosphere scale — a gradient bar evoking a
   ppm / heat instrument reading, anchoring the hero to the subject */
.hero__scale { max-width: var(--container); margin: 56px auto 0; padding: 0 24px; }
.hero__scale-bar {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, #1c2b47 0%, #2e7a6e 35%, #b9752f 70%, #e8923d 100%);
}
.hero__scale-labels {
  display: flex; justify-content: space-between; margin-top: 10px;
  font-family: var(--font-mono); font-size: 11px; color: var(--paper-faint);
}

/* ---------------------------- Sections ---------------------------- */
.section {
  max-width: var(--container); margin: 0 auto;
  padding: 96px 24px 24px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 72px;
}
.section__head { max-width: 640px; margin-bottom: 40px; }
.section__index {
  font-family: var(--font-mono); font-size: 12px; color: var(--paper-faint);
  letter-spacing: 0.06em; display: block; margin-bottom: 14px;
}
.section h2 {
  font-family: var(--font-display); font-weight: 500; font-size: clamp(28px, 4vw, 38px);
  margin: 0 0 14px; color: var(--paper); letter-spacing: -0.01em;
}
.section p {
  color: var(--paper-dim); font-size: 16px; margin: 0;
}
.section strong { color: var(--teal); font-weight: 600; }

.chart-frame {
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 28px 24px; height: 380px; position: relative;
}
.chart-frame--tall { height: 460px; }

.legend {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px;
}
.legend__item {
  font-family: var(--font-mono); font-size: 12px; color: var(--paper-dim);
  border: 1px solid var(--line); border-radius: 20px; padding: 6px 14px;
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  background: var(--ink-2); transition: all 0.15s ease;
  user-select: none;
}
.legend__item:hover { border-color: var(--ember-dim); color: var(--paper); }
.legend__item.is-off { opacity: 0.35; }
.legend__swatch { width: 8px; height: 8px; border-radius: 50%; }

/* ---------------------------- Decoupling ledger table ---------------------------- */
.section--feature { padding-bottom: 40px; }

.decoupling-table {
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 6px;
  overflow: hidden;
}
.dt-row {
  display: grid;
  grid-template-columns: 32px 1fr 140px 140px;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  gap: 16px;
}
.dt-row:last-child { border-bottom: none; }
.dt-row.dt-head {
  font-family: var(--font-mono); font-size: 11px; color: var(--paper-faint);
  text-transform: uppercase; letter-spacing: 0.06em; background: var(--ink-3);
}
.dt-rank { font-family: var(--font-mono); font-size: 12px; color: var(--paper-faint); }
.dt-country { font-size: 15px; color: var(--paper); font-weight: 500; }
.dt-metric { font-family: var(--font-mono); font-size: 13px; text-align: right; }
.dt-metric--down { color: var(--teal); }
.dt-metric--up { color: var(--ember); }
.dt-metric-label { display: none; color: var(--paper-faint); font-size: 10px; }
.dt-bar-wrap { grid-column: 1 / -1; height: 3px; background: var(--line); margin-top: 10px; border-radius: 2px; overflow: hidden; }
.dt-bar { height: 100%; background: var(--teal); }

/* ---------------------------- Method ---------------------------- */
.method__grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 6px;
  overflow: hidden;
}
.method__card { background: var(--ink-2); padding: 24px; }
.method__label {
  font-family: var(--font-mono); font-size: 11px; color: var(--ember);
  text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 10px;
}
.method__card p { color: var(--paper-dim); font-size: 14.5px; margin: 0; }

/* ---------------------------- Footer ---------------------------- */
.footer {
  max-width: var(--container); margin: 0 auto;
  padding: 48px 24px 80px;
  font-family: var(--font-mono); font-size: 12px; color: var(--paper-faint);
  border-top: 1px solid var(--line); margin-top: 40px;
}
.footer a { color: var(--paper-dim); }

/* ---------------------------- Responsive ---------------------------- */
@media (max-width: 720px) {
  .hero { padding-top: 64px; }
  .hero__stats { grid-template-columns: 1fr; }
  .masthead__nav { display: none; }
  .method__grid { grid-template-columns: 1fr; }
  .dt-row {
    grid-template-columns: 20px 1fr auto auto;
    column-gap: 10px; row-gap: 8px; padding: 14px 16px;
  }
  .dt-row.dt-head { display: none; }
  .dt-country { grid-column: 2 / 3; }
  .dt-metric { text-align: right; font-size: 12px; }
  .dt-metric-label { display: inline; }
}

/* ---------------------------- Accessibility ---------------------------- */
a:focus-visible, .legend__item:focus-visible {
  outline: 2px solid var(--ember); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
