/* Optical gas imaging of cattle methane — companion site to the poster */

:root {
  --bg: #fcfcfb;
  --card: #ffffff;
  --ink: #1d2026;
  --ink-2: #444b56;
  --muted: #6b717c;
  --line: #e3e4e8;
  --accent: #8a1538;
  --accent-ink: #8a1538;
  --accent-soft: #f6e8ec;
  --hero-bg: #8a1538;
  --hero-ink: #ffffff;
  --hero-ink-2: #f4dbe2;

  /* Chart series (validated light-mode pair) and funnel ramp, light to dark */
  --series-event: #b02a4a;
  --series-chamber: #2e7bb0;
  --funnel-1: #d497a4;
  --funnel-2: #be6a7d;
  --funnel-3: #a43f57;
  --funnel-4: #8a1538;
  --funnel-5: #5c0d25;
  --grid: #e8e9ec;

  --radius: 12px;
  --wide: 1120px;
  --text: 68ch;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --card: #1e2024;
    --ink: #eceef1;
    --ink-2: #c3c7ce;
    --muted: #959aa3;
    --line: #2f3238;
    --accent: #e0607c;
    --accent-ink: #f08ea3;
    --accent-soft: #2b1b21;
    --hero-bg: #5e0f27;
    --hero-ink: #ffffff;
    --hero-ink-2: #f0c9d3;

    /* Dark mode gets its own validated steps: dim to bright */
    --series-event: #e0607c;
    --series-chamber: #4a98d0;
    --funnel-1: #8e3a50;
    --funnel-2: #aa4862;
    --funnel-3: #c55d78;
    --funnel-4: #dd7f96;
    --funnel-5: #f0aebd;
    --grid: #2c2f35;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 64px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, video { display: block; max-width: 100%; height: auto; }
a { color: var(--accent-ink); text-underline-offset: 2px; }

/* ------------------------------------------------------------------ hero */

.hero {
  background: var(--hero-bg);
  color: var(--hero-ink);
  padding: 56px 16px 64px;
}
.hero-inner { max-width: var(--wide); margin: 0 auto; }
.hero .eyebrow { color: var(--hero-ink-2); }
.hero h1 {
  font-size: clamp(2rem, 5.2vw, 3.5rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 12px 0 16px;
  max-width: 22ch;
}
.hero .subtitle {
  font-size: clamp(1.1rem, 2.3vw, 1.45rem);
  line-height: 1.35;
  color: var(--hero-ink-2);
  margin: 0 0 24px;
  max-width: 44ch;
}
.hero .authors { font-weight: 600; margin: 0; }
.hero .affiliation { color: var(--hero-ink-2); margin: 2px 0 0; }
.hero .lede {
  font-size: 1.1rem;
  max-width: 60ch;
  margin: 32px 0 0;
  color: var(--hero-ink);
}

.mit-logo { width: 54px; height: auto; fill: currentColor; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 40px;
}
@media (min-width: 820px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .value { font-size: clamp(1.6rem, 4vw, 2.3rem); font-weight: 650; line-height: 1.1; }
.stat .label { color: var(--hero-ink-2); font-size: 0.92rem; line-height: 1.4; margin-top: 6px; }

/* ------------------------------------------------------------------ nav */

.site-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-nav ul {
  list-style: none;
  margin: 0 auto;
  padding: 0 8px;
  max-width: var(--wide);
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.site-nav ul::-webkit-scrollbar { display: none; }
.site-nav a {
  display: block;
  white-space: nowrap;
  padding: 14px 10px;
  font-size: 0.9rem;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a.active { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ------------------------------------------------------------------ sections */

main section {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 72px 16px 8px;
}
main section + section { border-top: 1px solid var(--line); margin-top: 56px; }

.eyebrow {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-ink);
  margin: 0;
}
h2 {
  font-size: clamp(1.65rem, 3.6vw, 2.4rem);
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 8px 0 16px;
  max-width: 26ch;
}
h3 { font-size: 1.25rem; line-height: 1.3; margin: 48px 0 8px; }
h4 { font-size: 1.02rem; margin: 0 0 4px; }

.prose { max-width: var(--text); }
.prose p, .prose ul, .prose ol { margin: 0 0 16px; color: var(--ink-2); }
.prose strong { color: var(--ink); }
.lead { font-size: 1.15rem; color: var(--ink) !important; }
.prose li { margin-bottom: 6px; }

.callout {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 16px 20px;
  margin: 24px 0;
  max-width: var(--text);
}
.callout p { margin: 0; color: var(--ink); }

.sources { font-size: 0.82rem; color: var(--muted); max-width: var(--text); }

/* ------------------------------------------------------------------ figures */

figure { margin: 24px 0; }
figure.card, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
figure img, figure video { width: 100%; background: #000; }
figure img.on-white { background: #fff; }
figcaption {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--muted);
  padding: 10px 14px 14px;
}
figcaption strong { color: var(--ink); font-weight: 600; }
.figure-pad { padding: 12px; background: #fff; }

.grid-2, .grid-3, .grid-4 { display: grid; gap: 16px; margin: 24px 0; }
.grid-2 > figure, .grid-3 > figure, .grid-4 > figure { margin: 0; }
@media (min-width: 720px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 719px) {
  /* Photos sit two-up on phones too; captions stay short */
  .photos-2up { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .photos-2up figcaption { font-size: 0.8rem; padding: 8px 10px 10px; }
}
.span-2 { grid-column: 1 / -1; }

/* Photos are cropped to a common shape in galleries; the lightbox shows them whole */
.gallery img { aspect-ratio: 4 / 3; object-fit: cover; cursor: zoom-in; }
.gallery .tall img { aspect-ratio: 3 / 4; }

.split { display: grid; gap: 24px; align-items: start; margin: 24px 0; }
@media (min-width: 860px) {
  .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 40px; }
  .split.text-first > .prose { order: 0; }
}

/* Wide panel strips switch to stacked versions on phones */
.only-wide { display: none; }
@media (min-width: 720px) {
  .only-wide { display: block; }
  .only-narrow { display: none; }
}
.only-narrow video { max-height: 86svh; width: auto; margin: 0 auto; }

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; margin: 24px 0; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; min-width: 560px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
tr.ours td { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
td.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ steps */

.steps { list-style: none; padding: 0; margin: 24px 0; display: grid; gap: 12px; max-width: var(--text); }
.steps li {
  display: grid;
  /* minmax(0, ...) lets a wide equation scroll inside its box instead of widening the page */
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  color: var(--ink-2);
}
.steps .n {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  font-size: 0.9rem;
  display: grid;
  place-items: center;
  margin-top: 1px;
}
.steps strong { color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; padding: 0; list-style: none; }
.chips li {
  font-size: 0.88rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--ink-2);
  background: var(--card);
}

.evolution { display: grid; gap: 10px; margin: 24px 0; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.evolution > div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.evolution .what { font-weight: 600; font-size: 0.95rem; }
.evolution .from { color: var(--muted); font-size: 0.88rem; }
.evolution .to { color: var(--accent-ink); font-size: 0.92rem; font-weight: 600; }

/* ------------------------------------------------------------------ math */

.math { overflow-x: auto; overflow-y: hidden; padding: 4px 0; margin: 8px 0 16px; color: var(--ink); }
.katex { font-size: 1.08em; }

/* ------------------------------------------------------------------ interactive widgets */

.widget { padding: 20px; margin: 28px 0; }
.widget h3 { margin-top: 0; }
.widget .hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 16px; }

.controls { display: grid; gap: 16px; margin: 16px 0; }
@media (min-width: 640px) { .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.control label { display: flex; justify-content: space-between; font-size: 0.92rem; color: var(--ink-2); }
.control output { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin-top: 6px; }

.readout { display: flex; flex-wrap: wrap; gap: 8px 32px; align-items: baseline; margin-top: 8px; }
.readout .big { font-size: clamp(2.4rem, 7vw, 3.4rem); font-weight: 700; line-height: 1; color: var(--ink); }
.readout .unit { font-size: 1.2rem; font-weight: 600; color: var(--ink-2); }
.readout .side { color: var(--muted); font-size: 0.95rem; }

/* Funnel */
.funnel { display: grid; gap: 14px; margin: 20px 0 8px; }
.funnel-row { display: grid; gap: 4px 16px; outline: none; position: relative; }
@media (min-width: 720px) { .funnel-row { grid-template-columns: 240px 1fr; align-items: center; } }
.funnel-label .name { font-weight: 600; color: var(--ink); line-height: 1.3; }
.funnel-label .detail { font-size: 0.85rem; color: var(--muted); line-height: 1.35; }
.funnel-track { display: flex; align-items: center; gap: 10px; min-height: 24px; }
.funnel-bar { height: 22px; border-radius: 0 4px 4px 0; min-width: 4px; transition: filter 0.15s; }
.funnel-value { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.funnel-row:hover .funnel-bar, .funnel-row:focus-visible .funnel-bar { filter: brightness(1.12); }
.funnel-row:focus-visible { box-shadow: 0 0 0 2px var(--accent); border-radius: 6px; }

/* SVG chart (chamber explainer) */
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis text, .chart .panel-title { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.chart .panel-title { fill: var(--ink-2); font-weight: 600; font-size: 13px; }
.chart .burp { fill: var(--series-event); }
.chart .chamber-line { fill: none; stroke: var(--series-chamber); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .chamber-area { fill: var(--series-chamber); opacity: 0.1; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart .dot { fill: var(--series-chamber); stroke: var(--card); stroke-width: 2; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  min-width: 150px;
  opacity: 0;
  transition: opacity 0.1s;
}
.tooltip.show { opacity: 1; }
.tooltip .t { color: var(--muted); margin-bottom: 4px; }
.tooltip .row { display: flex; align-items: center; gap: 8px; }
.tooltip .key { width: 14px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .v { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.tooltip .s { color: var(--muted); }
.chart-wrap { position: relative; }

/* belched = carried out + left, kept on one row at every width */
.balance { display: grid; gap: 8px; margin-top: 12px; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch; }
.balance > div { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.balance .k { font-size: 0.82rem; color: var(--muted); }
.balance .v { font-size: 1.3rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.balance .op { border: none; display: grid; place-items: center; font-size: 1.4rem; color: var(--muted); padding: 0; }

/* ------------------------------------------------------------------ lightbox */

dialog.lightbox {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 96vw;
  max-height: 94vh;
}
dialog.lightbox::backdrop { background: rgba(0, 0, 0, 0.85); }
dialog.lightbox img { max-width: 96vw; max-height: 88vh; width: auto; border-radius: 8px; }
dialog.lightbox p { color: #ddd; margin: 8px 4px 0; font-size: 0.9rem; }

/* ------------------------------------------------------------------ footer */

footer {
  border-top: 1px solid var(--line);
  margin-top: 80px;
  padding: 40px 16px 56px;
  color: var(--muted);
  font-size: 0.9rem;
}
footer .inner { max-width: var(--wide); margin: 0 auto; display: grid; gap: 24px; }
@media (min-width: 820px) { footer .inner { grid-template-columns: 1.2fr 1fr 1fr; } }
footer h4 { color: var(--ink); }
footer p { margin: 0 0 8px; }

/* Funnel tooltip: same details on hover and keyboard focus */
.funnel-row[data-tip]:hover::after, .funnel-row[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  right: 0;
  top: -30px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  z-index: 2;
}

@media (max-width: 480px) {
  /* Long display equations fit a phone better slightly smaller; they still scroll if needed */
  .math .katex-display > .katex { font-size: 0.92em; }
  .balance > div { padding: 8px; }
  .balance .k { font-size: 0.74rem; line-height: 1.3; }
  .balance .v { font-size: 1.1rem; }
}
