/* Critical Mass — data essay styles */
:root {
  --bg: #0d1117;
  --bg-raised: #131920;
  --bg-inset: #0a0d12;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #a5b3c0;
  --faint: #7d8b99;
  --green: #3fb950;
  --yellow: #d9a820;
  --orange: #e08209;
  --red: #f85149;
  --blue: #58a6ff;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --maxw: 1120px;
}

* { box-sizing: border-box; }

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

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

::selection { background: var(--red); color: #fff; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--red);
  color: #fff;
  padding: 0.6rem 1rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }

a { color: var(--blue); }
a:hover { text-decoration-style: wavy; }

main:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(13, 17, 23, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.status-pill {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
}
.pulse-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

.topbar nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  flex-wrap: wrap;
}
.topbar nav a {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
  padding: 0.3rem 0.55rem;
  border-radius: 4px;
}
.topbar nav a:hover { color: var(--text); background: var(--bg-raised); }

#motion-toggle {
  font-family: var(--mono);
  font-size: 0.72rem;
  background: var(--bg-raised);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
}
#motion-toggle[aria-pressed="true"] { color: var(--yellow); border-color: var(--yellow); }
#motion-toggle:hover { color: var(--text); }

/* ---------- shared ---------- */
main { display: block; }

section {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 4.5rem 1.25rem 3rem;
  border-top: 1px solid var(--line);
  scroll-margin-top: 70px;
}
section.hero { border-top: none; }

.kicker {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--red);
  margin: 0 0 1rem;
}
section#load .kicker { color: var(--blue); }

h1, h2, h3 { line-height: 1.05; margin: 0 0 1.1rem; letter-spacing: -0.02em; }
h1 { font-size: clamp(3.2rem, 11vw, 7.5rem); font-weight: 800; }
h2 { font-size: clamp(2rem, 5.5vw, 3.6rem); font-weight: 800; }
h3 { font-size: clamp(1.2rem, 2.6vw, 1.6rem); font-weight: 700; }

.lede { font-size: clamp(1.05rem, 2.2vw, 1.35rem); color: var(--muted); max-width: 44rem; }
.caption { color: var(--muted); max-width: 46rem; margin-top: -0.4rem; }

figure { margin: 2.5rem 0; }
.chart-title {
  font-family: var(--mono);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 0.9rem;
}
.fig-note { color: var(--faint); font-size: 0.88rem; margin-top: 0.7rem; }
.fig-note strong { color: var(--text); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.5rem;
}
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- hero ---------- */
.hero { padding-top: 5.5rem; min-height: 92vh; display: flex; flex-direction: column; justify-content: center; }
.hero h1 { text-shadow: 0 0 80px rgba(248, 81, 73, 0.25); }

.counter-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  margin: 2.5rem 0 1rem;
}
.counter-card {
  background: var(--bg-raised);
  padding: 1.1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.counter {
  font-family: var(--mono);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.counter-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}
@media (max-width: 640px) { .counter-strip { grid-template-columns: 1fr 1fr; } }

.src-note { font-size: 0.85rem; color: var(--faint); }

.hero-strip-fig { margin: 2rem 0 0; }
.hero-strip-fig figcaption {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--faint);
  margin-bottom: 0.5rem;
}
#hero-strip {
  border-bottom: 1px solid var(--line);
  padding-bottom: 2px;
  overflow: hidden;
}

.scroll-cue {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--faint);
  margin-top: 3rem;
}
.cue-arrow { display: inline-block; margin-left: 0.5rem; animation: bob 2.2s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(5px); } }

/* ---------- uptime matrix ---------- */
.matrix-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  padding: 1rem;
  border-radius: 6px;
}
.scroll-hint {
  display: none;
  margin: 0 0 0.5rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  color: var(--faint);
  text-align: right;
}
@media (max-width: 1080px) {
  .scroll-hint { display: block; }
}
#uptime-matrix { min-width: 980px; }
.matrix-year {
  display: grid;
  grid-template-columns: 3.2rem 1fr 4.6rem;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 4px;
}
.matrix-year-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
}
.matrix-days {
  display: grid;
  grid-template-columns: repeat(366, 1fr);
  gap: 0;
  align-items: end;
}
.matrix-days span.c {
  display: block;
  height: 15px;
  align-self: end;
  background: var(--line);
}
/* severity is encoded by height as well as color, so the grid reads without color */
.matrix-days span.l0 { background: var(--green); }
.matrix-days span.l1 { background: var(--yellow); height: 7px; }
.matrix-days span.l2 { background: var(--orange); height: 11px; }
.matrix-days span.l3 { background: var(--red); height: 15px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55); }
.matrix-days span.off { visibility: hidden; }
.matrix-year-stat {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--faint);
  white-space: nowrap;
}
.matrix-year-stat b { color: var(--text); font-weight: 600; }

.legend {
  list-style: none;
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  padding: 0;
  margin: 0.9rem 0 0.3rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 0.45rem; }
.sw { width: 12px; height: 12px; border-radius: 2px; display: inline-block; align-self: end; }
.sw.l0 { background: var(--green); }
.sw.l1 { background: var(--yellow); height: 7px; }
.sw.l2 { background: var(--orange); height: 11px; }
.sw.l3 { background: var(--red); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55); }
.legend-note { flex-basis: 100%; color: var(--faint); font-size: 0.7rem; }

/* ---------- charts (SVG) ---------- */
svg.chart { display: block; width: 100%; height: auto; }
.chart .axis-label { font-family: var(--mono); font-size: 10px; fill: var(--faint); }
.chart .bar { transition: opacity 0.15s; }
.chart .bar:hover { opacity: 0.8; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .threshold { stroke: var(--red); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .anno { font-family: var(--mono); font-size: 10px; fill: var(--text); }
.chart .anno-dim { font-family: var(--mono); font-size: 9.5px; fill: var(--faint); }
/* charts re-rendered at a narrower width scale their labels back up */
svg.chart[data-narrow] .axis-label { font-size: 15px; }
svg.chart[data-narrow] .anno { font-size: 15px; }
svg.chart[data-narrow] .anno-dim { font-size: 13.5px; }

/* draw-on-scroll animation hooks */
.draw-path { transition: stroke-dashoffset 1.6s ease-out; }
.fade-line { transition: opacity 1.2s ease-out; }
.pre-draw .fade-line { opacity: 0; }
.grow-bar { transform-origin: bottom; transition: transform 0.9s cubic-bezier(0.2, 0.7, 0.2, 1); }
.pre-draw .draw-path { stroke-dashoffset: var(--dash, 2000) !important; }
.pre-draw .grow-bar { transform: scaleY(0); }
.pre-draw .grow-bar-x { transform: scaleX(0); }
.grow-bar-x { transform-origin: left; transition: transform 0.9s cubic-bezier(0.2, 0.7, 0.2, 1); }

/* ---------- timeline ---------- */
.timeline {
  list-style: none;
  margin: 2.5rem 0 3.5rem;
  padding: 0 0 0 1.4rem;
  border-left: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 1.6rem;
}
.timeline li {
  position: relative;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1rem 1.2rem;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: calc(-1.4rem - 7px);
  top: 1.35rem;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--bg);
  border: 3px solid var(--orange);
}
.timeline li.sev-major::before { border-color: var(--red); }
.tl-date {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: var(--faint);
  text-transform: uppercase;
}
.tl-name { font-weight: 700; font-size: 1.05rem; margin: 0.25rem 0 0.35rem; }
.tl-cause { color: var(--muted); font-size: 0.95rem; margin: 0 0 0.6rem; }
.tl-meta {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
}
.tl-meta b { color: var(--text); }
.tl-blast { display: inline-flex; gap: 3px; align-items: center; }
.tl-blast i {
  width: 9px; height: 9px;
  border-radius: 2px;
  background: var(--orange);
}
.tl-blast i.hot { background: var(--red); }
.tl-src { font-size: 0.78rem; margin-top: 0.5rem; display: block; }

/* ---------- stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin: 2.5rem 0;
}
.stat-grid.two { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .stat-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 540px) { .stat-grid, .stat-grid.two { grid-template-columns: 1fr; } }
.stat-card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1.2rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.stat-value {
  font-family: var(--mono);
  font-size: clamp(1.9rem, 4vw, 2.7rem);
  font-weight: 700;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}
#collision .stat-value, .stat-card .stat-value { color: var(--blue); }
.stat-card:nth-child(1) .stat-value { color: var(--red); }
.stat-label { color: var(--muted); font-size: 0.9rem; }
.stat-src {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--faint);
  margin-top: auto;
}

.pull-stat {
  border-left: 4px solid var(--red);
  background: var(--bg-raised);
  padding: 1.4rem 1.6rem;
  margin: 3rem 0;
  border-radius: 0 6px 6px 0;
  max-width: 46rem;
}
.pull-number {
  font-family: var(--mono);
  font-size: clamp(2.6rem, 7vw, 4.2rem);
  font-weight: 700;
  color: var(--red);
  display: block;
  font-variant-numeric: tabular-nums;
}
.pull-stat p { margin: 0.4rem 0 0; color: var(--muted); font-size: 1.05rem; }
.pull-stat .stat-src { display: block; margin-top: 0.6rem; }

/* ---------- July panel & closing ---------- */
.july-panel {
  border: 1px solid var(--red);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(248,81,73,0.07), rgba(248,81,73,0.02));
  padding: 1.8rem 1.6rem;
  margin: 3rem 0;
}
.july-facts { margin: 0.8rem 0 1rem; padding-left: 1.2rem; color: var(--muted); }
.july-facts li { margin-bottom: 0.55rem; }
.july-facts strong { color: var(--red); font-family: var(--mono); font-size: 1.15em; }

.closing {
  margin: 4rem 0 1rem;
  padding: 2.4rem 1.8rem;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.closing h3 { font-size: clamp(1.6rem, 4vw, 2.4rem); }
.closing p { color: var(--muted); max-width: 44rem; }
.closing em { color: var(--text); font-style: italic; }

/* ---------- sources ---------- */
.sources { padding-bottom: 6rem; }
.src-h {
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--faint);
  margin-top: 2rem;
}
.src-list li, .method-list li { margin-bottom: 0.7rem; color: var(--muted); font-size: 0.95rem; }
.src-list a { word-break: break-word; }
.colophon { margin-top: 3rem; font-family: var(--mono); font-size: 0.78rem; color: var(--faint); }

/* ---------- data details / tables ---------- */
.data-details { margin-top: 0.8rem; }
.data-details summary {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--blue);
  cursor: pointer;
  padding: 0.3rem 0;
}
.data-details summary:hover { text-decoration: underline; }
.data-details .table-wrap { overflow-x: auto; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; margin-top: 0.5rem; }
.data-details table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--mono);
  font-size: 0.75rem;
}
.data-details th, .data-details td {
  text-align: left;
  padding: 0.35rem 0.7rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-details th { color: var(--text); background: var(--bg-raised); position: sticky; top: 0; }
.data-details td { color: var(--muted); }

/* ---------- tooltip ---------- */
#tooltip {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  background: #010409;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text);
  max-width: 260px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
#tooltip .tt-date { color: var(--faint); display: block; }
#tooltip .tt-status { display: block; margin-top: 2px; }

/* ---------- reveal ---------- */
.reveal { opacity: 1; transform: none; }
body.motion-on .reveal { opacity: 0; transform: translateY(22px); transition: opacity 0.7s ease-out, transform 0.7s ease-out; }
body.motion-on .reveal.in { opacity: 1; transform: none; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}
body.motion-off .pulse-dot,
body.motion-off .cue-arrow { animation: none; }
/* the Reduce-motion toggle kills every animation/transition, not just the decorative ones */
body.motion-off *, body.motion-off *::before, body.motion-off *::after {
  animation: none !important;
  transition: none !important;
}
body.motion-off .pre-draw .grow-bar,
body.motion-off .pre-draw .grow-bar-x { transform: none; }
body.motion-off .pre-draw .fade-line { opacity: 1; }
body.motion-off .pre-draw .draw-path { stroke-dashoffset: 0 !important; }

/* ---------- noscript ---------- */
.noscript-note {
  max-width: var(--maxw);
  margin: 2rem auto;
  padding: 1.5rem;
  border: 1px solid var(--yellow);
  border-radius: 8px;
  color: var(--muted);
}

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  body { font-size: 16px; }
  section { padding: 3.2rem 1rem 2.2rem; scroll-margin-top: 170px; }
  .topbar-inner { gap: 0.5rem; }
  .topbar nav {
    order: 3;
    flex-basis: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .topbar nav a {
    padding: 0.55rem 0.6rem;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
  }
  #motion-toggle { min-height: 40px; }
  .timeline { padding-left: 1.1rem; }
  .timeline li::before { left: calc(-1.1rem - 7px); }
}
