:root {
  --bg-0: #07080d;
  --bg-1: #0d1019;
  --bg-2: #131726;
  --bg-3: #1a1f33;
  --line: #232a44;
  --ink-0: #e6ecff;
  --ink-1: #aab3d5;
  --ink-2: #6b7299;
  --accent: #ff5fb0;
  --accent-2: #5fe2ff;
  --accent-3: #c084ff;
  --warn: #ffb53d;
  --bad: #ff5d6c;
  --good: #6ce58b;
  --shadow: 0 4px 24px #000a;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(ellipse at top left, #11142a 0%, #07080d 70%) fixed;
  color: var(--ink-0);
  font: 13px/1.4 -apple-system, "SF Pro Text", "Inter", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100vh;
}

/* ─────────── topbar ─────────── */
#topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 18px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 250px;
}
.brand h1 {
  font-size: 14px;
  margin: 0;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink-0);
}
.brand-sub {
  color: var(--ink-2);
  font-size: 11px;
  letter-spacing: 0.04em;
}
.brand-glyph {
  width: 14px; height: 14px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, var(--accent) 0%, transparent 50%),
    radial-gradient(circle at 70% 70%, var(--accent-2) 0%, transparent 50%);
  box-shadow: 0 0 14px var(--accent), 0 0 8px var(--accent-2) inset;
  align-self: center;
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  flex: 1;
}

.ctl {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.ctl > span:first-child { padding-left: 2px; }
.ctl select {
  background: var(--bg-0);
  color: var(--ink-0);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
  font: inherit;
  font-size: 12px;
  text-transform: none;
  letter-spacing: normal;
  outline: none;
  min-width: 110px;
  cursor: pointer;
  transition: border-color 0.12s;
}
.ctl select:hover { border-color: var(--accent-2); }
.ctl select:focus { border-color: var(--accent); }

.ctl.toggle {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
}
.ctl.toggle input { accent-color: var(--accent); }

.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--bg-0);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  height: 28px;
  text-transform: none;
  letter-spacing: normal;
}
.stepper button {
  background: none;
  border: none;
  color: var(--ink-1);
  width: 26px;
  height: 100%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.stepper button:hover { color: var(--accent); }
.stepper #voices-count {
  min-width: 28px;
  text-align: center;
  color: var(--ink-0);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

button {
  font: inherit;
  cursor: pointer;
}

button.primary, button.danger, button.ghost {
  border: 1px solid var(--line);
  background: var(--bg-0);
  color: var(--ink-1);
  padding: 8px 14px;
  border-radius: 6px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.15s;
}
button.primary {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 0 var(--accent);
}
button.primary:hover { background: var(--accent); color: var(--bg-0); }
button.primary.engaged {
  background: var(--accent);
  color: var(--bg-0);
  box-shadow: 0 0 14px -2px var(--accent);
}
button.danger { color: var(--bad); border-color: var(--bad); }
button.danger:hover { background: var(--bad); color: var(--bg-0); }
button.ghost:hover { color: var(--accent-2); border-color: var(--accent-2); }

/* ─────────── stage ─────────── */
#stage {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 280px;
  overflow: hidden;
}

#field {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  /* Prevent iOS Safari from intercepting the touch as scroll/zoom. */
  touch-action: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background:
    radial-gradient(ellipse at center, #0e1226 0%, #07080d 80%);
}

.field-axes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: var(--ink-2);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.axis {
  position: absolute;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.axis-x {
  bottom: 12px;
  left: 24px;
  right: 304px;
}
.axis-x span:nth-child(2) { color: var(--ink-1); }
.axis-y {
  top: 24px;
  bottom: 28px;
  left: 14px;
  flex-direction: column-reverse;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
.axis-y span:nth-child(2) { color: var(--ink-1); }

/* ─────────── globals (sidebar) ─────────── */
#globals {
  background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
  border-left: 1px solid var(--line);
  padding: 18px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#globals h2 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-2);
  font-weight: 500;
}

.slider-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider {
  display: grid;
  grid-template-columns: 70px 1fr 44px;
  align-items: center;
  gap: 8px;
  height: 22px;
  padding: 0 2px;
  border-radius: 4px;
  cursor: ew-resize;
}
.slider:hover { background: #0a0d18; }

.slider-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slider-track {
  position: relative;
  height: 6px;
  background: #1a1f33;
  border-radius: 3px;
  overflow: hidden;
  touch-action: none;
}
.slider-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, #5fe2ff 0%, #c084ff 55%, #ff5fb0 100%);
  pointer-events: none;
}
.slider-value {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-1);
  text-align: right;
  white-space: nowrap;
}

#temperament {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#temperament-pad {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 220px;
  cursor: crosshair;
  touch-action: none;
  border-radius: 6px;
  background: var(--bg-0);
}
.temperament-label {
  font-size: 11px;
  height: 16px;
  line-height: 16px;
  letter-spacing: 0.04em;
  color: var(--ink-1);
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* ─────────── midi monitor ─────────── */
#monitor {
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border-top: 1px solid var(--line);
  max-height: 280px;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
#monitor.collapsed { max-height: 38px; }
#monitor.collapsed #monitor-log { display: none; }

#monitor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
#monitor-toggle {
  font-family: ui-monospace, monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
  border: none;
  padding: 4px 8px;
  background: transparent;
  color: var(--ink-1);
}
#monitor-toggle:hover { color: var(--accent-2); border: none; }

#monitor-log {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  font: 11px/1.45 ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--bg-0);
}
#monitor-log .row {
  display: grid;
  grid-template-columns: 70px 38px 56px 1fr;
  gap: 8px;
  padding: 1px 12px;
  white-space: nowrap;
}
#monitor-log .row:nth-child(odd) { background: rgba(255,255,255,0.012); }
#monitor-log .t  { color: var(--ink-2); font-variant-numeric: tabular-nums; }
#monitor-log .ch { color: var(--accent-2); }
#monitor-log .k  { color: var(--ink-1); font-weight: 600; }
#monitor-log .d  { color: var(--ink-1); }

#monitor-log .row.note-on  .k { color: var(--good); }
#monitor-log .row.note-off .k { color: var(--ink-2); }
#monitor-log .row.cc       .k { color: var(--accent-3); }
#monitor-log .row.pb       .k { color: var(--accent); }
#monitor-log .row.at       .k { color: var(--warn); }
#monitor-log .row.rpn      { background: rgba(192,132,255,0.08); }

/* ─────────── statusbar ─────────── */
#statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.04em;
}
.status-led {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-2);
  box-shadow: 0 0 0 0 transparent;
  transition: all 0.2s;
}
.status-led[data-state="ready"] { background: var(--good); box-shadow: 0 0 6px var(--good); }
.status-led[data-state="engaged"] {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 1.4s infinite;
}
.status-led[data-state="error"] { background: var(--bad); box-shadow: 0 0 6px var(--bad); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.spacer { flex: 1; }
#rate-text {
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}

/* small screens — let the sidebar wrap under */
@media (max-width: 760px) {
  #stage { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #globals { border-left: none; border-top: 1px solid var(--line); }
  .axis-x { right: 24px; }
}
