:root {
  --bg: #0a0d12;
  --panel: #11161f;
  --panel-2: #161c27;
  --line: #232b38;
  --text: #e8ebf0;
  --muted: #8a93a3;
  --amber: #ffb020;     /* primary action / live accent */
  --cyan: #39d0d8;      /* secondary data accent */
  --radius: 10px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --display: "Chakra Petch", var(--mono);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* --- header --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0d1118, var(--bg));
}
.brand { display: flex; align-items: stretch; gap: 16px; }
.brand .rule {
  width: 4px; border-radius: 2px;
  background: linear-gradient(180deg, var(--amber), var(--cyan));
}
.brand h1 {
  font-family: var(--display);
  font-weight: 700; letter-spacing: 0.22em;
  margin: 0; font-size: 22px;
}
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

main { max-width: 1180px; margin: 0 auto; padding: 20px 24px 48px; }

/* --- panels --- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
#controls {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.field.grow { flex: 1 1 320px; min-width: 260px; }
label {
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted);
}
.hint { color: var(--amber); text-transform: none; letter-spacing: 0; }

select {
  appearance: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono); font-size: 13px;
  cursor: pointer;
}
select:disabled { opacity: 0.45; cursor: not-allowed; }
select:focus-visible, button:focus-visible {
  outline: 2px solid var(--cyan); outline-offset: 1px;
}

/* --- driver chips --- */
.drivers {
  display: flex; flex-wrap: wrap; gap: 8px;
  min-height: 42px; align-content: flex-start;
}
.placeholder { color: var(--muted); font-size: 12px; padding: 10px 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--mono);
  cursor: pointer; user-select: none;
  font-weight: 500; font-size: 13px;
  transition: border-color .12s, background .12s;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip:hover { border-color: var(--muted); }
.chip.selected { background: color-mix(in srgb, var(--chip) 22%, var(--panel-2)); border-color: var(--chip); }

/* --- view selector --- */
.viewbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--panel-2); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.seg {
  border: 0; background: transparent; color: var(--muted);
  padding: 9px 14px; border-radius: 7px; cursor: pointer;
  font-family: var(--display); font-weight: 600; letter-spacing: 0.04em; font-size: 13px;
}
.seg:hover { color: var(--text); }
.seg.active { background: var(--bg); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.render {
  border: 0; cursor: pointer;
  background: var(--amber); color: #1a1205;
  font-family: var(--display); font-weight: 700; letter-spacing: 0.06em;
  padding: 11px 26px; border-radius: 9px; font-size: 14px;
}
.render:hover { filter: brightness(1.06); }
.render:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }

.actions { display: flex; align-items: center; gap: 14px; }
.auto {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--muted); cursor: pointer; user-select: none;
  font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase;
}
.auto input { accent-color: var(--amber); width: 15px; height: 15px; cursor: pointer; }
.auto:hover { color: var(--text); }

.status { min-height: 18px; margin: 4px 2px 12px; color: var(--muted); font-size: 12px; }
.status.error { color: #ff6b6b; }

/* --- plot --- */
.plotwrap { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
#plot { width: 100%; min-height: 200px; }
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: rgba(10,13,18,0.82); border-radius: var(--radius);
}
/* .overlay sets display:flex, which would otherwise beat the `hidden`
   attribute's UA display:none (same specificity). This makes hidden win. */
.overlay[hidden] { display: none; }
.overlay p { color: var(--muted); font-size: 13px; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--amber);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

footer { border-top: 1px solid var(--line); padding: 16px 24px; }
footer p { margin: 0; color: var(--muted); font-size: 11px; }

@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
@media (max-width: 640px) {
  .brand h1 { font-size: 18px; letter-spacing: 0.16em; }
  .field, .field.grow { min-width: 100%; flex-basis: 100%; }
  .viewbar { flex-direction: column; align-items: stretch; }
  .actions { width: 100%; justify-content: space-between; }
  .render { flex: 1; }
}
