:root {
  color-scheme: dark;
  --bg: #060606;
  --paper: #f2f0e8;
  --muted: #7e7d76;
  --faint: rgba(242, 240, 232, 0.46);
  --axis-label: #a29f96;
  --line: rgba(242, 240, 232, 0.14);
  --hairline: rgba(242, 240, 232, 0.08);
  --mono: "SFMono-Regular", "Roboto Mono", "IBM Plex Mono", Consolas, monospace;
  --sans: Inter, "Helvetica Neue", "Hiragino Sans", "Yu Gothic", sans-serif;
  --gutter: clamp(1.25rem, 3vw, 3rem);

  /* The plot box. field.js measures #plot, so this is the single source of
     truth for where the timeline lives. The baseline sits at its vertical
     centre and every arc rises into the upper half. Height is capped rather
     than purely proportional, so a tall window does not stretch the band away
     from the masthead. */
  --plot-left: var(--gutter);
  --plot-right: var(--gutter);
  --plot-height: min(42vh, 24rem);
  --plot-shift: 3.5rem;

  /* Distance from the baseline to the node labels and the time axis. */
  --stem: 2.9rem;
  --label-offset: 3.5rem;
  --tick-offset: 1.5rem;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
html, body { margin: 0; background: var(--bg); color: var(--paper); }

body {
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, a { font: inherit; }
a { color: inherit; }

.skip-link {
  position: fixed;
  z-index: 100;
  left: 1rem;
  top: -5rem;
  padding: .75rem 1rem;
  background: var(--paper);
  color: var(--bg);
}
.skip-link:focus { top: 1rem; }

.stage { position: relative; width: 100%; height: 100svh; isolation: isolate; overflow: hidden; }
#field { position: absolute; inset: 0; width: 100%; height: 100%; outline: none; cursor: crosshair; }
#field:focus-visible { box-shadow: inset 0 0 0 1px var(--faint); }
.stage[data-dragging] #field { cursor: grabbing; }

.noise {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .07;
  z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
  mix-blend-mode: screen;
}

.eyebrow, .sync-block, .controls, .repo-legend, .legend-title,
.time-ticks, .event-labels, .feed-heading, .zoom-controls {
  font-family: var(--mono);
  font-size: .64rem;
  letter-spacing: .14em;
}

/* ---------- masthead ---------- */

.masthead {
  position: absolute; z-index: 3; inset: 0 0 auto;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 2rem;
  padding: var(--gutter);
  pointer-events: none;
}
/* A long repository legend must not squeeze the title into a column of
   two-word lines, so give the brand block a floor and the legend a ceiling. */
.brand-block { flex: 1 1 26rem; min-width: 0; }
.masthead-side { flex: 0 1 min(58%, 60rem); min-width: 0; }
.eyebrow { display: block; margin-bottom: .8rem; color: var(--muted); }
h1 {
  margin: 0;
  max-width: 16ch;
  font-size: clamp(1.6rem, 2.5vw, 2.5rem);
  font-weight: 640;
  letter-spacing: -.028em;
  line-height: 1.08;
}
.masthead-side { display: grid; gap: 1.5rem; justify-items: end; text-align: right; }
.sync-block { display: grid; grid-template-columns: auto auto; gap: .35rem .55rem; align-items: center; }
.sync-block time { grid-column: 2; color: var(--muted); }
.status-dot { width: .4rem; height: .4rem; border-radius: 50%; background: var(--muted); animation: blink 2s infinite; }
.stage[data-state="live"] .status-dot { background: #3fcf8e; }
.stage[data-state="stale"] .status-dot { background: #f0603a; }
@keyframes blink { 50% { opacity: .28; } }

.legend-title { display: block; margin-bottom: .7rem; color: var(--muted); }
.repo-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .35rem 1.15rem; list-style: none; margin: 0; padding: 0; }
.repo-legend li { display: flex; align-items: center; gap: .45rem; color: var(--faint); }
.repo-legend .swatch { width: .45rem; height: .45rem; border-radius: 50%; background: var(--repo-color); }
.repo-legend .tally { color: var(--muted); }

/* ---------- chart chrome ---------- */

.chart { position: absolute; inset: 0; z-index: 2; pointer-events: none; }

.plot {
  position: absolute;
  left: var(--plot-left);
  right: var(--plot-right);
  top: calc(50% + var(--plot-shift));
  height: var(--plot-height);
  transform: translateY(-50%);
}

.baseline {
  position: absolute; left: 0; right: 0; top: 50%;
  height: 1px;
  transform: translateY(-.5px);
  background: linear-gradient(to right, transparent, var(--line) 3%, var(--line) 97%, transparent);
}

.axis-endpoints {
  position: absolute;
  left: 0; right: 0;
  top: calc(50% + var(--tick-offset) + 4.35rem);
  display: flex;
  justify-content: space-between;
  color: var(--axis-label);
  font: .58rem var(--mono);
  letter-spacing: .16em;
  pointer-events: none;
}

.time-ticks, .event-labels { position: absolute; inset: 0; }

.time-day-marker {
  position: absolute; top: 4%; bottom: 4%;
  width: 1px;
  z-index: 1;
  background: var(--line);
}
.time-day-marker span {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  color: var(--axis-label);
  white-space: nowrap;
}
.time-day-marker[data-align="start"] span { left: 0; transform: none; }
.time-day-marker[data-align="end"] span { left: auto; right: 0; transform: none; }

.time-ruler {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}
.time-ruler[hidden] { display: none; }
.time-ruler-line {
  position: absolute;
  top: 4%; bottom: 4%;
  width: 1px;
  background: linear-gradient(to bottom, transparent, var(--axis-label) 22%, var(--axis-label) 78%, transparent);
  opacity: .42;
}
.time-ruler-label {
  position: absolute;
  top: calc(50% + var(--tick-offset));
  left: 50%;
  transform: translateX(-50%);
  padding: .28rem .42rem;
  border: 1px solid var(--line);
  background: rgba(6, 6, 6, .96);
  color: var(--axis-label);
  font: .62rem var(--mono);
  letter-spacing: .04em;
  white-space: nowrap;
}
.time-ruler-label[data-align="start"] { left: 0 !important; transform: none; }
.time-ruler-label[data-align="end"] { left: auto !important; right: 0; transform: none; }

/* Node labels: a stem off the baseline, then type and ref. Sides alternate so
   twice as many fit before the collision filter drops one. */
.event-label { position: absolute; top: 50%; width: 0; }
.event-label .label-stem {
  position: absolute; left: 0;
  width: 1px; height: var(--stem);
  background: var(--repo-color);
  opacity: .34;
}
.event-label .label-body {
  position: absolute; left: 0;
  transform: translateX(-50%);
  display: grid; gap: .2rem;
  text-align: center;
  white-space: nowrap;
  line-height: 1.25;
  padding: .16rem .34rem;
  border: 1px solid transparent;
  background: rgba(6, 6, 6, .82);
}
.event-label[data-side="up"] .label-stem { bottom: .55rem; }
.event-label[data-side="up"] .label-body { bottom: var(--label-offset); }
.event-label[data-side="down"] .label-stem { top: .55rem; }
.event-label[data-side="down"] .label-body { top: var(--label-offset); }
.event-label .label-type { color: var(--repo-color); }
.event-label .label-ref { font-style: normal; color: var(--muted); }
.event-label[data-dim="true"] { opacity: .26; }
.event-label { transition: opacity .2s ease; }
.event-label[data-focus="true"] {
  z-index: 8;
  opacity: 1;
}
.event-label[data-focus="true"] .label-body {
  border-color: var(--repo-color);
  background: rgba(6, 6, 6, .96);
  box-shadow: 0 0 .9rem rgba(6, 6, 6, .9);
}

.live-ping {
  position: absolute;
  width: 3.6rem; height: 3.6rem;
  margin: -1.8rem 0 0 -1.8rem;
  border-radius: 50%;
  border: 1px solid var(--repo-color, var(--line));
  opacity: 0;
  animation: ping 3.4s cubic-bezier(.2, .6, .3, 1) infinite;
}
@keyframes ping {
  0% { transform: scale(.16); opacity: .5; }
  70% { transform: scale(1); opacity: 0; }
  100% { transform: scale(1); opacity: 0; }
}

/* ---------- bottom bar ---------- */

.stage-bar {
  position: absolute; z-index: 3;
  left: var(--gutter); right: var(--gutter);
  bottom: var(--gutter);
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
.controls { display: flex; gap: 1.4rem; color: var(--muted); pointer-events: none; }
.controls span { display: flex; align-items: baseline; gap: .45rem; }
.controls b { color: var(--faint); font-weight: 400; }

.zoom-controls { display: flex; align-items: center; gap: .5rem; }
.pin-state { margin-right: .5rem; color: var(--repo-color, var(--faint)); }
.zoom-controls button {
  min-width: 2rem; height: 2rem;
  padding: 0 .6rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--faint);
  font-family: var(--mono); font-size: .64rem; letter-spacing: .14em;
  cursor: pointer;
  transition: color .18s ease, border-color .18s ease;
}
.zoom-controls button:hover, .zoom-controls button:focus-visible { color: var(--paper); border-color: var(--faint); outline: none; }

/* ---------- feed ---------- */

.feed { padding: clamp(3rem, 7vw, 6rem) var(--gutter) clamp(4rem, 9vw, 8rem); }
.feed-heading {
  display: flex; align-items: center; gap: 1rem;
  color: var(--muted);
  padding-bottom: 1.4rem;
}
.feed-heading::after { content: ""; flex: 1; height: 1px; background: var(--line); order: 1; }
.feed-heading span:last-child { order: 2; }

.feed-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: .25rem;
  grid-template-columns: repeat(auto-fit, minmax(26rem, 1fr));
  column-gap: clamp(2rem, 5vw, 5rem);
}
.feed-list a {
  display: grid;
  grid-template-columns: .5rem 6.8rem 1fr;
  gap: .3rem .8rem;
  padding: .85rem .6rem;
  margin: 0 -.6rem;
  text-decoration: none;
  border-radius: 2px;
  transition: background .18s ease;
}
.feed-list a:hover, .feed-list a:focus-visible { background: rgba(242, 240, 232, .045); outline: none; }
.feed-list li[data-selected="true"] a { background: rgba(242, 240, 232, .07); }

.feed-dot { grid-row: 1; width: .45rem; height: .45rem; margin-top: .42rem; border-radius: 50%; background: var(--repo-color); }
.feed-time { grid-row: 1; font: .68rem var(--mono); color: var(--muted); white-space: nowrap; }
.feed-head { grid-row: 1; font: .72rem var(--mono); color: var(--faint); overflow-wrap: anywhere; }
.feed-head .repo { color: var(--paper); }
.feed-head .ref { color: var(--repo-color); }
.feed-type { grid-row: 2; grid-column: 3; font: .66rem var(--mono); letter-spacing: .1em; color: var(--repo-color); }

/* ---------- misc ---------- */

.webgl-error { position: fixed; inset: auto 1rem 1rem; padding: 1rem; border: 1px solid #f0603a; background: var(--bg); z-index: 20; font-family: var(--mono); }
.webgl-error p { margin: 0 0 .4rem; color: #f0603a; }
.webgl-error span { font-size: .72rem; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 1100px) {
  .masthead { flex-direction: column; gap: 1.5rem; }
  .brand-block, .masthead-side { flex: 0 0 auto; }
  .masthead-side { justify-items: start; text-align: left; }
  .repo-legend { justify-content: flex-start; }
  :root { --plot-shift: 5rem; }
}

@media (max-width: 720px) {
  :root {
    --plot-height: min(38vh, 18rem);
    --plot-shift: 3rem;
    --stem: 2rem;
    --label-offset: 2.6rem;
  }
  h1 { font-size: 1.5rem; }
  .controls span:nth-child(n + 3) { display: none; }
  .controls b { display: none; }
  .feed-list { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .noise, .live-ping { display: none; }
  .status-dot { animation: none; }
  #field { opacity: .6; }
  .event-label { transition: none; }
}
