:root {
  color-scheme: dark;
  --surface: #0b0e15;
  --surface-raised: #151922;
  --surface-high: #1e2430;
  --on-surface: #e6e8ef;
  --on-surface-muted: #aab2c2;
  --outline: #2c3442;
  --outline-strong: #596579;
  --primary: #adc6ff;
  --theorem: #ffb86b;
  --def: #67e8f9;
  --structure: #c084fc;
  --class: #f472b6;
  --inductive: #a3e635;
  --module: #94a3b8;
  --gutter: 16px;
  --neighbor-drawer-height: 220px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--surface);
  color: var(--on-surface);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  line-height: 20px;
  letter-spacing: 0;
}

button,
input,
a {
  font: inherit;
}

button,
a {
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

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

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--surface);
}

#graph-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#graph-canvas:active {
  cursor: grabbing;
}

#graph-canvas[data-camera-mode="move"] {
  cursor: move;
}

.hud {
  position: absolute;
  z-index: 4;
}

.panel,
.top-bar {
  border: 1px solid var(--outline);
  background: var(--surface-raised);
}

.top-bar {
  top: var(--gutter);
  left: var(--gutter);
  right: var(--gutter);
  display: grid;
  grid-template-columns: minmax(220px, 420px) auto auto auto minmax(220px, 360px);
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px;
}

input[type="search"] {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--outline);
  border-radius: 0;
  background: #070a10;
  color: var(--on-surface);
  padding: 0 12px;
  outline: none;
}

input[type="search"]::placeholder {
  color: #748094;
}

input[type="search"]:focus-visible,
input[type="range"]:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible,
.node-row-button:focus-visible {
  border-color: #3b82f6;
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.mode-tabs,
.camera-tools,
.chip-grid,
.inspector-actions,
.bottom-controls {
  display: flex;
  gap: 8px;
}

.mode-tabs {
  min-width: 0;
  overflow-x: auto;
}

.mode-button,
.camera-button,
.download-tools summary,
.download-option,
.chip,
.inspector-actions button,
.inspector-actions a,
.drawer-action,
.neighbor-restore,
.rail-toggle,
summary {
  min-height: 40px;
  border: 1px solid var(--outline);
  border-radius: 0;
  background: transparent;
  color: var(--on-surface-muted);
  text-decoration: none;
}

.mode-button {
  min-width: 92px;
  padding: 0 12px;
  white-space: nowrap;
}

.camera-button {
  min-width: 74px;
  padding: 0 10px;
  white-space: nowrap;
}

.download-tools {
  position: relative;
  justify-self: start;
}

.download-tools summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 40px;
  padding: 0;
  color: var(--on-surface);
  list-style: none;
}

.download-tools summary::-webkit-details-marker {
  display: none;
}

.download-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: square;
  stroke-linejoin: miter;
  stroke-width: 2;
}

.download-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 8;
  width: 164px;
  border: 1px solid var(--outline-strong);
  background: var(--surface-raised);
  padding: 6px;
}

.download-option {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 38px;
  padding: 0 8px;
  color: var(--on-surface);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  text-transform: uppercase;
}

.download-option:hover,
.download-option:focus-visible {
  background: var(--surface-high);
}

.download-option small {
  color: var(--on-surface-muted);
  font-size: 10px;
  font-weight: 600;
  line-height: 14px;
}

.mode-button.is-active,
.camera-button.is-active,
.chip.is-active {
  border-color: var(--primary);
  background: var(--surface-high);
  color: var(--on-surface);
}

.top-metrics,
.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

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

.top-metrics div,
.detail-grid div {
  min-width: 0;
}

dt {
  color: #7f899a;
  font-size: 11px;
  font-weight: 700;
  line-height: 14px;
  letter-spacing: 0;
  text-transform: uppercase;
}

dd {
  margin: 0;
  overflow: hidden;
  color: var(--on-surface);
  font-size: 12px;
  line-height: 18px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-drawer {
  top: 84px;
  left: var(--gutter);
  width: 236px;
  max-height: calc(100dvh - 108px);
  overflow: hidden;
}

summary {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  color: var(--on-surface);
  list-style: none;
  text-transform: uppercase;
}

summary::-webkit-details-marker {
  display: none;
}

.filter-drawer[open] {
  padding: 10px;
  overflow: auto;
}

.filter-drawer[open] summary {
  margin: -10px -10px 10px;
}

.field-label,
.panel-title {
  margin: 0 0 8px;
  color: var(--on-surface-muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.filter-group + .filter-group {
  margin-top: 14px;
}

.chip-grid {
  flex-wrap: wrap;
}

.chip {
  min-width: 0;
  min-height: 30px;
  padding: 0 8px;
  font-size: 11px;
  line-height: 16px;
  overflow-wrap: anywhere;
  max-width: 100%;
  padding-block: 6px;
  text-transform: uppercase;
}

.node-inspector {
  top: 84px;
  right: var(--gutter);
  width: 360px;
  max-height: calc(100dvh - 120px);
  padding: 0;
  overflow: hidden;
  transform: translateX(calc(100% - 44px));
  transition: transform 180ms ease-out;
}

.node-inspector.is-open {
  transform: translateX(0);
}

.rail-toggle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 44px;
  min-height: 100%;
  border-width: 0 1px 0 0;
  writing-mode: vertical-rl;
  text-transform: uppercase;
}

.node-inspector:not(.has-selection) .rail-toggle {
  color: #687486;
}

.inspector-content {
  max-height: calc(100dvh - 120px);
  margin-left: 44px;
  padding: 12px;
  overflow: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease-out;
}

.node-inspector.is-open .inspector-content {
  opacity: 1;
  pointer-events: auto;
}

.node-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-bottom: 4px;
}

.type-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  background: var(--def);
  color: #05070a;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-transform: uppercase;
}

h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--on-surface);
  font-size: 18px;
  font-weight: 600;
  line-height: 26px;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.long-name {
  margin: 0 0 12px;
  overflow-wrap: anywhere;
  color: var(--on-surface-muted);
  font-size: 12px;
  line-height: 18px;
}

.lean-preview {
  min-height: 70px;
  margin: 12px 0;
  border: 1px solid var(--outline);
  background: #070a10;
  color: var(--on-surface);
  padding: 10px;
  overflow: auto;
  font-size: 12px;
  line-height: 18px;
  white-space: pre-wrap;
}

.inspector-actions {
  flex-wrap: wrap;
}

.inspector-actions button,
.inspector-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.neighbor-drawer {
  left: var(--gutter);
  right: var(--gutter);
  bottom: var(--gutter);
  height: min(var(--neighbor-drawer-height), calc(100dvh - 128px));
  padding: 14px 12px 10px;
  overflow: hidden;
  transform: translateY(calc(100% + 20px));
  transition: transform 180ms ease-out;
}

.neighbor-drawer.is-open {
  transform: translateY(0);
}

.neighbor-drawer.is-resizing {
  transition: none;
  user-select: none;
}

.neighbor-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 14px;
  cursor: ns-resize;
  touch-action: none;
}

.neighbor-resize-handle::before {
  position: absolute;
  top: 5px;
  left: 50%;
  width: 72px;
  height: 2px;
  background: var(--outline-strong);
  content: "";
  opacity: 0.65;
  transform: translateX(-50%);
}

.neighbor-resize-handle:hover::before,
.neighbor-resize-handle:focus-visible::before {
  background: var(--primary);
  opacity: 1;
}

.bottom-controls {
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}

.bottom-controls > div:first-child {
  min-width: 0;
}

.bottom-tools {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}

.drawer-action {
  min-height: 32px;
  padding: 0 10px;
  color: var(--on-surface-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.path-summary {
  max-width: min(720px, 58vw);
  overflow: hidden;
  color: var(--on-surface-muted);
  font-size: 12px;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.depth-control {
  display: grid;
  grid-template-columns: auto 150px 24px;
  align-items: center;
  gap: 8px;
  color: var(--on-surface-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

input[type="range"] {
  accent-color: var(--primary);
}

.neighbors-table-wrap {
  height: calc(100% - 90px);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
  line-height: 18px;
}

th,
td {
  border-top: 1px solid #1c2430;
  padding: 5px 8px;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  color: #7f899a;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.is-selected {
  background: var(--surface-high);
}

.node-row-button {
  width: 100%;
  min-height: 28px;
  border: 0;
  background: transparent;
  color: var(--on-surface);
  padding: 0;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.neighbor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  border-top: 1px solid #1c2430;
  padding-top: 6px;
  color: var(--on-surface-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.neighbor-footer .drawer-action {
  min-height: 30px;
}

.neighbor-restore {
  left: var(--gutter);
  bottom: var(--gutter);
  min-height: 40px;
  padding: 0 12px;
  color: var(--on-surface);
  font-size: 11px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  text-transform: uppercase;
  transform: translateY(10px);
  transition: opacity 160ms ease-out, transform 160ms ease-out;
}

.neighbor-restore.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.tooltip,
.graph-label,
.cluster-label {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  border: 1px solid var(--outline);
  border-radius: 0;
  background: #070a10;
  color: var(--on-surface);
  font-size: 11px;
  line-height: 15px;
  padding: 5px 7px;
  transform: translate(12px, 12px);
}

.tooltip {
  display: none;
  max-width: 260px;
}

.labels-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.graph-label {
  z-index: 3;
  max-width: 180px;
  overflow: hidden;
  color: var(--primary);
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translate(-50%, -140%);
}

.cluster-label {
  z-index: 2;
  color: var(--on-surface);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
}

@media (prefers-reduced-motion: reduce) {
  .node-inspector,
  .inspector-content,
  .neighbor-drawer {
    transition: none;
  }
}

@media (max-width: 980px) {
  :root {
    --gutter: 10px;
  }

  .top-bar {
    grid-template-columns: minmax(160px, 1fr) auto auto;
  }

  .mode-tabs {
    grid-column: 1 / -1;
  }

  .camera-tools {
    grid-row: 1;
    grid-column: 2;
  }

  .download-tools {
    grid-row: 1;
    grid-column: 3;
  }

  .top-metrics {
    display: none;
  }

  .filter-drawer {
    top: 134px;
  }

  .node-inspector {
    top: 134px;
    width: min(360px, calc(100vw - 20px));
  }
}

@media (max-width: 680px) {
  .top-bar {
    left: var(--gutter);
    right: var(--gutter);
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .mode-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
    padding-bottom: 0;
  }

  .mode-button {
    min-width: 0;
    width: 100%;
  }

  .camera-button {
    min-width: 62px;
  }

  .download-tools {
    grid-column: 3;
    grid-row: 1;
  }

  .download-tools summary {
    width: 44px;
  }

  .filter-drawer {
    top: 174px;
    width: min(236px, calc(100vw - 20px));
  }

  .node-inspector {
    top: auto;
    bottom: var(--gutter);
    right: var(--gutter);
    max-height: 260px;
  }

  .node-inspector.is-open {
    left: var(--gutter);
    width: auto;
  }

  .node-inspector.is-open ~ .neighbor-restore.is-visible {
    bottom: calc(var(--gutter) + 268px);
  }

  .inspector-content {
    max-height: 258px;
  }

  .lean-preview {
    display: none;
  }

  .bottom-controls {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px;
  }

  .path-summary {
    max-width: 100%;
  }

  .bottom-tools {
    width: 100%;
    justify-content: space-between;
  }

  .neighbors-table-wrap {
    height: calc(100% - 122px);
  }

  .depth-control {
    grid-template-columns: auto 94px 18px;
  }

  th,
  td {
    padding: 4px 6px;
  }
}
