/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0d0d0d;
    --bg2: #1a1a1a;
    --bg3: #252525;
    --text: #e0e0e0;
    --text-dim: #888;
    --accent: #00e5ff;
    --kick: #ff3b3b;
    --snare: #ff9800;
    --hihat: #00e5ff;
    --clap: #ffe040;
    --hey: #ff69b4;
    --ho: #8b5cf6;
    --yeah: #06b6d4;
    --ugh: #84cc16;
    --tablahi: #e879f9;
    --tablalo: #f97316;
    --loop-colors: #a855f7, #22c55e, #ec4899, #3b82f6, #f97316, #14b8a6, #ef4444, #eab308;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 12px 16px 32px;
}

h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; }
h2 { font-size: 1rem; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 10px; }

/* ===== BUTTONS ===== */
.btn {
    border: none;
    border-radius: 6px;
    padding: 8px 18px;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform .1s, box-shadow .15s, background .15s;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.btn:active { transform: scale(.95); }
.btn-play {
    background: #22c55e;
    color: #000;
}
.btn-play.playing {
    background: #ef4444;
}
.btn-preset {
    background: var(--bg3);
    color: var(--text);
}
.btn-preset:hover { background: #333; }
.btn-preset-indian {
    background: linear-gradient(135deg, #3a2a1a, #4a3a2a);
    color: #f59e0b;
    border: 1px solid #f59e0b44;
}
.btn-preset-indian:hover { background: linear-gradient(135deg, #4a3a2a, #5a4a3a); }
.btn-record {
    background: var(--bg3);
    color: var(--text);
}
.btn-record.recording {
    background: #ef4444;
    color: #fff;
    animation: pulse-record 1s infinite;
}
@keyframes pulse-record {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); }
    50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
.btn-danger {
    background: #3a1a1a;
    color: #ef4444;
}
.btn-danger:hover { background: #4a1a1a; }

.btn-save { background: #1a3a1a; color: #22c55e; }
.btn-save:hover { background: #2a4a2a; }
.btn-load { background: #1a2a3a; color: #3b82f6; }
.btn-load:hover { background: #2a3a4a; }
.btn-record-song { background: #3a1a2a; color: #ec4899; }
.btn-record-song:hover { background: #4a2a3a; }
.btn-record-song.recording-song { background: #ec4899; color: #fff; animation: pulse-record 1s infinite; }
.btn-mic { background: linear-gradient(135deg, #1a3a1a, #2a4a2a); color: #4ADE80; font-size: 1rem; padding: 12px 24px; border: 2px solid #4ADE80; }
.btn-mic:hover { background: linear-gradient(135deg, #2a4a2a, #3a5a3a); }
.btn-mic.mic-active { background: #4ADE80; color: #000; animation: pulse-record 1s infinite; }
.mic-status { font-size: .75rem; color: var(--text-dim); }
.mic-status.active { color: #4ADE80; font-weight: 600; }

.save-status, .record-song-status {
    font-size: .75rem;
    color: var(--text-dim);
    min-width: 80px;
}
.save-status.success { color: #22c55e; }
.save-status.error { color: #ef4444; }
.record-song-status.active { color: #ec4899; font-weight: 600; }

.separator {
    color: #333;
    font-size: 1.2rem;
    margin: 0 4px;
}

/* ===== MASTER CONTROLS ===== */
#master-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 12px 0 16px;
    border-bottom: 1px solid #333;
    margin-bottom: 16px;
}
.master-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    flex: 1;
}
.bpm-control, .master-vol {
    display: flex;
    align-items: center;
    gap: 8px;
}
.bpm-control label, .master-vol label {
    font-size: .75rem;
    text-transform: uppercase;
    color: var(--text-dim);
}
#bpm-display {
    font-weight: 700;
    min-width: 30px;
    text-align: center;
    color: var(--accent);
}
.presets { display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== RANGE INPUTS ===== */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--bg3);
    border-radius: 3px;
    outline: none;
    width: 100px;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

/* ===== DRUM MACHINE ===== */
#drum-machine {
    margin-bottom: 20px;
}
#drum-grid {
    display: grid;
    grid-template-columns: 70px repeat(16, 1fr);
    gap: 3px;
}
.drum-label {
    display: flex;
    align-items: center;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    padding-right: 6px;
    justify-content: flex-end;
}
.drum-cell {
    aspect-ratio: 1;
    background: var(--bg2);
    border-radius: 4px;
    cursor: pointer;
    transition: background .1s, box-shadow .15s;
    min-width: 0;
    position: relative;
}
.drum-cell:hover { background: #2a2a2a; }
.drum-cell.active.kick { background: var(--kick); box-shadow: 0 0 8px var(--kick); }
.drum-cell.active.snare { background: var(--snare); box-shadow: 0 0 8px var(--snare); }
.drum-cell.active.hihat { background: var(--hihat); box-shadow: 0 0 8px var(--hihat); }
.drum-cell.active.clap { background: var(--clap); box-shadow: 0 0 8px var(--clap); }
.drum-cell.active.hey { background: var(--hey); box-shadow: 0 0 8px var(--hey); }
.drum-cell.active.ho { background: var(--ho); box-shadow: 0 0 8px var(--ho); }
.drum-cell.active.yeah { background: var(--yeah); box-shadow: 0 0 8px var(--yeah); }
.drum-cell.active.ugh { background: var(--ugh); box-shadow: 0 0 8px var(--ugh); }
.drum-cell.active.tablahi { background: var(--tablahi); box-shadow: 0 0 8px var(--tablahi); }
.drum-cell.active.tablalo { background: var(--tablalo); box-shadow: 0 0 8px var(--tablalo); }

/* Step indicator column highlight */
.drum-cell.current-step {
    outline: 2px solid #fff;
    outline-offset: -1px;
}

/* Beat grouping — subtle bg on 1st of each 4 */
.drum-cell.beat-start { background: #1f1f1f; }
.drum-cell.active.beat-start.kick { background: var(--kick); }
.drum-cell.active.beat-start.snare { background: var(--snare); }
.drum-cell.active.beat-start.hihat { background: var(--hihat); }
.drum-cell.active.beat-start.clap { background: var(--clap); }
.drum-cell.active.beat-start.hey { background: var(--hey); }
.drum-cell.active.beat-start.ho { background: var(--ho); }
.drum-cell.active.beat-start.yeah { background: var(--yeah); }
.drum-cell.active.beat-start.ugh { background: var(--ugh); }
.drum-cell.active.beat-start.tablahi { background: var(--tablahi); }
.drum-cell.active.beat-start.tablalo { background: var(--tablalo); }

/* ===== INLINE RECORD CONTROLS ===== */
#piano-record-section,
#xypad-record-section {
    margin-bottom: 8px;
}

.inline-record-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg2);
    border-radius: 8px;
    border: 1px solid #333;
}

.inline-record-controls .btn-record {
    padding: 6px 14px;
    font-size: .8rem;
}

.inline-record-controls select {
    padding: 6px 10px;
    font-size: .8rem;
}

.inline-record-label {
    font-size: .75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .5px;
}

/* ===== LOOP RECORDER ===== */
#loop-recorder { margin-bottom: 20px; }
.recorder-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}
select {
    background: var(--bg2);
    color: var(--text);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: .85rem;
    cursor: pointer;
    outline: none;
}
select:focus { border-color: var(--accent); }

#loops-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.loop-strip {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg2);
    border-radius: 8px;
    padding: 8px 12px;
    border-left: 4px solid;
}
.loop-strip .loop-name {
    font-weight: 600;
    font-size: .8rem;
    min-width: 80px;
}
.loop-strip canvas.loop-waveform {
    flex: 1;
    height: 36px;
    border-radius: 4px;
    background: var(--bg);
    min-width: 100px;
}
.loop-strip .loop-vol {
    width: 70px;
}
.loop-strip .btn-mute {
    background: var(--bg3);
    color: var(--text);
    padding: 5px 10px;
    font-size: .7rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
}
.loop-strip .btn-mute.muted {
    background: #555;
    color: #999;
}
.loop-strip .btn-del {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 2px 6px;
}

/* ===== DJ SCRATCH DISK ===== */
#dj-section { margin-bottom: 20px; }

.dj-container {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

#dj-disk {
    width: 280px;
    height: 280px;
    border-radius: 50%;
    cursor: grab;
    touch-action: none;
    box-shadow: 0 0 30px rgba(0, 229, 255, 0.15), inset 0 0 60px rgba(0, 0, 0, 0.5);
}
#dj-disk:active { cursor: grabbing; }

.dj-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-dj {
    background: var(--bg3);
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 10px 20px;
    font-size: .85rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-dj:hover { background: rgba(0, 229, 255, 0.1); }
.btn-dj.active-sound {
    background: var(--accent);
    color: #000;
    font-weight: 700;
}

/* ===== XY PAD ===== */
#pad-section { margin-bottom: 20px; }

#xy-pad {
    width: 100%;
    height: 220px;
    background: var(--bg2);
    border: 1px solid #333;
    border-radius: 10px;
    cursor: crosshair;
    touch-action: none;
    display: block;
}

.pad-hint {
    text-align: center;
    font-size: .7rem;
    color: var(--text-dim);
    margin-top: 6px;
}

/* ===== PIANO ===== */
#piano-section { margin-bottom: 20px; }
#piano-keyboard {
    display: flex;
    position: relative;
    height: 140px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}
.piano-key {
    position: relative;
    cursor: pointer;
    transition: background .06s;
}
.piano-key.white {
    background: linear-gradient(to bottom, #f0f0f0, #d8d8d8);
    border: 1px solid #999;
    border-radius: 0 0 5px 5px;
    flex: 1;
    height: 100%;
    z-index: 1;
}
.piano-key.black {
    background: linear-gradient(to bottom, #333, #111);
    border: 1px solid #000;
    border-radius: 0 0 4px 4px;
    width: 28px;
    height: 60%;
    position: absolute;
    z-index: 2;
    margin-left: -14px;
}
.piano-key.white.pressed {
    background: linear-gradient(to bottom, var(--accent), #0099aa);
}
.piano-key.black.pressed {
    background: linear-gradient(to bottom, var(--accent), #007788);
}
.piano-key .key-label {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    font-size: .55rem;
    color: #666;
    pointer-events: none;
}
.piano-key.black .key-label {
    color: #888;
    font-size: .5rem;
}

.keyboard-hint {
    text-align: center;
    font-size: .7rem;
    color: var(--text-dim);
    margin-top: 8px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
    #drum-grid { grid-template-columns: 50px repeat(16, 1fr); gap: 2px; }
    .drum-label { font-size: .6rem; }
    .presets { display: none; }
    #piano-keyboard { height: 110px; }
    .piano-key.black { width: 22px; margin-left: -11px; }
}
