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

body {
    font-family: "Courier New", monospace;
    background: #1a1a2e;
    color: #eee;
    min-height: 100vh;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background: #16213e;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #0f3460;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex-shrink: 0;
}

h1 { color: #e94560; font-size: 1.2rem; }
#controls { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.separator { color: #0f3460; }

#pattern-selector { display: flex; align-items: center; gap: 0.5rem; }
#pattern-selector span { font-size: 0.75rem; color: #888; }
#pattern-buttons { display: flex; gap: 2px; }

.pat-btn {
    width: 22px; height: 22px; padding: 0;
    font-size: 0.7rem; background: #0f3460; border: 1px solid #333;
}
.pat-btn:hover { border-color: #e94560; }
.pat-btn.active { background: #e94560; border-color: #e94560; }

#zoomLevel { display: inline-block; width: 1.5rem; text-align: center; color: #e94560; }

button {
    background: #0f3460; color: #eee; border: 1px solid #e94560;
    padding: 0.3rem 0.6rem; cursor: pointer; font-family: inherit; font-size: 0.8rem;
}
button:hover { background: #e94560; }
#zoomIn, #zoomOut { padding: 0.2rem 0.4rem; font-weight: bold; }

input[type="number"], input[type="range"] {
    background: #0f3460; border: 1px solid #e94560; color: #eee; padding: 0.2rem; width: 55px;
}

select {
    background: #0f3460; border: 1px solid #e94560; color: #eee;
    padding: 0.25rem; font-family: inherit; cursor: pointer;
}

/* Main container - flexible height */
#main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Left panel */
#track-panel {
    width: 200px;
    overflow-x: hidden;
    background: #16213e;
    border-right: 2px solid #0f3460;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    padding: 0.5rem;
}

#track-panel-header { margin-bottom: 0.5rem; }

#trackName {
     background: #0f3460; border: 2px solid #e94560;
    color: #e94560; padding: 0.3rem; font-size: 0.85rem;
    font-family: inherit; font-weight: bold; text-align: center;
}

#track-panel-upload, #bulk-upload { margin-bottom: 0.4rem; }
#sampleFile, #folderInput {  font-size: 0.6rem; }

#trackSampleList { list-style: none; flex: 1; overflow-y: auto; }

#trackSampleList li {
    padding: 0.25rem 0.4rem; cursor: pointer; border: 1px solid transparent;
    margin-bottom: 2px; background: #0f3460; font-size: 0.7rem;
    display: flex; align-items: center; gap: 0.3rem;
    border-radius: 3px;
}
#trackSampleList li:hover { border-color: #e94560; }
#trackSampleList li.active { background: #e94560; color: #fff; }

.sample-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sample-delete {
    background: transparent; border: none; color: #666;
    font-size: 0.75rem; padding: 0 0.15rem; cursor: pointer; line-height: 1;
}
.sample-delete:hover { color: #e94560; background: transparent; }
#trackSampleList li.active .sample-delete { color: rgba(255,255,255,0.6); }
.loop-sample { border-left: 2px solid #3b82f6; }

/* Center grid */
#tracker-grid {    flex: 1;    display: flex;    flex-direction: column;    overflow: auto;    padding: 0.5rem;}

#track-headers {
    width: fit-content;
    display: flex; gap: 1px; margin-bottom: 2px;
    position: sticky; top: 0; background: #1a1a2e; padding-bottom: 2px; z-index: 10;
}

#pattern-grid { display: flex; flex-direction: column; gap: 0; }

.pattern-row {
    width: fit-content;
    display: flex; gap: 1px;
    border-top: 1px solid #0f3460;
}
.pattern-row.beat-start { border-top: 2px solid #4a5568; }
.pattern-row.bar-start { border-top: 3px solid #e94560; }

.row-number {
    background: #0f3460; text-align: center;
    display: flex; align-items: center; justify-content: center;
}
.row-number.beat { background: #4a5568; }
.row-number.bar { background: #e94560; font-weight: bold; }

.track-header {
    background: #0f3460; text-align: center; font-weight: bold;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; border: 1px solid transparent;
}
.track-header:hover { border-color: #e94560; }
.track-header.selected { background: #e94560; color: #fff; }
.track-header:first-child { cursor: default; }
.track-header:first-child:hover { border-color: transparent; }

.track-header.loop-track { background: #1e3a5f; }
.track-header.loop-track.selected { background: #3b82f6; }
.track-header.muted { opacity: 0.4; }
.track-header.solo { border-color: #4ade80; }

.cell {
    background: #16213e; border: 1px solid #0a1628; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.cell:hover { border-color: #e94560; }
.cell.has-note { background: #e94560; color: #fff; }
.cell.playing { background: #fff; color: #000; }
.cell.loop-cell { background: #1e2a3e; }
.cell.loop-cell.has-note { background: #3b82f6; }
.cell.note-selected { outline: 2px solid #4ade80 !important; outline-offset: -1px; }
.cell.selected { outline: 2px solid #4ade80; outline-offset: -2px; background: #1a3a2e; }

/* Zoom levels */
.zoom-1 .track-header { width: 44px; height: 18px; font-size: 0.55rem; }
.zoom-1 .track-header:first-child { width: 24px; }
.zoom-1 .row-number { width: 24px; height: 14px; font-size: 0.5rem; }
.zoom-1 .cell { width: 44px; height: 14px; font-size: 0.45rem; }

.zoom-2 .track-header { width: 54px; height: 20px; font-size: 0.6rem; }
.zoom-2 .track-header:first-child { width: 28px; }
.zoom-2 .row-number { width: 28px; height: 16px; font-size: 0.55rem; }
.zoom-2 .cell { width: 54px; height: 16px; font-size: 0.5rem; }

.zoom-3 .track-header { width: 70px; height: 24px; font-size: 0.7rem; }
.zoom-3 .track-header:first-child { width: 32px; }
.zoom-3 .row-number { width: 32px; height: 20px; font-size: 0.6rem; }
.zoom-3 .cell { width: 70px; height: 20px; font-size: 0.55rem; }

/* Right FX panel */
#fx-panel {
    width: 180px;
    padding: 0.75rem;
    background: #16213e;
    border-left: 2px solid #0f3460;
    flex-shrink: 0;
    overflow-y: auto;
}

#fx-panel h3 {
    color: #e94560;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid #0f3460;
}

#fx-track-name {
    text-align: center;
    font-size: 0.9rem;
    font-weight: bold;
    color: #e94560;
    background: #0f3460;
    padding: 0.3rem;
    margin-bottom: 0.5rem;
    border-radius: 4px;
}

.fx-mute-solo {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    justify-content: center;
}

.mute-btn, .solo-btn {
    width: 32px; height: 22px;
    font-size: 0.7rem; font-weight: bold;
    border-radius: 3px;
}

.mute-btn { border-color: #f59e0b; color: #f59e0b; }
.mute-btn:hover, .mute-btn.active { background: #f59e0b; color: #000; }
.solo-btn { border-color: #4ade80; color: #4ade80; }
.solo-btn:hover, .solo-btn.active { background: #4ade80; color: #000; }

.fx-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.4rem;
}

.fx-row label {
    font-size: 0.65rem;
    color: #888;
    width: 30px;
    flex-shrink: 0;
}

.fx-row input[type="range"] {
    flex: 1;
    width: auto;
    min-width: 40px;
    height: 4px;
    -webkit-appearance: none;
    background: #0f3460;
    border-radius: 2px;
    border: none;
    padding: 0;
}

.fx-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px; height: 10px;
    background: #e94560;
    border-radius: 50%;
    cursor: pointer;
}

.fx-row span {
    font-size: 0.6rem;
    color: #666;
    width: 24px;
    text-align: right;
}

.fx-row select { flex: 1; font-size: 0.65rem; }

.fx-divider {
    height: 1px;
    background: #0f3460;
    margin: 0.5rem 0;
}

.fx-section-header {
    font-size: 0.6rem;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 0.3rem;
}

.fx-note-info {
    background: #0f3460;
    padding: 0.2rem 0.3rem;
    border-radius: 3px;
    font-size: 0.65rem;
    color: #555;
    margin-bottom: 0.3rem;
    text-align: center;
}
.fx-note-info.has-note { color: #4ade80; border: 1px solid #4ade80; }

#fxNoteOffset:disabled { opacity: 0.3; }

/* ============================================
   WAVEFORM FOOTER - BIG SLICE EDITOR
   ============================================ */
#waveform-footer {
    background: #0f1a2e;
    border-top: 3px solid #3b82f6;
    flex-shrink: 0;
}

#waveform-footer.hidden {
    display: none;
}

#waveform-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: #16213e;
}

#waveform-header h3 {
    color: #3b82f6;
    font-size: 1rem;
    margin: 0;
}

#slice-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#sliceCount {
    color: #888;
    font-size: 0.8rem;
}

#clearSlicesBtn {
    font-size: 0.7rem;
    padding: 0.25rem 0.6rem;
    border-color: #666;
}

#waveform-body {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 1rem 1rem;
}

#waveform-container {
    min-width: 0;
    flex: 1;
    background: #0a1220;
    border-radius: 6px;
    cursor: crosshair;
    border: 2px solid #1e3a5f;
}

#waveformCanvas {
    box-sizing: border-box;
    
    height: 220px;
    display: block;
}

#slice-list {
    width: 180px;
    max-height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.slice-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    background: #16213e;
    cursor: pointer;
    border-radius: 4px;
    border: 1px solid transparent;
}

.slice-item:hover { border-color: #3b82f6; }
.slice-item.active { background: #3b82f6; color: #fff; }

.slice-note {
    font-weight: bold;
    color: #4ade80;
    font-size: 0.9rem;
}
.slice-item.active .slice-note { color: #fff; }

.slice-pos { color: #666; }
.slice-item.active .slice-pos { color: rgba(255,255,255,0.7); }

/* Modal */
.modal {
    display: none; position: fixed; top: 0; left: 0;
     height: 100%; background: rgba(0,0,0,0.8);
    z-index: 1000; justify-content: center; align-items: center;
}
.modal.active { display: flex; }

.modal-content {
    background: #16213e; border: 2px solid #e94560;
    border-radius: 8px; max-width: 90vw; max-height: 80vh; overflow: auto;
}

.bulk-modal { width: 500px; }

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.75rem 1rem; border-bottom: 1px solid #0f3460;
}
.modal-header h2 { color: #e94560; font-size: 1rem; }

#bulkModalClose {
    background: none; border: none; color: #e94560;
    font-size: 1.2rem; cursor: pointer; padding: 0;
}
#bulkModalClose:hover { color: #fff; }

.modal-body { padding: 1rem; }
#folderMappings { margin-bottom: 1rem; }

.folder-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.4rem;
    background: #0f3460; margin-bottom: 0.5rem; border-radius: 4px;
}

.folder-name { flex: 1; font-size: 0.85rem; }
.folder-count { font-size: 0.7rem; color: #888; }
.folder-track { width: 100px; }

.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
#bulkCancelBtn { background: #333; border-color: #666; }

#zoomInBtn, #zoomOutBtn {
    width: 28px;
    padding: 4px 0;
    font-size: 16px;
    font-weight: bold;
}

#metronomeBtn {
    width: 32px;
    font-weight: bold;
}
#metronomeBtn.active {
    background: #22c55e;
    color: #000;
}

#link-mode-row {
    padding: 0.25rem 0;
}
#linkModeBtn {
    width: 100%;
    padding: 0.3rem;
    font-size: 0.8rem;
}
#linkModeBtn.active {
    background: #f59e0b;
    color: #000;
    font-weight: bold;
}

#copyPatBtn, #pastePatBtn {
    padding: 0.2rem 0.4rem;
    font-size: 0.7rem;
    margin-left: 0.25rem;
}

#bank-loader {
    display: flex;
    gap: 0.25rem;
    padding: 0.25rem 0;
    margin-bottom: 0.5rem;
}
#bankSelect {
    flex: 1;
    padding: 0.25rem;
    font-size: 0.75rem;
    background: #1a1a2e;
    color: #fff;
    border: 1px solid #333;
    border-radius: 3px;
}
#loadBankBtn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    white-space: nowrap;
}
#loadBankBtn:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* Melody track styles */
.track-header.melody-track { background: #3d2574; }
.track-header.melody-track.selected { background: #8b5cf6; }

.cell.melody-cell { background: #2d1f54; }
.cell.melody-cell.has-note { background: #8b5cf6; }
.cell.melody-cell.melody-cursor {
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
    background: #4a3670;
}
.cell.melody-cell.melody-cursor.has-note {
    background: #9d6dff;
}

#melody-controls {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
}

#melody-controls span {
    color: #888;
}

#melody-controls button {
    width: 20px;
    height: 20px;
    padding: 0;
    font-size: 0.8rem;
}

#octaveDisplay, #stepDisplay {
    display: inline-block;
    width: 18px;
    text-align: center;
    color: #8b5cf6;
    font-weight: bold;
}

/* Missing Samples Modal */
.missing-modal { width: 450px; }

.missing-info {
    color: #888;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

#missingList {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 1rem;
    background: #0f3460;
    border-radius: 4px;
    padding: 0.5rem;
}

#missingList li {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid #1a1a2e;
    font-size: 0.8rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#missingList li:last-child { border-bottom: none; }

#missingList li.loaded {
    opacity: 0.5;
    text-decoration: line-through;
}

.missing-track {
    background: #e94560;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: bold;
}

.missing-name {
    flex: 1;
    color: #ccc;
}

.missing-upload {
    margin-bottom: 1rem;
}

.missing-upload input[type="file"] {
    width: 100%;
    font-size: 0.75rem;
}

#saveBtn, #loadBtn {
    padding: 0.3rem 0.6rem;
}
