:root {
  --paper: #f5f2ec;
  --paper-strong: #fbfaf7;
  --ink: #171915;
  --muted: #6d6e68;
  --hairline: rgba(23, 25, 21, 0.15);
  --panel-shadow: 0 22px 70px rgba(35, 31, 24, 0.13);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 540px;
  overflow: hidden;
  background:
    radial-gradient(circle at 56% 47%, rgba(255, 255, 255, 0.72), transparent 42%),
    var(--paper);
}

#graph-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#graph-canvas.is-dragging {
  cursor: grabbing;
}

.hero {
  position: absolute;
  z-index: 3;
  top: clamp(24px, 4.2vw, 64px);
  left: clamp(24px, 4.1vw, 68px);
  width: min(390px, 30vw);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 13px;
  color: #77776f;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-size: clamp(33px, 4.1vw, 66px);
  font-weight: 680;
  letter-spacing: -0.055em;
  line-height: 0.91;
}

.hero h1 span {
  color: #55574f;
  font-weight: 510;
}

.hero-copy {
  max-width: 280px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.toolbar {
  position: absolute;
  z-index: 8;
  top: 24px;
  right: 26px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-wrap {
  position: relative;
  display: flex;
  width: min(360px, 34vw);
  min-width: 245px;
  height: 42px;
  align-items: center;
  border: 1px solid rgba(28, 29, 25, 0.12);
  border-radius: 12px;
  background: rgba(251, 250, 247, 0.91);
  box-shadow: 0 8px 28px rgba(39, 36, 30, 0.08);
  backdrop-filter: blur(14px);
}

.search-wrap:focus-within {
  border-color: rgba(73, 97, 121, 0.45);
  box-shadow: 0 8px 30px rgba(39, 36, 30, 0.1), 0 0 0 3px rgba(77, 116, 151, 0.09);
}

.search-wrap > svg {
  width: 17px;
  height: 17px;
  margin-left: 13px;
  fill: none;
  stroke: #777a73;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.search-wrap input {
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  padding: 0 8px 0 10px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}

.search-wrap input::placeholder {
  color: #95958d;
}

.search-wrap kbd {
  margin-right: 10px;
  border: 1px solid rgba(34, 35, 31, 0.14);
  border-bottom-color: rgba(34, 35, 31, 0.24);
  border-radius: 5px;
  padding: 1px 6px 2px;
  color: #7b7c74;
  background: rgba(255, 255, 255, 0.58);
  font-family: inherit;
  font-size: 11px;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  overflow: hidden;
  border: 1px solid rgba(28, 29, 25, 0.12);
  border-radius: 13px;
  background: rgba(251, 250, 247, 0.98);
  box-shadow: var(--panel-shadow);
}

.search-result {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid rgba(28, 29, 25, 0.08);
  padding: 10px 12px;
  text-align: left;
  background: transparent;
  cursor: pointer;
}

.search-result:last-child {
  border-bottom: 0;
}

.search-result:hover,
.search-result:focus-visible {
  outline: 0;
  background: rgba(83, 105, 124, 0.08);
}

.search-result strong,
.search-result code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result strong {
  margin-bottom: 3px;
  font-size: 12px;
  font-weight: 650;
}

.search-result code {
  color: #777970;
  font-size: 10px;
}

.search-empty {
  margin: 0;
  padding: 14px;
  color: var(--muted);
  font-size: 12px;
}

.control-group {
  display: flex;
  height: 42px;
  align-items: center;
  gap: 2px;
  border: 1px solid rgba(28, 29, 25, 0.12);
  border-radius: 12px;
  padding: 3px;
  background: rgba(251, 250, 247, 0.91);
  box-shadow: 0 8px 28px rgba(39, 36, 30, 0.08);
  backdrop-filter: blur(14px);
}

.control-button,
.icon-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.control-button {
  height: 34px;
  border-radius: 9px;
  padding: 0 11px;
  color: #6d6f68;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.control-button:hover,
.control-button:focus-visible {
  color: var(--ink);
  outline: 0;
}

.control-button.is-active {
  color: #f8f6f0;
  background: #282a26;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(28, 29, 25, 0.12);
  border-radius: 12px;
  background: rgba(251, 250, 247, 0.91);
  box-shadow: 0 8px 28px rgba(39, 36, 30, 0.08);
  backdrop-filter: blur(14px);
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: rgba(28, 29, 25, 0.25);
  outline: 0;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.metrics {
  position: absolute;
  z-index: 3;
  bottom: 42px;
  left: clamp(24px, 4.1vw, 68px);
  display: grid;
  gap: 6px;
  pointer-events: none;
}

.metrics > div {
  display: grid;
  grid-template-columns: 8px auto auto;
  align-items: baseline;
  gap: 7px;
}

.metrics strong {
  min-width: 64px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  font-weight: 690;
}

.metrics small {
  color: #666861;
  font-size: 11px;
}

.metric-dot {
  width: 6px;
  height: 6px;
  align-self: center;
  border-radius: 50%;
}

.dot-statements { background: #999a92; }
.dot-edges { background: #252722; }
.dot-closure { background: #bd4f73; }

.legend {
  position: absolute;
  z-index: 3;
  right: 28px;
  bottom: 31px;
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 6px 18px;
  color: #65675f;
  font-size: 10px;
  pointer-events: none;
}

#branch-legend {
  pointer-events: auto;
}

#year-legend {
  pointer-events: auto;
}

.legend p {
  grid-column: 1 / -1;
  margin: 0 0 2px;
  color: #3f413c;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.legend-item,
.year-scale,
.year-missing {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-item {
  border-radius: 6px;
  padding: 3px 5px;
  margin: -3px -5px;
  transition: opacity 140ms ease, color 140ms ease, background 140ms ease;
  cursor: crosshair;
}

.legend-item:hover,
.legend-item:focus-visible,
.legend-item.is-highlighted {
  color: #292b27;
  background: rgba(251, 250, 247, 0.82);
  outline: 0;
}

.legend-item.is-highlighted {
  font-weight: 720;
}

.legend-item.is-muted {
  opacity: 0.28;
}

.legend-item > span {
  width: 14px;
  height: 2px;
  background: var(--legend-color);
}

.year-legend {
  width: min(350px, calc(100vw - 56px));
  grid-template-columns: 1fr;
  gap: 6px;
}

.year-cutoff-control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 12px;
}

.year-cutoff-control label {
  grid-column: 1;
  grid-row: 1;
  color: #4f514a;
  font-size: 11px;
  font-weight: 650;
}

.year-cutoff-control output {
  color: #22241f;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.year-cutoff-control small {
  grid-column: 2;
  grid-row: 1;
  color: #777970;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.year-cutoff {
  --year-progress: 100%;
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  height: 18px;
  margin: 0;
  appearance: none;
  border: 0;
  outline: 0;
  background: transparent;
  cursor: ew-resize;
}

.year-cutoff::-webkit-slider-runnable-track {
  height: 7px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent 0 var(--year-progress), rgba(245, 242, 236, 0.82) var(--year-progress) 100%),
    linear-gradient(90deg, #a6653f 0%, #bd8c4f 38%, #5f947d 63%, #557fae 78%, #7665b5 89%, #b84d85 100%);
  box-shadow: inset 0 0 0 1px rgba(40, 42, 37, 0.1);
}

.year-cutoff::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -4.5px;
  appearance: none;
  border: 2px solid #fbfaf7;
  border-radius: 50%;
  background: #282a25;
  box-shadow: 0 1px 5px rgba(28, 29, 25, 0.28);
}

.year-cutoff::-moz-range-track {
  height: 7px;
  border: 0;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent 0 var(--year-progress), rgba(245, 242, 236, 0.82) var(--year-progress) 100%),
    linear-gradient(90deg, #a6653f 0%, #bd8c4f 38%, #5f947d 63%, #557fae 78%, #7665b5 89%, #b84d85 100%);
  box-shadow: inset 0 0 0 1px rgba(40, 42, 37, 0.1);
}

.year-cutoff::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 2px solid #fbfaf7;
  border-radius: 50%;
  background: #282a25;
  box-shadow: 0 1px 5px rgba(28, 29, 25, 0.28);
}

.year-cutoff:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(85, 127, 174, 0.26), 0 1px 5px rgba(28, 29, 25, 0.28);
}

.year-cutoff:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 3px rgba(85, 127, 174, 0.26), 0 1px 5px rgba(28, 29, 25, 0.28);
}

.year-scale {
  display: flex !important;
  justify-content: space-between;
  gap: 0 !important;
  color: #75776f;
  font-variant-numeric: tabular-nums;
}

.year-scale span {
  width: auto;
  height: auto;
  background: none;
}

.year-missing {
  justify-self: end;
}

.year-missing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a9aaa3;
}

.interaction-hint {
  position: absolute;
  z-index: 3;
  bottom: 9px;
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  color: #898a83;
  font-size: 10px;
  white-space: nowrap;
  pointer-events: none;
}

.interaction-hint::before {
  position: fixed;
  right: 28px;
  bottom: 27px;
  left: 28px;
  height: 1px;
  background: rgba(29, 30, 27, 0.12);
  content: "";
}

.interaction-hint span {
  color: #55574f;
}

.inspector {
  position: absolute;
  z-index: 10;
  top: 82px;
  right: 26px;
  bottom: 72px;
  width: min(390px, calc(100vw - 52px));
  overflow: auto;
  border: 1px solid rgba(30, 31, 27, 0.12);
  border-radius: 18px;
  padding: 25px 24px 22px;
  background: rgba(251, 250, 247, 0.97);
  box-shadow: var(--panel-shadow);
  opacity: 0;
  transform: translateX(18px);
  transition: opacity 160ms ease, transform 190ms ease;
  pointer-events: none;
  backdrop-filter: blur(18px);
}

.inspector.is-open {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.close-button {
  position: absolute;
  top: 13px;
  right: 14px;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #74766e;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.close-button:hover,
.close-button:focus-visible {
  outline: 0;
  background: rgba(35, 37, 32, 0.07);
}

.inspector-branch {
  margin: 0 34px 9px 0;
  color: var(--branch-color, #6d6f68);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.inspector h2 {
  margin: 0 26px 9px 0;
  font-size: 22px;
  line-height: 1.14;
  letter-spacing: -0.025em;
}

.inspector > code {
  display: block;
  overflow-wrap: anywhere;
  color: #74766e;
  font-size: 10px;
  line-height: 1.45;
}

.inspector-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 20px 0 24px;
}

.inspector-stat {
  border-top: 2px solid var(--branch-color, #777);
  padding-top: 8px;
}

.inspector-stat strong,
.inspector-stat span {
  display: block;
}

.inspector-stat strong {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.inspector-stat span {
  margin-top: 2px;
  color: #7b7c75;
  font-size: 9px;
}

.provenance-panel {
  margin: 0 0 24px;
  border-top: 1px solid rgba(31, 33, 29, 0.11);
  border-bottom: 1px solid rgba(31, 33, 29, 0.11);
  padding: 17px 0;
}

.provenance-panel h3 {
  margin: 0 0 11px;
  color: #3f413c;
  font-size: 11px;
  font-weight: 740;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.provenance-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}

.provenance-grid div {
  min-width: 0;
}

.provenance-grid dt {
  color: #888981;
  font-size: 9px;
}

.provenance-grid dd {
  margin: 4px 0 0;
  color: #343631;
  font-size: 12px;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
}

.curated-origin {
  margin-top: 13px;
  border-left: 3px solid var(--branch-color, #777);
  border-radius: 0 8px 8px 0;
  padding: 9px 11px;
  background: rgba(43, 45, 39, 0.045);
}

.curated-origin strong,
.curated-origin span {
  display: block;
}

.curated-origin strong {
  color: #30322d;
  font-size: 11px;
  line-height: 1.4;
}

.curated-origin span {
  margin-top: 4px;
  color: #75776f;
  font-size: 9px;
  line-height: 1.5;
}

.provenance-disclaimer {
  margin: 12px 0 0;
  color: #85867f;
  font-size: 9px;
  line-height: 1.5;
}

.reference-details {
  margin-top: 12px;
}

.reference-details summary {
  color: #526d82;
  font-size: 10px;
  font-weight: 650;
  cursor: pointer;
}

.reference-list {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
  padding-left: 18px;
  color: #696b64;
  font-size: 9px;
  line-height: 1.45;
}

.reference-list .reference-loading,
.reference-list .reference-empty {
  list-style: none;
  margin-left: -18px;
  color: #92938b;
}

.dependency-columns {
  display: grid;
  gap: 18px;
}

.dependency-columns h3 {
  margin: 0 0 8px;
  color: #4f514b;
  font-size: 11px;
  font-weight: 720;
}

.dependency-columns h3 span {
  color: #96978f;
  font-weight: 560;
}

.node-list {
  display: grid;
  gap: 4px;
}

.node-link {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 7px 8px;
  text-align: left;
  background: rgba(43, 45, 39, 0.035);
  cursor: pointer;
}

.node-link:hover,
.node-link:focus-visible {
  outline: 0;
  background: rgba(43, 45, 39, 0.08);
}

.node-link strong,
.node-link code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-link strong {
  color: #343631;
  font-size: 10px;
  font-weight: 640;
}

.node-link code {
  margin-top: 2px;
  color: #86877f;
  font-size: 9px;
}

.node-list-empty {
  margin: 0;
  padding: 8px;
  color: #92938b;
  font-size: 10px;
}

.node-list-more {
  margin: 3px 0 0 8px;
  color: #8b8c84;
  font-size: 9px;
}

.source-link {
  display: inline-block;
  margin-top: 22px;
  color: #3e617b;
  font-size: 11px;
  font-weight: 650;
  text-decoration: none;
}

.source-link:hover,
.source-link:focus-visible {
  text-decoration: underline;
  outline: 0;
}

.graph-tooltip {
  position: absolute;
  z-index: 12;
  width: min(310px, calc(100vw - 32px));
  border: 1px solid rgba(24, 25, 22, 0.13);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(251, 250, 247, 0.98);
  box-shadow: 0 12px 34px rgba(35, 31, 24, 0.14);
  pointer-events: none;
}

.graph-tooltip strong,
.graph-tooltip code,
.graph-tooltip span {
  display: block;
}

.graph-tooltip strong {
  margin-bottom: 4px;
  font-size: 12px;
  line-height: 1.3;
}

.graph-tooltip code {
  overflow-wrap: anywhere;
  color: #74766e;
  font-size: 9px;
  line-height: 1.35;
}

.graph-tooltip span {
  margin-top: 7px;
  color: #777970;
  font-size: 9px;
}

.graph-tooltip .tooltip-year {
  margin-top: 3px;
  color: #4e6e84;
  font-weight: 680;
}

.loading,
.error-message {
  position: absolute;
  z-index: 20;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(27, 28, 25, 0.12);
  border-radius: 13px;
  padding: 13px 17px;
  background: rgba(251, 250, 247, 0.96);
  box-shadow: 0 18px 54px rgba(35, 31, 24, 0.12);
  color: #62645d;
  font-size: 12px;
}

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.loading-mark {
  width: 10px;
  height: 10px;
  border: 2px solid rgba(48, 50, 44, 0.2);
  border-top-color: #363832;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.error-message {
  max-width: 520px;
  color: #8d3446;
  line-height: 1.5;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

@media (max-width: 980px) {
  .hero {
    width: 265px;
  }

  .hero-copy,
  .legend {
    display: none;
  }

  .toolbar {
    right: 18px;
  }

  .search-wrap {
    width: 250px;
  }

  .control-button {
    padding: 0 8px;
  }
}

@media (max-width: 720px) {
  .app {
    min-height: 460px;
  }

  .hero {
    top: 18px;
    left: 18px;
  }

  .eyebrow {
    display: none;
  }

  .hero h1 {
    font-size: 29px;
  }

  .toolbar {
    top: auto;
    right: 14px;
    bottom: 42px;
    left: 14px;
    flex-wrap: wrap;
  }

  .search-wrap {
    order: -1;
    width: 100%;
  }

  .control-group {
    flex: 1 1 220px;
  }

  .control-button {
    flex: 1;
  }

  .metrics {
    top: 100px;
    bottom: auto;
    left: 18px;
  }

  .metrics small {
    display: none;
  }

  .interaction-hint {
    display: none;
  }

  .inspector {
    top: auto;
    right: 10px;
    bottom: 98px;
    left: 10px;
    width: auto;
    max-height: 56vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
