:root {
  --bg: #0b0e14;
  --bg-card: #11161f;
  --border: #232b36;
  --text: #e6edf3;
  --muted: #8b949e;
  /* identity accent: teal, deliberately NOT the heatmap's GitHub green */
  --accent: #2dd4bf;
  --accent-dim: #14b8a6;
  --radius-sm: 6px;
  --radius-md: 12px;
  --lv0: #161b22;
  --lv1: #0e4429;
  --lv2: #006d32;
  --lv3: #26a641;
  --lv4: #39d353;
  --punch: #7c86ff;
  --conc: #fb7185;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --bg-card: #f6f8fa;
    --border: #d0d7de;
    --text: #1f2328;
    --muted: #57606a;
    --accent: #0f766e;
    --accent-dim: #0d9488;
    --lv0: #ebedf0;
    --lv1: #9be9a8;
    --lv2: #40c463;
    --lv3: #30a14e;
    --lv4: #216e39;
    --punch: #4f46e5;
    --conc: #be123c;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* NOTE: content-visibility:auto was tried here and removed twice-bitten:
   its style containment broke CSS counters, and its placeholder heights
   made every anchor/nav jump undershoot (page grows mid-scroll). The page
   loads in ~270ms without it — not worth the correctness cost. */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.fine { color: var(--muted); font-size: 0.75rem; margin-top: 6px; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

a { color: var(--accent); text-decoration: none; transition: color 0.15s ease; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent); color: var(--bg); }

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

html { scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { height: 8px; width: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

h2 { font-size: 1.15rem; margin-bottom: 4px; }
section { margin-top: 44px; }

/* Numbered section kickers — the hero's kicker pattern, extended. Numbers
   are stamped at build time (data-n): CSS counters can't cross the style
   containment that content-visibility:auto puts on each section. */
h2[data-n]::before {
  content: attr(data-n);
  display: block;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  color: var(--accent);
  margin-bottom: 3px;
}
.section-sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 14px; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
html { scroll-padding-top: 52px; }

/* Staleness banner (inserted client-side past the freshness thresholds) */
.stale-banner {
  background: color-mix(in srgb, #e3b341 16%, var(--bg));
  border: 1px solid #e3b341;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  padding: 10px 14px;
  margin: 16px 0 0;
}
.stale-banner.stale-error {
  background: color-mix(in srgb, #f85149 16%, var(--bg));
  border-color: #f85149;
}

/* YoY delta chips */
.delta {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 6px;
  white-space: nowrap;
  display: inline-block;
}
.delta.up { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.delta.down { color: #f85149; background: color-mix(in srgb, #f85149 14%, transparent); }

/* Sticky section nav — links carry the vertical padding so tap targets
   reach ~44px on touch screens */
/* nav.mini-nav (not .mini-nav): the nav also carries .scrollable for the
   fade hints, whose position:relative would otherwise override sticky at
   equal specificity */
nav.mini-nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  padding: 0 2px;
  margin: 8px -2px 0;
  overflow-x: auto;
  font-size: 0.8rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  scrollbar-width: none;
}
.mini-nav::-webkit-scrollbar { display: none; }
.mini-nav a {
  color: var(--muted);
  display: inline-block;
  padding: 13px 6px;
}
.mini-nav a:hover { color: var(--text); text-decoration: none; }
.mini-nav a.on { color: var(--accent); }
@media (max-width: 640px) {
  .mini-nav { font-size: 0.85rem; gap: 10px; }
}

/* Hero */
.hero { padding: 56px 0 8px; }
.kicker {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--accent);
  letter-spacing: 0.08em;
  margin-bottom: 14px;
}
.hero h1 { font-size: 1.35rem; font-weight: 500; color: var(--muted); }
.hero-num {
  display: block;
  font-size: clamp(3.2rem, 10vw, 5.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.hero-sub { color: var(--muted); max-width: 620px; margin-top: 12px; }

/* Heatmap */
.heatmap-wrap { overflow-x: auto; padding: 14px 0 4px; }
.heatmap-wrap svg { min-width: 760px; width: 100%; height: auto; display: block; }
.hm-lab { fill: var(--muted); font-size: 9px; }
.lv0 { fill: var(--lv0); }
.lv1 { fill: var(--lv1); }
.lv2 { fill: var(--lv2); }
.lv3 { fill: var(--lv3); }
.lv4 { fill: var(--lv4); }
.legend {
  display: flex; align-items: center; gap: 4px;
  color: var(--muted); font-size: 0.75rem; margin-top: 6px;
}
.legend i { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }
.legend .lv0 { background: var(--lv0); }
.legend .lv1 { background: var(--lv1); }
.legend .lv2 { background: var(--lv2); }
.legend .lv3 { background: var(--lv3); }
.legend .lv4 { background: var(--lv4); }

/* Stat tiles */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}
.tile-num {
  display: block;
  font-size: 1.55rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.tile-lab { color: var(--muted); font-size: 0.78rem; line-height: 1.35; display: block; margin-top: 2px; }
.tile.record .tile-num { color: var(--accent); }

/* Charts */
.chart-wrap { overflow-x: auto; }
.chart-wrap > svg { min-width: 560px; width: 100%; height: auto; display: block; }
.grad-hi { stop-color: var(--accent); stop-opacity: 0.32; }
.grad-lo { stop-color: var(--accent); stop-opacity: 0; }
.area-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area-dot { fill: var(--accent); }
.area-hit { fill: transparent; }
.area-hit:hover + .area-dot { r: 5; }
.ax-lab { fill: var(--muted); font-size: 10px; }
.punch-dot { fill: var(--punch); opacity: 0.85; }

/* Bar rows */
.bar-row {
  display: grid;
  grid-template-columns: 72px 1fr 44px;
  align-items: center;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 0.82rem;
}
.bar-label {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-svg { width: 100%; height: 10px; display: block; border-radius: 4px; }
.bar-bg { fill: var(--lv0); }
.bar-val { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* Two-column sections */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 36px;
}
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }
/* grid items default to min-width:auto, letting a wide chart blow out the
   track (and the page) instead of scrolling inside its own wrap */
.two-col > div { min-width: 0; }
.two-col .tiles { grid-template-columns: 1fr; }

/* Repo cards */
.repo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.repo-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: border-color 0.15s ease;
}
.repo-card:hover { border-color: var(--accent-dim); }
.repo-card h3 { font-size: 0.95rem; font-weight: 600; }
.repo-card.anon h3 { color: var(--muted); font-style: italic; font-weight: 500; }
.repo-tag { color: var(--muted); font-size: 0.78rem; }
.repo-nums { font-size: 0.8rem; color: var(--muted); margin: 6px 0 8px; }
.repo-nums strong { color: var(--text); font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 26px; display: block; }
.spark-line { fill: none; stroke: var(--accent-dim); stroke-width: 1.5; stroke-linecap: round; }
.repos-more { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; }

/* Portfolio domain chips */
.dom-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.dom-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.82rem;
  color: var(--text);
  text-decoration: none;
}
.dom-chip:hover { border-color: var(--accent-dim); color: var(--accent); text-decoration: none; }

/* Footer */
footer {
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
footer h2 { color: var(--text); font-size: 0.95rem; }
footer p { margin-top: 8px; }
.stamp {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.75rem;
  margin-top: 14px;
}

/* Isometric skyline: lit top face, two shaded sides per intensity level.
   No min-width floor — a cropped skyline loses the silhouette entirely,
   so it scales down whole instead of forcing horizontal scroll. */
.chart-wrap > svg.skyline { min-width: 0; }

/* Linked highlighting across time charts (classes toggled by stats.js) */
rect[data-d].linked { stroke: var(--conc); stroke-width: 1.5; }
.conc-hit.linked { fill: var(--conc); opacity: 0.7; }
.area-hit.linked { stroke: var(--accent); stroke-width: 2; fill: transparent; }
rect[data-m].linked { fill: var(--conc); fill-opacity: 0.10; }

/* Today's heatmap cell (class added client-side against the viewer's date) */
rect.today { stroke: var(--accent); stroke-width: 1.5; }
@media (prefers-reduced-motion: no-preference) {
  rect.today { animation: today-pulse 2.4s ease-in-out infinite; }
  @keyframes today-pulse {
    0%, 100% { stroke-opacity: 1; }
    50% { stroke-opacity: 0.25; }
  }
}

/* Isometric skyline: lit top face, two shaded sides per intensity level */
.sky-t-0 { fill: var(--lv0); }
.sky-t-1 { fill: var(--lv1); }
.sky-t-2 { fill: var(--lv2); }
.sky-t-3 { fill: var(--lv3); }
.sky-t-4 { fill: var(--lv4); }
.sky-l-1 { fill: color-mix(in srgb, var(--lv1) 55%, black); }
.sky-l-2 { fill: color-mix(in srgb, var(--lv2) 55%, black); }
.sky-l-3 { fill: color-mix(in srgb, var(--lv3) 55%, black); }
.sky-l-4 { fill: color-mix(in srgb, var(--lv4) 55%, black); }
.sky-r-1 { fill: color-mix(in srgb, var(--lv1) 75%, black); }
.sky-r-2 { fill: color-mix(in srgb, var(--lv2) 75%, black); }
.sky-r-3 { fill: color-mix(in srgb, var(--lv3) 75%, black); }
.sky-r-4 { fill: color-mix(in srgb, var(--lv4) 75%, black); }

/* Survival tiles under the cohort chart */
.survival-tiles { margin-top: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* Year-over-year pace: current year solid, prior years dashed ghosts */
.pace-now { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.pace-ghost { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 5; opacity: 0.65; stroke-linecap: round; }
.pace-lab { fill: var(--muted); font-size: 11px; font-weight: 600; }
.pace-lab-now { fill: var(--accent); }

/* Concurrency + yearly charts */
.conc-fill { fill: var(--conc); opacity: 0.18; }
.conc-line { fill: none; stroke: var(--conc); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.conc-hit { fill: transparent; }
.conc-hit:hover { fill: var(--conc); opacity: 0.6; }
.yearly { max-width: 340px; min-width: 0 !important; }
.year-bar { fill: var(--accent-dim); }
.year-val { fill: var(--text); font-size: 12px; font-weight: 600; }

/* Stacked 100% bar + legend chips */
.stacked-bar {
  width: 100%;
  height: 22px;
  border-radius: var(--radius-sm);
  display: block;
  margin: 10px 0 10px;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.78rem; color: var(--muted); }
.chip svg { margin-right: 5px; vertical-align: -1px; }
.stack-gap { margin-top: 28px; }

/* Wide/narrow chart variants: narrow screens get taller charts, never a
   horizontal scrollbar */
.narrow-var { display: none; }
@media (max-width: 640px) {
  .wide-var { display: none; }
  .narrow-var { display: block; }
  .chart-wrap > svg,
  .heatmap-wrap svg { min-width: 0; }
}

/* Scroll-fade affordances (classes toggled by stats.js) */
.scrollable { position: relative; }
.scrollable.has-more {
  -webkit-mask-image: linear-gradient(90deg, #000 92%, transparent);
  mask-image: linear-gradient(90deg, #000 92%, transparent);
}
.scrollable.has-less.has-more {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}

/* Repo controls (revealed by stats.js) */
.js-only { display: none; }
.js-only.ready { display: flex; }
.repo-controls {
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.repo-controls input,
.repo-controls button {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  padding: 6px 12px;
}
.repo-controls input { flex: 1 1 180px; min-width: 140px; }
.repo-controls button { cursor: pointer; color: var(--muted); transition: color 0.15s ease, border-color 0.15s ease; }
.repo-controls button.on { color: var(--accent); border-color: var(--accent-dim); }
@media (max-width: 640px) {
  .repo-controls input,
  .repo-controls button { padding: 11px 14px; font-size: 0.9rem; }
  .dom-chip { padding: 10px 15px; font-size: 0.88rem; }
}

/* Long-tail expander */
.repos-more-details { margin-top: 14px; }
.repos-more-details summary {
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px 0;
}
.repos-more-details summary:hover { color: var(--text); }
.repos-more-details .repo-grid { margin-top: 12px; }

/* Cursor tooltip */
#tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text);
  pointer-events: none;
  max-width: 280px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
