:root {
  --bg: #07080a;
  --bg-elev: #0e1014;
  --bg-panel: #10131a;
  --line: rgba(236, 234, 228, 0.12);
  --line-strong: rgba(236, 234, 228, 0.2);
  --text: #eceae4;
  --muted: #9a958c;
  --faint: #6a6660;
  --focus: #e8c07a;
  --focus-dim: rgba(232, 192, 122, 0.2);
  --danger: #d9897a;
  --node-fill: #16181e;
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --ctrl: 40px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --detail-w: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --type-human: #d9a441;
  --type-org: #5b9fd4;
  --type-agent: #5caf7e;
  --type-human-fill: #3a2e18;
  --type-org-fill: #1a2d3f;
  --type-agent-fill: #1a3226;
  --type-human-ink: #f3e2b8;
  --type-org-ink: #d5ebf8;
  --type-agent-ink: #d4f0e0;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--focus); text-decoration: none; overflow-wrap: anywhere; }
a:hover { text-decoration: underline; }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px var(--focus-dim);
}
.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 {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(1000px 600px at 65% 40%, rgba(232,192,122,0.04), transparent 55%),
    var(--bg);
}
.top {
  z-index: 3;
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 8, 10, 0.96);
}
.brand {
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center;
  min-width: 0; flex: 1 1 220px;
}
.brand h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}
.data-status { color: var(--muted); font-size: 13px; min-width: 0; }
.about-wrap { position: relative; }
.about-wrap summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--muted);
  background: var(--bg-elev);
}
.about-wrap summary::-webkit-details-marker { display: none; }
.about-wrap[open] summary { border-color: var(--focus); color: var(--focus); }
.about-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  width: min(360px, calc(100vw - 28px));
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 13px;
}
.about-panel p { margin: 0 0 8px; overflow-wrap: anywhere; }
.about-panel p:last-child { margin-bottom: 0; }
.about-panel .label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 2px;
}
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: center; justify-content: flex-end;
  flex: 2 1 420px;
}
.cluster {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
}
.search-box { position: relative; }
#search {
  width: min(240px, 56vw);
  height: var(--ctrl);
  padding: 0 12px 0 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
#search::placeholder { color: var(--faint); }
.search-box > .mag {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; border: 1.6px solid var(--muted); border-radius: 50%;
  pointer-events: none;
  box-shadow: 5px 5px 0 -6px var(--muted);
}
#search-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: min(320px, 80vw);
  max-height: min(320px, 50vh);
  overflow: auto;
  z-index: 30;
  margin: 0; padding: 6px;
  list-style: none;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--bg-panel);
  box-shadow: var(--shadow);
}
#search-results.open { display: block; }
#search-results li[role="option"] {
  display: flex; gap: 10px; align-items: center;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  text-align: left;
}
#search-results li[role="option"]:hover,
#search-results li[role="option"][aria-selected="true"] {
  background: rgba(232,192,122,0.12);
}
#search-results .empty { padding: 10px; color: var(--faint); font-size: 13px; }
.sr-handle { font-weight: 600; }
.sr-meta { color: var(--muted); font-size: 12px; }
.icon-btn {
  height: var(--ctrl); min-width: var(--ctrl);
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 13px;
}
.icon-btn:hover { border-color: var(--line-strong); }
.icon-btn[aria-pressed="true"] {
  border-color: var(--focus);
  color: var(--focus);
  background: var(--focus-dim);
}
.icon-btn .label {
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.type-btn .swatch {
  width: 10px; height: 10px;
  border: 2px solid currentColor;
  background: currentColor;
  display: inline-block;
}
.type-btn[data-type="human"] .swatch { border-radius: 50%; color: var(--type-human); }
.type-btn[data-type="org"] .swatch { border-radius: 2px; color: var(--type-org); }
.type-btn[data-type="agent"] .swatch {
  border-radius: 1px; color: var(--type-agent);
  transform: rotate(45deg) scale(0.85);
}
.type-btn[aria-pressed="true"][data-type="human"] {
  border-color: var(--type-human); color: var(--type-human-ink);
  background: var(--type-human-fill);
}
.type-btn[aria-pressed="true"][data-type="org"] {
  border-color: var(--type-org); color: var(--type-org-ink);
  background: var(--type-org-fill);
}
.type-btn[aria-pressed="true"][data-type="agent"] {
  border-color: var(--type-agent); color: var(--type-agent-ink);
  background: var(--type-agent-fill);
}
.counts {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  width: 100%;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--muted);
  font-size: 12px;
  background: transparent;
}
.pill.dim { opacity: 0.45; }
.pill .swatch {
  width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid currentColor;
  background: currentColor;
}
.pill[data-type="human"] { border-color: rgba(217,164,65,0.45); }
.pill[data-type="org"] { border-color: rgba(91,159,212,0.45); }
.pill[data-type="agent"] { border-color: rgba(92,175,126,0.45); }
.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--detail-w);
  transition: grid-template-columns 180ms ease;
}
.app.detail-open { --detail-w: min(360px, 42vw); }
.map-pane {
  position: relative;
  min-width: 0; min-height: 0;
  overflow: hidden;
}
#network {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  background: transparent;
}
.detail {
  min-width: 0;
  border-left: 1px solid var(--line);
  background: var(--bg-panel);
  overflow: auto;
  display: none;
}
.app.detail-open .detail { display: block; }
.detail-head {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
  background: var(--bg-panel);
  z-index: 1;
}
.detail-avatar, .navatar {
  border-radius: 50%;
  background: var(--node-fill);
  border: 1px solid var(--line-strong);
  display: grid; place-items: center;
  overflow: hidden; flex: 0 0 auto;
  font-weight: 650; letter-spacing: 0.04em;
  color: var(--text);
}
.detail-avatar { width: 48px; height: 48px; font-size: 15px; }
.navatar { width: 30px; height: 30px; font-size: 11px; }
.detail-avatar img, .navatar img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.detail-head .meta { min-width: 0; flex: 1; }
.detail-head .handle {
  margin: 0; font-size: 17px; font-weight: 650;
  overflow-wrap: anywhere;
}
.detail-head .sub {
  margin: 3px 0 0; color: var(--muted); font-size: 13px;
  overflow-wrap: anywhere;
}
.detail-close {
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--muted);
  width: 36px; height: 36px; border-radius: 10px; font-size: 18px; line-height: 1;
  flex: 0 0 auto;
}
.detail-close:hover { color: var(--text); }
.detail-body { padding: 14px; min-width: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.section-title {
  margin: 16px 0 8px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}
.notes, .empty-state {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.empty-state {
  padding: 10px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  color: var(--faint);
  font-size: 13px;
}
.link-card, .conn-card, .evidence-card {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  margin: 0 0 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.02);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.link-card .link-label { font-weight: 600; color: var(--focus); }
.link-card .link-url {
  display: block; margin-top: 4px;
  color: var(--muted); font-size: 12px;
  overflow-wrap: anywhere;
}
.list { list-style: none; margin: 0; padding: 0; }
.list > li { margin: 0 0 10px; min-width: 0; }
.neighbor {
  all: unset;
  cursor: pointer;
  display: flex; gap: 10px; align-items: flex-start;
  width: 100%; min-width: 0;
  border-radius: 8px;
}
.neighbor:hover .nhandle { color: var(--focus); }
.neighbor .info { min-width: 0; flex: 1; }
.nhandle { font-weight: 600; overflow-wrap: anywhere; }
.nmeta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.kind-tag {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--focus);
  letter-spacing: 0.03em;
}
.bottom {
  z-index: 3;
  display: flex; flex-wrap: wrap; gap: 8px 12px;
  align-items: center; justify-content: space-between;
  padding: 8px 14px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(7, 8, 10, 0.96);
  color: var(--muted);
  font-size: 12px;
}
.hint kbd {
  display: inline-block;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 0 5px;
  font: 11px/1.5 var(--mono);
  color: var(--text);
}
#edge-legend { display: flex; flex-wrap: wrap; gap: 6px; }
.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(56px + var(--safe-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  max-width: min(90vw, 420px);
  text-align: center;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { color: var(--danger); border-color: rgba(217,137,122,0.5); }
.overlay-error {
  position: fixed; inset: 0; z-index: 50;
  display: none; place-items: center;
  background: rgba(7,8,10,0.72); padding: 24px;
}
.overlay-error.show { display: grid; }
.overlay-error .card {
  width: min(420px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.overlay-error h2 { margin: 0 0 8px; font-size: 17px; }
.overlay-error p { margin: 0 0 14px; color: var(--muted); overflow-wrap: anywhere; }
.vis-tooltip {
  background: var(--bg-elev) !important;
  border: 1px solid var(--line-strong) !important;
  color: var(--text) !important;
  border-radius: 10px !important;
  padding: 8px 10px !important;
  font: 13px/1.35 var(--font) !important;
  box-shadow: var(--shadow) !important;
  max-width: 240px;
  overflow-wrap: anywhere;
}
@media (max-width: 820px) {
  .app.detail-open { --detail-w: 0px; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .app.detail-open .detail {
    display: block;
    max-height: 42vh;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .icon-btn .label { display: none; }
  .icon-btn .label-keep { display: inline; font-size: 11px; }
  #search { width: min(150px, 42vw); }
  .counts { display: none; }
  .hint .long { display: none; }
}
@media (max-width: 520px) {
  .brand h1 { letter-spacing: 0.08em; }
  .data-status { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  .workspace { transition: none; }
}
