:root {
  --bg: #0e0f12;
  --bg-2: #15171c;
  --bg-3: #1d2027;
  --fg: #e8e6df;
  --fg-dim: #8a8c93;
  --accent: #c2f04a;
  --accent-2: #6ee7ff;
  --danger: #ff6b6b;
  --border: #262933;
  --step: #2a2e38;
  --step-on: #c2f04a;
  --step-now: #ffffff;
}

* { box-sizing: border-box; }

/* Disable double-tap zoom site-wide on touch devices. `manipulation` permits
   panning + pinch zoom but suppresses the 300ms double-tap-to-zoom gesture,
   which otherwise fires when a user taps the step grid / pads fast. The step
   grid and roll grid still override this with their own touch-action values
   (none / pan-y) where they capture pointer events directly. */
html, body, button, input, select, textarea, label, a,
.step, .pattern-cell, .se-pad {
  touch-action: manipulation;
}
/* Piano roll cells: JS owns the gesture (tap to add, drag right to extend
   length, drag up/down to repitch). `manipulation` here would let the browser
   pan the horizontally-scrollable .roll-grid and cancel the drag mid-gesture,
   so notes never grow past length 1 on touch. Users still scroll horizontally
   by touching the sticky label column or beat ruler row, which keep the
   default touch-action. Same for the velocity lane. */
.roll-cell, .roll-vel-cell { touch-action: none; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.01em;
}

.transport {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-wrap: wrap;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-right: 6px;
  color: var(--fg);
  font-weight: 700;
  letter-spacing: 0.02em;
  user-select: none;
}
.logo img { width: 30px; height: 30px; }
.logo span { font-size: 15px; }

.transport .spacer { flex: 1; }

.field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--fg-dim);
}

.field label { text-transform: lowercase; }

input[type="number"],
input[type="text"],
select {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font: inherit;
  outline: none;
}

input[type="number"] { width: 64px; }
input[type="range"] { accent-color: var(--accent); }

button {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 12px;
  font: inherit;
  cursor: pointer;
  text-transform: lowercase;
}

button:hover { border-color: var(--fg-dim); }
button:active { transform: translateY(1px); }

button.play {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
  font-weight: 600;
  min-width: 68px;
}

#set-share {
  align-self: stretch;
  background: var(--accent-2);
  color: #0b0d10;
  border-color: var(--accent-2);
  font-weight: 600;
  text-transform: none;
  padding: 0 14px;
  min-width: 68px;
}

button.play.playing {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

button.ghost { background: transparent; }
button.danger { color: var(--danger); }

.status {
  color: var(--fg-dim);
  font-size: 12px;
  min-width: 120px;
  text-align: right;
}

.meter {
  position: relative;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}
.meter-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: #4ade80;
  transition: width 40ms linear;
}
.meter-bar.clip { background: #ef4444; }

.beat-indicator { flex-shrink: 0; display: block; }
.beat-indicator .beat-dot { fill: var(--bg-3); stroke: var(--border); stroke-width: 0.6; transition: fill 40ms linear; }
.beat-indicator .beat-dot.beat-strong { stroke: color-mix(in oklab, var(--accent) 55%, var(--border)); }
.beat-indicator .beat-dot.now { fill: var(--accent); stroke: var(--accent); }
.beat-indicator .beat-dot.beat-strong.now { fill: var(--accent-2); stroke: var(--accent-2); }
.beat-indicator .beat-label {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  font-weight: 600;
  fill: var(--fg);
  letter-spacing: 0.02em;
}

#metronome[aria-pressed="true"] { background: var(--accent); color: #0b0d10; border-color: var(--accent); }
#metronome[aria-pressed="true"] .btn-icon { color: #0b0d10; }
/* Palette toggle: full color when on, desaturated when off. */
#note-colors .btn-icon { transition: filter 80ms linear, opacity 80ms linear; }
#note-colors[aria-pressed="false"] .btn-icon { filter: grayscale(1); opacity: 0.55; }

.track-oct { display: inline-flex; gap: 2px; }
.track-oct button { padding: 3px 8px; font-size: 11px; min-width: 44px; }
.track-len-extend { display: inline-flex; gap: 2px; }
.track-len-extend button { padding: 3px 8px; font-size: 11px; min-width: 36px; }
.master-meter { width: 80px; height: 12px; }
.track-meter  { width: 100%; height: 100%; }

/* Vol slider + meter: native slider on top, thin meter strip immediately below.
   Both children stretch to the same width (140px minus any flex-cross-axis trim). */
.vol-combo {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  width: 140px;
  gap: 3px;
}
.vol-combo > * { box-sizing: border-box; }
.track-head .field.vol-field .vol-combo input[type="range"] {
  width: 100%;
  margin: 0;
  padding: 0;
  display: block;
}
.vol-combo .track-meter {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  border: 0;
}
.status.err { color: var(--danger); }

.pattern-bar {
  display: flex;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.pattern-grid {
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  grid-auto-rows: 22px;
  gap: 3px;
  flex: 1;
}
.pattern-cell {
  background: var(--step);
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font-size: 10px;
  color: var(--fg-dim);
  display: grid;
  place-items: center;
  padding: 0;
  min-height: 22px;
}
.pattern-cell.filled { background: color-mix(in oklab, var(--step-on) 35%, var(--step)); color: var(--fg); }
.pattern-cell.active { border-color: var(--step-now); box-shadow: 0 0 0 1px var(--step-now) inset; }
.pattern-cell.queued { border-color: var(--accent-2); }
.pattern-cell.drag-over { border-color: var(--accent); background: color-mix(in oklab, var(--accent) 20%, var(--step)); }
.repeat-wrap { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; color: var(--fg-dim); font-size: 11px; }
.repeat-wrap input { width: 48px; text-align: center; }
.repeat-wrap select { width: 64px; text-align: center; }
#pattern-mode[aria-pressed="true"] { background: var(--accent-2); color: #0b0d10; border-color: var(--accent-2); }
#pattern-switch[aria-pressed="true"] { background: var(--accent-2); color: #0b0d10; border-color: var(--accent-2); }
#set-save, #set-load, #set-export, #set-import, #set-share { text-transform: none; }
#set-save, #set-load, #set-export, #set-import,
#pattern-dup { padding: 3px 10px; font-size: 12px; min-width: 64px; }
.icon-btn {
  padding: 0;
  min-width: 32px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn .btn-icon { display: block; }
.ai-btn { display: inline-flex; align-items: center; gap: 5px; }
.ai-btn .ai-icon { display: inline-flex; color: inherit; }
.ai-btn:disabled .ai-icon { color: var(--fg-dim); }

.dl-btn { display: inline-flex; align-items: center; gap: 5px; }
.dl-btn .dl-icon { display: inline-flex; color: inherit; }
.dl-btn:disabled .dl-icon { color: var(--fg-dim); }
.set-stack, .mode-stack, .len-stack { display: flex; flex-direction: column; gap: 4px; }
.len-stack button { min-width: 36px; }
.mode-row { display: flex; gap: 4px; }

.master-prompt {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.master-prompt input[type="text"] { flex: 1; }
#master-prompt {
  flex: 1;
  font: inherit;
  resize: none;
  min-height: 32px;
  max-height: 180px;
  overflow-y: auto;
  line-height: 1.35;
  padding: 6px 8px;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.master-toggle,
.gen-toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--fg-dim); white-space: nowrap; }
.gen-toggle-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
}
.gen-toggle-btn[data-state="on"] {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
}
.gen-toggle-btn[data-state="all"] {
  background: #ffa94d;
  color: #0b0d10;
  border-color: #ffa94d;
}

.track-drumkit[aria-pressed="true"] {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
}
#master-prompt-go {
  background: #ff6fa3;
  color: #0b0d10;
  border-color: #ff6fa3;
  font-weight: 600;
}
#master-prompt-go:disabled { opacity: 0.5; cursor: progress; }
#master-variate-go {
  background: #a68bff;
  color: #0b0d10;
  border-color: #a68bff;
  font-weight: 600;
}
#master-variate-go:disabled { opacity: 0.5; cursor: progress; }
.gen-toggle-btn {
  background: transparent;
  color: var(--fg-dim);
  border-color: var(--border);
  font-weight: normal;
}
.gen-count-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--fg-dim);
}
.gen-count-wrap input { width: 50px; text-align: center; }
.gen-sound-engine { padding: 4px 8px; font-size: 12px; }

main {
  padding: 16px;
  display: grid;
  gap: 12px;
  max-width: 1400px;
  margin: 0 auto;
}

.track {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.track.muted { opacity: 0.45; }

.track-head {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.track-synth-row {
  flex-basis: 100%;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: stretch;
}
.track-synth-row:empty { display: none; }
.track-synth-row > .param-group[hidden] + .param-group[hidden] { /* no-op, just a placeholder */ }

.track-head .field input[type="range"] { width: 72px; }
.track-head .field label { font-size: 11px; }

.param-group {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255,255,255,0.015);
}
.param-group .field input[type="range"] { width: 60px; }
.timbre-group { border-color: color-mix(in oklab, var(--accent) 40%, var(--border)); }
.timbre-group[hidden] { display: none !important; }
.osc-mix-group { border-color: color-mix(in oklab, var(--accent-2) 40%, var(--border)); }
.osc-mix-group[hidden] { display: none !important; }
.osc-mod-group { border-color: color-mix(in oklab, #d5a6ff 40%, var(--border)); }
.osc-mod-group[hidden] { display: none !important; }
.moog-osc-group { border-color: color-mix(in oklab, #e0a868 40%, var(--border)); flex-direction: column; align-items: stretch; gap: 4px; }
.moog-osc-group[hidden] { display: none !important; }
.moog-osc-group .moog-osc-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.moog-osc-group .moog-osc-lbl { min-width: 32px; color: var(--fg-dim); }
.moog-osc-group .moog-freq { display: inline-flex; align-items: center; gap: 4px; }
.moog-osc-group .moog-freq input[type="range"] { width: 70px; }
.moog-osc-group select { padding: 2px 6px; font-size: 11px; }
.moog-osc-group .moog-noise { display: flex; align-items: center; gap: 6px; }
.moog-osc-group .moog-noise input[type="range"] { width: 70px; }
.param-group .field[hidden] { display: none !important; }
.filter-group { border-color: color-mix(in oklab, var(--accent-2) 40%, var(--border)); }

.panel-btn-group {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.panel-btn-group > button {
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--border);
  padding: 7px 10px;
}
.panel-btn-group > button:last-child { border-right: none; }

.track-mod[aria-pressed="true"] {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
}

.track-mod-panel {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}

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

.track-aut-panel {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: grid;
  gap: 6px;
}
.track-aut-panel[hidden] { display: none; }
.aut-empty { color: var(--fg-dim); font-size: 11px; padding: 4px 0; }
.aut-add-row { display: flex; gap: 6px; align-items: center; margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--border); }
.aut-add-btn { font-size: 11px; padding: 4px 10px; }
.aut-add-select { font-size: 11px; padding: 3px 6px; max-width: 220px; }
.aut-lane {
  display: grid;
  grid-template-columns: 120px 28px 1fr 52px 24px;
  gap: 8px;
  align-items: center;
  padding: 2px 0;
}
.aut-lane .aut-label { color: var(--fg-dim); font-size: 11px; text-transform: lowercase; }
.aut-lane.active .aut-label { color: var(--accent); font-weight: 600; }
.aut-lane .aut-enable { accent-color: var(--accent); }
.aut-lane .aut-clear { font-size: 10px; padding: 2px 6px; }
.aut-lane .aut-remove {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  font-size: 13px;
  line-height: 1;
  width: 22px; height: 22px;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
}
.aut-lane .aut-remove:hover { color: var(--danger); }
.aut-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 1px;
  height: 96px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px;
  cursor: crosshair;
  user-select: none;
}
.aut-step {
  position: relative;
  background: transparent;
  border-radius: 1px;
  overflow: hidden;
}
.aut-step::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--v, 0) * 100%);
  background: var(--accent);
  opacity: 0.85;
}
.aut-lane.active .aut-step::after { background: var(--accent); }
.aut-lane:not(.active) .aut-step::after { background: var(--fg-dim); opacity: 0.4; }
.aut-step.playing { box-shadow: inset 0 0 0 1px var(--accent-2); }

.track-roll-panel {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: grid;
  gap: 6px;
}
.track-roll-panel[hidden] { display: none; }
.track-roll[aria-pressed="true"] {
  background: #8ec7ff;
  color: #0b0d10;
  border-color: #8ec7ff;
}
.roll-head {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--fg-dim);
}
.roll-head .roll-title { color: #8ec7ff; font-weight: 600; }
.roll-head .roll-hint { font-size: 10px; color: var(--fg-dim); font-style: italic; }
.roll-head label { display: inline-flex; align-items: center; gap: 6px; }
.roll-head .roll-oct-btns { display: inline-flex; gap: 4px; }
.roll-head .roll-oct-btns button { padding: 2px 8px; font-size: 11px; }
.roll-head .roll-range { color: var(--fg-dim); font-variant-numeric: tabular-nums; }
.roll-head .roll-transforms { display: inline-flex; gap: 4px; margin-left: auto; }
.roll-head .roll-transforms button {
  padding: 2px 8px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.roll-grid {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 2px;
  max-height: 320px;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--bg-2);
  border-radius: 4px;
  padding: 2px;
}
.roll-row {
  display: contents;
}
.roll-label {
  font-size: 10px;
  color: var(--fg-dim);
  padding: 2px 6px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  background: var(--bg-3);
  border-radius: 3px;
  line-height: 1.4;
  user-select: none;
  position: sticky;
  left: 0;
  z-index: 2;
}
.roll-label { color: var(--note-color, var(--fg-dim)); }
.roll-label.black { color: var(--note-color, var(--fg-dim)); background: var(--bg-2); }
.roll-label.root { color: var(--note-color, #8ec7ff); font-weight: 600; }
.roll-label.micro { color: color-mix(in oklab, var(--fg-dim) 60%, transparent); font-size: 9px; padding-inline: 3px; }
.roll-cells {
  display: grid;
  gap: 1px;
  min-width: max-content;
}
.roll-beat-label {
  background: transparent;
  border: none;
}
.roll-beat-row {
  font-size: 10px;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
}
.roll-beat-cell {
  text-align: left;
  padding: 0 2px;
  line-height: 14px;
  min-height: 14px;
}
.roll-beat-cell.beat-start { color: var(--fg); }
.roll-cell {
  height: 16px;
  background: var(--bg-3);
  border-radius: 2px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 40ms linear, border-color 40ms linear;
  position: relative;
  font-family: ui-monospace, monospace;
  font-size: 9px;
  line-height: 14px;
  color: #0b0d10;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}
.roll-cell:hover { background: color-mix(in srgb, var(--row-color, var(--bg-4, #30363d)) 32%, var(--bg-3)); }
.roll-cell.on:hover { background: color-mix(in srgb, var(--note-color, var(--accent)) 88%, #fff 12%); }
.roll-cell.beat { border-left: 1px solid var(--border); }
.roll-cell.row-black { background: var(--bg-2); }
.roll-cell.row-micro { background: color-mix(in oklab, var(--bg-3) 70%, var(--bg-2)); }
.roll-cell.on {
  background: var(--note-color, var(--accent));
  border-color: var(--note-color, var(--accent));
}
/* Multi-step notes: square the adjoining corners and bridge the 1px grid gap
   with a pseudo so a held note reads as a single continuous bar. */
.roll-cell.on.held {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.roll-cell.on.note-joins-next {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.roll-cell.on.note-joins-next::after {
  content: "";
  position: absolute;
  top: -1px;
  bottom: -1px;
  right: -3px;
  width: 3px;
  background: var(--note-color, var(--accent));
  pointer-events: none;
}
.roll-cell.on.chord { background: var(--note-color, #8ec7ff); border-color: var(--note-color, #8ec7ff); }
.roll-cell.on.chord.note-joins-next::after { background: var(--note-color, #8ec7ff); }
.roll-cell.now { outline: 1px solid #fff6; }

.roll-vel-lane {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 2px;
  background: var(--bg-2);
  border-radius: 4px;
  padding: 2px;
  overflow-x: auto;
  overscroll-behavior: contain;
}
.roll-vel-spacer {
  font-size: 10px;
  color: var(--fg-dim);
  padding: 2px 6px;
  text-align: right;
  background: var(--bg-3);
  border-radius: 3px;
  align-self: end;
  user-select: none;
  position: sticky;
  left: 0;
  z-index: 2;
}
.roll-vel-cells {
  display: grid;
  gap: 1px;
  height: 48px;
  min-width: max-content;
}
.roll-vel-cell {
  background: var(--bg-3);
  border-radius: 2px;
  position: relative;
  cursor: ns-resize;
  overflow: hidden;
}
.roll-vel-cell.beat { border-left: 1px solid var(--border); }
.roll-vel-cell.on { background: var(--bg-2); }
.roll-vel-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to top, var(--accent), #8ec7ff);
  pointer-events: none;
  min-height: 2px;
}
.roll-vel-cell.now { outline: 1px solid #fff6; }

.track-fx-panel {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}
.track-fx-panel[hidden] { display: none; }
.track-fx[aria-pressed="true"] {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
}

.track-filter-panel {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}
.track-filter-panel[hidden] { display: none; }
.track-filter[aria-pressed="true"] {
  background: var(--accent-2);
  color: #0b0d10;
  border-color: var(--accent-2);
}
.track-env-panel {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}
.track-env-panel[hidden] { display: none; }
.track-env[aria-pressed="true"] {
  background: #d5a6ff;
  color: #0b0d10;
  border-color: #d5a6ff;
}
.fx-row[data-fx="filter"] .fx-title { color: var(--accent-2); }
.fx-row[data-fx="env"] .fx-title { color: #d5a6ff; }
.fx-row[data-fx="eq"] .fx-title { color: #ffa94d; }

.track-eq-panel {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}
.track-eq-panel[hidden] { display: none; }
.track-eq[aria-pressed="true"] {
  background: #ffa94d;
  color: #0b0d10;
  border-color: #ffa94d;
}

.track-comp-panel {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
}
.track-comp-panel[hidden] { display: none; }
.track-comp[aria-pressed="true"] {
  background: #66d9b4;
  color: #0b0d10;
  border-color: #66d9b4;
}
.fx-row[data-fx="comp"] .fx-title { color: #66d9b4; }
.track-comp-panel select.comp-source { min-width: 110px; }

.fx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
  flex-wrap: wrap;
}
.fx-row .fx-title {
  color: var(--fg-dim);
  text-transform: lowercase;
  font-size: 11px;
  letter-spacing: 0.08em;
  min-width: 120px;
}
.fx-row[data-fx="vinyl"] .fx-title { color: #c79a74; }
.fx-row[data-fx="cassette"] .fx-title { color: #d9c07a; }
.fx-row[data-fx="fuzz"] .fx-title { color: #ff7a7a; }
.fx-row[data-fx="ringmod"] .fx-title { color: #e0a8ff; }
.fx-row[data-fx="autowah"] .fx-title { color: #ffd166; }
.fx-row[data-fx="chorus"] .fx-title { color: #9fd7ff; }
.fx-row[data-fx="phaser"] .fx-title { color: #b69cff; }
.fx-row[data-fx="flanger"] .fx-title { color: #7adfc8; }
.fx-row[data-fx="pitchshift"] .fx-title { color: #ffaad5; }
.fx-row[data-fx="delay"] .fx-title { color: var(--accent-2); }
.fx-row[data-fx="reverb"] .fx-title { color: var(--accent); }
.fx-ctl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--fg-dim);
}
.fx-ctl span { min-width: 30px; font-size: 11px; }
.fx-ctl input[type="range"] { width: 88px; }
.fx-sync-wrap { gap: 4px; }

.lfo-row {
  display: grid;
  grid-template-columns: 52px 52px 96px 62px minmax(0, 1fr) minmax(0, 1fr) 28px;
  gap: 10px;
  align-items: center;
  padding: 2px 0;
}

.lfo-sync-wrap { color: var(--fg-dim); display: inline-flex; align-items: center; gap: 4px; }
.lfo-rate-field .lfo-rate,
.lfo-rate-field .lfo-div { flex: 1; }
.lfo-rate-field[data-mode="sync"] .lfo-rate { display: none; }
.lfo-rate-field[data-mode="hz"] .lfo-div { display: none; }

.lfo-row.active .lfo-target { color: var(--accent); font-weight: 600; }
.lfo-row .lfo-target { color: var(--fg-dim); text-transform: lowercase; }
.lfo-row .lfo-enable { color: var(--fg-dim); display: inline-flex; align-items: center; gap: 4px; }
.lfo-row .field { width: 100%; }
.lfo-row .field input[type="range"] { flex: 1; width: auto; min-width: 40px; }
.lfo-row .lfo-rate-label,
.lfo-row .lfo-depth-label { color: var(--fg-dim); font-size: 11px; min-width: 56px; }

.track-name {
  width: 120px;
  font-weight: 600;
}

.track-engine { min-width: 160px; }
.track-len { width: 56px; }

.scale-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--fg-dim);
}
.scale-toggle { display: inline-flex; align-items: center; gap: 4px; }
#scale-root, #scale-mode { padding: 4px 6px; }

.track-midi {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg-dim);
  align-self: flex-start;
}
.track-midi[hidden] { display: none; }
.track-midi select { min-width: 180px; }
.track-midi input[type="number"] { width: 56px; }


.track-save:disabled { opacity: 0.35; cursor: not-allowed; }

.track-lock[aria-pressed="true"] {
  background: var(--accent-2);
  color: #0b0d10;
  border-color: var(--accent-2);
}
.track.locked { border-color: var(--accent-2); }

.track-solo[aria-pressed="true"] {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
}
.track.soloed { border-color: var(--accent); }

.track-glide { width: 70px; }

.steps {
  display: grid;
  grid-template-columns: repeat(var(--count, 16), minmax(0, 1fr));
  /* Floor wrapped rows: a multi-bar pattern where a row contains only a
     single held cell has no aspect-ratio reference, so the row would
     otherwise collapse to the label height. Cells with aspect-ratio:1
     still grow rows past this floor when they need to. */
  grid-auto-rows: minmax(44px, auto);
  gap: 4px;
}

.step {
  aspect-ratio: 1 / 1;
  background: var(--step);
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  min-height: 28px;
  transition: background 60ms linear;
}

/* held cells span multiple columns; stop them from also doubling in height */
.step.held { aspect-ratio: auto; height: auto; align-self: stretch; }
.steps { align-items: stretch; }

.step.on {
  background: var(--note-color, var(--step-on));
  filter: brightness(calc(0.35 + var(--vel, 1) * 0.65));
}
.step.beat { outline: 1px solid rgba(255,255,255,0.06); }
.step.now { border-color: var(--step-now); box-shadow: 0 0 0 1px var(--step-now) inset; }

.step.accent { background: #363b47; }
.step.accent.on { background: var(--note-color, color-mix(in oklab, var(--step-on) 85%, #fff 15%)); }
.step.accent::before {
  content: "";
  position: absolute;
  top: 0; left: 4px; right: 4px;
  height: 3px;
  background: var(--accent-2);
  opacity: 0.75;
  border-radius: 0 0 3px 3px;
}
.step.accent.on::before { background: #0b0d10; opacity: 0.45; }

.step.held {
  background: linear-gradient(
    90deg,
    var(--note-color, var(--step-on)) 0 calc(100% / var(--span, 1) - 2px),
    color-mix(in oklab, var(--note-color, var(--step-on)) 70%, transparent) calc(100% / var(--span, 1))
  );
  position: relative;
}
.step.held::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; right: 0;
  width: 3px;
  background: #0b0d10;
  opacity: 0.3;
  border-radius: 0 4px 4px 0;
}
.step, .step * { user-select: none; -webkit-user-select: none; }
.steps { touch-action: none; }

.step-editor {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
  min-width: 300px;
  max-width: min(94vw, 860px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.55);
  z-index: 100;
}
.step-editor .se-title {
  color: var(--fg-dim);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.step-editor .se-field {
  display: grid;
  grid-template-columns: 60px 1fr 84px;
  gap: 10px;
  align-items: center;
}
.step-editor .se-field[hidden] { display: none; }
.step-editor .se-field > label:first-child { white-space: nowrap; }
.step-editor .se-field.se-chord-field {
  grid-template-columns: 60px auto auto 1fr;
}
.step-editor .se-cpx-row { grid-template-columns: 60px 1fr; }
.step-editor .se-cpx-row select { width: 100%; }
.step-editor .se-arp-selects {
  display: flex;
  gap: 8px;
  grid-column: 2 / -1;
}
.step-editor .se-arp-selects select { flex: 1; min-width: 0; }
.step-editor .se-arp-row { grid-template-columns: 60px 1fr; }

.step-editor .se-note-field {
  grid-template-columns: 60px minmax(0, 1fr);
  grid-template-rows: auto auto;
  row-gap: 10px;
}
.step-editor .se-note-field > label:first-child { align-self: start; padding-top: 4px; }
.step-editor .se-note-header {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.step-editor .se-note-header .se-note-label {
  font-size: 11px;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
}
.step-editor .se-oct-pager {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
}
.step-editor .se-oct-pager button {
  padding: 2px 8px;
  font-size: 10px;
}
.step-editor .se-oct-pager button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}
.step-editor .se-oct-range { min-width: 60px; text-align: center; }
.step-editor .se-keyboard {
  --se-pad-size: 48px;
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(12, var(--se-pad-size));
  gap: 4px;
  padding: 4px;
  min-width: 0;
  max-width: 100%;
  justify-content: start;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0;
  overflow-x: auto;
}
.step-editor .se-keyboard .se-pad {
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-3));
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  line-height: 1;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
  text-transform: lowercase;
}
.step-editor .se-keyboard .se-pad.root {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
}
.step-editor .se-keyboard .se-pad.selected {
  background: var(--accent-2);
  color: #0b0d10;
  border-color: var(--accent-2);
}
.step-editor .se-keyboard .se-pad:hover { filter: brightness(1.15); }

.step-editor .se-sample-row { grid-template-columns: 60px 1fr; }
.step-editor .se-sample-ctl {
  display: grid;
  gap: 6px;
  grid-column: 2 / -1;
  font-size: 11px;
  color: var(--fg-dim);
}
.step-editor .se-waveform {
  width: 100%;
  height: 72px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: ew-resize;
  display: block;
  touch-action: none;
  background: #0e0f12;
}
.step-editor .se-sample-fade {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  font-size: 11px;
  color: var(--fg-dim);
}
.step-editor .se-sample-fade label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.step-editor .se-sample-fade input[type="range"] { min-width: 0; }

.step-editor .se-sample-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.step-editor .se-smp-info {
  color: var(--fg-dim);
  font-size: 11px;
  flex: 1 1 100%;
}
.step-editor .se-smp-snap select,
.step-editor .se-smp-fit  select { padding: 2px 6px; font-size: 11px; }
.step-editor .se-preview {
  background: var(--accent-2);
  color: #0b0d10;
  border-color: var(--accent-2);
  font-weight: 600;
  padding: 3px 10px;
}
.step-editor .se-chord-field .se-chord-label {
  text-align: right;
  color: var(--fg-dim);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.step-editor .se-field label { color: var(--fg-dim); }
.step-editor .se-field input[type="range"] { width: 100%; }
.step-editor .se-field .se-note-label,
.step-editor .se-field .se-vel-label { color: var(--fg); font-size: 12px; text-align: right; }
.step-editor .se-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 2px;
}
.step-editor .se-arp-wrap,
.step-editor .se-cpx-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--fg-dim);
  font-size: 11px;
}
.step-editor .se-cpx-wrap input { width: 44px; }
.step-editor .se-arp-wrap input:disabled + * { opacity: 0.4; }

.step-editor .se-close {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
  font-weight: 600;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: grid;
  place-items: center;
  z-index: 200;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 22px;
  min-width: 360px;
  max-width: 520px;
  display: grid;
  gap: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
.modal-title {
  color: var(--fg);
  font-size: 13px;
}
.modal-input {
  width: 100%;
  font: inherit;
}
.modal-multiline {
  min-height: 110px;
  resize: vertical;
  line-height: 1.45;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Audio gate dialog: shown on page load until the user taps to unlock
   audio. Sits above the rest of the UI so it must be the first interaction. */
.audio-gate-overlay { z-index: 300; }
.audio-gate-modal {
  text-align: center;
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 380px;
}
.audio-gate-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: 0.02em;
}
.audio-gate-hint {
  font-size: 12px;
  color: var(--fg-dim);
  line-height: 1.5;
  min-height: 3.2em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 180ms ease;
}
.audio-gate-hint strong { color: var(--fg); }
.audio-gate-btn {
  padding: 14px 18px;
  font-size: 14px;
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
  font-weight: 700;
  min-height: 48px;
}
.audio-gate-btn:disabled { opacity: 0.6; cursor: progress; }
.audio-gate-status {
  font-size: 11px;
  color: var(--fg-dim);
  min-height: 14px;
}

/* Panel modal: hosts a reparented track panel (.track-roll-panel,
   .track-mod-panel, .track-aut-panel) as a centered overlay. The panel keeps
   its existing render + event wiring; only its parent changes. */
.panel-modal {
  width: min(96vw, 1100px);
  max-width: 96vw;
  min-width: 0;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
}
.panel-modal > .track-roll-panel,
.panel-modal > .track-mod-panel,
.panel-modal > .track-aut-panel,
.panel-modal > .track-filter-panel,
.panel-modal > .track-env-panel,
.panel-modal > .track-fx-panel,
.panel-modal > .track-eq-panel,
.panel-modal > .track-comp-panel {
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  overflow-y: auto;
}
.panel-modal .panel-modal-close {
  align-self: stretch;
  padding: 10px;
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
  font-weight: 600;
  min-height: 40px;
}
.roll-modal .roll-head { flex-wrap: wrap; }
.roll-modal .roll-grid { max-height: calc(80vh - 80px); }
.mod-modal,
.aut-modal {
  width: min(96vw, 820px);
}
.filter-modal,
.env-modal,
.eq-modal,
.comp-modal {
  width: min(96vw, 680px);
}
.fx-modal {
  width: min(96vw, 900px);
}
.mod-modal > .track-mod-panel,
.aut-modal > .track-aut-panel,
.filter-modal > .track-filter-panel,
.env-modal > .track-env-panel,
.fx-modal > .track-fx-panel,
.eq-modal > .track-eq-panel,
.comp-modal > .track-comp-panel {
  max-height: calc(92vh - 80px);
}
.bounce-opts { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.bounce-opts label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg-dim); }
.bounce-opts input[type="number"] { width: 64px; }
.bounce-opts input[type="text"] { width: 220px; }
.bounce-note { color: var(--fg-dim); font-size: 11px; }
.bounce-progress-label { font-size: 11px; color: var(--fg-dim); }
.bounce-progress-bar { position: relative; height: 10px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.bounce-progress-fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: var(--accent); transition: width 80ms linear; }
.bounce-progress-status { font-size: 11px; color: var(--fg-dim); }

.patch-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 40vh; overflow-y: auto; }
.patch-list .patch-row { display: flex; gap: 6px; align-items: stretch; }
.patch-list .patch-load { flex: 1; text-align: left; }
.patch-list .patch-del { padding: 4px 10px; }
.patch-empty { color: var(--fg-dim); font-size: 12px; padding: 8px 0; }

.track-mod-panel .mod-ctl-row { display: flex; gap: 16px; padding-bottom: 4px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.track-mod-panel .mod-ctl { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--fg-dim); }
.track-mod-panel .mod-ctl input[type="range"] { width: 110px; }
.track-mod-panel .mod-rows { display: grid; gap: 4px; }
.track-mod-panel .mod-add-row { display: flex; gap: 6px; align-items: center; margin-top: 4px; padding-top: 6px; border-top: 1px solid var(--border); }
.track-mod-panel .mod-add-btn { font-size: 11px; padding: 4px 10px; }
.track-mod-panel .mod-add-select { font-size: 11px; padding: 3px 6px; }
.track-mod-panel .lfo-row .lfo-remove {
  padding: 0;
  font-size: 13px;
  line-height: 1;
  color: var(--fg-dim);
  width: 24px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.track-mod-panel .lfo-row .lfo-remove:hover { color: var(--danger); }
.modal-ok {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
  font-weight: 600;
}
.modal-ok:disabled,
.sound-preview:disabled,
.sound-regen:disabled { opacity: 0.45; cursor: not-allowed; }
.sound-preview {
  background: var(--accent-2);
  color: #0b0d10;
  border-color: var(--accent-2);
  font-weight: 600;
}
.sound-dialog { min-width: 460px; max-width: 640px; }
.sound-dialog-status {
  color: var(--fg-dim);
  font-size: 11px;
  letter-spacing: 0.02em;
  padding: 2px 2px;
}

.step-note {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 10px;
  color: #0b0d10;
  pointer-events: none;
  font-weight: 700;
  opacity: 0.75;
}
.step:not(.on) .step-note { display: none; }

/* ============================================================ */
/* mobile / portrait-phone adaptations                          */
/* ------------------------------------------------------------ */
/* Everything below is mobile-only. No horizontal scroll: every */
/* row wraps within the viewport width.                          */
/* ============================================================ */

/* track-extras-toggle: hidden on desktop, visible on mobile */
.mobile-only { display: none !important; }

@media (max-width: 768px) {
  html, body { font-size: 12px; }

  /* respect notch / home indicator on iOS */
  body { padding-bottom: env(safe-area-inset-bottom); }
  .transport { padding-top: max(6px, env(safe-area-inset-top)); }

  /* show mobile-only elements (track "more" toggle etc.) */
  .mobile-only { display: inline-flex !important; }

  /* ---------- TRANSPORT BAR ---------- */
  .transport {
    padding: 6px 8px;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    row-gap: 4px;
  }
  .transport .logo { padding-right: 4px; gap: 6px; }
  .transport .logo img { width: 26px; height: 26px; }
  .transport .logo span { display: none; }

  .transport button.play {
    min-width: 64px;
    padding: 9px 14px;
    font-weight: 700;
    font-size: 13px;
  }

  .transport .field { gap: 4px; }
  .transport .field label { font-size: 10px; }
  .transport input[type="number"] { width: 48px; padding: 5px 6px; }
  .transport input[type="range"] { width: 80px; }

  .transport .scale-field {
    flex: 1 1 100%;
    order: 100;
    gap: 4px;
    flex-wrap: wrap;
  }
  .transport .scale-field select { padding: 4px 6px; min-width: 0; flex: 1 1 0; }
  .transport #add-track { order: 99; padding: 6px 10px; }
  .transport .spacer { display: none; }

  .transport .status {
    flex: 1 1 100%;
    order: 200;
    min-width: 0;
    text-align: left;
    font-size: 11px;
  }
  .master-meter { width: 50px; height: 8px; }
  .beat-indicator { width: 30px; height: 30px; }

  /* ---------- PATTERN BAR (mobile = Share + Menu only) ---------- */
  .pattern-bar {
    padding: 6px 8px;
    gap: 6px;
    align-items: center;
  }
  /* Hide every pattern-bar child by default on mobile. Share + Menu opt in. */
  .pattern-bar > * { display: none; }
  .pattern-bar > #set-share {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 0;
    padding: 0 12px;
    min-height: 36px;
  }
  .pattern-bar > #pattern-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 0;
    padding: 0 12px;
    min-height: 36px;
    background: var(--bg-3);
    color: var(--fg);
    border: 1px solid var(--border);
    text-transform: none;
    font-weight: 600;
  }

  /* When the pattern menu modal is open, its children appear inside it.
     Layout matches what the bar used to look like, vertically stacked. */
  .pattern-menu-modal {
    width: 96vw;
    max-width: 96vw;
    min-width: 0;
    max-height: 92vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
  }
  .pattern-menu-modal #set-save,
  .pattern-menu-modal #set-load,
  .pattern-menu-modal #set-export,
  .pattern-menu-modal #set-import,
  .pattern-menu-modal #bounce-audio,
  .pattern-menu-modal #bounce-track,
  .pattern-menu-modal #pattern-dup {
    padding: 8px 10px;
    font-size: 12px;
    min-width: 0;
    min-height: 36px;
  }
  .pattern-menu-modal .set-stack,
  .pattern-menu-modal .mode-stack { display: flex; flex-direction: row; gap: 6px; }
  .pattern-menu-modal .set-stack > *,
  .pattern-menu-modal .mode-stack > * { flex: 1; }
  .pattern-menu-modal .mode-row { display: flex; gap: 6px; flex: 1; }
  .pattern-menu-modal .mode-row > * { flex: 1; }
  .pattern-menu-modal .repeat-wrap {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    font-size: 12px;
  }
  .pattern-menu-modal .repeat-wrap input,
  .pattern-menu-modal .repeat-wrap select {
    width: auto;
    flex: 1;
    padding: 6px 8px;
    text-align: center;
  }
  /* mini-row that groups sig + rep + dup */
  .pattern-menu-modal .pattern-menu-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
  }
  .pattern-menu-modal .pattern-menu-row > * { flex: 1 1 auto; }

  /* pattern grid inside the modal: wide cells, 8 per row */
  .pattern-menu-modal .pattern-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-auto-rows: 34px;
    gap: 4px;
    width: 100%;
  }
  .pattern-cell { min-height: 28px; font-size: 11px; }
  .pattern-menu-modal .pattern-cell { min-height: 34px; font-size: 12px; }

  .pattern-menu-modal .pattern-menu-close {
    align-self: stretch;
    margin-top: 4px;
    padding: 10px;
    background: var(--accent);
    color: #0b0d10;
    border-color: var(--accent);
    font-weight: 600;
    min-height: 40px;
  }
  .pattern-menu-modal .dl-btn { gap: 6px; }
  .pattern-menu-modal .dl-btn .dl-label { display: inline; }

  /* ---------- MAIN AREA ---------- */
  main { padding: 8px; gap: 8px; }
  .track { padding: 8px; gap: 8px; border-radius: 6px; }

  /* ---------- TRACK HEAD ---------- */
  .track-head { gap: 6px; row-gap: 4px; }
  .track-head .field input[type="range"] { width: 70px; }
  .track-head .field label { font-size: 10px; }

  .track-head .track-name {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    font-size: 13px;
    padding: 6px 8px;
  }
  .track-head .track-engine {
    flex: 2 1 0;
    min-width: 0;
    max-width: none;
    padding: 6px 6px;
  }
  .track-head .vol-field { flex: 1 1 100%; }
  .track-head .vol-combo { width: 100%; }

  /* len + spd group: keep inline but compact */
  .track-head .field:has(.track-len) { gap: 3px; }
  .track-head .track-len { width: 44px; padding: 4px 4px; }
  .track-head .track-speed { padding: 4px 4px; }
  .track-len-extend { gap: 2px; flex-wrap: nowrap; }
  .track-len-extend button {
    padding: 4px 6px;
    min-width: 32px;
    font-size: 10px;
    min-height: 28px;
  }

  .track-oct { gap: 2px; flex-wrap: nowrap; }
  .track-oct button {
    padding: 4px 6px;
    min-width: 36px;
    font-size: 10px;
    min-height: 28px;
  }

  /* Hide-by-default extras inside the track-head; the "more" button opens
     these in a centered modal instead (.track-menu-modal). The selectors
     are scoped to .track-head so when nodes are reparented into the modal
     they become visible again automatically. */
  .track-head .track-save,
  .track-head .track-load-patch,
  .track-head .track-dup,
  .track-head .track-remove,
  .track-head .track-oct,
  .track-head .track-len-extend,
  .track-head .track-synth-row,
  .track-head .field:has(.track-speed) {
    display: none;
  }

  /* "more" toggle button injected by JS */
  .track-head .track-more {
    padding: 6px 10px;
    min-height: 32px;
    font-size: 16px;
    line-height: 1;
    min-width: 36px;
    text-transform: none;
  }
  .track-head .track-more[aria-pressed="true"] {
    background: var(--accent);
    color: #0b0d10;
    border-color: var(--accent);
  }

  /* Track menu modal: hosts the reparented track-head extras. Layout
     vertically stacks the groups for thumb-friendly tapping. */
  .track-menu-modal {
    width: 96vw;
    max-width: 96vw;
    min-width: 0;
    max-height: 92vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
  }
  .track-menu-modal .track-menu-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--fg);
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
  }
  .track-menu-modal .track-save,
  .track-menu-modal .track-load-patch,
  .track-menu-modal .track-dup,
  .track-menu-modal .track-remove {
    padding: 8px 10px;
    font-size: 12px;
    min-width: 0;
    min-height: 36px;
  }
  .track-menu-modal .track-len-extend,
  .track-menu-modal .track-oct {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
  }
  .track-menu-modal .track-len-extend > button,
  .track-menu-modal .track-oct > button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 34px;
    padding: 6px 4px;
    font-size: 11px;
  }
  .track-menu-modal .track-synth-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
  }
  .track-menu-modal .track-synth-row[hidden],
  .track-menu-modal .param-group[hidden] { display: none; }
  .track-menu-modal .param-group {
    padding: 4px 6px;
    gap: 6px;
    flex-wrap: wrap;
  }
  .track-menu-modal .field:has(.track-speed) {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  .track-menu-modal .track-menu-close {
    align-self: stretch;
    margin-top: 4px;
    padding: 10px;
    background: var(--accent);
    color: #0b0d10;
    border-color: var(--accent);
    font-weight: 600;
    min-height: 40px;
  }

  /* solo/mute/clear: pinned, finger-friendly */
  .track-head .track-solo,
  .track-head .track-mute,
  .track-head .track-clear {
    padding: 6px 10px;
    min-height: 32px;
    font-size: 12px;
  }

  /* synth-row: stack groups */
  .track-synth-row { gap: 4px; flex-direction: column; align-items: stretch; }
  .param-group { padding: 4px 6px; gap: 6px; flex-wrap: wrap; }
  .param-group .field input[type="range"] { width: 60px; }
  .moog-osc-group .moog-osc-row { flex-wrap: wrap; }
  .moog-osc-group .moog-freq input[type="range"] { width: 60px; }

  /* panel-btn-group: full-width row, smaller buttons */
  .track-head .panel-btn-group {
    flex: 1 1 100%;
    flex-wrap: wrap;
    border-radius: 6px;
  }
  .track-head .panel-btn-group > button {
    flex: 1 1 0;
    padding: 8px 4px;
    font-size: 11px;
    min-width: 0;
    min-height: 34px;
    border-right: 1px solid var(--border);
  }

  /* ---------- FX / FILTER / EQ / COMP / ENV panels ---------- */
  .track-fx-panel,
  .track-filter-panel,
  .track-env-panel,
  .track-eq-panel,
  .track-comp-panel,
  .track-mod-panel,
  .track-aut-panel,
  .track-roll-panel {
    padding: 6px 8px;
  }
  .fx-row {
    gap: 6px;
    padding: 4px 0;
    row-gap: 4px;
  }
  .fx-row .fx-title {
    flex: 1 1 100%;
    min-width: 0;
    font-size: 10px;
  }
  .fx-ctl { gap: 4px; }
  .fx-ctl span { min-width: 28px; font-size: 10px; }
  .fx-ctl input[type="range"] { width: 70px; }
  .fx-ctl select { padding: 3px 4px; font-size: 11px; }

  /* lfo row: 2-column stacked layout */
  .lfo-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    gap: 6px;
    row-gap: 4px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
  }
  .lfo-row .lfo-target {
    grid-column: 1 / -1;
    font-size: 11px;
  }
  .lfo-row .lfo-enable { grid-column: 1; }
  .lfo-row .lfo-shape { grid-column: 2; }
  .lfo-row .lfo-sync-wrap { grid-column: 1; }
  .lfo-row .lfo-rate-field {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  .lfo-row .field:last-of-type { grid-column: 1 / -1; }
  .lfo-row .lfo-remove {
    grid-row: 1;
    grid-column: 2 / -1;
    justify-self: end;
    align-self: start;
  }

  /* automation lane: stack label/buttons above grid */
  .aut-lane {
    grid-template-columns: 1fr auto auto auto;
    grid-template-rows: auto auto;
    gap: 4px;
    row-gap: 4px;
  }
  .aut-lane .aut-grid {
    grid-column: 1 / -1;
    grid-row: 2;
    height: 64px;
  }

  /* keep wide piano-roll contents from pushing the page width.
     Tracks (and main grid items) default to min-width: auto, which lets
     intrinsic content grow them — explicitly clamp to 0 so the page stays
     bounded and the overflow lives inside the roll-grid. */
  main, .track { min-width: 0; }
  .track > * { min-width: 0; }
  .track-roll-panel { min-width: 0; overflow: hidden; }

  /* piano roll: allow horizontal scroll INSIDE the roll-grid only.
     Sticky labels keep pitch names visible while scrolling steps. */
  .roll-grid {
    grid-template-columns: 36px minmax(0, 1fr);
    max-height: 260px;
    overflow: auto;
    overscroll-behavior: contain;
  }
  .roll-label {
    font-size: 9px;
    padding: 2px 4px;
    line-height: 1.3;
    position: sticky;
    left: 0;
    z-index: 2;
  }
  .roll-cells { min-width: max-content; }
  .roll-cell { height: 18px; min-width: 30px; }
  .roll-vel-lane { grid-template-columns: 36px minmax(0, 1fr); }
  .roll-vel-spacer { position: sticky; left: 0; z-index: 2; }
  .roll-vel-cells { height: 96px; min-width: max-content; }
  .roll-vel-cell { min-width: 30px; }

  /* ---------- STEP GRID (no horizontal scroll) ---------- */
  /* 16 cols stay; cells are tall to compensate for narrow width. */
  .steps {
    grid-auto-rows: 52px;
    gap: 2px;
    touch-action: pan-y;
  }
  .step {
    aspect-ratio: auto;
    min-height: 52px;
    height: 52px;
    border-radius: 3px;
  }
  .step.held {
    height: auto;
    min-height: 52px;
    align-self: stretch;
  }
  /* note label larger so a finger can read it before tapping */
  .step-note { font-size: 11px; }
  .step.beat { outline: 1px solid rgba(255,255,255,0.10); }

  /* ---------- STEP EDITOR MODAL ---------- */
  .step-editor {
    padding: 10px;
    max-width: 96vw;
    width: 96vw;
    max-height: 92vh;
    overflow-y: auto;
    gap: 6px;
    min-width: 0;
  }
  .step-editor .se-title { font-size: 10px; }
  .step-editor .se-field {
    grid-template-columns: 50px minmax(0, 1fr) 60px;
    gap: 6px;
  }
  .step-editor .se-chord-field {
    grid-template-columns: 50px 1fr auto;
    row-gap: 4px;
  }
  .step-editor .se-chord-field .se-chord-label {
    grid-column: 1 / -1;
    text-align: left;
  }
  .step-editor .se-note-field {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 6px;
  }
  .step-editor .se-note-field > label:first-child { display: none; }
  .step-editor .se-note-header {
    grid-column: 1;
    grid-row: 1;
  }
  .step-editor .se-keyboard {
    --se-pad-size: 30px;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 3px;
    grid-column: 1;
    grid-row: 2;
  }
  .step-editor .se-keyboard .se-pad {
    font-size: 10px;
    aspect-ratio: 1 / 1;
  }
  .step-editor .se-arp-selects { flex-wrap: wrap; }
  .step-editor .se-arp-selects select { flex: 1 1 30%; }
  .step-editor .se-sample-row { grid-template-columns: 1fr; }
  .step-editor .se-sample-row > label:first-child { display: none; }
  .step-editor .se-sample-ctl { grid-column: 1; }
  .step-editor .se-sample-meta { gap: 6px; }
  .step-editor .se-sample-fade { grid-template-columns: 1fr; gap: 6px; }
  .step-editor .se-waveform { height: 60px; }

  /* ---------- GENERIC MODALS ---------- */
  .modal {
    min-width: 0;
    width: 94vw;
    max-width: 94vw;
    padding: 14px 16px;
    gap: 8px;
  }
  .modal-actions button {
    padding: 8px 12px;
    min-height: 36px;
  }
  .bounce-opts input[type="text"] { width: 100%; }
  .bounce-opts label { flex: 1 1 100%; }

  .patch-list .patch-row button { padding: 8px 10px; min-height: 36px; }
}

/* very small phones: a touch tighter */
@media (max-width: 380px) {
  main { padding: 6px; }
  .track { padding: 6px; }
  .transport { padding: 5px 6px; }
  .pattern-bar { padding: 5px 6px; }
  .steps { grid-auto-rows: 48px; }
  .step { min-height: 48px; height: 48px; }
}

