/* Innate Immune Atlas 3D — UI chrome
   Dark, low-glare shell so the 3D scene carries the color signal. */

:root {
  --bg:            #05070c;
  --panel:         rgba(14, 19, 30, 0.90);
  --panel-solid:   #0e131e;
  --edge:          rgba(255,255,255,0.10);
  --edge-strong:   rgba(255,255,255,0.20);
  --ink:           #dfe6f2;
  --ink-dim:       #8e9bb3;
  --ink-faint:     #5d6a80;
  --accent:        #46c8ff;
  --accent-warm:   #ffb454;

  --ev-S: #46d18a;
  --ev-G: #d1a246;
  --ev-I: #e0674f;

  --radius: 9px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

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

#viewport { position: fixed; inset: 0; }
#gl { display: block; width: 100%; height: 100%; }

/* CSS2D label layer sits over the canvas but must not eat pointer events */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.panel {
  position: fixed; z-index: 10;
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
}

.hidden { display: none !important; }

/* ── Left rail ─────────────────────────────────────────────── */
#rail {
  left: 14px; top: 14px; bottom: 14px; width: 268px;
  padding: 0; display: flex; flex-direction: column;
  overflow-y: auto; overscroll-behavior: contain;
}
#rail::-webkit-scrollbar { width: 8px; }
#rail::-webkit-scrollbar-thumb { background: var(--edge-strong); border-radius: 4px; }

.rail-head { padding: 15px 16px 12px; border-bottom: 1px solid var(--edge); }
.rail-head h1 { margin: 0; font-size: 14.5px; font-weight: 650; letter-spacing: 0.01em; }
.rail-head .sub { margin: 3px 0 0; font-size: 11px; color: var(--ink-faint); }

.rail-sec { padding: 13px 16px; border-bottom: 1px solid var(--edge); }
.rail-sec h2 {
  margin: 0 0 9px; font-size: 10px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-faint);
}

.chip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.chip {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 7px; border-radius: 6px; cursor: pointer;
  background: rgba(255,255,255,0.035);
  border: 1px solid transparent;
  font-size: 11px; color: var(--ink-dim);
  transition: background .13s, color .13s, border-color .13s;
  user-select: none;
}
.chip:hover { background: rgba(255,255,255,0.09); color: var(--ink); }
.chip.active { border-color: currentColor; color: var(--ink); background: rgba(255,255,255,0.10); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }

.wide-btn, .mini-btn {
  font: inherit; font-size: 11px; color: var(--ink-dim); cursor: pointer;
  background: rgba(255,255,255,0.05); border: 1px solid var(--edge);
  border-radius: 6px; padding: 6px 9px;
  transition: background .13s, color .13s;
}
.wide-btn { width: 100%; margin-top: 8px; }
.wide-btn:hover, .mini-btn:hover { background: rgba(255,255,255,0.12); color: var(--ink); }
.row-btns { display: flex; gap: 6px; margin-top: 8px; }
.row-btns .mini-btn { flex: 1; }

.layer {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 2px; cursor: pointer; user-select: none;
  font-size: 11.5px; color: var(--ink-dim);
}
.layer:hover { color: var(--ink); }
.layer .swatch {
  width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px;
  border: 1px solid rgba(255,255,255,0.25);
}
.layer input { accent-color: var(--accent); margin: 0; }
.layer.off { opacity: 0.42; }
.layer .count { margin-left: auto; font-size: 9.5px; color: var(--ink-faint); font-family: var(--mono); }

.tour {
  display: block; width: 100%; text-align: left; margin-bottom: 5px;
  padding: 7px 9px; border-radius: 6px; cursor: pointer;
  background: rgba(255,255,255,0.04); border: 1px solid var(--edge);
  color: var(--ink-dim); font: inherit; font-size: 11.5px;
  transition: background .13s, color .13s;
}
.tour:hover { background: rgba(70,200,255,0.14); color: var(--ink); border-color: rgba(70,200,255,0.4); }
.tour b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 1px; }
.tour span { font-size: 10.5px; color: var(--ink-faint); }

.toggle, .sel {
  display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; color: var(--ink-dim); padding: 3px 0; cursor: pointer;
}
.toggle input { accent-color: var(--accent); margin: 0; }
.sel { justify-content: space-between; }
.sel select {
  font: inherit; font-size: 11px; background: var(--panel-solid); color: var(--ink);
  border: 1px solid var(--edge); border-radius: 5px; padding: 3px 5px; cursor: pointer;
}

.rail-foot { padding: 11px 16px; font-size: 10px; color: var(--ink-faint); line-height: 1.7; }
.ev {
  display: inline-block; width: 15px; height: 15px; line-height: 15px; text-align: center;
  border-radius: 4px; font-size: 9px; font-weight: 700; color: #06090f; vertical-align: -2px;
}
.ev-S { background: var(--ev-S); }
.ev-G { background: var(--ev-G); }
.ev-I { background: var(--ev-I); }

/* ── Top bar / search ──────────────────────────────────────── */
#topbar { left: 296px; top: 14px; width: 340px; padding: 0; }
#search {
  width: 100%; font: inherit; font-size: 12.5px; color: var(--ink);
  background: transparent; border: 0; outline: 0; padding: 10px 13px;
}
#search::placeholder { color: var(--ink-faint); }
#search-results { max-height: 46vh; overflow-y: auto; }
#search-results:not(:empty) { border-top: 1px solid var(--edge); padding: 5px; }
.sr {
  display: flex; align-items: baseline; gap: 7px;
  padding: 6px 8px; border-radius: 5px; cursor: pointer; font-size: 12px;
}
.sr:hover, .sr.sel { background: rgba(70,200,255,0.16); }
.sr b { font-weight: 600; }
.sr i { font-style: normal; font-size: 10.5px; color: var(--ink-faint); margin-left: auto; }

/* ── Inspector ─────────────────────────────────────────────── */
#inspector {
  right: 14px; top: 14px; bottom: 14px; width: 356px;
  padding: 18px 20px 22px; overflow-y: auto; overscroll-behavior: contain;
}
#inspector::-webkit-scrollbar { width: 8px; }
#inspector::-webkit-scrollbar-thumb { background: var(--edge-strong); border-radius: 4px; }

.close-btn {
  position: absolute; right: 11px; top: 9px;
  background: none; border: 0; color: var(--ink-faint);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 2px 6px;
}
.close-btn:hover { color: var(--ink); }

.insp-kicker { font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-faint); }
.insp-title { margin: 4px 0 2px; font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.insp-full  { margin: 0 0 12px; font-size: 11.5px; color: var(--ink-dim); }

.insp-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 14px; }
.tag {
  font-size: 10px; padding: 2.5px 7px; border-radius: 20px;
  background: rgba(255,255,255,0.07); border: 1px solid var(--edge); color: var(--ink-dim);
}
.tag.ev-S { background: rgba(70,209,138,0.16); border-color: rgba(70,209,138,0.45); color: #7ce4ae; }
.tag.ev-G { background: rgba(209,162,70,0.16); border-color: rgba(209,162,70,0.45); color: #e6c07a; }
.tag.ev-I { background: rgba(224,103,79,0.16); border-color: rgba(224,103,79,0.45); color: #f09079; }

#inspector h4 {
  margin: 16px 0 6px; font-size: 10px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-faint);
}
#inspector p { margin: 0 0 9px; font-size: 12.5px; color: var(--ink); }
#inspector .dim { color: var(--ink-dim); font-size: 12px; }

.samhd1-box {
  border-left: 2.5px solid var(--accent-warm);
  background: rgba(255,180,84,0.07);
  padding: 9px 11px; border-radius: 0 6px 6px 0; margin: 4px 0 10px;
  font-size: 12px;
}

/* Case notes — private build only, deliberately conspicuous */
#inspector h4.private-head { color: #e0674f; }
.case-box {
  border: 1px dashed rgba(224,103,79,0.55);
  background: repeating-linear-gradient(
    -45deg, rgba(224,103,79,0.05) 0 10px, rgba(224,103,79,0.09) 10px 20px);
  padding: 10px 12px; border-radius: 6px; margin: 4px 0 10px;
}
.case-box p { font-size: 12px !important; margin: 0 0 8px !important; }
.case-box p:last-child { margin-bottom: 0 !important; }

.edge-list { list-style: none; margin: 0; padding: 0; }
.edge-list li {
  display: flex; gap: 7px; align-items: baseline;
  padding: 5px 7px; border-radius: 5px; cursor: pointer; font-size: 11.5px;
  color: var(--ink-dim);
}
.edge-list li:hover { background: rgba(255,255,255,0.07); color: var(--ink); }
.edge-list .arrow { font-family: var(--mono); font-size: 12px; flex: 0 0 auto; }
.edge-list .en { color: var(--ink); font-weight: 550; }
.edge-list .el { font-size: 10.5px; color: var(--ink-faint); }

.ref-list { list-style: none; margin: 0; padding: 0; font-size: 11px; color: var(--ink-dim); }
.ref-list li { padding: 3px 0 3px 13px; text-indent: -13px; }
.ref-list a { color: var(--accent); text-decoration: none; }
.ref-list a:hover { text-decoration: underline; }

.drug-pill {
  display: inline-block; font-size: 10.5px; padding: 3px 8px; border-radius: 20px;
  background: rgba(70,200,255,0.13); border: 1px solid rgba(70,200,255,0.35);
  color: #8fdcff; margin: 0 4px 4px 0; cursor: pointer;
}
.drug-pill:hover { background: rgba(70,200,255,0.28); }

/* ── Hint bar ──────────────────────────────────────────────── */
#hint {
  left: 296px; bottom: 14px; padding: 7px 12px;
  font-size: 10.5px; color: var(--ink-faint); max-width: 620px;
}
#hint b { color: var(--ink-dim); font-weight: 600; }

/* ── 3D labels (CSS2DRenderer) ─────────────────────────────── */
.node-label {
  font-family: var(--font); font-size: 11px; font-weight: 550;
  color: #eef3fb; text-shadow: 0 1px 3px #000, 0 0 9px rgba(0,0,0,0.95);
  white-space: nowrap; pointer-events: none; user-select: none;
  transform: translateY(-2px);
}
.node-label.dim { color: #93a2ba; font-size: 10px; font-weight: 450; }
.compartment-label {
  font-family: var(--font); font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.14em;
  text-shadow: 0 1px 4px #000; white-space: nowrap;
  pointer-events: none; user-select: none; opacity: 0.75;
}

/* ── Tour caption ──────────────────────────────────────────── */
#tour-hud {
  position: fixed; z-index: 12; left: 50%; bottom: 26px; transform: translateX(-50%);
  width: min(660px, calc(100vw - 720px));
  background: var(--panel); backdrop-filter: blur(14px);
  border: 1px solid var(--edge); border-radius: var(--radius);
  padding: 14px 18px; box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}
#tour-hud .step-kicker { font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--accent); }
#tour-hud h3 { margin: 4px 0 5px; font-size: 15px; font-weight: 620; }
#tour-hud p { margin: 0; font-size: 12.5px; color: var(--ink-dim); }
#tour-hud .nav { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
#tour-hud .nav .spacer { flex: 1; }
#tour-hud .dots { display: flex; gap: 4px; }
#tour-hud .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--edge-strong); display: block; }
#tour-hud .dots i.on { background: var(--accent); }

#loading {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: var(--bg); color: var(--ink-faint); font-size: 13px;
  transition: opacity .5s; pointer-events: none;
}
#loading.done { opacity: 0; }

@media (max-width: 1180px) {
  #topbar { left: 296px; width: 260px; }
  #inspector { width: 300px; }
  #hint { display: none; }
  #tour-hud { width: min(560px, calc(100vw - 640px)); }
}

/* ── Stream chips ─────────────────────────────────────────────── */
.stream {
  display: flex; align-items: center; gap: 8px; width: 100%;
  margin-bottom: 4px; padding: 6px 8px 6px 0;
  background: rgba(255,255,255,0.03); border: 1px solid transparent;
  border-radius: 6px; cursor: pointer; font: inherit; text-align: left;
  color: var(--ink-dim); transition: background .13s, border-color .13s, color .13s;
}
.stream:hover { background: rgba(255,255,255,0.09); color: var(--ink); }
.stream.active { border-color: var(--stream); background: color-mix(in srgb, var(--stream) 16%, transparent); color: var(--ink); }
.stream .bar { width: 4px; align-self: stretch; border-radius: 3px; background: var(--stream); flex: 0 0 4px; }
.stream .txt { flex: 1; min-width: 0; }
.stream .txt b { display: block; font-size: 11.5px; font-weight: 620; color: var(--stream); }
.stream .txt span { display: block; font-size: 9.5px; color: var(--ink-faint); line-height: 1.35; }
.stream .ev { flex: 0 0 15px; }

#btn-consequences {
  border-color: rgba(255,180,84,0.4); color: var(--accent-warm);
  background: rgba(255,180,84,0.08); font-weight: 550;
}
#btn-consequences:hover { background: rgba(255,180,84,0.2); color: #ffd8a0; }

/* ── Pills, chains, hops (stream + consequences inspectors) ───── */
.pill-row { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.node-pill {
  font-size: 10.5px; padding: 3px 8px; border-radius: 20px; cursor: pointer;
  background: rgba(255,255,255,0.06); border: 1px solid var(--edge); color: var(--ink);
  transition: background .12s;
}
.node-pill:hover { background: rgba(255,255,255,0.18); }

.chain-list { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.chain-list li {
  position: relative; padding: 6px 8px 6px 26px; border-radius: 5px;
  cursor: pointer; font-size: 11.5px; color: var(--ink-dim);
  border-left: 2px solid var(--edge); margin-left: 4px;
}
.chain-list li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 7px; top: 7px;
  font-family: var(--mono); font-size: 9px; color: var(--ink-faint);
}
.chain-list li:hover { background: rgba(255,255,255,0.07); color: var(--ink); }
.chain-list .en { color: var(--ink); font-weight: 600; }
.chain-list .el { font-size: 10px; color: var(--ink-faint); }
.chain-list .cb {
  font-style: normal; font-size: 8.5px; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 1px 5px; border-radius: 8px; margin-left: 6px; vertical-align: 1px;
}
.chain-list .cb.in  { background: rgba(70,209,138,0.22); color: #7ce4ae; }
.chain-list .cb.out { background: rgba(224,103,79,0.22); color: #f09079; }

.hop { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 7px; }
.hop-n {
  flex: 0 0 20px; text-align: center; font-family: var(--mono); font-size: 10px;
  color: var(--ink-faint); background: rgba(255,255,255,0.05);
  border-radius: 4px; padding: 2px 0; margin-top: 2px;
}

/* ── Cascade path mode ────────────────────────────────────────── */
.path-preset:hover { background: rgba(255,215,94,0.14); border-color: rgba(255,215,94,0.4); }

.trace-btn {
  display: block; width: 100%; margin: 14px 0 4px; padding: 8px 10px;
  font: inherit; font-size: 11.5px; font-weight: 550; text-align: left; cursor: pointer;
  color: #ffd75e; background: rgba(255,215,94,0.09);
  border: 1px solid rgba(255,215,94,0.35); border-radius: 6px;
  transition: background .13s;
}
.trace-btn:hover { background: rgba(255,215,94,0.22); }

.route-list { list-style: none; margin: 0; padding: 0; }
.route-list li {
  padding: 8px 10px; margin-bottom: 5px; border-radius: 6px; cursor: pointer;
  background: rgba(255,255,255,0.035); border: 1px solid transparent;
  transition: background .12s, border-color .12s;
}
.route-list li:hover { background: rgba(255,255,255,0.10); }
.route-list li.sel { border-color: rgba(255,215,94,0.5); background: rgba(255,215,94,0.12); }
.route-head { display: flex; align-items: center; gap: 7px; margin-bottom: 3px; }
.route-sign { font-size: 15px; font-weight: 700; line-height: 1; width: 12px; }
.route-sign.up { color: #e0674f; }
.route-sign.down { color: #46d18a; }
.route-n { font-size: 11px; color: var(--ink); font-weight: 600; }
.route-loops {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 1px 6px; border-radius: 8px;
  background: rgba(192,107,255,0.2); color: #d3a6ff;
}
.route-via { font-size: 10.5px; color: var(--ink-faint); line-height: 1.4; }

/* Stepper HUD — reuses #tour-hud geometry with its own accents */
#tour-hud.path-hud { border-color: rgba(255,215,94,0.3); }
.path-hud .step-kicker { color: var(--ink-faint); text-transform: none; letter-spacing: 0; font-size: 10.5px; }
.path-hud .step-kicker b.up { color: #e0674f; }
.path-hud .step-kicker b.down { color: #46d18a; }
.path-hud h3 { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.path-hud .hop-node {
  cursor: pointer; border-bottom: 1px dashed rgba(255,255,255,0.25);
}
.path-hud .hop-node:hover { color: var(--accent); border-bottom-color: var(--accent); }
.path-hud .hop-kind { font-size: 20px; line-height: 1; }
.path-hud .step-meta {
  display: flex; align-items: center; gap: 7px; margin-top: 9px;
  font-size: 10.5px; color: var(--ink-dim);
}
.path-hud .dots i.past { background: rgba(255,215,94,0.55); }
.path-hud .dots i.on { background: #ffd75e; }
