/* Keyboard Styles Live - soft minimalism on generated HSLA tokens.
   js/tokens.js is the source of truth for every colour; the values below are
   first-paint fallbacks mirroring the generated light/dark ramps. */

:root {
  --bg: hsla(30, 40%, 96.4%, 1);
  --surface: hsla(30, 45%, 98.6%, 1);
  --surface-2: hsla(30, 30%, 93.4%, 1);
  --inset: hsla(30, 28%, 91%, 1);
  --line: hsla(30, 24%, 86.5%, 0.9);
  --line-strong: hsla(30, 20%, 76%, 1);
  --ink: hsla(30, 22%, 19%, 1);
  --ink-2: hsla(30, 12%, 35%, 0.92);
  --ink-3: hsla(30, 10%, 46%, 0.85);
  --accent: hsla(84, 32%, 60%, 1);
  --accent-strong: hsla(84, 34%, 42%, 1);
  --accent-ink: hsla(84, 32%, 21%, 1);
  --accent-soft: hsla(84, 36%, 86%, 0.8);
  --accent-faint: hsla(84, 32%, 92%, 0.6);
  --ember: hsla(10, 62%, 56%, 1);
  --ember-ink: hsla(10, 64%, 30%, 1);
  --ember-soft: hsla(10, 56%, 91%, 0.8);
  --focus: hsla(84, 38%, 46%, 0.8);
  --shadow: hsla(30, 30%, 30%, 0.12);
  --key-white: hsla(30, 45%, 98.6%, 1);
  --key-white-down: hsla(84, 36%, 82%, 1);
  --key-black: hsla(30, 18%, 22%, 1);
  --key-black-down: hsla(84, 30%, 36%, 1);

  --font-head: "Raleway", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
  --r-s: 10px;
  --r-m: 14px;
  --r-l: 22px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

html[data-theme="dark"] {
  --bg: hsla(30, 13%, 10.5%, 1);
  --surface: hsla(30, 12%, 14%, 1);
  --surface-2: hsla(30, 11%, 18%, 1);
  --inset: hsla(30, 13%, 8%, 1);
  --line: hsla(30, 10%, 24%, 0.9);
  --line-strong: hsla(30, 10%, 33%, 1);
  --ink: hsla(30, 16%, 90%, 1);
  --ink-2: hsla(30, 10%, 72%, 0.92);
  --ink-3: hsla(30, 8%, 58%, 0.85);
  --accent: hsla(84, 26%, 56%, 1);
  --accent-strong: hsla(84, 32%, 66%, 1);
  --accent-ink: hsla(84, 34%, 88%, 1);
  --accent-soft: hsla(84, 24%, 26%, 0.85);
  --accent-faint: hsla(84, 20%, 20%, 0.55);
  --ember: hsla(10, 58%, 62%, 1);
  --ember-ink: hsla(10, 60%, 84%, 1);
  --ember-soft: hsla(10, 42%, 22%, 0.85);
  --focus: hsla(84, 36%, 62%, 0.85);
  --shadow: hsla(30, 30%, 2%, 0.45);
  --key-white: hsla(30, 10%, 86%, 1);
  --key-white-down: hsla(84, 24%, 70%, 1);
  --key-black: hsla(30, 12%, 16%, 1);
  --key-black-down: hsla(84, 26%, 38%, 1);
}

* { box-sizing: border-box; }

/* quiet, themed scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--line-strong);
  background-clip: padding-box;
}
::-webkit-scrollbar-track,
::-webkit-scrollbar-corner { background: transparent; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

button { font: inherit; color: inherit; }

::selection { background: var(--accent-soft); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-s);
}

/* ---------- shell ---------- */

.app {
  display: grid;
  grid-template-columns: 208px 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.32s var(--ease-out);
}

body[data-rail="collapsed"] .app { grid-template-columns: 78px 1fr; }
body[data-rail="collapsed"] .wordmark { display: none; }
body[data-rail="collapsed"] .rail { padding-left: 14px; padding-right: 14px; }
body[data-rail="collapsed"] .rail-item span,
body[data-rail="collapsed"] .rail-foot .btn span,
body[data-rail="collapsed"] .rail-foot a span { display: none; }
body[data-rail="collapsed"] .rail-item,
body[data-rail="collapsed"] .rail-foot .btn { justify-content: center; }
body[data-rail="collapsed"] #rail-collapse i { transform: rotate(180deg); }
#rail-collapse i { transition: transform 0.3s var(--ease-out); }

.rail {
  display: flex;
  flex-direction: column;
  gap: 40px;
  padding: 36px 20px 24px 28px;
}

.wordmark {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 21px;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.wordmark em {
  font-style: italic;
  color: var(--accent-strong);
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rail-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 0;
  border-radius: var(--r-m);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 14px;
  text-align: left;
  transition: background 0.18s ease, color 0.18s ease;
}

.rail-item i { width: 18px; text-align: center; opacity: 0.75; }

.rail-item:hover { background: var(--surface-2); color: var(--ink); }

.rail-item.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.rail-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rail-foot .btn { justify-content: flex-start; gap: 10px; color: var(--ink-3); }
.rail-foot .btn span { font-size: 13px; }
.rail-foot .btn.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
#engine-chip[data-state="ready"] { color: var(--accent-strong); }
#engine-chip[data-state="error"] { color: var(--ember); }

.view {
  padding: 32px 40px 40px 24px;
  min-width: 0;
}

/* one orchestrated entrance per module switch */
.view > section {
  animation: viewIn 0.4s var(--ease-out) both;
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 17px;
  border: none;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: background 0.18s ease, color 0.18s ease, transform 0.14s var(--ease-out), box-shadow 0.18s ease;
}

.btn:hover { background: var(--accent-faint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.35; pointer-events: none; }

.btn.ghost { background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.ghost.danger:hover { background: var(--ember-soft); color: var(--ember-ink); }

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
}
html[data-theme="dark"] .btn.primary { color: var(--bg); }
.btn.primary:hover { background: var(--accent-strong); }

.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.icon-btn {
  width: 31px;
  height: 31px;
  padding: 0;
  border-radius: 50%;
}

.btn.round {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  padding: 0;
  font-size: 17px;
}
.btn.round.small { width: 38px; height: 38px; font-size: 14px; }

.btn.toggle { background: var(--surface-2); color: var(--ink-3); }
.btn.toggle.on {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.btn.on { background: var(--accent-soft); color: var(--accent-ink); }

.select, .input {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--r-m);
  padding: 8px 14px;
  min-width: 0;
  transition: background 0.18s ease;
}
.select.small { padding: 5px 10px; font-size: 13px; }
.select:hover, .input:hover { background: var(--accent-faint); }
.input:focus { background: var(--surface); border-color: var(--line); }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field.stack { margin-bottom: 14px; }

.field-label {
  font-family: var(--font-head);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}
.field-label.gap { margin-left: 18px; }

.value {
  min-width: 34px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.slider {
  --range-fill: 0%;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 18px;
  background:
    linear-gradient(
      to right,
      var(--accent) 0 var(--range-fill),
      var(--line) var(--range-fill) 100%
    )
    center / 100% 4px no-repeat;
  cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: transparent;
}
.slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  margin-top: -6px;
}
.slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: transparent;
}
.slider::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}

.muted { color: var(--ink-3); }
.hint { font-size: 12.5px; }

/* ---------- studio ---------- */

.studio {
  display: flex;
  flex-direction: column;
  gap: 26px;
  max-width: 1240px;
}

.studio-top {
  display: flex;
  flex-wrap: wrap;
  gap: 28px 48px;
  justify-content: space-between;
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 22px;
}

.chord-display {
  font-family: var(--font-head);
  font-size: 26px;
  font-weight: 800;
  min-width: 70px;
  line-height: 1.3;
  color: var(--accent-strong);
}

.volume {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 150px;
}

.volume .meter { display: none !important; }

.meter {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(0);
}

.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px 34px;
  padding: 18px 22px;
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: 0 2px 4px -2px var(--shadow), 0 16px 40px -28px var(--shadow);
}

.transport-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.transport-group.sections { gap: 14px; }
.transport-group.run { margin-left: auto; gap: 14px; }

.seg-group { display: inline-flex; gap: 4px; }

.btn.seg {
  background: var(--inset);
  color: var(--ink-2);
  padding: 8px 14px;
}
.btn.seg.main { min-width: 42px; font-family: var(--font-head); font-weight: 700; }
.btn.seg:hover { background: var(--accent-faint); color: var(--ink); }
.btn.seg.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.btn.seg.queued { background: var(--ember-soft); color: var(--ember-ink); animation: queued 0.9s ease-in-out infinite alternate; }

@keyframes queued {
  from { opacity: 1; }
  to { opacity: 0.45; }
}

.lamp {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--line-strong);
  opacity: 0.5;
}
.lamp.pulse { animation: lampPulse 0.35s ease-out; }
.lamp.accent { background: var(--accent-strong); }
@keyframes lampPulse {
  0% { transform: scale(1.7); opacity: 1; }
  100% { transform: scale(1); opacity: 0.5; }
}

.transport-readout {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 88px;
}
.section-name { font-family: var(--font-head); font-weight: 700; font-size: 14px; }
.position { color: var(--ink-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.registrations {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}
.registrations .field-label { margin-right: 8px; }

.btn.reg {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  padding: 0;
  background: var(--inset);
  color: var(--ink-3);
  font-family: var(--font-head);
  font-weight: 700;
}
.btn.reg.filled {
  color: var(--accent-ink);
  background: var(--accent-soft);
}
.btn.reg.flash { background: var(--accent); color: var(--accent-ink); transform: scale(1.12); }

.style-health-slot {
  max-width: 920px;
}

.style-health {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
}

.style-health.compact {
  gap: 10px;
  padding: 12px;
}

.style-health-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.health-score {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--inset);
  color: var(--ink);
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.style-health.red .health-score {
  background: var(--ember-soft);
  color: var(--ember-ink);
}

.style-health.yellow .health-score {
  background: color-mix(in srgb, var(--ember-soft) 52%, var(--accent-soft));
  color: var(--ink);
}

.style-health.green .health-score {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.health-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.health-title strong {
  font-family: var(--font-head);
  font-size: 16px;
  line-height: 1.1;
}

.health-chip {
  justify-self: end;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--inset);
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.health-dimensions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 12px;
}
.style-health.compact .health-dimensions {
  grid-template-columns: 1fr;
}

.health-dimension {
  display: grid;
  gap: 4px;
}

.health-dimension-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.health-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--inset);
  overflow: hidden;
}

.health-bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.style-health.red .health-bar-fill { background: var(--ember); }
.style-health.yellow .health-bar-fill { background: color-mix(in srgb, var(--ember) 42%, var(--accent)); }

.health-warnings {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.health-warning {
  display: grid;
  grid-template-columns: minmax(78px, auto) minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1.25;
}

.health-warning.critical { color: var(--ember-ink); }
.health-warning-id {
  color: var(--ink-3);
  font-family: var(--font-head);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* advanced chain */
.advanced-mode {
  background: var(--surface);
  border-radius: var(--r-l);
  padding: 12px 18px 16px;
  box-shadow: 0 2px 4px -2px var(--shadow), 0 16px 40px -28px var(--shadow);
}

.advanced-mode summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  font-family: var(--font-head);
  font-weight: 700;
  list-style: none;
}
.advanced-mode summary::-webkit-details-marker { display: none; }
.advanced-mode summary i { margin-right: 8px; color: var(--accent-strong); }

.advanced-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 16px;
}

.chain-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}
.chain-controls .field { min-width: 150px; }
.device-amount { width: 130px; }

.chain-blocks {
  display: flex;
  align-items: stretch;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.device-block {
  flex: 0 0 214px;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 10px;
  padding: 12px;
  border-radius: var(--r-m);
  background: var(--inset);
  min-height: 128px;
}
.device-block.output {
  flex-basis: 150px;
  min-height: 0;
  align-content: center;
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.device-block.bypassed { opacity: 0.52; }
.device-block.planned { border: 1px dashed var(--line-strong); }

.device-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.device-head i { color: var(--accent-strong); width: 18px; text-align: center; }
.device-head strong,
.device-head small {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-head small { color: var(--ink-3); font-size: 11px; }

.device-slider {
  display: grid;
  grid-template-columns: 1fr 42px;
  align-items: center;
  gap: 8px;
}
.device-slider .value { font-size: 12px; color: var(--ink-2); }

.device-actions {
  display: flex;
  gap: 4px;
}
.chain-empty {
  display: grid;
  place-items: center;
  min-width: 120px;
  padding: 18px;
  border-radius: var(--r-m);
  background: var(--inset);
}

/* ---------- piano ---------- */

.kb-wrap {
  background: var(--surface);
  border-radius: var(--r-l);
  padding: 18px 18px 14px;
  box-shadow: 0 2px 4px -2px var(--shadow), 0 16px 40px -28px var(--shadow);
}

.piano {
  position: relative;
  height: 168px;
  touch-action: none;
  user-select: none;
}

.piano-whites {
  display: flex;
  height: 100%;
}

.key.white {
  flex: 1;
  background: var(--key-white);
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0 0 5px 5px;
  cursor: pointer;
  transition: background 0.08s ease;
}
.key.white:first-child { border-left: none; }
.key.white.down { background: var(--key-white-down); }
.key.white.chord-zone { background: color-mix(in srgb, var(--key-white) 88%, var(--accent)); }
.key.white.chord-zone.down { background: var(--key-white-down); }

.key.black {
  position: absolute;
  top: 0;
  height: 60%;
  transform: translateX(-50%);
  background: var(--key-black);
  border-radius: 0 0 4px 4px;
  cursor: pointer;
  z-index: 2;
  transition: background 0.08s ease;
}
.key.black.down { background: var(--key-black-down); }

.studio-foot {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  color: var(--ink-3);
  font-size: 13px;
  padding: 0 6px;
}
.studio-foot .hint { margin-left: auto; }

/* ---------- builder ---------- */

.builder {
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: calc(100vh - 72px);
  min-height: 540px;
}

.builder-top {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.name-input {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 19px;
  background: transparent;
  border: 1px solid transparent;
  max-width: 300px;
}
.name-input:hover, .name-input:focus { border-color: var(--line); background: var(--surface); }
.preset-select {
  min-width: 180px;
  max-width: min(320px, 100%);
}

.spacer { flex: 1; }

.toast {
  opacity: 0;
  font-size: 13px;
  color: var(--accent-strong);
  transition: opacity 0.25s ease;
}
.toast.show { opacity: 1; }
.toast.error { color: var(--ember); }

.new-style-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 220px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: 0 12px 36px var(--shadow);
  animation: popIn 0.22s var(--ease-out) both;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.builder-body {
  display: grid;
  grid-template-columns: 150px 1fr 240px;
  gap: 26px;
  min-height: 0;
  flex: 1;
}

.section-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding-right: 4px;
}

.section-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn.chip {
  justify-content: space-between;
  padding: 7px 14px;
  background: var(--inset);
  color: var(--ink-2);
  font-size: 13px;
}
.btn.chip small { color: var(--ink-3); font-weight: 400; }
.btn.chip:hover { background: var(--accent-faint); color: var(--ink); }
.btn.chip.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.btn.chip.ghost-chip { background: transparent; color: var(--ink-3); opacity: 0.8; }
.btn.chip.ghost-chip:hover { background: var(--surface-2); opacity: 1; }
.btn.chip.empty { opacity: 0.6; }

/* staggered reveal for the section rail */
.section-group {
  animation: viewIn 0.45s var(--ease-out) both;
}
.section-group:nth-child(2) { animation-delay: 0.04s; }
.section-group:nth-child(3) { animation-delay: 0.08s; }
.section-group:nth-child(4) { animation-delay: 0.12s; }
.section-group:nth-child(5) { animation-delay: 0.16s; }

.grid-area {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  min-height: 0;
}

.grid-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.part-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.part-chips .btn.chip { justify-content: center; }

.grid-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.velocity-paint { width: 110px; }

.step-grid-wrap {
  overflow: auto;
  background: var(--surface);
  border-radius: var(--r-l);
  padding: 14px;
  box-shadow: 0 2px 4px -2px var(--shadow), 0 16px 40px -28px var(--shadow);
  flex: 1;
  min-height: 0;
}

.step-grid {
  position: relative;
}

.grid-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: stretch;
  height: 22px;
}
.step-grid.pitched .grid-row { height: 18px; }

.row-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  padding-right: 10px;
  justify-content: flex-end;
  font-variant-numeric: tabular-nums;
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 3;
}
.row-label.chord-tone { color: var(--accent-strong); }

.lane {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(17px, 1fr));
  grid-template-rows: 1fr;
  position: relative;
}

.cell {
  grid-row: 1;
  cursor: pointer;
  border-radius: 6px;
}
.cell.shade { background: color-mix(in srgb, var(--inset) 55%, transparent); border-radius: 0; }
.cell.beat-start { box-shadow: inset 1px 0 0 var(--line); border-radius: 0; }
.cell.bar-start { box-shadow: inset 2px 0 0 var(--line-strong); border-radius: 0; }
.cell:hover { background: var(--accent-faint); }
.grid-row:hover .row-label { color: var(--ink); }

.grid-note {
  grid-row: 1;
  background: var(--accent);
  border-radius: 99px;
  margin: 3px 1.5px;
  z-index: 2;
  cursor: pointer;
  min-width: 8px;
  transition: background 0.15s ease;
}
.grid-note:hover { background: var(--ember); }
.grid-note.selected {
  outline: 2px solid var(--ember);
  outline-offset: 1px;
}
.grid-note.preview { pointer-events: none; opacity: 0.6; }

.grid-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--ember);
  border-radius: 2px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--surface) 45%, transparent), 0 0 12px var(--ember);
  pointer-events: none;
  z-index: 4;
  will-change: transform;
}
.grid-playhead.hidden { display: none; }

.inspector {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 4px 2px;
}
.inspector h3 { font-size: 17px; }
.inspector .btn { margin-top: 6px; }

.small-note { font-size: 12.5px; line-height: 1.45; }

.note-editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: var(--r-m);
  background: var(--inset);
}
.note-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.note-editor-head strong { font-size: 13px; }
.param.compact {
  grid-template-columns: 62px 1fr 38px;
  gap: 8px;
}

/* ---------- voices ---------- */

.voices {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 220px;
  gap: 32px;
  max-width: 1080px;
}

.families {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn.family {
  justify-content: flex-start;
  gap: 12px;
  background: transparent;
  color: var(--ink-2);
  border-radius: var(--r-m);
}
.btn.family i { width: 18px; text-align: center; opacity: 0.7; }
.btn.family:hover { background: var(--surface-2); }
.btn.family.active { background: var(--accent-soft); color: var(--accent-ink); }

.voice-card {
  background: var(--surface);
  border-radius: var(--r-l);
  padding: 30px 34px;
  box-shadow: 0 2px 4px -2px var(--shadow), 0 16px 40px -28px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.voice-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.voice-head h2 { font-size: 26px; }
.voice-head p { margin: 4px 0 0; }

.view-switch {
  display: inline-flex;
  gap: 6px;
  align-self: flex-start;
  padding: 4px;
  border-radius: 999px;
  background: var(--inset);
}
.view-switch .btn { min-width: 84px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 4px 10px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.badge.show { opacity: 1; }

.params {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 32px;
}

.param {
  display: grid;
  grid-template-columns: 86px 1fr 52px;
  align-items: center;
  gap: 10px;
}
.param .value { font-size: 12.5px; color: var(--ink-2); }

.voice-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.sample-loader {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.sample-status { font-size: 12.5px; }

.advanced-voice {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.voice-chain {
  padding-bottom: 2px;
}

.mini-kb .piano { height: 110px; }

.related {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn.related-item {
  justify-content: flex-start;
  background: var(--surface);
  border-radius: var(--r-m);
  box-shadow: 0 2px 4px -2px var(--shadow), 0 16px 40px -28px var(--shadow);
}
.btn.related-item:hover { background: var(--accent-faint); }
.btn.related-item.active { background: var(--accent-soft); color: var(--accent-ink); }

/* drum pads + sound check */
.drum-pads {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.btn.drum-pad {
  border-radius: var(--r-m);
  background: var(--inset);
  color: var(--ink-2);
  padding: 22px 8px;
  font-size: 13px;
}
.btn.drum-pad:hover { background: var(--accent-faint); }
.btn.drum-pad.hit { background: var(--accent-soft); color: var(--accent-ink); transform: scale(0.96); }
.soundcheck-status { font-size: 12.5px; padding-left: 16px; min-height: 18px; }

/* ---------- changelog ---------- */

.changelog {
  max-width: 980px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.changelog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.changelog-head h1 {
  font-size: 34px;
  margin: 0 0 8px;
}

.version-chip {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 800;
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.change-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.change-entry {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 24px;
  padding: 22px 24px;
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: 0 2px 4px -2px var(--shadow), 0 16px 40px -30px var(--shadow);
}

.change-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.change-body h2 {
  font-size: 21px;
  margin: 0 0 6px;
}

.change-points {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--ink-2);
}

.change-points li + li { margin-top: 6px; }

.reference-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.reference-list a {
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--inset);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.reference-list a:hover {
  color: var(--accent-strong);
}

/* ---------- settings ---------- */

.settings-grid {
  display: grid;
  grid-template-columns: minmax(280px, 520px);
  gap: 16px;
  margin-top: 18px;
}

.setting-card {
  display: grid;
  gap: 18px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
}

.setting-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.setting-head h3 {
  margin: 0 0 4px;
  font-family: var(--font-head);
  font-size: 18px;
}

.hue-value { color: var(--accent-strong); }
.hue-slider { max-width: 420px; }

.hue-swatch-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hue-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line-strong);
}

.hue-swatch.accent { background: var(--accent); }
.hue-swatch.ember { background: var(--ember); }

.sound-library-card {
  max-width: 820px;
}

.module-toggle-category {
  display: grid;
  gap: 10px;
}

.module-toggle-list {
  display: grid;
  gap: 8px;
}

.module-toggle-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.module-toggle-row:first-child {
  border-top: 0;
}

.module-toggle-row.paused .module-toggle-copy,
.module-toggle-row.off .module-toggle-copy {
  opacity: 0.68;
}

.module-toggle-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.module-toggle-name {
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
}

.module-toggle-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.module-toggle-state {
  min-width: 58px;
  text-align: right;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0;
}

.module-toggle-shell {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
}

.module-toggle-input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.module-toggle-input:disabled {
  cursor: default;
}

.module-toggle-slider {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background 140ms ease;
}

.module-toggle-slider::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px color-mix(in srgb, var(--ink) 18%, transparent);
  transition: transform 140ms ease;
}

.module-toggle-input:checked + .module-toggle-slider {
  background: var(--accent);
}

.module-toggle-input:checked + .module-toggle-slider::after {
  transform: translateX(20px);
}

.module-toggle-input:focus-visible + .module-toggle-slider {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.module-reload-status {
  min-width: 118px;
  text-align: right;
}

.module-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 720px) {
  .module-toggle-row {
    grid-template-columns: 1fr;
  }

  .module-toggle-meta {
    justify-content: space-between;
  }
}

/* ---------- drop overlay ---------- */

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

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(3px);
}

.drop-card {
  background: var(--surface);
  border: 1px dashed var(--accent);
  border-radius: var(--r-l);
  padding: 44px 56px;
  text-align: center;
  color: var(--ink-2);
  box-shadow: 0 18px 48px var(--shadow);
  animation: popIn 0.25s var(--ease-out) both;
}
.drop-card i { font-size: 30px; color: var(--accent-strong); margin-bottom: 12px; }

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  .voices { grid-template-columns: 150px minmax(0, 1fr); }
  .voices .related { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  .builder-body { grid-template-columns: 130px 1fr; }
  .builder-body .inspector { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .change-entry { grid-template-columns: 1fr; gap: 14px; }
  .change-meta { flex-direction: row; align-items: center; }
}

@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 16px 20px 8px;
  }
  .wordmark br { display: none; }
  .rail-nav { flex-direction: row; }
  .rail-foot { margin-top: 0; margin-left: auto; flex-direction: row; }
  .rail-foot .btn span { display: none; }
  .view { padding: 18px 20px 32px; }
  .piano { height: 130px; }
  .transport-group.run { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
