:root {
  color-scheme: light dark;
  --bg: #f7f7f4;
  --ink: #18181b;
  --muted: #6d6d74;
  --line: #d8d8d2;
  --panel: #ffffff;
  --panel-elevated: rgba(255, 255, 255, 0.92);
  --accent: #7c6bd9;
  --accent-soft: #ece8ff;
  --code: #eeeeea;
  --graph-content: #277d73;
  --graph-nav: #5c6e9b;
  --graph-header: #a65273;
  --graph-footer: #8a6f26;
  --graph-aside: #4b7f52;
  --graph-external: #a8612d;
  --graph-resource: #68708a;
  --graph-danger: #b34646;
  --graph-muted: #9b9b94;
  --graph-selected: #18181b;
  --host-1: #426fc2;
  --host-2: #a65273;
  --host-3: #8a6f26;
  --host-4: #277d73;
  --host-5: #7c6bd9;
  --host-6: #b34646;
  --host-7: #4b7f52;
  --shadow: 0 16px 36px rgba(24, 24, 27, 0.12);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f11;
    --ink: #f2f2f0;
    --muted: #a0a0a8;
    --line: #303034;
    --panel: #17171a;
    --panel-elevated: rgba(23, 23, 26, 0.92);
    --accent: #c0b4ff;
    --accent-soft: #242033;
    --code: #1c1c20;
    --graph-content: #76cfc4;
    --graph-nav: #9dacdf;
    --graph-header: #e48aaa;
    --graph-footer: #d8bd6c;
    --graph-aside: #8bc891;
    --graph-external: #de9a5f;
    --graph-resource: #a5acc2;
    --graph-danger: #f07b7b;
    --graph-muted: #5e5e66;
    --graph-selected: #f2f2f0;
    --host-1: #85a7f0;
    --host-2: #e48aaa;
    --host-3: #d8bd6c;
    --host-4: #76cfc4;
    --host-5: #c0b4ff;
    --host-6: #f07b7b;
    --host-7: #8bc891;
    --shadow: 0 16px 36px rgba(0, 0, 0, 0.32);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.visually-hidden {
  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 {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
}

.graph-chrome {
  z-index: 5;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.graph-status {
  width: min(100% - 2rem, 58rem);
  min-width: 0;
  margin: -1.65rem auto 1rem;
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls-panel {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 4;
  display: grid;
  gap: 14px;
  width: min(324px, calc(100vw - 32px));
  max-height: calc(100% - 32px);
  overflow: auto;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel-elevated);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.controls-panel[hidden],
.panel-tab[hidden] {
  display: none;
}

.panel-body {
  display: grid;
  gap: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.panel-button,
.panel-tab {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0 10px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
}

.panel-button:hover,
.panel-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.panel-tab {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 4;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.search-box {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.search-box input {
  width: 100%;
}

.search-box input {
  height: 34px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0 11px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.toolbar button {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0 11px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.toolbar button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.toolbar button[aria-pressed="false"] {
  color: var(--muted);
  background: var(--code);
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.preset-grid button {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.preset-grid button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.preset-grid button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 720;
}

.control-section {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.section-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.legend-hint {
  font-weight: 560;
  letter-spacing: 0;
  text-transform: none;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  white-space: nowrap;
}

.toggle-row input {
  accent-color: var(--accent);
  flex: 0 0 auto;
}

#surfaceFilterList {
  grid-template-columns: 1fr;
}

.filter-toggle {
  justify-content: flex-start;
}

.filter-swatch {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.filter-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-shape {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border: 1.5px solid var(--ink);
  background: var(--accent-soft);
}

.node-shape-circle {
  border-radius: 50%;
}

.node-shape-double-circle {
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--ink);
}

.node-shape-hexagon {
  clip-path: polygon(25% 7%, 75% 7%, 100% 50%, 75% 93%, 25% 93%, 0 50%);
}

.node-shape-triangle,
.node-shape-warning {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.node-shape-pill {
  width: 14px;
  border-radius: 999px;
}

.node-shape-diamond,
.node-shape-diamond-ring {
  width: 9px;
  height: 9px;
  margin-inline: 1px;
  transform: rotate(45deg);
}

.node-shape-diamond-ring {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--panel), inset 0 0 0 3px var(--ink);
}

.node-shape-ring {
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--panel), inset 0 0 0 3px var(--ink);
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}

#graphCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#graphCanvas.dragging {
  cursor: grabbing;
}

.details-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 4;
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100% - 32px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel-elevated);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.details-panel[hidden] {
  display: none;
}

.details-panel .eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.details-panel h2 {
  margin: 6px 0 14px;
  font-size: 20px;
  line-height: 1.16;
  font-weight: 760;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.linked-pages {
  display: grid;
  gap: 7px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.linked-pages li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px;
  align-items: baseline;
}

.link-direction {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.linked-pages a {
  min-width: 0;
  overflow-wrap: anywhere;
}

.linked-pages-more {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.details-panel dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.details-panel dl > div {
  display: grid;
  gap: 3px;
}

.details-panel dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.details-panel dd {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.details-panel a {
  color: inherit;
  text-decoration-color: var(--link);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

.details-panel a:hover {
  color: var(--link);
}

.tooltip {
  position: absolute;
  z-index: 8;
  max-width: 280px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel-elevated);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.status-message {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 10;
  transform: translate(-50%, -50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 16px 18px;
  border: 1px solid var(--graph-danger);
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

@media (max-width: 780px) {
  .graph-status {
    margin-top: -1.25rem;
  }

  .details-panel {
    top: auto;
    right: 10px;
    left: 10px;
    bottom: 10px;
    width: auto;
    max-height: 34vh;
  }

  .controls-panel {
    left: 10px;
    top: 10px;
    width: min(324px, calc(100vw - 20px));
    max-height: 42vh;
    padding: 12px;
  }

  .panel-tab {
    left: 10px;
    top: 10px;
  }

  .toggle-grid {
    grid-template-columns: 1fr;
  }

  .panel-button,
  .panel-tab,
  .toolbar button,
  .preset-grid button,
  .search-box input,
  .toggle-row {
    min-height: 44px;
    height: auto;
  }
}
