:root {
  --bg: #080d19;
  --surface: #101829;
  --surface-2: #162238;
  --border: #23324f;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22d3ee;
  --accent-2: #38bdf8;
  --green: #34d399;
  --amber: #f59e0b;
  --rose: #fb7185;
  --mono: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
  color: #bae6fd;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px 18px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 10px;
  border-right: 1px solid var(--border);
}

.tool-group:last-child {
  border-right: none;
  padding-right: 0;
}

.btn {
  appearance: none;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 11px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: #1d2c48;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: #0e7490;
  border-color: #06b6d4;
  color: #f8fafc;
}

.btn-primary:hover:not(:disabled) {
  background: #0891b2;
}

.btn-quiet {
  color: #cbd5e1;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 12px;
}

.select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
}

.select-sm {
  padding: 3px 6px;
  font-size: 12px;
}

.select-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}

.badge-live {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
  border-color: rgba(52, 211, 153, 0.4);
}

.badge-file {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-2);
  border-color: rgba(56, 189, 248, 0.4);
}

.badge-demo {
  background: rgba(245, 158, 11, 0.15);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.4);
}

.badge-warn {
  background: rgba(251, 113, 133, 0.15);
  color: var(--rose);
  border-color: rgba(251, 113, 133, 0.4);
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  background: #0c1322;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.status-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.dot-info { background: var(--accent); }
.dot-ok { background: var(--green); }
.dot-warn { background: var(--amber); }
.dot-error { background: var(--rose); }

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
}

.progress-wrap progress {
  width: 140px;
  height: 10px;
}

.help-banner {
  margin: 12px 20px 0;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
  font-size: 13px;
}

.help-banner strong {
  color: #fde68a;
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 10px;
  padding: 14px 20px 6px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.kpi.clickable {
  cursor: pointer;
}

.kpi.clickable:hover {
  border-color: var(--accent);
}

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.kpi-value {
  margin-top: 3px;
  font-size: 17px;
  font-weight: 700;
  font-family: var(--mono);
}

.kpi-sub {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--muted);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 20px 0;
  border-bottom: 1px solid var(--border);
}

.tab {
  appearance: none;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--border);
  position: relative;
  top: 1px;
}

.workspace {
  padding: 16px 20px 36px;
}

.tab-panel[hidden] {
  display: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  min-width: 0;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 10px;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.card-subhead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 14px 0 6px;
}

.card-subhead h3 {
  margin: 0;
  font-size: 13.5px;
}

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

.overview-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.two-col,
.detail-split {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 14px;
}

@media (max-width: 1050px) {
  .two-col,
  .detail-split {
    grid-template-columns: minmax(0, 1fr);
  }
}

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.chart-host {
  width: 100%;
}

.curve-svg,
.dist-svg,
.mini-svg {
  width: 100%;
  height: auto;
  display: block;
}

.grid-line {
  stroke: #1e2d48;
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.grid-line.threshold {
  stroke: rgba(245, 158, 11, 0.55);
  stroke-dasharray: 5 4;
}

.plot-border {
  stroke: #32476d;
  stroke-width: 1;
}

.axis-tick {
  fill: #94a3b8;
  font-size: 10.5px;
  font-family: var(--mono);
}

.axis-subtick {
  fill: #64748b;
  font-size: 9.5px;
  font-family: var(--mono);
}

.axis-tick-midi {
  fill: #38bdf8;
  font-size: 10.5px;
  font-family: var(--mono);
}

.axis-label {
  fill: #94a3b8;
  font-size: 11px;
}

.peer-envelope {
  fill: rgba(56, 189, 248, 0.1);
}

.peer-curve {
  fill: none;
  stroke: rgba(148, 163, 184, 0.25);
  stroke-width: 1.1;
}

.peer-curve.outlier {
  stroke: rgba(251, 113, 133, 0.42);
}

.default-curve {
  fill: none;
  stroke: #94a3b8;
  stroke-width: 1.8;
  stroke-dasharray: 6 4;
}

.default-anchor {
  fill: #0b1120;
  stroke: #cbd5e1;
  stroke-width: 1.5;
}

.anchor-tag {
  fill: #e2e8f0;
  font-size: 10px;
  font-family: var(--mono);
}

.probe-line {
  stroke: var(--amber);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.probe-dot {
  fill: var(--amber);
  stroke: #080d19;
  stroke-width: 2;
}

.crosshair-line {
  stroke: rgba(226, 232, 240, 0.45);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.mini-diag {
  stroke: #1e293b;
  stroke-width: 1;
}

.mini-default {
  fill: none;
  stroke: #64748b;
  stroke-width: 1.2;
  stroke-dasharray: 3 2;
}

.dist-whisker {
  stroke: #64748b;
  stroke-width: 1.6;
}

.dist-iqr {
  fill: rgba(34, 211, 238, 0.18);
  stroke: rgba(34, 211, 238, 0.55);
  stroke-width: 1;
}

.dist-median {
  stroke: #22d3ee;
  stroke-width: 2.2;
}

.dist-dot {
  fill: #38bdf8;
  opacity: 0.78;
}

.dist-dot.outlier {
  fill: var(--rose);
  opacity: 0.95;
}

.dist-dot.selected {
  fill: #ffffff;
  stroke: var(--amber);
  stroke-width: 2;
  opacity: 1;
}

.hover-readout {
  font-family: var(--mono);
  font-size: 12px;
  color: #cbd5e1;
  background: #0b1322;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 8px;
}

.pin-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.pin-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.pin-swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

/* Pad Matrix */
.pad-matrix {
  display: grid;
  grid-template-columns: repeat(8, minmax(105px, 1fr));
  gap: 8px;
}

@media (max-width: 960px) {
  .pad-matrix {
    grid-template-columns: repeat(4, minmax(100px, 1fr));
  }
}

.pad-tile {
  background: #0c1424;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
  cursor: pointer;
  transition: border-color 0.14s, transform 0.1s;
  user-select: none;
}

.pad-tile:hover {
  border-color: var(--accent-2);
}

.pad-tile.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  background: #13213b;
}

.pad-tile.pinned {
  border-color: var(--amber);
}

.pad-tile.outlier {
  border-color: rgba(251, 113, 133, 0.75);
}

.tile-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  font-weight: 600;
  margin-bottom: 3px;
}

.tile-meta {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 3px;
}

/* Piano Bed */
.piano-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}

.piano-bed {
  position: relative;
  height: 122px;
  min-width: 780px;
  user-select: none;
}

.piano-key {
  position: absolute;
  top: 0;
  border-radius: 0 0 6px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 6px;
  font-family: var(--mono);
  font-size: 10px;
  transition: transform 0.08s;
}

.piano-key.white {
  height: 118px;
  background: #e2e8f0;
  color: #0f172a;
  border: 1px solid #334155;
  z-index: 1;
}

.piano-key.black {
  height: 74px;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #475569;
  z-index: 4;
}

.piano-key.selected {
  box-shadow: inset 0 0 0 2.5px var(--accent);
}

.piano-key.white.selected {
  z-index: 2;
}

.piano-key.black.selected {
  z-index: 5;
}

.piano-key.pinned {
  box-shadow: inset 0 -5px 0 var(--amber);
}

.piano-key.outlier::after {
  content: "";
  position: absolute;
  top: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rose);
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  appearance: none;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.pill.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(34, 211, 238, 0.1);
}

.keys-mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 8px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

th,
td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td.mono,
th.mono {
  font-family: var(--mono);
}

td.wrap-cell {
  white-space: normal;
  min-width: 140px;
}

.delta-pos { color: #38bdf8; }
.delta-neg { color: #fbbf24; }
.delta-warn { color: var(--rose); font-weight: 700; }

/* Pedal Probe */
.probe-box {
  background: #0c1424;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.probe-box input[type="range"] {
  width: 100%;
  margin: 8px 0;
}

.probe-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-family: var(--mono);
  font-size: 12.5px;
}

/* Hex Dump */
.hex-dump {
  margin: 0;
  max-height: 460px;
  overflow: auto;
  background: #070b14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  color: #cbd5e1;
}

.hex-row-pad { color: #67e8f9; }
.hex-row-key { color: #93c5fd; }
.hex-row-pedal { color: #fcd34d; }
.hex-row-marker { color: #6ee7b7; font-weight: 600; }

/* Drag & Drop */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 13, 25, 0.85);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-overlay[hidden] {
  display: none;
}

.drop-box {
  padding: 34px 48px;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: var(--surface);
  font-size: 16px;
  font-weight: 600;
}
