:root {
  color-scheme: light;
  --background: #f7f7f4;
  --surface: #ffffff;
  --text: #20231f;
  --muted: #626861;
  --border: #d8dcd6;
  --link: #175b8a;
  --closed: #2f7d4a;
  --open: #77827d;
  --tail: #c0801f;
  --semantic: #347ca5;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
}

a {
  color: var(--link);
}

a:hover {
  text-decoration-thickness: 2px;
}

.site-header,
main,
.site-footer {
  width: min(100% - 2rem, 72rem);
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

nav a[aria-current="page"] {
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
}

main {
  min-height: calc(100vh - 10rem);
  padding-block: 3rem 4rem;
}

h1,
h2,
h3 {
  line-height: 1.2;
  letter-spacing: 0;
}

h1 {
  margin-top: 0;
  font-size: 3rem;
}

h2 {
  margin-top: 2.5rem;
  font-size: 1.35rem;
}

.lede,
.muted,
.source-path {
  color: var(--muted);
}

.lede {
  max-width: 48rem;
  font-size: 1.1rem;
}

.status-grid,
.navigation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: 0.75rem;
  margin-block: 1.5rem;
}

.status-card,
.navigation-grid a,
.node,
.placeholder,
.document-list li {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.status-card {
  padding: 1rem;
  border-top: 4px solid var(--status-color, var(--border));
}

.status-card strong {
  display: block;
  font-size: 1.8rem;
}

.status-closed { --status-color: var(--closed); }
.status-open { --status-color: var(--open); }
.status-tail { --status-color: var(--tail); }
.status-semantic { --status-color: var(--semantic); }

.navigation-grid a {
  min-height: 6rem;
  padding: 1rem;
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
}

.navigation-grid span {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 400;
}

.snapshot-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
}

.snapshot-meta dt {
  font-weight: 650;
}

.snapshot-meta dd {
  margin: 0;
  color: var(--muted);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0;
  border: 0;
}

.filters legend {
  width: 100%;
  margin-bottom: 0.5rem;
  font-weight: 650;
}

.filter-button {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.filter-button[aria-pressed="true"] {
  border-color: var(--text);
  background: var(--text);
  color: #fff;
}

.node-list,
.document-list {
  display: grid;
  gap: 0.75rem;
  margin: 1.5rem 0;
  padding: 0;
  list-style: none;
}

.node {
  padding: 1rem;
  border-left: 5px solid var(--status-color, var(--border));
}

.node h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}

.node-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.document-list li {
  padding: 0.85rem 1rem;
}

.document-list a {
  font-weight: 650;
}

.source-path {
  display: block;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.82rem;
}

.placeholder {
  padding: 1rem;
  border-style: dashed;
}

.markdown-body {
  max-width: 52rem;
  overflow-wrap: anywhere;
}

.markdown-body pre,
.markdown-body code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  background: #eceeea;
}

.markdown-body code {
  padding: 0.1rem 0.25rem;
}

.markdown-body pre {
  overflow-x: auto;
  padding: 1rem;
}

.markdown-body pre code {
  padding: 0;
}

.error {
  padding: 0.75rem;
  border-left: 4px solid #a6382e;
  background: #fff1ef;
}

.site-footer {
  padding-block: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.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;
}

.dag-page {
  background: #f2f5f1;
}

.dag-main {
  width: min(100% - 2rem, 96rem);
  padding-top: 2rem;
}

.dag-heading {
  display: grid;
  grid-template-columns: minmax(18rem, 1fr) minmax(30rem, 1.15fr);
  align-items: end;
  gap: 2rem;
  margin-bottom: 1.5rem;
}

.dag-heading h1 {
  margin-bottom: 0.3rem;
  font-size: 3.5rem;
}

.dag-heading .lede {
  margin-block: 0;
  font-size: 1rem;
}

.eyebrow {
  margin: 0;
  color: #386354;
  font-size: 0.74rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dag-provenance {
  display: grid;
  grid-template-columns: 1.35fr repeat(4, minmax(4.6rem, 0.75fr));
  margin: 0;
  border-block: 1px solid #ccd4ce;
}

.dag-provenance-group {
  min-width: 0;
}

.dag-provenance div {
  min-width: 0;
  padding: 0.8rem 0.65rem;
  border-left: 1px solid #ccd4ce;
}

.dag-provenance div:first-child {
  border-left: 0;
}

.dag-provenance dt {
  color: #69736c;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.dag-provenance dd {
  margin: 0.1rem 0 0;
  overflow: hidden;
  color: #17221d;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.86rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dag-workspace {
  min-width: 0;
}

.graph-toolbar {
  display: flex;
  align-items: end;
  gap: 0.75rem;
  padding: 0.7rem;
  border: 1px solid #cbd3cd;
  border-bottom: 0;
  background: #fff;
}

.graph-toolbar button,
.graph-toolbar input,
.graph-toolbar select {
  min-height: 2.35rem;
  border: 1px solid #bfc8c1;
  border-radius: 4px;
  background: #fff;
  color: #202a24;
  font: inherit;
  font-size: 0.84rem;
}

.graph-toolbar button {
  padding: 0.42rem 0.7rem;
  cursor: pointer;
}

.graph-toolbar button:hover,
.graph-toolbar button:focus-visible,
.graph-toolbar input:focus-visible,
.graph-toolbar select:focus-visible {
  border-color: #227255;
  outline: 2px solid #b8dfce;
  outline-offset: 1px;
}

.graph-segments {
  display: flex;
  padding: 0;
  border: 0;
}

.graph-segments button {
  border-radius: 0;
  border-left-width: 0;
}

.graph-segments button:first-of-type {
  border-left-width: 1px;
  border-radius: 4px 0 0 4px;
}

.graph-segments button:last-of-type {
  border-radius: 0 4px 4px 0;
}

.graph-segments button[aria-pressed="true"] {
  border-color: #205d47;
  background: #205d47;
  color: #fff;
}

.graph-select,
.graph-search {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: #59645d;
  font-size: 0.75rem;
  font-weight: 700;
}

.graph-select select {
  min-width: 8.8rem;
  padding-inline: 0.5rem 1.8rem;
}

.graph-search {
  flex: 1;
}

.graph-search input {
  width: min(100%, 20rem);
  padding-inline: 0.65rem;
}

.graph-search button {
  background: #e9f0eb;
}

.graph-actions {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
}

.graph-stage {
  position: relative;
  height: min(72vh, 48rem);
  min-height: 36rem;
  overflow: hidden;
  border: 1px solid #263b34;
  background: #07100e;
}

#graph {
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#graph:active {
  cursor: grabbing;
}

#graph svg {
  display: block;
  width: 100%;
  height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

.dag-edge {
  fill: none;
  stroke: #9bb9aa;
  stroke-opacity: 0.44;
  stroke-width: 1.35;
  transition: stroke 140ms ease, stroke-opacity 140ms ease, stroke-width 140ms ease;
}

.dag-edge.is-muted {
  stroke-opacity: 0.08;
}

.dag-edge.is-upstream {
  stroke: #7ed8ff;
  stroke-opacity: 1;
  stroke-width: 3;
}

.dag-rank-band {
  fill: rgba(39, 71, 61, 0.16);
  stroke: rgba(160, 190, 178, 0.08);
  stroke-width: 1;
}

.dag-rank-band.rank-1 {
  fill: rgba(12, 29, 24, 0.25);
}

.dag-depth-label {
  fill: #9ab4a8;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.dag-node {
  cursor: pointer;
  opacity: 1;
  transition: opacity 140ms ease;
}

.dag-node.is-muted {
  opacity: 0.22;
}

.dag-node-hit {
  fill: transparent;
}

.dag-node-dot {
  stroke: #dce9e1;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

.dag-node.is-parent .dag-node-dot {
  stroke: #7ed8ff;
  stroke-width: 3;
}

.dag-node.is-selected .dag-node-dot,
.dag-node:focus-visible .dag-node-dot {
  stroke: #f5fbf8;
  stroke-width: 4;
}

.dag-node-label {
  display: none;
  fill: #edf6f0;
  font-size: 12px;
  font-weight: 700;
  dominant-baseline: middle;
  pointer-events: none;
}

.dag-node.is-selected .dag-node-label,
.dag-node:focus-visible .dag-node-label {
  display: block;
  paint-order: stroke;
  stroke: #07100e;
  stroke-linejoin: round;
  stroke-width: 4px;
}

.graph-status,
.graph-legend,
.node-detail {
  position: absolute;
  z-index: 2;
  border: 1px solid rgba(176, 205, 195, 0.28);
  background: rgba(7, 16, 14, 0.9);
  color: #dbe8e1;
  backdrop-filter: blur(8px);
}

.graph-status {
  top: 0.75rem;
  right: 0.75rem;
  max-width: min(28rem, calc(100% - 1.5rem));
  padding: 0.45rem 0.65rem;
  font-size: 0.76rem;
}

.graph-status-ready {
  color: #b8d1c6;
}

.graph-status-error {
  border-color: rgba(242, 173, 74, 0.7);
  color: #ffd99b;
}

.graph-legend {
  top: 0.75rem;
  left: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  max-width: calc(100% - 18rem);
  padding: 0.45rem 0.6rem;
  font-size: 0.72rem;
}

.graph-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #b69bff;
}

.legend-dot.closed { background: #42c47a; }
.legend-dot.open { background: #f2ad4a; }
.legend-dot.tail { background: #d39432; }
.legend-dot.semantic { background: #4b91b8; }

.legend-line {
  position: relative;
  width: 1px;
  height: 0.85rem;
  background: #a8c8bd;
}

.legend-line::after {
  position: absolute;
  right: -0.2rem;
  bottom: -0.1rem;
  width: 0;
  height: 0;
  border-top: 0.34rem solid #a8c8bd;
  border-right: 0.22rem solid transparent;
  border-left: 0.22rem solid transparent;
  content: "";
}

.node-detail {
  right: 0.75rem;
  bottom: 0.75rem;
  width: min(27rem, calc(100% - 1.5rem));
  max-height: calc(100% - 5.25rem);
  overflow: auto;
  padding: 1rem;
}

.node-detail h2 {
  margin: 0.15rem 0 0;
  overflow-wrap: anywhere;
  color: #f3f7f4;
  font-size: 0.98rem;
}

.node-detail-summary {
  margin: 0.45rem 0 0;
  color: #dce9e3;
  font-size: 0.78rem;
  line-height: 1.45;
}

.node-detail-section {
  margin-top: 0.9rem;
  padding-top: 0.8rem;
  border-top: 1px solid rgba(176, 205, 195, 0.2);
}

.node-detail-section h3 {
  margin: 0;
  color: #c8d9d1;
  font-size: 0.72rem;
  text-transform: uppercase;
}

.node-detail-section h3 span {
  color: #7ed8ff;
}

.node-detail-theorem,
.node-detail-commentary {
  margin: 0.55rem 0 0;
  color: #b9cbc2;
  font-size: 0.75rem;
  line-height: 1.4;
}

.node-detail-theorem strong {
  display: block;
  color: #80978d;
  font-size: 0.62rem;
  text-transform: uppercase;
}

.node-detail-empty,
.node-detail-id {
  margin: 0;
  color: #a9bbb3;
  font-size: 0.76rem;
}

.node-detail-id {
  margin-top: 0.25rem;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.node-detail-state {
  margin: 0;
  color: #b69bff;
  font-size: 0.7rem;
  font-weight: 750;
  text-transform: uppercase;
}

.node-detail-state.state-closed { color: #62d895; }
.node-detail-state.state-open { color: #ffc461; }

.node-detail dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0.9rem 0 0;
}

.node-detail dl div {
  min-width: 0;
}

.node-detail dt {
  color: #80978d;
  font-size: 0.63rem;
  text-transform: uppercase;
}

.node-detail dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: #dce9e3;
  font-size: 0.72rem;
}

.node-relations {
  display: grid;
  gap: 0.25rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
}

.node-relations button {
  display: grid;
  width: 100%;
  padding: 0.45rem 0;
  border: 0;
  border-bottom: 1px solid rgba(176, 205, 195, 0.12);
  background: transparent;
  color: #e3eee8;
  font: inherit;
  font-size: 0.75rem;
  text-align: left;
  cursor: pointer;
}

.node-relations button:hover,
.node-relations button:focus-visible {
  color: #7ed8ff;
  outline: 0;
}

.node-relations small {
  margin-top: 0.1rem;
  color: #80978d;
  font-size: 0.64rem;
}

.node-relation-empty {
  margin: 0.45rem 0 0;
  color: #80978d;
  font-size: 0.72rem;
}

.graph-tooltip {
  position: absolute;
  z-index: 3;
  display: grid;
  gap: 0.15rem;
  max-width: 24rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid rgba(190, 218, 208, 0.4);
  background: rgba(7, 16, 14, 0.94);
  color: #eaf2ed;
  font-size: 0.75rem;
  pointer-events: none;
}

.graph-tooltip[hidden] {
  display: none;
}

.graph-tooltip strong,
.graph-tooltip span {
  overflow-wrap: anywhere;
}

.graph-tooltip span {
  color: #aec0b8;
}

.layer-key {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 0;
  padding: 0;
  border-inline: 1px solid #cbd3cd;
  border-bottom: 1px solid #cbd3cd;
  background: #cbd3cd;
  list-style: none;
}

.layer-key li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.6rem;
  padding: 0.5rem 0.75rem;
  background: #fff;
  color: #59645d;
  font-size: 0.73rem;
}

.layer-key span {
  color: #1d593f;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 800;
}

@media (max-width: 36rem) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
  }

  main {
    padding-top: 2rem;
  }

  h1 {
    font-size: 2.25rem;
  }

  .snapshot-meta {
    grid-template-columns: 1fr;
  }

  .snapshot-meta dd {
    margin-bottom: 0.6rem;
  }

  .dag-main {
    width: min(100% - 1rem, 96rem);
    padding-top: 1.25rem;
  }

  .dag-heading {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .dag-provenance {
    grid-template-columns: repeat(3, 1fr);
  }

  .dag-provenance div {
    border-top: 1px solid #ccd4ce;
  }

  .dag-provenance div:nth-child(-n+3) {
    border-top: 0;
  }

  .graph-toolbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .graph-segments {
    width: 100%;
  }

  .graph-segments button {
    flex: 1;
  }

  .graph-search {
    order: 3;
    width: 100%;
  }

  .graph-search label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .graph-search input {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .graph-actions {
    flex: 1;
  }

  .graph-actions button {
    flex: 1;
  }

  .graph-stage {
    height: 72vh;
    min-height: 34rem;
  }

  .graph-legend {
    top: 3.2rem;
    max-width: calc(100% - 1.5rem);
  }

  .node-detail dl {
    grid-template-columns: repeat(2, 1fr);
  }

  .layer-key {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 36.01rem) and (max-width: 70rem) {
  .dag-heading {
    grid-template-columns: 1fr;
  }

  .graph-toolbar {
    flex-wrap: wrap;
  }

  .graph-search {
    order: 3;
    flex-basis: 100%;
  }
}

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