:root {
  --ink: #111113;
  --ink-soft: #6a6a70;
  --paper: #ececef;
  --paper-2: #e1e1e5;
  --card: #f7f7f8;
  --line: #c8c8ce;
  --hero-fg: #f4f4f5;
  --hero-muted: rgba(244, 244, 245, 0.68);
  --accent: #f4f4f5;
  --apogee: #111113;
  --perigee: #6a6a70;
  --flux: #8a8a90;
  --danger: #4a4a50;
  --shadow: none;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  --header-h: 3.25rem;
  --radius: 3px;
}

html[data-theme="dark"] {
  --ink: #f2f2f3;
  --ink-soft: #8a8a90;
  --paper: #0a0a0b;
  --paper-2: #161618;
  --card: #121214;
  --line: #2a2a2e;
  --accent: #f4f4f5;
  --apogee: #ffffff;
  --perigee: #6e6e74;
  --flux: #4a4a50;
  --danger: #b0b0b6;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--mono);
  font-size: 16px;
  font-feature-settings: "tnum" 1, "ss01" 1;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
  letter-spacing: -0.01em;
}

img { max-width: 100%; }
button, input { font-family: inherit; }

a {
  color: inherit;
  text-decoration-color: var(--ink-soft);
  text-underline-offset: 0.18em;
}
a:hover { color: var(--accent); text-decoration-color: var(--accent); }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  background: #0a0a0b;
  color: #f4f4f5;
  border-bottom: 1px solid #2a2a2e;
}

.wordmark {
  font-size: 0.86rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.theme-toggle {
  background: transparent;
  color: #f4f4f5;
  border: 1px solid #3a3a40;
  border-radius: var(--radius);
  padding: 0.28rem 0.7rem;
  cursor: pointer;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.theme-toggle:hover { border-color: #f4f4f5; }

.hero {
  position: relative;
  min-height: 26rem;
  height: 68vh;
  max-height: 40rem;
  color: var(--hero-fg);
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  background: #050506;
}

.hero-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to top, #0a0a0b 0%, rgba(10, 10, 11, 0.55) 42%, rgba(10, 10, 11, 0.42) 100%),
    url("../HST-SM4.jpeg") center 28% / cover no-repeat;
  filter: grayscale(0.28) contrast(1.06);
}

.hero-inner {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 2.4rem));
  margin: 0 auto 4.2rem;
}

.eyebrow {
  margin: 0 0 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
  font-weight: 500;
  color: #a0a0a6;
}

.altitude {
  font-size: clamp(3.6rem, 11vw, 7.6rem);
  font-weight: 500;
  line-height: 0.92;
  letter-spacing: -0.06em;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.altitude span {
  font-size: 0.26em;
  letter-spacing: 0.12em;
  margin-left: 0.28em;
  color: var(--hero-muted);
  font-weight: 400;
  text-transform: uppercase;
}

.lede {
  max-width: 38rem;
  font-size: 1.02rem;
  line-height: 1.55;
  color: var(--hero-muted);
  margin: 1.05rem 0 0;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 1.5rem;
  margin-top: 1.15rem;
  color: #9a9aa0;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.wrap {
  width: min(1120px, calc(100% - 2.4rem));
  margin: 0 auto;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: -2.1rem auto 1.6rem;
  position: relative;
  z-index: 2;
  background: var(--line);
  border: 1px solid var(--line);
}

.metric {
  background: var(--card);
  padding: 0.95rem 1rem 0.9rem;
}

.metric dt {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}

.metric dd {
  margin: 0.4rem 0 0;
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.metric .sub {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  font-weight: 400;
  text-transform: none;
}

.chart-panel {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 0.9rem 0.9rem 0.85rem;
  margin-bottom: 1.5rem;
  scroll-margin-top: 4.5rem;
  position: relative;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  padding: 0.15rem 0.35rem 0.7rem;
}

.chart-head h2 {
  font-size: 0.86rem;
  font-weight: 500;
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.swatch {
  display: inline-block;
  width: 0.85rem;
  height: 2px;
  margin-right: 0.35rem;
  vertical-align: middle;
}
.swatch.apogee { background: var(--apogee); }
.swatch.perigee { background: var(--perigee); }
.swatch.flux { background: var(--flux); }
.swatch.ref { background: var(--danger); height: 0; border-top: 1.5px dashed var(--danger); }

#graph {
  width: 100%;
  height: min(62vh, 640px);
  min-height: 360px;
  overflow: hidden;
}

#graph svg { display: block; overflow: visible; }

.grid-line { stroke: var(--line); stroke-width: 1; }
.axis text {
  fill: var(--ink-soft);
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
.axis path, .axis line { stroke: var(--line); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.7rem 0.2rem 0.15rem;
}

.controls button,
.controls label {
  appearance: none;
  background: var(--paper-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.32rem 0.62rem;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.controls button:hover,
.controls label:hover {
  border-color: var(--ink);
}

.controls button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.gap-note {
  color: var(--ink-soft);
  font-size: 0.8rem;
  padding: 0.45rem 0.35rem 0;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: #0a0a0b;
  color: #f4f4f5;
  border: 1px solid #2a2a2e;
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  font-size: 0.8rem;
  min-width: 10.5rem;
  opacity: 0;
  transform: translate(-20px, -12px);
  transition: opacity 0.12s;
  z-index: 5;
  font-variant-numeric: tabular-nums;
}

html[data-theme="light"] .tooltip {
  background: #111113;
  color: #f4f4f5;
}

.prose, .systems {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 1.25rem 1.35rem 1.15rem;
  margin-bottom: 1px;
}

.prose h2, .systems h2 {
  font-weight: 500;
  font-size: 0.86rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0 0 0.85rem;
}

.prose p, .prose li { max-width: 48rem; color: var(--ink); font-size: 0.98rem; line-height: 1.65; }
.prose code {
  font-family: inherit;
  font-size: 0.9em;
  border: 1px solid var(--line);
  padding: 0.05em 0.28em;
}
.prose p { margin: 0 0 0.85rem; }
.prose p:last-child { margin-bottom: 0; }
.prose ul {
  margin: 0 0 0.85rem;
  padding-left: 1.15rem;
}
.prose li { margin-bottom: 0.35rem; }

.systems p { color: var(--ink-soft); margin: 0 0 0.85rem; max-width: 42rem; font-size: 0.98rem; }
.systems p:last-child { margin-bottom: 0; }

.site-footer {
  padding: 1.6rem 0 2.2rem;
  color: var(--ink-soft);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

.site-footer p { margin: 0.3rem 0; }

@media (max-width: 860px) {
  .metrics { grid-template-columns: 1fr 1fr; margin-top: -1.2rem; }
  .hero-inner { margin-bottom: 3rem; }
  #graph { height: 55vh; min-height: 320px; }
}

@media (max-width: 560px) {
  .hero { height: 70vh; max-height: none; }
  .lede { font-size: 0.88rem; }
  .hero-inner { margin-bottom: 2.4rem; }
  .site-header { padding: 0 0.85rem; }
  .wrap, .hero-inner { width: min(100% - 1.4rem, 1120px); }
  .metrics { gap: 1px; }
  .metric { padding: 0.75rem; }
  .metric dd { font-size: 1.22rem; }
  .chart-head { flex-direction: column; }
  .prose, .systems { padding: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
