:root {
  --background: #121212;
  --primary: #0099ff;
  --secondary: #f5f5f5;
  --accent: #ff6b6b;
  --light-gray: #2a2a2a;
  --border: #333333;
  --text-muted: #999999;
  --panel: #181818;
  --t-person: #5eb3ff;
  --t-corp: #c084fc;
  --t-fund: #f472b6;
  --t-nonprofit: #34d399;
  --t-institution: #fbbf24;
  --t-project: #ff6b6b;
  --t-document: #94a3b8;
  --t-miner: #fb923c;
  --font: "Courier New", Courier, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--background);
  color: var(--secondary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  height: 100dvh;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  grid-template-rows: auto auto minmax(0, 1fr);
}
.cats {
  grid-column: 1 / -1;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  overflow-x: auto;
  scrollbar-width: thin;
}
.cats-label {
  position: sticky;
  left: 0;
  z-index: 1;
  flex: 0 0 auto;
  padding-right: 6px;
  background: var(--panel);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.cats .chip { flex: 0 0 auto; }
header {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  padding: 8px 12px 6px;
  background: var(--panel);
  min-height: 44px;
}
.back {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  flex: 0 0 auto;
}
.back:hover { color: var(--primary); }
h1 { font-size: 15px; font-weight: 600; margin: 0; color: var(--primary); white-space: nowrap; }
.info {
  position: relative;
  flex: 0 0 auto;
  border: 0;
  padding: 0;
}
.info summary {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 50%;
  list-style: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}
.info summary::-webkit-details-marker { display: none; }
.info summary:hover { color: var(--primary); border-color: var(--primary); }
.info:not([open]) .panel { display: none; }
.info .panel {
  position: fixed;
  z-index: 9;
  top: 46px;
  left: 12px;
  width: min(420px, calc(100vw - 24px));
  margin: 0;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
}
.info .panel p { margin: 0 0 8px; }
.info .panel p:last-child { margin-bottom: 0; }
.info .panel a { color: var(--primary); }
.counts { margin: 0; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.search { position: relative; margin-left: auto; flex: 1 1 240px; max-width: 420px; }
.search input {
  width: 100%;
  padding: 8px 32px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--background);
}
.qclear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.results {
  position: absolute;
  z-index: 8;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: min(360px, 50dvh);
  overflow: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.results button {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  cursor: pointer;
}
.results button:last-child { border-bottom: 0; }
.results button:hover, .results button[aria-selected="true"] { background: var(--light-gray); }
.results .meta { margin-left: auto; color: var(--text-muted); font-size: 12px; }
.stage { min-width: 0; min-height: 0; }
#graph { position: relative; width: 100%; height: 100%; overflow: hidden; background: var(--background); }
#cv { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#cv.dragging { cursor: grabbing; }
.float {
  position: absolute;
  z-index: 4;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: calc(100% - 20px);
}
.float button, .btn, .pop-head button {
  border: 1px solid var(--border);
  background: rgba(18, 18, 18, 0.92);
  border-radius: 6px;
  min-width: 36px;
  min-height: 36px;
  padding: 0 10px;
  cursor: pointer;
  color: var(--secondary);
}
.float button:hover, .btn:hover { border-color: var(--primary); color: var(--primary); }
.float button:disabled { opacity: 0.4; cursor: default; }
.float button:disabled:hover { border-color: var(--border); color: var(--secondary); }
.float button[aria-pressed="true"] { border-color: var(--primary); color: var(--primary); }
.pop {
  position: absolute;
  z-index: 5;
  bottom: 58px;
  right: 12px;
  width: min(460px, calc(100% - 20px));
  max-height: min(68dvh, 520px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.pop-head strong { font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); font-weight: 500; }
.filters { display: flex; flex-direction: column; gap: 8px; }
.group { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.group > span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  width: 100%;
}
.chip {
  border: 1px solid var(--border);
  background: var(--background);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
}
.chip[aria-pressed="true"] { color: var(--secondary); border-color: var(--primary); background: #141414; }
.chip[aria-pressed="false"] { opacity: 0.42; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; flex: 0 0 auto; }
.dot.stale { background: transparent; border: 1.5px dashed #8d8d8d; box-sizing: border-box; }
.hint, .tip {
  position: absolute;
  z-index: 3;
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(24, 24, 24, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  margin: 0;
  pointer-events: none;
  max-width: min(440px, calc(100% - 24px));
}
.hint { left: 50%; top: 50%; bottom: auto; transform: translate(-50%, -50%); max-width: min(280px, calc(100% - 24px)); text-align: center; }
.credit {
  position: absolute;
  z-index: 6;
  top: 10px;
  left: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(18, 18, 18, 0.94);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.01em;
}
.credit::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  background: url("/affiliations/btcdecoded.png") center / contain no-repeat;
}
.credit strong { color: var(--primary); font-weight: 600; }
.credit:hover { border-color: var(--primary); color: var(--secondary); }
.hint.fail { color: var(--accent); }
.tip { color: var(--secondary); }
.side {
  background: var(--panel);
  border-left: 1px solid var(--border);
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.tabs button {
  flex: 1;
  min-height: 42px;
  padding: 8px 6px;
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.pane { padding: 12px 14px 24px; overflow: auto; min-height: 0; flex: 1 1 auto; }
.node-head {
  position: sticky;
  top: -12px;
  z-index: 1;
  background: var(--panel);
  padding: 12px 0 8px;
  margin-top: -12px;
}
.pane h2 { font-size: 16px; margin: 0 0 8px; color: var(--secondary); }
.pane h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 16px 0 4px;
  font-weight: 500;
}
.pane p { margin: 6px 0; }
.note { color: #d5d5d5; }
.edge-filter {
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--background);
}
.pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  margin: 0 6px 0 0;
}
.tier {
  font-size: 10px;
  padding: 0 5px;
  border-radius: 3px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  margin-left: auto;
}
.tier.P { color: #34d399; border-color: #34d399; }
.tier.A { color: #5eb3ff; border-color: #5eb3ff; }
.tier.S { color: #fbbf24; border-color: #fbbf24; }
.tier.U { color: #f472b6; border-color: #f472b6; }
.row {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  padding: 9px 0;
  cursor: pointer;
}
.row .top { display: flex; gap: 8px; align-items: baseline; }
.row .dir { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; flex: 0 0 auto; }
.row .nm { color: var(--secondary); }
.row .lb, .row .src { display: block; color: var(--text-muted); font-size: 12px; margin-top: 3px; }
.row .src {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.row:hover .nm { color: var(--primary); }
ul.plain { margin: 6px 0; padding-left: 18px; }
ul.plain li { margin: 8px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 8px 0; font-size: 12px; color: var(--text-muted); }
.actions { display: flex; gap: 6px; margin: 8px 0 0; flex-wrap: wrap; }
details { border-top: 1px solid var(--border); padding: 8px 0; }
details summary { cursor: pointer; color: var(--secondary); }
details summary:hover { color: var(--primary); }
@media (max-width: 860px) {
  body { overflow: auto; }
  .app {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(62dvh, 68dvh) auto;
  }
  header { flex-wrap: wrap; }
  h1 { font-size: 15px; }
  .counts { order: 4; width: 100%; }
  .search { order: 3; margin-left: 0; max-width: none; flex-basis: 100%; }
  .cats { grid-row: 2; }
  .stage { grid-row: 3; height: 100%; }
  .side { border-left: 0; border-top: 1px solid var(--border); grid-row: 4; min-height: 42dvh; }
  .desk { display: none; }
  .hint:not(.fail):not(.empty) { display: none; }
  .search input, .edge-filter { font-size: 16px; }
  .cats .chip { min-height: 36px; }
  .float button { min-width: 40px; min-height: 40px; }
  .pop { left: 10px; right: 10px; width: auto; bottom: 64px; }
  .float { bottom: max(12px, env(safe-area-inset-bottom)); }
  .credit { top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); }
  .hint { left: 50%; top: 50%; bottom: auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
