:root {
  --bg: #0f1116;
  --panel: #161922;
  --panel-2: #1d212c;
  --line: #2a2f3d;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #7aa2ff;
  --down: #ff8a4c;
  --up: #4cc2ff;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }

header {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: .01em; margin-right: 6px; }
.spacer { flex: 1; }
header button, header select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer;
}
header button:hover, header select:hover { border-color: #3c4458; }
header select { max-width: 280px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; color: var(--muted); }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { background: #2b3350; color: var(--text); border-color: #46527a; position: relative; }
.chk { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); cursor: pointer; user-select: none; }

main { flex: 1; display: grid; grid-template-columns: 260px 1fr 360px; min-height: 0; }
aside { background: var(--panel); overflow-y: auto; min-height: 0; }
#left { border-right: 1px solid var(--line); padding: 10px; }
#right { border-left: 1px solid var(--line); padding: 14px 16px 30px; }

#search {
  width: 100%; padding: 7px 10px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--line); outline: none;
}
#search:focus { border-color: var(--accent); }

.fgroup { margin-top: 12px; }
.fgroup h4, .sec h4 {
  margin: 0 0 6px; font-size: 10.5px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; font-size: 11.5px;
  background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; user-select: none;
}
.chip.off { opacity: .38; text-decoration: line-through; }
.chip.static { cursor: default; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dash { width: 14px; height: 0; border-top: 2px solid; flex: none; }

#nodeList { margin-top: 14px; }
#nodeList h5 {
  margin: 12px 0 3px; font-size: 11px; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.nl-item {
  display: flex; align-items: baseline; gap: 6px; padding: 3px 6px; border-radius: 5px; cursor: pointer;
}
.nl-item:hover { background: var(--panel-2); }
.nl-item.sel { background: #2b3350; }
.nl-item.down { box-shadow: inset 2px 0 0 var(--down); }
.nl-item.up { box-shadow: inset 2px 0 0 var(--up); }
.nl-item .dot { transform: translateY(-1px); }
.nl-item .ln { margin-left: auto; color: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 8px 6px; }

#stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#graph { width: 100%; height: 100%; display: block; cursor: grab; }
#graph:active { cursor: grabbing; }

.lane rect { fill: #ffffff; fill-opacity: .025; }
.lane:nth-child(even) rect { fill-opacity: .05; }
.lane text { font-size: 15px; font-weight: 650; }

.link path.vis { fill: none; stroke-width: 1.6; stroke-opacity: .5; }
.link.soft path.vis { stroke-width: 1; stroke-opacity: .32; }
.link.inferred path.vis { stroke-dasharray: 5 4; }
.link path.hit { fill: none; stroke: transparent; stroke-width: 12; cursor: help; }
.link.dim path.vis { stroke-opacity: .05; }
.link.down path.vis { stroke: var(--down); stroke-opacity: .95; stroke-width: 2.2; }
.link.up path.vis { stroke: var(--up); stroke-opacity: .95; stroke-width: 2.2; }
.link.soft.down path.vis, .link.soft.up path.vis { stroke-width: 1.3; stroke-opacity: .75; }
.link.hidden, .node.hidden { display: none; }

.node { cursor: pointer; }
.node circle { stroke: #0f1116; stroke-width: 1.5; }
.node text {
  fill: var(--text); font-size: 10.5px; text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: var(--bg); stroke-width: 3.5px; stroke-linejoin: round;
}
.node.dim { opacity: .13; }
.node.down circle { stroke: var(--down); stroke-width: 3; }
.node.up circle { stroke: var(--up); stroke-width: 3; }
.node.sel circle { stroke: #fff; stroke-width: 4; }
.node.sel text { font-weight: 700; font-size: 12px; }
.node.match circle { stroke: #fff; stroke-width: 2.5; stroke-dasharray: 3 2; }
.node:hover text { font-weight: 700; }

#hint {
  position: absolute; left: 12px; bottom: 10px; color: var(--muted); font-size: 11.5px;
  background: #0f1116cc; padding: 4px 8px; border-radius: 6px; pointer-events: none;
}
#hint .k { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 2.5px solid; vertical-align: -1px; }
#hint .k.down { border-color: var(--down); }
#hint .k.up { border-color: var(--up); }

#tooltip {
  position: absolute; max-width: 320px; pointer-events: none; z-index: 5;
  background: #05070bf2; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 6px 24px #0008;
}
#tooltip b { display: block; margin-bottom: 2px; }
#tooltip .t-meta { color: var(--muted); font-size: 11px; }

#banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); max-width: 80%;
  background: #4a1d1d; border: 1px solid #8a3b3b; color: #ffd9d9; padding: 8px 12px; border-radius: 8px;
  white-space: pre-wrap; font-size: 12px; z-index: 6;
}
#drop {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: #0f1116e6; z-index: 7;
}
#drop[hidden] { display: none; }
#drop > div { border: 2px dashed #3c4458; border-radius: 14px; padding: 40px 56px; max-width: 520px; }
#drop h2 { margin: 0 0 8px; }
#drop p { color: var(--muted); margin: 0; }
body.dragging #drop > div { border-color: var(--accent); }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* details panel */
#right h2 { margin: 8px 0 2px; font-size: 18px; line-height: 1.25; }
#right h1 { margin: 0 0 2px; font-size: 19px; line-height: 1.25; }
#right .sub { color: var(--muted); margin-bottom: 10px; }
#right p { margin: 8px 0; }
.meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.meta .lines { color: var(--muted); font-size: 11.5px; margin-left: 4px; }
blockquote {
  margin: 10px 0; padding: 6px 12px; border-left: 3px solid #46527a; color: #cdd3e3;
  background: var(--panel-2); border-radius: 0 6px 6px 0; font-style: italic;
}
.sec { margin-top: 18px; }
.impact { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.impact div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.impact .n { font-size: 20px; font-weight: 650; line-height: 1.1; }
.impact .down .n { color: var(--down); }
.impact .up .n { color: var(--up); }
.impact .l { color: var(--muted); font-size: 11px; }
.rel {
  padding: 7px 9px; border-radius: 7px; background: var(--panel-2); border: 1px solid var(--line);
  margin-bottom: 5px; cursor: pointer;
}
.rel:hover { border-color: #46527a; }
.rel .top { display: flex; align-items: center; gap: 6px; }
.rel .name { font-weight: 600; }
.rel .etype { margin-left: auto; font-size: 10.5px; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.rel .note { color: #b6bdcf; font-size: 12px; margin-top: 2px; }
.tag { font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; padding: 0 5px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.occ { display: flex; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--line); font-size: 12px; }
.occ:last-child { border-bottom: 0; }
.occ .g { flex: none; width: 118px; color: var(--muted); }
.occ .ln { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
details { margin-top: 16px; }
summary { cursor: pointer; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; }
.script { margin-top: 8px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.script div { display: flex; gap: 8px; padding: 1px 0; }
.script i { flex: none; width: 28px; text-align: right; color: #566078; font-style: normal; font-variant-numeric: tabular-nums; }
.script .ctx { opacity: .45; }
.top-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.top-item:hover { background: var(--panel-2); }
.top-item .cnt { margin-left: auto; color: var(--down); font-weight: 650; font-variant-numeric: tabular-nums; }
.clear { float: right; background: none; border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; cursor: pointer; color: var(--muted); }
.clear:hover { color: var(--text); }

@media (max-width: 1000px) {
  main { grid-template-columns: 1fr; grid-template-rows: 55vh auto auto; overflow-y: auto; }
  body { overflow: auto; }
  #stage { order: 1; height: 55vh; }
  #right { order: 2; border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  #left { order: 3; border-right: 0; border-top: 1px solid var(--line); overflow: visible; }
}
