:root {
  --bg: #0f1419;
  --bg-panel: #171e27;
  --bg-elev: #1e2733;
  --border: #2a3544;
  --text: #e7ecf1;
  --muted: #8b9aab;
  --accent: #5eb0ff;
  --ie: #f0a04b;
  --e: #5eb0ff;
  --l: #7dce9a;
  --lat: #c9a0e8;
  --unk: #9aa6b4;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  grid-template-rows: auto 1fr auto;
  height: 100%;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar .sub {
  color: var(--muted);
  font-size: 12px;
}

.sidebar, .detail {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow: auto;
  padding: 12px;
}

.detail {
  border-right: none;
  border-left: 1px solid var(--border);
}

.chart-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.chart-area {
  flex: 1;
  min-height: 0;
  position: relative;
  padding: 8px 12px 4px;
}

svg.chart {
  width: 100%;
  height: 100%;
  display: block;
}

.hint {
  position: absolute;
  left: 72px;
  top: 16px;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}

label.ctrl, .chip, button.btn {
  font-size: 12px;
  color: var(--text);
}

.chip, button.btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text);
}

.chip.active, button.btn.primary {
  border-color: var(--accent);
  color: var(--accent);
  background: #1a2a3a;
}

.chip:hover, button.btn:hover { border-color: #4a5d73; }

.search {
  width: 100%;
  margin: 8px 0;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 4px 0 6px;
}

.gene-list { display: flex; flex-direction: column; gap: 2px; }

.gene-row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.gene-row:hover, .gene-row.hovered { background: var(--bg-elev); }
.gene-row.pinned { background: #1a2d22; }
.gene-row .swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3a4654;
}
.gene-row .name { font-family: var(--mono); font-size: 12px; }
.gene-row .meta { font-size: 11px; color: var(--muted); }

.cls-IE { color: var(--ie); }
.cls-E { color: var(--e); }
.cls-L { color: var(--l); }
.cls-Latent { color: var(--lat); }
.cls-Unk { color: var(--unk); }

.legend-line { stroke-width: 2.4; fill: none; }
.ghost { fill: none; stroke: #6b7c8d; stroke-width: 1; opacity: 0.13; }
.band { fill: #5eb0ff; opacity: 0.08; }
.median { fill: none; stroke: #8b9aab; stroke-width: 1.5; stroke-dasharray: 4 3; opacity: 0.55; }
.focus { fill: none; stroke-width: 2.4; }
.focus.hovered { stroke-width: 3.6; }
.ghost.hovered { opacity: 0.95; stroke: #e7ecf1; stroke-width: 2.2; }

.axis text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.axis line, .axis path { stroke: #334155; }
.grid line { stroke: #243040; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: #0b1016;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  display: none;
  z-index: 5;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.tooltip strong { font-family: var(--mono); }

.detail h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-family: var(--mono);
}
.detail .empty { color: var(--muted); font-size: 13px; line-height: 1.45; }
.kv { display: grid; grid-template-columns: 88px 1fr; gap: 4px 8px; font-size: 12px; margin: 10px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }

table.pts {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: var(--mono);
}
table.pts th, table.pts td {
  text-align: right;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}
table.pts th:first-child, table.pts td:first-child { text-align: left; }
table.pts .peak td { color: var(--accent); }

.note {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
  margin-top: 14px;
}

.cite {
  grid-column: 1 / -1;
  padding: 8px 18px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
}
.cite a { color: var(--accent); text-decoration: none; }
.cite a:hover { text-decoration: underline; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 420px auto; }
  .sidebar, .detail { border: none; max-height: 280px; }
}
