:root {
  --bg: #0b0c0f;
  --panel: #111318;
  --panel-2: #161922;
  --line: #232733;
  --line-strong: #2f3442;
  --text: #e8e9ed;
  --text-2: #a9aeb9;
  --muted: #7b8090;
  --faint: #4f5461;
  --focus: #c9ccd6;
  --radius: 6px;
  --sans: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --topbar-h: 56px;
  --sidebar-w: 300px;
  --inspector-w: 320px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, a { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { text-decoration: none; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

:focus-visible { outline: 1.5px solid var(--focus); outline-offset: 2px; border-radius: var(--radius); }

/* ---------- top bar ---------- */

.topbar {
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr auto;
  align-items: center;
  padding: 0 12px 0 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  gap: 16px;
}

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 4px; justify-self: end; }

.wordmark { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.wordmark-org { font-weight: 600; letter-spacing: -0.01em; }
.wordmark-sep { width: 1px; height: 12px; background: var(--line-strong); align-self: center; }
.wordmark-app { color: var(--text-2); }

.topbar-stats { display: flex; align-items: center; gap: 18px; color: var(--muted); }
.stat { white-space: nowrap; }
.stat-n { color: var(--text); font-weight: 500; margin-right: 2px; }
.stat-btn {
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: var(--radius);
  color: var(--muted);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.stat-btn:hover { background: var(--panel-2); color: var(--text-2); }
.stat-btn[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.stat-btn[aria-pressed="true"] .stat-n { color: var(--bg); }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 17px;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn:active { transform: scale(0.96); }

.text-btn {
  height: 32px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.text-btn i { font-size: 15px; }
.text-btn:hover { background: var(--panel-2); color: var(--text); }
.text-btn:active { transform: scale(0.98); }

.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px 0 8px; margin-right: 4px;
  color: var(--muted); font-size: 12px;
  border-right: 1px solid var(--line);
}
.user-chip i { font-size: 16px; }
.user-chip span { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.state-action { margin-left: 6px; color: var(--text); border-bottom: 1px solid var(--line-strong); cursor: pointer; }

.link-btn { color: var(--muted); font-size: 12px; }
.link-btn:hover { color: var(--text); }

/* ---------- shell ---------- */

.shell {
  height: calc(100% - var(--topbar-h));
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--inspector-w);
  transition: grid-template-columns 0.28s var(--ease);
}
.shell.sidebar-collapsed { grid-template-columns: 0 1fr var(--inspector-w); }

/* ---------- sidebar ---------- */

.sidebar {
  display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--panel);
  opacity: 1;
  transition: opacity 0.2s var(--ease);
}
.shell.sidebar-collapsed .sidebar { opacity: 0; pointer-events: none; border-right-color: transparent; }

.panel-block { padding: 14px 14px 12px; border-bottom: 1px solid var(--line); }
.panel-grow { flex: 1; display: flex; flex-direction: column; min-height: 0; border-bottom: 0; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.block-title { font-weight: 500; color: var(--text-2); }
.block-meta { color: var(--muted); font-size: 12px; }

.field {
  position: relative; display: block;
}
.field input {
  width: 100%; height: 34px;
  padding: 0 30px 0 32px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color 0.15s var(--ease);
}
.field input::placeholder { color: var(--faint); }
.field input:focus { outline: none; border-color: var(--line-strong); }
.field input::-webkit-search-cancel-button { display: none; }
.field-icon { position: absolute; left: 10px; top: 9px; font-size: 16px; color: var(--muted); pointer-events: none; }
.field-clear {
  position: absolute; right: 6px; top: 6px;
  width: 22px; height: 22px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.field-clear:hover { color: var(--text); background: var(--panel-2); }

.band-list { display: flex; flex-direction: column; gap: 2px; }
.band-row {
  display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 10px;
  height: 30px; padding: 0 8px; margin: 0 -8px;
  border-radius: var(--radius);
  cursor: pointer; user-select: none;
  color: var(--text-2);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), opacity 0.15s var(--ease);
}
.band-row:hover { background: var(--panel-2); color: var(--text); }
.band-row.off { color: var(--faint); }
.band-row.off .band-swatch { background: transparent !important; box-shadow: inset 0 0 0 1.5px var(--faint); }
.band-swatch { width: 10px; height: 10px; border-radius: 50%; justify-self: center; }
.band-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.band-count { color: var(--muted); font-size: 12px; }
.band-row.off .band-count { color: var(--faint); }

.directory { flex: 1; overflow-y: auto; margin: 0 -8px; padding: 0 8px 8px; }
.dir-row {
  display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 10px;
  height: 30px; padding: 0 8px; margin: 0 -8px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-2);
  transition: background-color 0.12s var(--ease), color 0.12s var(--ease);
}
.dir-row:hover, .dir-row.active { background: var(--panel-2); color: var(--text); }
.dir-dot { width: 8px; height: 8px; border-radius: 50%; justify-self: center; }
.dir-dot.multi { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-2); }
.dir-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dir-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.dir-meta .ph-crown { color: var(--text-2); font-size: 13px; }
.dir-empty { color: var(--muted); padding: 12px 0; }

.panel-foot {
  display: flex; gap: 16px; align-items: center;
  padding: 10px 14px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; }
.legend-multi { box-shadow: inset 0 0 0 1.5px var(--text-2); }
.legend-crown { color: var(--text-2); font-size: 13px; }

/* ---------- canvas ---------- */

.canvas { position: relative; min-width: 0; background: var(--bg); }
#graph { width: 100%; height: 100%; display: block; cursor: grab; }
#graph:active { cursor: grabbing; }

.node { cursor: pointer; }
.node text {
  font-family: var(--sans);
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.node .label-band { font-weight: 600; font-size: 12px; fill: var(--text); }
.node .label-band-code { font-family: var(--mono); font-weight: 500; font-size: 11px; fill: var(--text); stroke: none; }
.node .label-pod { font-weight: 500; font-size: 11px; fill: var(--text-2); }
.node .label-member { font-size: 10px; fill: var(--muted); }

.node, .link { transition: opacity 0.2s var(--ease); }
.node.dim { opacity: 0.12; }
.link.dim { opacity: 0.04; }
.link { stroke-linecap: round; }

.state {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  pointer-events: none;
}
.state-inner { display: flex; align-items: center; gap: 10px; }
.state.error { color: var(--text-2); }
.state.error .spinner { display: none; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--line-strong); border-top-color: var(--text-2);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  position: absolute; top: 14px; left: 14px;
  display: inline-flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 6px 0 12px;
  background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text-2);
}
.banner-close { width: 22px; height: 22px; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.banner-close:hover { color: var(--text); background: var(--panel-2); }

.zoom-controls {
  position: absolute; right: 14px; bottom: 14px;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.zoom-controls .icon-btn { border-radius: 0; }
.zoom-controls .icon-btn + .icon-btn { border-top: 1px solid var(--line); }

/* ---------- inspector ---------- */

.inspector {
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  min-width: 0;
}
.inspector.pinned { box-shadow: inset 2px 0 0 var(--text-2); }
.inspector-empty { padding: 20px 16px; color: var(--muted); }
.inspector-empty p { margin: 0; }

.inspector-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.inspector-kicker { font-size: 11px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.inspector-title { margin: 0 0 8px; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.inspector-badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  color: var(--text-2); font-size: 12px;
}
.inspector-badge .swatch { width: 8px; height: 8px; border-radius: 50%; }

.inspector-content { padding: 12px 16px 20px; }
.sec { margin-bottom: 16px; }
.sec:last-child { margin-bottom: 0; }
.sec-title { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.sec-title .mono { color: var(--muted); }

.rows { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px;
  padding: 7px 8px; margin: 0 -8px;
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.12s var(--ease);
}
.row:hover { background: var(--panel-2); }
.row .swatch { width: 8px; height: 8px; border-radius: 50%; }
.row-main { min-width: 0; }
.row-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-tag { color: var(--muted); font-size: 11.5px; }
.row-tag.lead { color: var(--text-2); display: inline-flex; align-items: center; gap: 4px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; color: var(--text-2); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { height: 22px; padding: 0 8px; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--text-2); font-size: 12px; }
.chip .mono { color: var(--muted); }

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  :root { --inspector-w: 280px; --sidebar-w: 260px; }
  .topbar-stats { gap: 12px; }
}
@media (max-width: 860px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .topbar-stats { display: none; }
  .shell { grid-template-columns: var(--sidebar-w) 1fr 0; }
  .shell.sidebar-collapsed { grid-template-columns: 0 1fr 0; }
  .inspector { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 0.01ms !important; }
}
