*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: #0d0d1a;
  color: #ccc;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ─── Header ─────────────────────────────────── */

header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 20px;
  background: #12122a;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 3px;
  color: #00d4aa;
  text-transform: uppercase;
}

.controls {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* Volume */

.vol-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.vol-control label {
  min-width: 20px;
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: #00d4aa;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.vol-control input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  background: #2a2a4a;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.vol-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #00d4aa;
  cursor: pointer;
}

.vol-control input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #00d4aa;
  border: none;
  cursor: pointer;
}

.vol-control input[type="range"]::-moz-range-track {
  background: #2a2a4a;
  height: 4px;
  border-radius: 2px;
  border: none;
}

/* BPM */

.bpm-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#bpm {
  width: 64px;
  background: #1c1c38;
  color: #eee;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 0.9rem;
  text-align: center;
}

#bpm:focus {
  outline: none;
  border-color: #00d4aa;
}

/* Waveform */

.waveform-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.waveform-btn {
  padding: 5px 12px;
  background: #1c1c38;
  color: #777;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.waveform-btn:hover {
  border-color: #00d4aa88;
  color: #aaa;
}

.waveform-btn.selected {
  background: #00d4aa1a;
  border-color: #00d4aa;
  color: #00d4aa;
}

/* Playmode */

.playmode-control {
  display: flex;
  align-items: center;
  gap: 4px;
}

.playmode-btn {
  padding: 5px 12px;
  background: #1c1c38;
  color: #777;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.playmode-btn:hover {
  border-color: #00d4aa88;
  color: #aaa;
}

.playmode-btn.selected {
  background: #00d4aa1a;
  border-color: #00d4aa;
  color: #00d4aa;
}

/* Transport */

.transport-controls {
  display: flex;
  gap: 8px;
}

#play-btn,
#stop-btn {
  padding: 6px 18px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  transition: background 0.12s, color 0.12s;
}

#play-btn {
  background: #00d4aa;
  color: #0d0d1a;
}

#play-btn:hover {
  background: #00eebb;
}

#stop-btn {
  background: #1c1c38;
  color: #888;
  border: 1px solid #3a3a5a;
}

#stop-btn:hover {
  background: #252545;
  color: #ccc;
}

/* ADSR */

.adsr-controls {
  display: flex;
  align-items: center;
  gap: 20px;
}

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

.adsr-group label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #00d4aa;
  text-transform: uppercase;
  letter-spacing: 1px;
  min-width: 36px;
  flex-shrink: 0;
}

.adsr-group input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 4px;
  background: #2a2a4a;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.adsr-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #00d4aa;
  cursor: pointer;
  transition: background 0.12s;
}

.adsr-group input[type="range"]::-webkit-slider-thumb:hover {
  background: #00eebb;
}

.adsr-group input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #00d4aa;
  border: none;
  cursor: pointer;
}

.adsr-group input[type="range"]::-moz-range-track {
  background: #2a2a4a;
  height: 4px;
  border-radius: 2px;
  border: none;
}

.adsr-val {
  font-size: 0.75rem;
  font-family: monospace;
  color: #778;
  min-width: 36px;
}

/* Effects (Filter + Reverb) */

.fx-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.fx-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fx-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #556;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.fx-sep {
  width: 1px;
  height: 18px;
  background: #2a2a4a;
}

.fx-type {
  display: flex;
  gap: 4px;
}

.filter-type-btn {
  padding: 4px 9px;
  background: #1c1c38;
  color: #777;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.filter-type-btn:hover {
  border-color: #00d4aa88;
  color: #aaa;
}

.filter-type-btn.selected {
  background: #00d4aa1a;
  border-color: #00d4aa;
  color: #00d4aa;
}

/* Seq actions (Random Seq + Clear All) */

.seq-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}


/* Pitch controls (Octave + Root) */

.pitch-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.octave-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.oct-btn {
  width: 24px;
  height: 24px;
  background: #1c1c38;
  color: #00d4aa;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s, background 0.12s;
}

.oct-btn:hover {
  background: #00d4aa1a;
  border-color: #00d4aa;
}

#oct-display {
  font-size: 0.9rem;
  font-family: monospace;
  color: #ccc;
  min-width: 18px;
  text-align: center;
}

.root-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.root-btns {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.root-btn {
  padding: 3px 7px;
  background: #1c1c38;
  color: #666;
  border: 1px solid #2a2a4a;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: monospace;
  letter-spacing: 0;
  transition: border-color 0.1s, color 0.1s, background 0.1s;
  white-space: nowrap;
}

.root-btn:hover {
  border-color: #00d4aa88;
  color: #aaa;
}

.root-btn.selected {
  background: #00d4aa1a;
  border-color: #00d4aa;
  color: #00d4aa;
}

/* Metronome */

.metro-btn {
  padding: 5px 10px;
  background: #1c1c38;
  color: #777;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.metro-btn::before { content: '○ '; }
.metro-btn.active::before { content: '● '; }

.metro-btn:hover { border-color: #00d4aa88; color: #aaa; }

.metro-btn.active {
  background: #00d4aa1a;
  border-color: #00d4aa;
  color: #00d4aa;
}

/* Settings toggle */

#settings-panel {
  overflow: hidden;
  max-height: 200px;
  transition: max-height 0.22s ease, opacity 0.22s ease;
  opacity: 1;
}

#settings-panel.collapsed {
  max-height: 0;
  opacity: 0;
}

.settings-btn {
  padding: 5px 12px;
  background: #1c1c38;
  color: #777;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: border-color 0.12s, color 0.12s;
}

.settings-btn.open {
  border-color: #00d4aa;
  color: #00d4aa;
}

/* Clear All */

#clear-btn {
  padding: 5px 14px;
  background: #1c1c38;
  color: #c06060;
  border: 1px solid #5a2a2a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

#clear-btn:hover {
  background: #3a1a1a;
  color: #ff8888;
  border-color: #883333;
}

/* ─── Section bars ───────────────────────────── */

.section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px;
  background: #0f0f24;
  border-top: 1px solid #1a1a30;
  border-bottom: 1px solid #1a1a30;
  flex-shrink: 0;
}

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #444;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.collapse-btn {
  background: none;
  border: none;
  color: #444;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
  transition: color 0.12s, transform 0.2s;
}

.collapse-btn:hover { color: #00d4aa; }

.collapse-btn.collapsed { transform: rotate(-90deg); }

/* ─── Piano Roll ──────────────────────────────── */

#piano-roll {
  display: grid;
  grid-template-columns: 48px repeat(16, 1fr);
  grid-template-rows: 22px repeat(13, 30px);
  gap: 2px;
  padding: 12px 62px 8px 16px; /* right=62px matches drum-roll's 44px mute col + 2px gap + 16px padding */
  background: #0d0d1a;
  flex-shrink: 0;
  touch-action: none; /* allow pointer-drag-to-paint without triggering scroll */
}

.pr-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  font-size: 11px;
  font-family: monospace;
  color: #556;
  user-select: none;
}

.pr-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-family: monospace;
  color: #3a3a58;
  user-select: none;
}

.step-cell {
  background: #191929;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid #1e1e38;
  transition: background 0.07s, border-color 0.07s, box-shadow 0.07s;
  user-select: none;
}

.step-cell:hover {
  background: #20203a;
  border-color: #2a2a4a;
}

.step-cell.active {
  background: #00d4aa;
  border-color: #00d4aa;
  box-shadow: 0 0 8px rgba(0, 212, 170, 0.35);
}

.step-cell.playhead {
  background: #1c1c38;
  border-color: #303060;
}

.step-cell.active.playhead {
  background: #ffcc00;
  border-color: #ffcc00;
  box-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
}

/* ─── Drum Roll ──────────────────────────────────────────── */

#drum-roll-wrap {
  display: flex;
  align-items: stretch;
  padding: 12px 16px 8px;
  background: #0d0d1a;
  gap: 2px;
}

#drum-roll {
  display: grid;
  grid-template-columns: 48px repeat(16, 1fr);
  grid-template-rows: 22px repeat(6, 30px);
  gap: 2px;
  flex: 1;
  touch-action: none;
}

#drum-mute-col {
  display: grid;
  grid-template-rows: 22px repeat(6, 30px);
  gap: 2px;
  width: 44px;
  flex-shrink: 0;
}

.dr-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  font-size: 10px;
  font-family: monospace;
  color: #664444;
  user-select: none;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Per-track horizontal volume slider (replaces .dr-label on instrument rows) */
.dr-vol-slider {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ew-resize;
  user-select: none;
  overflow: hidden;
  border-radius: 2px;
  background: #110d0d;
}
.dr-vol-fill {
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  background: #3a1010;
  pointer-events: none;
}
.dr-vol-text {
  position: relative;
  z-index: 1;
  font-size: 9px;
  font-family: monospace;
  color: #cc6666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  pointer-events: none;
}

.dr-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-family: monospace;
  color: #3a3a58;
  user-select: none;
}

.drum-cell {
  background: #191929;
  border-radius: 3px;
  cursor: pointer;
  border: 1px solid #1e1e38;
  transition: background 0.07s, border-color 0.07s, box-shadow 0.07s;
}

.drum-cell:hover { background: #221824; border-color: #3a2a2a; }

.drum-cell.active {
  background: #ff6b6b;
  border-color: #ff6b6b;
  box-shadow: 0 0 8px rgba(255,107,107,0.35);
}

.drum-cell.playhead { background: #1c1c38; border-color: #303060; }

.drum-cell.active.playhead {
  background: #ffcc00;
  border-color: #ffcc00;
  box-shadow: 0 0 10px rgba(255,204,0,0.5);
}

.drum-cell.muted { opacity: 0.3; }

.drum-mute-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1c1c38;
  color: #555;
  border: 1px solid #2a2a3a;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.65rem;
  font-family: monospace;
  font-weight: 700;
  text-transform: uppercase;
  transition: border-color 0.12s, color 0.12s;
}

.drum-mute-btn.muted {
  background: #ff6b6b1a;
  border-color: #ff6b6b;
  color: #ff6b6b;
}

.drum-section-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  padding-left: 12px;
}

.drum-playmode-btn {
  padding: 3px 10px;
  background: #1c1c38;
  color: #777;
  border: 1px solid #3a3a5a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.drum-playmode-btn.selected {
  background: #ff6b6b1a;
  border-color: #ff6b6b;
  color: #ff6b6b;
}

/* ── SEQ toggle button ─────────────────────────────────── */
.seq-toggle-btn {
  padding: 2px 6px;
  background: #1c1c38;
  color: #444;
  border: 1px solid #2a2a4a;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.65rem;
  font-family: monospace;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.seq-toggle-btn:hover { border-color: #00d4aa44; color: #888; }
.seq-toggle-btn.active {
  background: color-mix(in srgb, var(--param-color) 15%, transparent);
  border-color: var(--param-color);
  color: var(--param-color);
}
/* Frozen live slider */
.adsr-group input[type="range"]:disabled {
  opacity: 0.25;
  pointer-events: none;
}
.adsr-group label.seq-frozen { opacity: 0.35; }
.adsr-val.seq-frozen          { opacity: 0.35; }

/* ── Sequence tabs ─────────────────────────────────────── */
.seq-tabs {
  display: flex;
  align-items: stretch;
  gap: 1px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}
.seq-tabs::-webkit-scrollbar { display: none; }
.seq-tab {
  padding: 3px 11px;
  background: transparent;
  color: #444;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
}
.seq-tab:hover { color: #888; }
.seq-tab.active {
  color: var(--tab-color, #00d4aa);
  border-bottom-color: var(--tab-color, #00d4aa);
}

/* ── Auto step sequencer panel ─────────────────────────── */
#seq-body {
  display: flex;
  flex-direction: column;
}
#auto-seq-panel {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 3px;
  padding: 8px 16px;
  background: #0d0d1a;
  /* matches piano roll: header(22) + 13 rows(390) + 13 gaps(26) + padding(20) = 458px */
  height: calc(22px + 13 * 30px + 13 * 2px + 12px + 8px);
  box-sizing: border-box;
}
.auto-seq-param-panel {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 3px;
  width: 100%;
  height: 100%;
}
.auto-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  height: 100%;
}
.auto-bar-step-num {
  font-size: 8px;
  font-family: monospace;
  color: #3a3a58;
  user-select: none;
  flex-shrink: 0;
}
.auto-bar-track {
  flex: 1;
  width: 100%;
  position: relative;
  background: #191929;
  border-radius: 3px;
  border: 1px solid #1e1e38;
  cursor: ns-resize;
  overflow: hidden;
  user-select: none;
  transition: border-color 0.07s;
}
.auto-bar-track:hover { border-color: #2a2a4a; }
.auto-bar-fill {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--bar-color);
  opacity: 0.72;
  border-radius: 2px 2px 0 0;
  pointer-events: none;
}
.auto-bar-track.playhead {
  border-color: #ffcc00;
  box-shadow: 0 0 6px rgba(255,204,0,0.35);
}
.auto-bar-track.playhead .auto-bar-fill { opacity: 1; }

/* Note-step indicator dot below bar track */
.auto-note-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #00d4aa;
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 0.1s;
}
.auto-bar-wrap.has-note .auto-note-dot { opacity: 0.85; }
.auto-bar-wrap.has-note .auto-bar-step-num { color: #00d4aa; }

/* ── Seq section contextual action button ──────────────── */
.seq-action-btn {
  padding: 2px 7px;
  background: none;
  color: #444;
  border: 1px solid #1a1a30;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.72rem;
  font-family: inherit;
  margin-left: 6px;
  flex-shrink: 0;
  transition: color 0.12s, border-color 0.12s;
}
.seq-action-btn:hover { color: #c06060; border-color: #5a2a2a; }
.seq-action-btn.active { color: #ff6b6b; border-color: #ff6b6b; background: #ff6b6b1a; }

/* Save pattern button — distinct teal accent */
.seq-action-btn.save-btn {
  color: #00d4aa88;
  border-color: #00d4aa33;
}
.seq-action-btn.save-btn:hover {
  color: #00d4aa;
  border-color: #00d4aa;
  background: #00d4aa1a;
}
#drum-save-btn {
  color: #ff6b6b88;
  border-color: #ff6b6b33;
}
#drum-save-btn:hover {
  color: #ff6b6b;
  border-color: #ff6b6b;
  background: #ff6b6b1a;
}

/* Save-new "+" button */
.seq-action-btn.save-new-btn {
  color: #00d4aa88;
  border-color: #00d4aa33;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 1px 8px;
}
.seq-action-btn.save-new-btn:hover {
  color: #00d4aa;
  border-color: #00d4aa;
  background: #00d4aa1a;
}
#drum-save-new-btn {
  color: #ff6b6b88;
  border-color: #ff6b6b33;
}
#drum-save-new-btn:hover {
  color: #ff6b6b;
  border-color: #ff6b6b;
  background: #ff6b6b1a;
}
.seq-action-btn.save-new-btn:disabled {
  color: #333;
  border-color: #1a1a30;
  cursor: not-allowed;
  opacity: 0.4;
  background: none;
}

/* ─── Graph ───────────────────────────────────── */

#graph-wrap {
  flex: 1;
  min-height: 380px;
  position: relative;
  border-top: 1px solid #1a1a30;
}

#graph {
  position: absolute;
  inset: 0;
  background: #08080f;
  overflow: hidden;
}

#fit-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  padding: 5px 11px;
  background: #12122a;
  color: #00d4aa;
  border: 1px solid #00d4aa44;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  opacity: 0.6;
  transition: opacity 0.15s, border-color 0.15s;
}

#fit-btn:hover {
  opacity: 1;
  border-color: #00d4aa;
}

/* ─── Minimal responsive wrap ────────────────── */

@media (max-width: 768px) {
  .header-row { flex-wrap: wrap; }
  .controls { flex-wrap: wrap; gap: 6px; }
  #graph-wrap { min-height: 220px; }
}
