:root {
    --pad-kick: #7FDBFF;      /* Blue for kick */
    --pad-snare: #2ECC40;     /* Green for snare */
    --pad-clap: #FF851B;      /* Orange for clap */
    --pad-hihat-closed: #39CCCC; /* Cyan for closed hihat */
    --pad-hihat-open: #01FF70;   /* Lime for open hihat */
    --pad-tom-high: #3D9970;   /* Olive for high tom */
    --pad-tom-low: #2ECC40;    /* Green for low tom */
    --pad-crash: #7FDBFF;     /* Blue for crash */
    --pad-ride: #B10DC9;      /* Purple for ride */
    --background: #1a1a1a;
    --button-bg: #333;
    --text-color: #fff;
}

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

body {
    background-color: var(--background);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: Arial, sans-serif;
    color: var(--text-color);
}

.drum-machine {
    background-color: #222;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    width: 90%;
    max-width: 1000px;
}

.controls-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    gap: 15px;
}

.view-controls {
    display: flex;
    gap: 10px;
}

button {
    background-color: var(--button-bg);
    color: var(--text-color);
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
}

button:hover {
    background-color: #444;
}

.sequencer {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    width: 100%;
    overflow-x: hidden; /* Prevent horizontal scroll */
    height: 60vh; /* Set a fixed height relative to viewport */
}

.track-labels {
    display: none;
}

.grid-container {
    display: grid;
    gap: 3px; /* Tighter spacing between pads */
    flex-grow: 1;
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 2px; /* Add slight padding around grid */
}

.pad {
    aspect-ratio: 1;
    width: 100%;
    height: 100%;
    background-color: var(--button-bg);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.pad.active-blue {
    background-color: var(--pad-active-blue);
}

.pad.active-green {
    background-color: var(--pad-active-green);
}

.controls-bottom {
    display: flex;
    justify-content: flex-end;
    padding: 10px 0 0 0;
}

.transport-controls, .playback-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.pad.active-kick { background-color: var(--pad-kick); }
.pad.active-snare { background-color: var(--pad-snare); }
.pad.active-clap { background-color: var(--pad-clap); }
.pad.active-hihat-closed { background-color: var(--pad-hihat-closed); }
.pad.active-hihat-open { background-color: var(--pad-hihat-open); }
.pad.active-tom-high { background-color: var(--pad-tom-high); }
.pad.active-tom-low { background-color: var(--pad-tom-low); }
.pad.active-crash { background-color: var(--pad-crash); }
.pad.active-ride { background-color: var(--pad-ride); }

.pad.playing {
    animation: padPulse 1.5s infinite;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.7);
    z-index: 1;
}

@keyframes padPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 30px rgba(255, 255, 255, 0.9);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.7);
    }
}

@media (max-width: 768px) {
    body {
        align-items: flex-start;
        min-height: 100vh;
        margin: 0;
        padding: 0;
    }

    .drum-machine {
        width: 100%;
        min-height: 100vh;
        margin: 0;
        padding: 10px;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
    }

    .sequencer {
        flex: 1;
        gap: 10px;
        margin-bottom: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .track-labels {
        gap: 3px;
        position: sticky;
        left: 0;
        z-index: 1;
        background-color: #222;
    }

    .track-label {
        height: 40px;
        font-size: 14px;
        padding: 0 8px;
        white-space: nowrap;
        min-width: 120px;
    }

    .grid-container {
        grid-template-rows: repeat(9, 40px);
        gap: 3px;
        min-width: min-content;
    }

    .pad {
        width: 40px;
        height: 40px;
        border-radius: 4px;
    }

    .controls-bottom {
        position: sticky;
        bottom: 0;
        background-color: #222;
        padding-top: 10px;
    }
}

@media (max-width: 480px) {
    .grid-container {
        grid-template-columns: repeat(4, 1fr);
    }

    .track-label {
        font-size: 10px;
    }
}

.tempo-control {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
}

.tempo-display {
    min-width: 80px;
    font-size: 14px;
}

.tempo-slider {
    -webkit-appearance: none;
    width: 150px;
    height: 4px;
    border-radius: 2px;
    background: #444;
    outline: none;
    cursor: pointer;
}

.tempo-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
}

.tempo-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-color);
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.tempo-slider::-webkit-slider-thumb:hover,
.tempo-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
    background: #fff;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .tempo-control {
        padding: 0 10px;
    }
    
    .tempo-slider {
        width: 120px;
    }
}

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

/* Add a subtle warning color for the clear button */
.clear-pattern {
    background-color: #444;
    border: 1px solid #ff4136;
}

.clear-pattern:hover {
    background-color: #ff4136;
}

/* Add to existing styles */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-success {
    border-left: 4px solid #2ECC40;
}

.toast-warning {
    border-left: 4px solid #FF851B;
}

.pattern-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #222;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    min-width: 300px;
}

.pattern-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #333;
}

.pattern-row:hover {
    background: #2a2a2a;
}

.delete-btn {
    background: none;
    border: none;
    color: #ff4136;
    font-size: 20px;
    cursor: pointer;
    padding: 0 8px;
}

.delete-btn:hover {
    color: #ff725c;
}

.steps-control {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
}

.steps-display {
    min-width: 80px;
    text-align: center;
    font-size: 14px;
}

.decrease-steps,
.increase-steps {
    padding: 4px 8px;
    font-size: 16px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .transport-controls {
        flex-wrap: wrap;
        gap: 10px;
    }

    .steps-control {
        order: 2; /* Move steps control below tempo on mobile */
        width: 100%;
        justify-content: center;
    }
}

/* Update mobile styles */
@media (max-width: 768px) {
    .drum-machine {
        padding: 10px 5px;
    }

    /* Better control layout for mobile */
    .controls-top {
        flex-direction: column;
        gap: 15px;
    }

    .transport-controls {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        width: 100%;
    }

    /* Make play button full width */
    .play {
        grid-column: 1 / -1;
        padding: 12px;
        font-size: 16px;
    }

    /* Tempo control adjustments */
    .tempo-control {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: auto 1fr;
        align-items: center;
        gap: 15px;
        padding: 0;
    }

    .tempo-slider {
        width: 100%;
        height: 20px; /* Bigger touch target */
    }

    .tempo-slider::-webkit-slider-thumb {
        width: 24px; /* Bigger touch target */
        height: 24px;
    }

    .tempo-slider::-moz-range-thumb {
        width: 24px; /* Bigger touch target */
        height: 24px;
    }

    /* Steps control adjustments */
    .steps-control {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: auto 1fr auto;
        gap: 15px;
        padding: 0;
    }

    .decrease-steps,
    .increase-steps {
        padding: 12px 20px; /* Bigger touch target */
        font-size: 18px;
    }

    /* Pattern controls adjustments */
    .pattern-controls {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .pattern-controls button {
        padding: 12px; /* Bigger touch target */
    }

    /* Grid adjustments */
    .grid-container {
        gap: 4px;
    }

    .pad {
        min-width: 35px;
        min-height: 35px;
        touch-action: none; /* Prevent scrolling while dragging */
    }

    /* Track labels adjustments */
    .track-label {
        padding: 0 12px;
        min-width: 100px;
        font-size: 12px;
    }

    /* Toast adjustments for mobile */
    .toast {
        width: 90%;
        max-width: none;
        bottom: 10px;
    }

    /* Pattern menu adjustments for mobile */
    .pattern-menu {
        width: 90%;
        max-height: 80vh;
        overflow-y: auto;
    }
}

/* Extra small devices */
@media (max-width: 380px) {
    .track-label {
        min-width: 80px;
        font-size: 11px;
    }

    .pad {
        min-width: 32px;
        min-height: 32px;
    }
}

/* Update grid and pad styles */
.sequencer {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    width: 100%;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

.grid-container {
    display: grid;
    gap: 5px;
    flex-grow: 1;
    width: 100%;
    min-width: 0; /* Allow grid to shrink */
}

.pad {
    aspect-ratio: 1; /* Keep pads square */
    width: 100%;
    min-width: 0;
    height: auto;
    background-color: var(--button-bg);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .sequencer {
        gap: 10px;
    }

    .grid-container {
        gap: 3px;
    }

    .track-labels {
        min-width: 80px; /* Smaller fixed width for labels */
    }

    .track-label {
        font-size: 11px;
        padding: 0 5px;
        min-width: 80px;
    }

    /* Remove fixed sizes for pads */
    .pad {
        min-width: unset;
        min-height: unset;
    }
}

/* Update track label styles */
.track-labels {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 100px; /* Base width for labels */
}

.track-label {
    aspect-ratio: 3/1; /* Make labels scale with height but stay readable */
    width: 100%;
    display: flex;
    align-items: center;
    padding: 0 10px;
    background-color: var(--button-bg);
    border-radius: 4px;
    font-size: clamp(11px, 2vw, 14px); /* Responsive font size */
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .track-labels {
        min-width: 80px;
        gap: 3px;
    }

    .track-label {
        padding: 0 5px;
        font-size: clamp(10px, 1.5vw, 12px);
    }
}

/* Extra small devices */
@media (max-width: 380px) {
    .track-labels {
        min-width: 70px;
    }

    .track-label {
        font-size: clamp(9px, 1.2vw, 11px);
    }
}

.feedback-link {
    color: var(--text-color);
    opacity: 0.6;
    text-decoration: none;
    font-size: 12px;
    padding: 8px;
    transition: opacity 0.2s;
}

.feedback-link:hover {
    opacity: 1;
}

.controls-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .step-indicators {
        gap: 3px;
    }

    .step-indicator {
        height: 6px;
    }
}

/* Update grid spacing */
.grid-container {
    display: grid;
    gap: 3px; /* Tighter spacing between pads */
    flex-grow: 1;
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 2px; /* Add slight padding around grid */
}

/* Hide track labels */
.track-labels {
    display: none;
}

/* Improve controls spacing */
.controls-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    gap: 15px;
}

.transport-controls {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 15px;
    width: 100%;
    align-items: center;
}

/* Adjust pattern controls spacing */
.pattern-controls {
    display: flex;
    gap: 8px;
}

/* Keep feedback button on the right */
.controls-bottom {
    display: flex;
    justify-content: flex-end;
    padding: 10px 0 0 0;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .transport-controls {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .pattern-controls {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .grid-container {
        gap: 2px; /* Even tighter spacing on mobile */
    }

    .drum-machine {
        padding: 10px;
    }
}