:root {
  --bg: #020305;
  --panel: #070a0f;
  --panel-2: #0a0f17;
  --line: rgba(255, 255, 255, 0.085);
  --line-acid: rgba(0, 255, 157, 0.36);
  --text: #eef2f7;
  --muted: #7688a1;
  --acid: #00ff9d;
  --lime: #b8ff00;
  --ice: #38e8ff;
  --warn: #f59e0b;
  --crit: #ff2e55;
  --display: "Chakra Petch", sans-serif;
  --sans: "Space Grotesk", -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100svh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.acid { color: var(--acid); }
.crit { color: var(--crit); }
.hidden { display: none !important; }

/* TOP TERMINAL HEADER */
.term-top {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 54px;
  background: rgba(4, 6, 10, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.term-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.term-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}
.term-logo svg { width: 26px; height: 26px; }
.term-word { font-family: var(--display); font-weight: 700; font-size: 16px; letter-spacing: 0.1em; }

.term-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 540px;
  background: #04070c;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 3px 3px 3px 10px;
  min-width: 0;
}
.term-search:focus-within { border-color: var(--acid); }
.term-search input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 12px;
  padding: 6px 2px;
}
.term-search input::placeholder { color: #54657d; }
.term-scan-btn {
  background: var(--acid);
  color: #02120b;
  border: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 7px 13px;
  border-radius: 2px;
  cursor: pointer;
}
.term-scan-btn:hover { background: var(--lime); }
.term-scan-btn:disabled { opacity: 0.5; cursor: wait; }

.term-right { display: flex; align-items: center; gap: 7px; flex-shrink: 0; font-size: 11px; }
.hud-stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
  color: #cbd5e1;
}
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--acid); box-shadow: 0 0 8px var(--acid); }

.ca-chip {
  background: rgba(0, 255, 157, 0.08);
  border: 1px solid var(--line-acid);
  color: var(--acid);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 3px;
  cursor: pointer;
}
.hdr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--text);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
}
.hdr-btn:hover { border-color: var(--acid); color: var(--acid); }
.hdr-btn.accent { border-color: var(--line-acid); color: var(--acid); }

/* SHELL */
.app-shell {
  display: flex;
  min-height: calc(100svh - 54px);
}

.rail {
  width: 72px;
  flex-shrink: 0;
  background: #04060a;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 10px 6px;
  gap: 6px;
}
.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 11px 4px;
  border-radius: 3px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: 0.15s;
}
.rail-btn svg { width: 19px; height: 19px; }
.rail-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.rail-btn.active {
  color: var(--acid);
  background: rgba(0, 255, 157, 0.09);
  border-color: var(--line-acid);
}
.rail-home { margin-top: auto; }

.stage {
  flex: 1;
  min-width: 0;
  padding: 12px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.view { display: none; flex-direction: column; gap: 12px; }
.view.active { display: flex; }

.err-bar {
  padding: 9px 12px;
  border-radius: 3px;
  background: rgba(255, 46, 85, 0.12);
  border: 1px solid rgba(255, 46, 85, 0.45);
  color: #ff859d;
  font-size: 11.5px;
}

/* PRESET BAR */
.preset-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11px;
}
.preset-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--panel);
  border: 1px solid var(--line);
  color: #cbd5e1;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: 0.15s;
}
.chip:hover { border-color: var(--acid); color: var(--acid); }
.chip:disabled { opacity: 0.4; cursor: not-allowed; }
.acid-chip { border-color: var(--line-acid); color: var(--acid); background: rgba(0, 255, 157, 0.07); }

/* BOXES */
.box {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 13px;
}
.box::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  width: 8px;
  height: 8px;
  border-top: 2px solid var(--acid);
  border-left: 2px solid var(--acid);
  pointer-events: none;
}
.box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 10.5px;
  letter-spacing: 0.1em;
}
.box-title { color: #cbd5e1; font-weight: 700; }
.mode-tag {
  margin-left: 8px;
  padding: 2px 6px;
  font-size: 9.5px;
  border-radius: 2px;
  background: rgba(56, 232, 255, 0.12);
  color: var(--ice);
  border: 1px solid rgba(56, 232, 255, 0.3);
}

/* RADAR WORKSPACE */
.radar-workspace {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 12px;
}
.graph-panel { display: flex; flex-direction: column; }
.legend { display: flex; gap: 10px; font-size: 10px; color: var(--muted); }
.lg { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; }
.lg.clean { background: var(--acid); }
.lg.high { background: #fb7185; }
.lg.crit { background: var(--crit); }

.graph-stage {
  position: relative;
  height: 410px;
  background: #030508;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
#fundingCanvas { width: 100%; height: 100%; display: block; }
.loader {
  position: absolute;
  inset: 0;
  background: rgba(2, 3, 5, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--acid);
  font-size: 11px;
}
.spin {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid rgba(0, 255, 157, 0.2);
  border-top-color: var(--acid);
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.node-bar {
  margin-top: 9px;
  padding: 8px 10px;
  background: #04070c;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 10.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.node-bar a { color: var(--ice); text-decoration: none; }

/* SIDE COLUMN */
.side-col { display: flex; flex-direction: column; gap: 12px; }
.score-top { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.dial-wrap { position: relative; width: 108px; height: 108px; flex-shrink: 0; }
.dial { width: 100%; height: 100%; transform: rotate(-90deg); }
.dial-bg { fill: none; stroke: rgba(255, 255, 255, 0.08); stroke-width: 9; }
.dial-fg {
  fill: none;
  stroke: var(--acid);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 314;
  stroke-dashoffset: 314;
  transition: stroke-dashoffset 0.7s ease, stroke 0.3s;
}
.dial-txt {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.dial-txt div { font-size: 30px; font-weight: 700; line-height: 1; }
.dial-txt span { font-size: 9.5px; font-weight: 700; color: var(--acid); margin-top: 4px; letter-spacing: 0.1em; }

.kpi-mini {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.km {
  background: #04070c;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 7px 8px;
}
.km span { display: block; font-family: var(--mono); font-size: 9px; }
.km strong { font-size: 12px; }

.addr-strip {
  font-size: 10px;
  color: var(--muted);
  word-break: break-all;
  padding: 6px 8px;
  background: #04070c;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.spider-wrap { height: 224px; }
#spiderCanvas { width: 100%; height: 100%; display: block; }

/* RADAR LOWER */
.radar-bottom { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 12px; }
.mini-act { background: none; border: none; color: var(--acid); cursor: pointer; font-size: 10.5px; font-weight: 700; }

.sig-grid { display: flex; flex-direction: column; gap: 8px; }
.sig-item {
  padding: 10px 12px;
  background: #04070c;
  border: 1px solid var(--line);
  border-left: 3px solid var(--acid);
  border-radius: 3px;
}
.sig-item.critical { border-left-color: var(--crit); background: rgba(255, 46, 85, 0.06); }
.sig-item.high { border-left-color: #fb7185; }
.sig-item.medium { border-left-color: var(--warn); }
.sig-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 700; margin-bottom: 3px; }
.sig-sev { font-family: var(--mono); font-size: 9px; text-transform: uppercase; padding: 2px 5px; border-radius: 2px; background: rgba(255, 255, 255, 0.08); }
.sig-item.critical .sig-sev { color: #ff6b86; background: rgba(255, 46, 85, 0.18); }
.sig-item.pass .sig-sev { color: var(--acid); background: rgba(0, 255, 157, 0.14); }
.sig-desc { font-size: 11.5px; color: var(--muted); line-height: 1.45; }

.tx-list { display: flex; flex-direction: column; gap: 7px; }
.tx-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: #04070c;
  border: 1px solid var(--line);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 11px;
  flex-wrap: wrap;
}
.tag-clean { color: var(--acid); }
.tag-leak { color: var(--crit); }
.empty-msg { font-size: 11px; color: var(--muted); padding: 10px 4px; }

/* STEALTH VIEW */
.stealth-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11.5px;
  padding: 10px 12px;
  background: rgba(0, 255, 157, 0.05);
  border: 1px solid var(--line-acid);
  border-radius: 3px;
}
.stealth-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.copy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  background: #04070c;
  border: 1px solid var(--line);
  border-radius: 3px;
  margin-bottom: 10px;
}
.copy-row.glow { border-color: var(--acid); background: rgba(0, 255, 157, 0.06); }
.copy-row code { font-size: 11px; word-break: break-all; }
.cbtn {
  background: rgba(0, 255, 157, 0.14);
  border: 1px solid var(--line-acid);
  color: var(--acid);
  font-size: 10px;
  font-weight: 700;
  padding: 5px 8px;
  border-radius: 2px;
  cursor: pointer;
  flex-shrink: 0;
}
.pair-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.kv-box {
  background: #04070c;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 8px;
}
.kv-box span { display: block; font-size: 9px; margin-bottom: 4px; }
.kv-box code { font-size: 10px; color: #94a3b8; word-break: break-all; }
.btn-row { display: flex; gap: 7px; flex-wrap: wrap; }

.stealth-inp {
  width: 100%;
  background: #04070c;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--text);
  font-size: 11.5px;
  padding: 10px;
  margin-bottom: 10px;
  outline: none;
}
.stealth-inp:focus { border-color: var(--acid); }
.derive-cta {
  width: 100%;
  background: var(--acid);
  color: #02120b;
  border: none;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 11px;
  border-radius: 3px;
  cursor: pointer;
}
.derive-cta:hover { background: var(--lime); }
.derived-panel { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.d-meta { font-size: 10.5px; line-height: 1.7; word-break: break-all; margin-bottom: 10px; }
.proof-box {
  margin-top: 10px;
  padding: 9px 10px;
  background: rgba(0, 255, 157, 0.07);
  border: 1px solid var(--line-acid);
  color: var(--acid);
  font-size: 10.5px;
  line-height: 1.6;
  word-break: break-all;
}

/* PULSE VIEW */
.pulse-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.spark-wrap { height: 140px; background: #030508; border: 1px solid var(--line); border-radius: 3px; margin-bottom: 12px; }
#sparkCanvas { width: 100%; height: 100%; display: block; }
.pulse-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pulse-kpis div { background: #04070c; border: 1px solid var(--line); padding: 10px; border-radius: 3px; }
.pulse-kpis span { display: block; font-size: 9px; margin-bottom: 4px; }
.pulse-kpis strong { font-size: 18px; }

.spec-cards { display: flex; flex-direction: column; gap: 10px; }
.sc-item { background: #04070c; border: 1px solid var(--line); padding: 12px; border-radius: 3px; }
.sc-item p { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.sc-item code { font-family: var(--mono); color: var(--ice); font-size: 11px; }

.toast {
  position: fixed;
  bottom: 72px;
  right: 16px;
  z-index: 90;
  background: #04150e;
  border: 1px solid var(--acid);
  color: var(--acid);
  font-size: 11px;
  padding: 9px 14px;
  border-radius: 3px;
}

/* MOBILE-NATIVE TERMINAL SHELL */
@media (max-width: 1040px) {
  .radar-workspace, .radar-bottom, .stealth-cols, .pulse-grid { grid-template-columns: 1fr; }
  .hide-md { display: none; }
}
@media (max-width: 720px) {
  .hide-sm { display: none; }
  .term-top { padding: 0 10px; gap: 6px; }
  .term-word { display: none; }
  .app-shell { flex-direction: column; padding-bottom: 64px; }
  .rail {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 60;
    width: 100%;
    height: 60px;
    flex-direction: row;
    justify-content: space-around;
    border-right: none;
    border-top: 1px solid var(--line);
    padding: 5px 6px;
  }
  .rail-home { margin-top: 0; }
  .rail-btn { flex: 1; padding: 6px 2px; }
  .stage { padding: 10px 10px 18px; }
  .graph-stage { height: 300px; }
  .pair-row { grid-template-columns: 1fr; }
}
