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

body {
  background: #fff0db;
  color: #0f4c81;
  font-family: 'DM Sans', sans-serif;
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 1.25rem 1.5rem;
  gap: 0.75rem;
}

/* ── Header ── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.title { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.03em; }
.title-dim { opacity: 0.35; }

.header-controls { display: flex; align-items: center; gap: 0.75rem; }

.clean-btn {
  background: none;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  color: #0f4c81;
  opacity: 0.28;
  cursor: pointer;
  padding: 0.2rem 0.45rem;
  border-radius: 5px;
  transition: opacity 0.15s, background 0.15s;
}
.clean-btn:hover { opacity: 0.7; background: rgba(15, 76, 129, 0.07); }

/* ── Toggles ── */

.toggle-group {
  display: flex;
  background: rgba(15, 76, 129, 0.08);
  border-radius: 7px;
  padding: 3px;
  gap: 2px;
}

.tog {
  background: none;
  border: none;
  border-radius: 5px;
  padding: 0.28rem 0.75rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: #0f4c81;
  opacity: 0.4;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.tog.active { background: #0f4c81; color: #fff0db; opacity: 1; }
.tog:not(.active):hover { opacity: 0.65; }

/* ── Play button ── */

.play-btn {
  background: #0f4c81;
  color: #fff0db;
  border: 2px solid #0f4c81;
  border-radius: 6px;
  padding: 0.38rem 1.1rem;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
  min-width: 68px;
}

.play-btn:hover { transform: scale(1.04); opacity: 0.85; }
.play-btn:active { transform: scale(0.97); }
.play-btn.playing { background: transparent; color: #0f4c81; }

.bpm-display { font-size: 0.8rem; font-weight: 600; opacity: 0.38; min-width: 58px; }

/* ── Main ── */

.main {
  display: flex;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.panel-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.35;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════
   SONG VIEW LAYOUT
   Default = ui mode: song-ui big, song-code small right
   ══════════════════════════════════════════ */

#panel-song-ui {
  display: flex;
  flex: 1;
  gap: 1.5rem;
  min-height: 0;
  min-width: 0;
}

#panel-song-code {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Song code panel label is slightly secondary in UI mode */
#panel-song-code .panel-label {
  opacity: 0.25;
}

/* Code mode: song-code big, song-ui narrow side */
.app.song-code #panel-song-code {
  flex: 1;
  width: auto;
}

.app.song-code #panel-song-ui {
  flex: unset;
  flex-direction: column;
  width: 220px;
  flex-shrink: 0;
  gap: 0;
}

.app.song-code .scenes-col { width: 100%; flex: 1; min-height: 0; }
.app.song-code .arr-col { display: flex; width: 100%; flex: 1; min-height: 0; }

.app.song-code .arr-col {
  border-top: 1px solid rgba(15, 76, 129, 0.1);
  padding-top: 0.6rem;
  margin-top: 0.25rem;
  overflow: hidden;
}

/* Vertical arrangement list in code mode */
.app.song-code .song-arr-list {
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 2px;
  gap: 3px;
  min-height: 0;
}

.app.song-code .song-arr-block {
  width: 100%;
  min-height: unset;
  flex-direction: row;
  align-items: center;
  padding: 0.32rem 0.5rem;
  gap: 6px;
}

.app.song-code .arr-step-num {
  min-width: 1.4rem;
  text-align: right;
}

.app.song-code .arr-block-scenes {
  flex-direction: row;
  width: auto;
  flex: 1;
  flex-wrap: wrap;
  gap: 3px;
}

.app.song-code .arr-scene-chip {
  width: 2rem;
  min-height: 2rem;
  flex-shrink: 0;
}

.app.song-code .arr-drop-zone {
  width: 100%;
  min-height: 36px;
}

/* Compact scene cards in side (code) mode */
.app.song-code .col-header { margin-bottom: 0.5rem; }
.app.song-code .scene-card { padding: 0.5rem 0.65rem; gap: 0.5rem; }
.app.song-code .scene-card-letter { font-size: 1.5rem; width: 2rem; }
.app.song-code .scene-card-tracks { display: none; }
.app.song-code .scene-card-bpm { font-size: 0.68rem; }
.app.song-code .scene-card-actions .card-btn:not([data-action="edit"]) { display: none; }
.app.song-code .scene-card-actions .card-btn[data-action="edit"] { padding: 0 0.5rem; height: 26px; font-size: 0.68rem; }
.app.song-code #panel-song-code .panel-label { opacity: 0.35; }

/* ── Song code editor ── */

#song-editor {
  flex: 1;
  background: rgba(15, 76, 129, 0.04);
  border: 1.5px solid rgba(15, 76, 129, 0.14);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  font-family: 'DM Mono', 'Fira Mono', 'Courier New', monospace;
  font-size: 0.82rem;
  color: #0f4c81;
  resize: none;
  outline: none;
  line-height: 1.8;
  caret-color: #0f4c81;
}

#song-editor:focus { border-color: rgba(15, 76, 129, 0.3); }
#song-editor::selection { background: rgba(15, 76, 129, 0.14); }

/* Slightly muted editor when song-ui mode (secondary panel) */
.app:not(.song-code) #song-editor {
  opacity: 0.7;
  font-size: 0.76rem;
  line-height: 1.75;
}
.app:not(.song-code) #song-editor:focus {
  opacity: 1;
  border-color: rgba(15, 76, 129, 0.3);
}

/* ══════════════════════════════════════════
   SONG UI: Columns + Cards
   ══════════════════════════════════════════ */

.song-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.scenes-col { width: 320px; flex-shrink: 0; }
.arr-col    { flex: 1; min-width: 0; }

.col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  margin-bottom: 0.75rem;
}

.new-scene-btn {
  background: none;
  border: 1.5px solid rgba(15, 76, 129, 0.22);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  color: #0f4c81;
  opacity: 0.55;
  cursor: pointer;
  transition: opacity 0.12s, background 0.12s;
}
.new-scene-btn:hover { opacity: 1; background: rgba(15, 76, 129, 0.06); }

.arr-total {
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.35;
}

/* ── Scene cards ── */

.scene-cards-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overflow-y: auto;
  flex: 1;
  padding: 6px 6px 0;
  margin: -6px -6px 0;
}

.scene-card {
  position: relative;
  background: rgba(15, 76, 129, 0.04);
  border: 1.5px solid rgba(15, 76, 129, 0.14);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-shrink: 0;
  transition: border-color 0.15s;
}

.scene-card.playing { border-color: #0f4c81; background: rgba(15, 76, 129, 0.08); }

.scene-card-letter {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: #0f4c81;
  opacity: 0.5;
  width: 2.5rem;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}

.scene-card.playing .scene-card-letter { opacity: 1; }

.scene-card-info { flex: 1; min-width: 0; }

.scene-card-bpm {
  display: block;
  font-size: 0.72rem; font-weight: 600; opacity: 0.4;
}

.scene-card-tracks {
  display: block;
  font-size: 0.7rem; opacity: 0.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 0.1rem;
}

.scene-card-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

.card-btn {
  height: 30px;
  padding: 0 0.7rem;
  border-radius: 6px;
  border: 1.5px solid rgba(15, 76, 129, 0.2);
  background: none; color: #0f4c81;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.73rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
}
.card-btn:hover { background: rgba(15, 76, 129, 0.07); border-color: rgba(15,76,129,0.35); }
.card-btn.primary { background: #0f4c81; color: #fff0db; border-color: #0f4c81; }
.card-btn.primary:hover { opacity: 0.85; }
.scene-card-remove {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: #0f4c81;
  color: #fff0db;
  font-size: 0.62rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}
.scene-card:hover .scene-card-remove { display: flex; }

.song-empty-hint {
  font-size: 0.8rem;
  opacity: 0.35;
  line-height: 1.6;
  padding: 0.5rem 0;
}

/* ── Song arrangement timeline (horizontal) ── */

.song-arr-list {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 3px;
  flex: 1;
  padding: 2px 2px 12px 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 76, 129, 0.18) transparent;
}

.song-arr-list::-webkit-scrollbar { height: 5px; }
.song-arr-list::-webkit-scrollbar-track { background: transparent; }
.song-arr-list::-webkit-scrollbar-thumb { background: rgba(15, 76, 129, 0.2); border-radius: 3px; }

.song-arr-list .song-empty-hint {
  margin: auto;
  padding: 0 0.5rem;
  white-space: nowrap;
}

.song-arr-block {
  position: relative;
  background: rgba(15, 76, 129, 0.04);
  border: 1.5px solid rgba(15, 76, 129, 0.13);
  border-radius: 10px;
  padding: 0.45rem 0.35rem 0.55rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
  width: var(--step-width, 80px);
  min-height: 72px;
  transition: border-color 0.12s, background 0.12s, opacity 0.12s;
}

.song-arr-block:active  { cursor: grabbing; }
.song-arr-block.dragging { opacity: 0.35; }
.song-arr-block.drag-over { border-color: #0f4c81; background: rgba(15,76,129,0.1); }
.song-arr-block.playing   { border-color: #0f4c81; background: rgba(15,76,129,0.08); }

.arr-step-num {
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  opacity: 0.2;
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
}

/* ── Scene chips within each arrangement step ── */

.arr-block-scenes {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
}

.arr-scene-chip {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 2.4rem;
  border-radius: 6px;
  background: rgba(15, 76, 129, 0.1);
  flex-shrink: 0;
  transition: background 0.1s, opacity 0.12s;
  padding: 0.22rem 0;
  gap: 1px;
  cursor: grab;
}
.arr-scene-chip:hover { background: rgba(15, 76, 129, 0.18); }
.arr-scene-chip.dragging { opacity: 0.3; cursor: grabbing; }

.arr-chip-letter {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: #0f4c81;
  cursor: pointer;
  user-select: none;
  line-height: 1;
}


.arr-chip-remove {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: #0f4c81;
  color: #fff0db;
  font-size: 0.58rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}
.arr-scene-chip:hover .arr-chip-remove { display: flex; }

/* ── Drag feedback ── */

.song-arr-block.drag-merge {
  border-color: #0f4c81;
  border-style: dashed;
  background: rgba(15, 76, 129, 0.05);
}

/* ── Block resize handle ── */

.arr-block-resize {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 2;
  border-radius: 0 10px 10px 0;
}
.arr-block-resize::after {
  content: '';
  position: absolute;
  right: 1px;
  top: 25%;
  height: 50%;
  width: 2px;
  border-radius: 1px;
  background: #0f4c81;
  opacity: 0.5;
}
.song-arr-block:hover .arr-block-resize { opacity: 1; }

.arr-block-ghost {
  opacity: 0.35;
  border-style: dashed;
  pointer-events: none;
}

/* ── Drop zone at end of timeline ── */

.arr-drop-zone {
  border: 1.5px dashed rgba(15, 76, 129, 0.2);
  border-radius: 8px;
  width: var(--step-width, 80px);
  min-height: 72px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  color: #0f4c81;
  opacity: 0.28;
  text-align: center;
  padding: 0.4rem;
  line-height: 1.35;
  transition: opacity 0.15s, border-color 0.15s, background 0.15s;
}
.arr-drop-zone.active {
  opacity: 1;
  border-color: #0f4c81;
  background: rgba(15, 76, 129, 0.04);
}

/* ══════════════════════════════════════════
   PATTERN EDITOR OVERLAY
   ══════════════════════════════════════════ */

.pattern-editor {
  position: fixed;
  inset: 0;
  background: #fff0db;
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.5rem;
  gap: 0.75rem;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.pattern-editor.open {
  pointer-events: all;
  opacity: 1;
  transform: translateY(0);
}

/* PE header */
.pe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.pe-title {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  opacity: 0.75;
}

.pe-title span {
  opacity: 1;
  color: #0f4c81;
}

.pe-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.pe-btn {
  height: 32px;
  padding: 0 0.9rem;
  border-radius: 6px;
  border: 1.5px solid rgba(15, 76, 129, 0.22);
  background: none;
  color: #0f4c81;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, border-color 0.1s, opacity 0.1s;
}
.pe-btn:hover { background: rgba(15, 76, 129, 0.07); border-color: rgba(15,76,129,0.35); }
.pe-btn.active { background: rgba(15, 76, 129, 0.12); border-color: rgba(15, 76, 129, 0.35); }
.pe-btn.primary { background: #0f4c81; color: #fff0db; border-color: #0f4c81; }
.pe-btn.primary:hover { opacity: 0.85; }

/* PE main area */
.pe-main {
  display: flex;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

/* PE code editor textarea */
#pe-editor {
  flex: 1;
  background: rgba(15, 76, 129, 0.04);
  border: 1.5px solid rgba(15, 76, 129, 0.14);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  font-family: 'DM Mono', 'Fira Mono', 'Courier New', monospace;
  font-size: 0.82rem;
  color: #0f4c81;
  resize: none;
  outline: none;
  line-height: 1.8;
  caret-color: #0f4c81;
}
#pe-editor:focus { border-color: rgba(15, 76, 129, 0.3); }
#pe-editor::selection { background: rgba(15, 76, 129, 0.14); }

/* PE default (code mode): code big, viz right, seq hidden */
#pe-panel-seq { display: none; }
#pe-panel-code { flex: 1; }
#pe-panel-viz  { width: 300px; flex-shrink: 0; }

/* PE ui mode: seq big, code small right, viz hidden */
.pattern-editor.pe-ui #pe-panel-seq  { display: flex; flex: 1; flex-direction: column; }
.pattern-editor.pe-ui #pe-panel-code { flex: unset; width: 260px; flex-shrink: 0; }
.pattern-editor.pe-ui #pe-panel-viz  { display: none; }

/* In ui mode, code editor is secondary */
.pattern-editor.pe-ui #pe-editor {
  opacity: 0.8;
  font-size: 0.76rem;
  line-height: 1.75;
}
.pattern-editor.pe-ui #pe-editor:focus {
  opacity: 1;
  border-color: rgba(15, 76, 129, 0.3);
}
.pattern-editor.pe-ui #pe-panel-code .panel-label {
  opacity: 0.25;
}

/* ── Viz (step display) ── */

.viz { display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }
.track-row { display: flex; align-items: center; gap: 0.5rem; }

.track-name {
  font-size: 0.7rem; font-weight: 600;
  width: 64px; flex-shrink: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0.6;
}

.track-steps { display: flex; gap: 2px; flex: 1; }
.step-group { display: flex; gap: 2px; }
.step-group + .step-group { margin-left: 3px; }

.step { width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }
.step.on  { background: #0f4c81; opacity: 0.85; }
.step.off { background: rgba(15, 76, 129, 0.12); }
.step.current.on  { opacity: 1; outline: 2px solid #0f4c81; outline-offset: 1px; }
.step.current.off { background: rgba(15, 76, 129, 0.3); }

/* ── Reference ── */

.ref-panel { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.ref-grid { display: flex; gap: 1rem; flex: 1; min-height: 0; overflow: hidden; }
.ref-section { flex: 1; }
.ref-title { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.35; margin-bottom: 0.35rem; }
.ref-item { display: flex; align-items: baseline; gap: 0.4rem; margin-bottom: 0.2rem; }
.ref-item code { font-family: 'DM Mono', 'Fira Mono', monospace; font-size: 0.7rem; background: rgba(15,76,129,0.08); padding: 0.05rem 0.3rem; border-radius: 3px; }
.ref-item span { font-size: 0.68rem; opacity: 0.45; }

/* ── Sequencer (PE ui mode) ── */

.seq-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; flex-shrink: 0; }
.bpm-control { display: flex; align-items: center; gap: 0.4rem; }
.bpm-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.35; margin-right: 0.15rem; }

.bpm-btn {
  width: 26px; height: 26px; border-radius: 5px;
  border: 1.5px solid rgba(15, 76, 129, 0.25);
  background: none; color: #0f4c81;
  font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: 'DM Sans', sans-serif;
  transition: background 0.12s;
}
.bpm-btn:hover { background: rgba(15, 76, 129, 0.08); }
.bpm-btn:active { transform: scale(0.93); }
#pe-bpm-value { font-size: 1.05rem; font-weight: 700; min-width: 2.2rem; text-align: center; }

.seq-tracks { display: flex; flex-direction: column; gap: 6px; flex: 1; overflow-y: auto; }
.seq-row { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.seq-name { font-size: 0.72rem; font-weight: 600; width: 78px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.65; }
.seq-steps { display: flex; gap: 3px; flex-shrink: 0; }
.seq-group { display: flex; gap: 3px; }
.seq-group + .seq-group { margin-left: 5px; }

.seq-step {
  width: 32px; height: 32px; border-radius: 5px; border: none;
  cursor: pointer; flex-shrink: 0;
  transition: transform 0.08s, opacity 0.08s, background 0.08s;
}
.seq-step.on  { background: #0f4c81; }
.seq-step.off { background: rgba(15, 76, 129, 0.1); }
.seq-step.off:hover { background: rgba(15, 76, 129, 0.22); }
.seq-step.on:hover  { opacity: 0.75; }
.seq-step:active { transform: scale(0.9); }
.seq-step.current.on  { outline: 2.5px solid #0f4c81; outline-offset: 2px; opacity: 1; }
.seq-step.current.off { background: rgba(15, 76, 129, 0.28); }

.seq-vol-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  width: 96px;
}

.seq-vol-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 96px;
  height: 3px;
  background: rgba(15, 76, 129, 0.18);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.seq-vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #0f4c81;
  cursor: pointer;
}
.seq-vol-slider::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #0f4c81;
  border: none;
  cursor: pointer;
}

.seq-vol-label {
  font-size: 0.6rem;
  font-weight: 600;
  color: #0f4c81;
  opacity: 0.4;
  line-height: 1;
}

.seq-delete {
  width: 24px; height: 24px; border: none; background: none;
  color: #0f4c81; opacity: 0.25; font-size: 1.1rem; cursor: pointer;
  border-radius: 4px; display: flex; align-items: center; justify-content: center;
  transition: opacity 0.12s, background 0.12s; flex-shrink: 0;
}
.seq-delete:hover { opacity: 0.7; background: rgba(15, 76, 129, 0.08); }

.add-track-row {
  display: flex; gap: 0.5rem; align-items: center;
  padding-top: 0.75rem; margin-top: 0.5rem;
  border-top: 1px solid rgba(15, 76, 129, 0.1); flex-shrink: 0;
}

.add-track-row select, .add-track-row input {
  border: 1.5px solid rgba(15, 76, 129, 0.2); border-radius: 6px;
  padding: 0.35rem 0.55rem;
  font-family: 'DM Sans', sans-serif; font-size: 0.78rem;
  color: #0f4c81; background: rgba(15, 76, 129, 0.04);
  outline: none; appearance: none; -webkit-appearance: none;
}
.add-track-row select {
  padding-right: 1.5rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%230f4c81' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.45rem center;
}
.add-track-row select:focus, .add-track-row input:focus { border-color: rgba(15, 76, 129, 0.4); }
.note-input { width: 52px; text-align: center; font-family: 'DM Mono', 'Fira Mono', monospace !important; }

.add-btn {
  background: rgba(15, 76, 129, 0.08); border: 1.5px solid rgba(15, 76, 129, 0.18);
  border-radius: 6px; padding: 0.35rem 0.8rem;
  font-family: 'DM Sans', sans-serif; font-size: 0.78rem; font-weight: 600;
  color: #0f4c81; cursor: pointer; white-space: nowrap;
  transition: background 0.12s;
}
.add-btn:hover { background: rgba(15, 76, 129, 0.14); }

/* ── Status bar ── */

.status-bar { flex-shrink: 0; font-size: 0.75rem; font-weight: 500; opacity: 0.4; height: 1.2rem; }
.status-bar.error { opacity: 1; color: #a0341a; }

/* ── Mobile ── */

@media (max-width: 600px) {
  body { overflow: auto; }

  .app { height: auto; min-height: 100vh; overflow: auto; padding: 1rem; }
  .main { flex-direction: column; }

  /* Song UI: stack columns */
  #panel-song-ui { flex-direction: column; gap: 1rem; }
  .scenes-col { width: 100%; }
  .arr-col { width: 100%; }

  /* Song code panel: full width below in UI mode */
  #panel-song-code { width: 100%; }

  /* Code mode on mobile: stack vertically */
  .app.song-code #panel-song-ui { width: 100%; }
  .app.song-code #panel-song-code { width: 100%; flex: none; }
  .app.song-code .arr-col { display: flex; }

  /* Pattern editor: full height scrollable */
  .pattern-editor { overflow-y: auto; position: fixed; }
  .pe-main { flex-direction: column; }
  #pe-panel-viz { width: 100%; }
  .ref-panel { display: none; }
  .pattern-editor.pe-ui #pe-panel-code { width: 100%; }
  .seq-tracks { overflow-x: auto; }
  .seq-row { min-width: max-content; }
  .seq-step { width: 26px; height: 26px; }
  .step { width: 10px; height: 10px; }
  .track-name { width: 52px; }
  .pe-controls { gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
  .pe-btn { height: 28px; padding: 0 0.65rem; font-size: 0.73rem; }
}
