:root {
  color-scheme: light;
  --bg-1: #f3f1ed;
  --bg-2: #efede8;
  --bg-3: #e9e5df;
  --bg-panel: #f9f7f3;
  --accent: #c8bfb3;
  --accent-2: #d6cdc2;
  --text-primary: #483f37;
  --text-muted: #8b8278;
  --border: #dcd5cb;
  --danger: #d27a7a;
  --success: #8cbf7f;
  --key-group-yellow: #d9b76a;
  --key-group-orange: #d99a74;
  --btn-surface: #f4f1eb;
  --btn-surface-2: #ebe4dc;
  --input-bg: rgba(255, 255, 255, 0.78);
  --input-border: rgba(72, 63, 55, 0.25);
  --panel-radius: 14px;
  --shadow-1: 6px 8px 18px rgba(0, 0, 0, 0.06), -6px -6px 18px rgba(255, 255, 255, 0.75);
  --shadow-inset: inset 4px 4px 10px rgba(0, 0, 0, 0.06), inset -4px -4px 10px rgba(255, 255, 255, 0.7);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.theme-2 {
  color-scheme: dark;
  --bg-1: #101317;
  --bg-2: #151a20;
  --bg-3: #1d242d;
  --bg-panel: #1c232c;
  --accent: #5dd6ff;
  --accent-2: #9b7df4;
  --text-primary: #f6f9fc;
  --text-muted: #a6b0bf;
  --border: #27303c;
  --danger: #ff6b7a;
  --success: #79f29c;
  --key-group-yellow: #ffd76d;
  --key-group-orange: #ffb07d;
  --btn-surface: #1c232c;
  --btn-surface-2: #27303c;
  --input-bg: rgba(13, 16, 22, 0.7);
  --input-border: rgba(67, 77, 92, 0.3);
  --panel-radius: 10px;
  --shadow-1: 0 12px 32px rgba(10, 12, 18, 0.32);
  --shadow-inset: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.9), transparent 35%), radial-gradient(circle at 80% 10%, rgba(200, 191, 179, 0.35), transparent 40%), var(--bg-1);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  font-size: 11px;
}

body.theme-2 {
  background: radial-gradient(circle at top right, rgba(93, 214, 255, 0.08), transparent 40%), radial-gradient(circle at bottom left, rgba(155, 125, 244, 0.1), transparent 45%), var(--bg-1);
  color-scheme: dark;
}

body.theme-1 {
  color-scheme: light;
}

#app {
  width: min(1980px, 100vw);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100vh;
}

.random-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compact-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.randomize-header {
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.drum-header {
  justify-content: flex-start;
  gap: 10px;
}

.inline-field {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.density-inline input[type="range"] {
  max-width: 160px;
}

.random-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.random-inline > button {
  flex: 1 1 130px;
  min-width: 130px;
}

/* Keep all three drum sliders aligned on the top row */
.drum-top-controls {
  flex-wrap: wrap;
}

.drum-top-controls .inline-field {
  flex: 1 1 160px;
}

.drum-top-controls .inline-field input[type="range"] {
  width: 100%;
}

.master-transport {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}

.transport-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: 100%;
}

.transport-toolbar .transport-action {
  flex: 1 1 0;
  min-width: 140px;
  justify-content: center;
  display: inline-flex;
  align-items: center;
  text-align: center;
}

.tall-action {
  min-height: 56px;
  padding-top: 12px;
  padding-bottom: 12px;
  font-size: 0.82rem;
  font-weight: 700;
}

.duration-control {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 0 0 auto;
}

.duration-control input {
  width: 64px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(16, 19, 23, 0.8);
  color: var(--text-primary);
}

.duration-control #durationDisplay {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.08em;
  position: relative;
}

.duration-time {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.key-mode-field {
  margin-top: 8px;
}

.key-mode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.key-mode-option {
  position: relative;
  cursor: pointer;
}

.key-mode-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.key-mode-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--btn-surface);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  transition: border 0.2s ease, color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  box-shadow: var(--shadow-1);
}

.key-mode-pill strong {
  font-size: 0.85rem;
  letter-spacing: 0;
}

.key-mode-pill small {
  font-size: 0.62rem;
  opacity: 0.75;
}

.key-mode-option input:checked + .key-mode-pill {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--btn-surface);
}

.key-mode-option:hover .key-mode-pill {
  border-color: var(--accent);
}

.tempo-display {
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-indicator::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-right: 5px;
  background: var(--danger);
}

.status-indicator.playing::before {
  background: var(--success);
  box-shadow: 0 0 6px rgba(121, 242, 156, 0.55);
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/* Layout shells */
.layout {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}

.layout-shell {
  width: 100%;
}

.layout.layout-unified .classic-shell {
  display: none;
}

.layout.layout-classic .classic-shell {
  display: block;
}

.layout.layout-classic .unified-shell {
  display: none;
}

.unified-shell {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.composition-tabs {
  width: 100%;
}

.panel-slot {
  width: 100%;
}

.panel-slot > .panel {
  height: 100%;
}

.lower-panels-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(200px, 1fr));
  gap: 10px;
  align-items: start;
}

.classic-shell {
  width: 100%;
}

.classic-grid {
  display: grid;
  grid-template-columns: 1fr minmax(480px, 640px);
  gap: 10px;
  align-items: start;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  box-shadow: var(--shadow-1);
}

.panel-title {
  margin: 0;
  font-size: 0.88rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.tracks-column {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.track-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(200px, 1fr));
  gap: 8px;
  flex: 1 1 auto;
  overflow: visible;
  padding-right: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  align-items: start;
  align-content: start;
}
.track-list::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* NEW: Styles for the new content wrappers */
.main-content-wrapper {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0; /* Prevents flexbox overflow issues */
}

.tracks-panel {
  flex: 1 1 auto;
  min-height: 0;
}

.controls-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.drum-panel-wide {
  width: 100%;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  align-items: start;
}

.controls-column-main,
.controls-column-side,
.controls-column-extra {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tabbed-panel {
  padding-top: 10px;
}

.tab-header {
  display: flex;
  gap: 8px;
  margin: -2px 0 6px;
}

.tab-btn {
  border-radius: 9px;
  border: 1px solid var(--border);
  padding: 7px 12px;
  background: var(--btn-surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.tab-btn.active {
  color: var(--text-primary);
  border-color: var(--accent);
  box-shadow: var(--shadow-1);
}

.tab-content {
  display: block;
}

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 10px;
}

.tab-pane.active {
  display: flex;
}


.track {
  gap: 9px;
  min-height: 0; /* Let cards size to content to avoid large bottom gaps */
}

.track-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.track-title {
  margin: 0;
  font-size: 0.84rem;
  letter-spacing: 0.03em;
}

.track-tags {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.field-caption {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
  min-width: 0;
}

.field-grid-3-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-grid-2-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.random-checkbox-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-grid label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 0;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

/* Fit preset + button on one row inside Theory panel's narrow column */
#theoryPanel .field-row .field.grow {
  flex: 1 1 auto;
  min-width: 0;
}
#theoryPanel .field-row .field.slim {
  flex: 0 0 100px;
  width: 100px;
}

.field-row .field {
  flex: 1;
  min-width: 120px;
}

.field-grid label input[type="range"],
.field-grid label select,
.field-grid label input[type="number"],
.field-grid label input[type="text"] {
  flex: 1;
}

.field-row.compact {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-primary);
}
.checkbox input[type="checkbox"] {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--btn-surface);
  box-shadow: var(--shadow-inset);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.checkbox input[type="checkbox"]::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: transparent;
  transition: background 0.2s ease;
}
.checkbox input[type="checkbox"]:checked::after {
  background: var(--accent);
}

input[type="range"],
select,
textarea,
input[type="text"],
input[type="number"] {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 10px;
  padding: 7px 9px;
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
  width: 100%;
}

#durationInput {
  max-width: 90px;
  padding: 6px 8px;
  font-size: 0.85rem;
  text-align: right;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(93, 214, 255, 0.2);
}

.algorithm-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 9px;
  align-items: center;
}

.algorithm-row label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.octave-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.octave-toggle {
  border: 1px solid rgba(93, 214, 255, 0.4);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.7rem;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.octave-toggle.active {
  background: rgba(93, 214, 255, 0.25);
  color: var(--text-primary);
  border-color: rgba(93, 214, 255, 0.8);
  box-shadow: 0 0 12px rgba(93, 214, 255, 0.35);
}

.track-top-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.track-mix-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.track-gen-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.track-gen-row .field {
  flex: 1 1 160px;
  min-width: 0;
}

.track-gen-row .seed-field {
  flex: 0 0 120px;
}

.track-gen-row .random-melody-btn {
  flex: 0 0 auto;
  align-self: flex-end;
}

.distribution-grid label {
  align-items: center;
}

.primary-btn,
.accent-btn,
.ghost-btn {
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 8px 14px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.primary-btn {
  background: var(--btn-surface);
  color: var(--text-primary);
  font-weight: 600;
  border-color: var(--border);
  box-shadow: var(--shadow-1);
}

.accent-btn {
  background: var(--btn-surface);
  color: var(--text-primary);
  border-color: var(--border);
  box-shadow: var(--shadow-1);
}

.ghost-btn {
  background: var(--btn-surface);
  color: var(--text-primary);
  border-color: var(--border);
  box-shadow: var(--shadow-1);
}

.primary-btn:hover,
.accent-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-1);
}

.primary-btn:active,
.accent-btn:active,
.ghost-btn:active {
  transform: translateY(0);
}

.mute-btn.active {
  background: rgba(255, 107, 122, 0.18);
  border-color: rgba(255, 107, 122, 0.4);
  color: #ff8b9c;
}

.chord-grid,
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(var(--chord-columns, 8), minmax(0, 1fr));
}

.chord-grid { gap: 8px; }
.toggle-grid { gap: 6px; }

.toggle-grid + .toggle-grid { margin-top: 4px; }

.toggle-divider {
  grid-column: 1 / -1;
  border-top: 1px solid var(--border);
  padding: 4px 6px 2px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* New: simple wrapper for stacked toggle rows */
.toggle-rows {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chord-cell,
.toggle-cell {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  position: relative;
  box-shadow: var(--shadow-inset);
}

/* Make per-step track toggles more compact */
.toggle-cell { min-height: 26px; }

.chord-cell {
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.chord-cell.active {
  background: rgba(140, 191, 127, 0.18);
  border-color: rgba(140, 191, 127, 0.45);
  color: var(--success);
  box-shadow: inset 0 0 0 1px rgba(121, 242, 156, 0.2);
}

.chord-cell.key-group-0.active:not(.playing) {
  background: rgba(121, 242, 156, 0.18);
  border-color: rgba(121, 242, 156, 0.45);
  color: var(--success);
}

.chord-cell.key-group-1.active:not(.playing) {
  background: rgba(217, 183, 106, 0.16);
  border-color: rgba(217, 183, 106, 0.45);
  color: var(--key-group-yellow);
  box-shadow: inset 0 0 0 1px rgba(255, 215, 109, 0.2);
}

.chord-cell.key-group-2.active:not(.playing) {
  background: rgba(217, 154, 116, 0.16);
  border-color: rgba(217, 154, 116, 0.45);
  color: var(--key-group-orange);
  box-shadow: inset 0 0 0 1px rgba(255, 176, 125, 0.2);
}

.chord-cell.playing {
  background: rgba(200, 191, 179, 0.25);
  border-color: rgba(200, 191, 179, 0.6);
  color: var(--accent);
  box-shadow: 0 0 14px rgba(93, 214, 255, 0.4), inset 0 0 0 1px rgba(93, 214, 255, 0.25);
}

.chord-cell.playing .chord-label {
  color: var(--accent);
}

.chord-cell.active .chord-label {
  color: var(--success);
}

.chord-cell.disabled {
  opacity: 0.45;
  border-color: rgba(0, 0, 0, 0.05);
  background: var(--bg-3);
}

.chord-cell.disabled .chord-label {
  color: rgba(72, 63, 55, 0.4);
}

.chord-cell .step-index,
.toggle-cell .step-index {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.45);
}

.toggle-cell button {
  width: 100%;
  height: 100%;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.75);
  font: inherit;
  cursor: pointer;
  border-radius: inherit;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.toggle-cell button:not(.active) {
  opacity: 0.7;
}

.toggle-cell button.active {
  background: rgba(121, 242, 156, 0.2);
  color: var(--success);
  box-shadow: inset 0 0 0 2px rgba(121, 242, 156, 0.35);
}

.toggle-cell.playing {
  border-color: rgba(93, 214, 255, 0.5);
  box-shadow: 0 0 12px rgba(93, 214, 255, 0.35);
}

.toggle-cell.playing button {
  background: rgba(93, 214, 255, 0.18);
  color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(93, 214, 255, 0.45);
}

.action-bar {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  gap: 14px;
  /* margin is now handled by the parent flex/grid gap */
  align-items: flex-start;
}

.action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-panel textarea {
  font-family: inherit;
}

.prompt-controls {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.prompt-controls .prompt-top-row {
  flex-wrap: nowrap;
}

.prompt-controls .prompt-top-row .field {
  flex: 1 1 0;
  min-width: 0;
}

.prompt-controls #localModelWrapper,
.prompt-controls #geminiModelWrapper {
  display: none;
}

.prompt-controls .compact-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compact-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.slim {
  flex: none;
  width: 140px;
}

.field.grow {
  flex: 1 1 220px;
  min-width: 180px;
}

.status-box {
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px dashed rgba(93, 214, 255, 0.4);
  background: rgba(13, 17, 23, 0.65);
  color: var(--text-muted);
  min-height: 34px;
}

.drum-kit-selectors {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

@media (max-width: 860px) {
  .drum-kit-selectors {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

.drum-select-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.drum-select-row select {
  flex: 1 1 auto;
  min-width: 0;
}

.inline-rand-btn {
  flex: 0 0 32px;
  min-width: 32px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--btn-surface);
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.inline-rand-btn:hover {
  background: var(--btn-surface);
  border-color: var(--accent);
}

.drum-volume-control {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.drum-volume-control span {
  color: var(--text-muted);
  font-size: 0.8rem;
  min-width: 26px;
}

.drum-volume-control input[type="range"] {
  flex: 1 1 auto;
}

.random-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 10px;
}

.random-filter-row .field {
  flex: 1 1 240px;
  min-width: 0;
}

.random-filter-row button {
  flex: 0 0 130px;
  white-space: nowrap;
}

.generation-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.generation-controls .field {
  flex: 1 1 auto;
}

@media (max-width: 1400px) {
  .classic-grid {
    grid-template-columns: minmax(360px, 1fr) 1fr;
  }
  .lower-panels-grid {
    grid-template-columns: repeat(3, minmax(220px, 1fr));
  }
  .controls-grid {
    grid-template-columns: 1fr 240px 220px;
  }
  .chord-grid,
  .toggle-grid {
    grid-template-columns: repeat(var(--chord-columns-sm, 4), minmax(0, 1fr));
  }
  .track-list {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
  }
}

@media (max-width: 1100px) {
  .classic-grid {
    grid-template-columns: 1fr;
  }
  .controls-grid {
    grid-template-columns: 1fr 1fr;
  }
  .lower-panels-grid {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
  }
  .action-bar {
    flex-direction: column;
  }
  .master-transport {
    align-items: stretch;
  }
  .track-list {
    grid-template-columns: 1fr;
    max-height: none;
  }
}

/* Mobile: surface only Master + Randomize panels */
@media (max-width: 900px) {
  .lower-panels-grid {
    grid-template-columns: 1fr;
  }
  .controls-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  /* Only surface Master, Randomize, Theory, Spatial FX */
  #compositionTabs,
  #distributionPanel,
  #tracksPanel,
  #drumPanel,
  .main-content-wrapper {
    display: none !important;
  }

  /* Hide secondary tabs */
  #ideasPanel .tab-btn[data-tab="promptTab"],
  #ideasPanel .tab-pane[data-tab="promptTab"],
  #masterPanel .tab-btn[data-tab="exportTab"],
  #masterPanel .tab-pane[data-tab="exportTab"] {
    display: none !important;
  }

  .controls-grid,
  .lower-panels-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
  }

  /* Flatten classic wrappers so slot order applies globally */
  .controls-grid > .controls-column-main,
  .controls-grid > .controls-column-side,
  .controls-grid > .controls-column-extra {
    display: contents;
  }

  /* Remove unused distribution slot to keep only the four mobile panels */
  #distributionSlotUnified,
  #distributionSlotClassic {
    display: none !important;
  }

  /* Enforce mobile order: Master, Randomize, Theory, Spatial FX */
  #masterSlotUnified,
  #masterSlotClassic { order: 1 !important; }
  #ideasSlotUnified,
  #ideasSlotClassic { order: 2 !important; }
  #theorySlotUnified,
  #theorySlotClassic { order: 3 !important; }
  #spatialSlotUnified,
  #spatialSlotClassic { order: 4 !important; }

  .controls-column {
    width: 100%;
  }
}
