/* ========================================
   TRAGEDY // BEATMAKER
======================================== */

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

html {
    color-scheme: dark;
}

body {
    min-height: 100vh;
    background: radial-gradient(circle at 50% 0%, #1a0505 0%, #090909 35%, #030303 75%);
    color: #f5f5f5;
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
    font: inherit;
}

/* ========================================
   HEADER
======================================== */

header {
    width: 100%;
    padding: 30px 40px;
}

.back-button {
    color: #777;
    text-decoration: none;
    font-size: 12px;
    letter-spacing: 2px;
    transition: color 0.2s ease;
}

.back-button:hover {
    color: #fff;
}

/* ========================================
   PAGE / TITLE
======================================== */

.beatmaker {
    width: min(1200px, 94%);
    margin: 20px auto 80px;
}

.title {
    text-align: center;
    margin-bottom: 55px;
}

.title p {
    color: #8b0000;
    font-size: 12px;
    letter-spacing: 8px;
    margin-bottom: 8px;
}

.title h1 {
    font-size: clamp(42px, 7vw, 82px);
    letter-spacing: 8px;
    font-weight: 900;
}

.title span {
    display: block;
    margin-top: 10px;
    color: #555;
    font-size: 11px;
    letter-spacing: 5px;
}

/* ========================================
   TOP CONTROLS
======================================== */

.controls {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 15px;
    margin-bottom: 35px;
}

.bpm-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.bpm-control label,
.volume-control label {
    color: #777;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 3px;
}

#bpm {
    width: 90px;
    height: 45px;
    padding: 0 12px;
    border: 1px solid #252525;
    background: #0c0c0c;
    color: #fff;
    outline: none;
}

#bpm:focus {
    border-color: #6d0000;
}

/* ========================================
   BUTTONS
======================================== */

button {
    height: 45px;
    padding: 0 22px;
    border: 1px solid #292929;
    background: #0c0c0c;
    color: #aaa;
    cursor: pointer;
    font-size: 11px;
    letter-spacing: 2px;
    transition:
        border-color 0.2s ease,
        color 0.2s ease,
        background 0.2s ease,
        box-shadow 0.2s ease;
}

button:hover {
    border-color: #750000;
    color: #fff;
    background: #140505;
}

#playButton {
    border-color: #550000;
}

/* ========================================
   SEQUENCER
======================================== */

.sequencer {
    max-width: 1200px;
    margin: 35px auto 0;
    padding: 30px;
    overflow-x: auto;
    background: linear-gradient(145deg, rgba(15, 15, 15, 0.95), rgba(5, 5, 5, 0.98));
    border: 1px solid #202020;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.45);
}

.track {
    min-width: 950px;
    display: grid;
    grid-template-columns: 130px 1fr;
    align-items: center;
    gap: 20px;
    min-height: 62px;
}

.track-controls {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.track-name {
    color: #777;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 2px;
}

/* ========================================
   SOUND SELECTS
======================================== */

.sound-select {
    width: 120px;
    padding: 8px 30px 8px 10px;
    appearance: none;
    -webkit-appearance: none;
    color: #ccc;
    background:
        #0c0c0c
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23777777' stroke-width='1.5'/%3E%3C/svg%3E")
        no-repeat right 10px center;
    border: 1px solid #292929;
    outline: none;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition:
        border-color 0.2s ease,
        background-color 0.2s ease;
}

.sound-select:hover,
.sound-select:focus {
    border-color: #8d1111;
    background-color: #111;
}

/* ========================================
   STEP GRID
======================================== */

.steps {
    display: grid;
    grid-template-columns: repeat(16, minmax(25px, 1fr));
    gap: 10px;
}

.step {
    width: 100%;
    min-width: 0;
    aspect-ratio: 1 / 1;
    border: 1px solid #292929;
    background: #101010;
    cursor: pointer;
    transition:
        background 0.12s ease,
        border-color 0.12s ease,
        transform 0.12s ease,
        box-shadow 0.12s ease;
}

.step:nth-child(4n + 1) {
    margin-left: 4px;
}

.step:first-child {
    margin-left: 0;
}

.step:hover {
    border-color: #555;
    transform: translateY(-1px);
}

.step.active {
    background: linear-gradient(145deg, #a00, #740000);
    border-color: #d51a1a;
    box-shadow:
        inset 0 0 10px rgba(255, 0, 0, 0.12),
        0 0 12px rgba(160, 0, 0, 0.08);
}

.step.playing {
    border-color: #a855f7;
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.45);
}

.step.active.playing {
    background: #c51111;
    border-color: #d8a7ff;
    box-shadow: 0 0 18px rgba(168, 85, 247, 0.55);
}

/* ========================================
   BOTTOM CONTROL BAR
======================================== */

.bottom-controls {
    max-width: 1200px;
    margin: 25px auto 0;
    padding: 22px 24px;
    display: grid;
    grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) auto;
    align-items: end;
    gap: 28px;
    background: #090909;
    border: 1px solid #1e1e1e;
}

.volume-control {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

#masterVolume {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    accent-color: #a00000;
}

.beat-storage {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(160px, 1fr) auto auto;
    gap: 8px;
}

#beatName {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding: 0 14px;
    background: #0d0d0d;
    color: #fff;
    border: 1px solid #292929;
    outline: none;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

#beatName::placeholder {
    color: #444;
}

#beatName:focus {
    border-color: #8d1111;
    box-shadow: 0 0 15px rgba(150, 0, 0, 0.08);
}

#saveBeatButton,
#loadBeatsButton,
#clearButton {
    min-height: 42px;
    height: 42px;
    padding: 0 18px;
    background: #0d0d0d;
    color: #999;
    border: 1px solid #292929;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 2px;
    white-space: nowrap;
}

#saveBeatButton:hover {
    color: #fff;
    background: #8c0000;
    border-color: #bd0000;
    box-shadow: 0 0 20px rgba(180, 0, 0, 0.15);
}

#loadBeatsButton:hover {
    color: #fff;
    border-color: #a855f7;
    background: rgba(168, 85, 247, 0.08);
}

#clearButton {
    color: #777;
}

#clearButton:hover {
    color: #ff5555;
    border-color: #6f2222;
    background: rgba(130, 0, 0, 0.08);
}

/* ========================================
   BEAT STATUS MESSAGE
======================================== */

#beatMessage {
    max-width: 1200px;
    min-height: 0;

    margin: 12px auto 0;
    padding: 0;

    color: #a855f7;

    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1.5px;

    transition:
        opacity 0.2s ease,
        border-color 0.2s ease,
        background 0.2s ease;
}


/* Only show the box when there is a message */

#beatMessage:not(:empty) {
    padding: 12px 16px;

    background:
        linear-gradient(
            90deg,
            rgba(168, 85, 247, 0.08),
            rgba(10, 10, 10, 0.95)
        );

    border: 1px solid #2c2035;
    border-left: 2px solid #a855f7;
}

/* ========================================
   SAVED BEATS
======================================== */

.saved-beats-panel {
    max-width: 1200px;
    margin: 25px auto 0;
    padding: 25px;
    background: #090909;
    border: 1px solid #242424;
}

.saved-beats-panel[hidden] {
    display: none;
}

.saved-beats-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 25px;
}

.saved-beats-header p {
    color: #a855f7;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 3px;
    margin-bottom: 6px;
}

.saved-beats-header h2 {
    font-size: 22px;
    letter-spacing: -1px;
}

#closeBeatsButton {
    width: 42px;
    height: 42px;
    padding: 0;
    background: transparent;
    color: #666;
    border: 1px solid #222;
}

#closeBeatsButton:hover {
    color: #fff;
    border-color: #555;
}

.saved-beats-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.saved-beat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 16px;
    background: #0d0d0d;
    border: 1px solid #1e1e1e;
}

.saved-beat-info h3 {
    margin-bottom: 5px;
    font-size: 13px;
    letter-spacing: 1px;
}

.saved-beat-info p,
.beats-loading {
    color: #666;
    font-size: 10px;
    letter-spacing: 1px;
}

.saved-beat-actions {
    display: flex;
    gap: 8px;
}

.saved-beat-actions button {
    height: 36px;
    padding: 0 14px;
    background: transparent;
    color: #aaa;
    border: 1px solid #333;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1px;
}

.saved-beat-actions button:hover {
    color: #fff;
    border-color: #a855f7;
}

.saved-beat-actions .delete-beat {
    color: #944;
    border-color: #422;
}

.saved-beat-actions .delete-beat:hover {
    color: #ff4444;
    border-color: #922;
}

/* ========================================
   RESPONSIVE
======================================== */

@media (max-width: 1050px) {
    .bottom-controls {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .volume-control {
        max-width: 300px;
    }
}

@media (max-width: 700px) {
    header {
        padding: 22px;
    }

    .beatmaker {
        margin-top: 10px;
    }

    .title {
        margin-bottom: 35px;
    }

    .title h1 {
        letter-spacing: 4px;
    }

    .controls {
        flex-wrap: wrap;
    }

    .sequencer {
        padding: 20px 15px;
    }

    .bottom-controls {
        padding: 18px;
        gap: 20px;
    }

    .beat-storage {
        grid-template-columns: 1fr 1fr;
    }

    #beatName {
        grid-column: 1 / -1;
    }

    #clearButton {
        width: 100%;
    }

    .saved-beat-item {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .beat-storage {
        grid-template-columns: 1fr;
    }

    #beatName {
        grid-column: auto;
    }

    #saveBeatButton,
    #loadBeatsButton {
        width: 100%;
    }
}
#beatMessage.success {
    color: #a855f7;

    border-left-color: #a855f7;
}

#beatMessage.error {
    color: #ff5555;

    border-color: #3b1b1b;
    border-left-color: #a00000;

    background:
        linear-gradient(
            90deg,
            rgba(150, 0, 0, 0.10),
            rgba(10, 10, 10, 0.95)
        );
}
/* ========================================
   MOBILE BEATMAKER
======================================== */

@media (max-width: 700px) {

    body {
        overflow-x: hidden;
    }

    .beatmaker {
        width: 100%;
        padding: 0 14px;
        margin: 10px auto 50px;
    }

    .title {
        margin-bottom: 30px;
    }

    .title h1 {
        font-size: clamp(36px, 12vw, 56px);
        letter-spacing: 3px;
    }

    .title p {
        letter-spacing: 5px;
    }

    /* PLAY / STOP / BPM */

    .controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        width: 100%;
    }

    .bpm-control {
        grid-column: 1 / -1;
        width: 100%;
    }

    #bpm {
        width: 100%;
        font-size: 16px;
    }

    #playButton,
    #stopButton {
        width: 100%;
        height: 50px;
    }

    /* SEQUENCER */

    .sequencer {
        width: 100%;
        padding: 15px;
        margin-top: 25px;
        overflow-x: hidden;
    }

    .track {
        min-width: 0;
        width: 100%;

        display: block;

        padding: 16px 0;

        border-bottom: 1px solid #1d1d1d;
    }

    .track:last-child {
        border-bottom: none;
    }

    /* TRACK NAME / SOUND */

    .track-controls {
        width: 100%;
        margin-bottom: 14px;

        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

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

    .sound-select {
        width: 130px;
        height: 42px;
        font-size: 11px;
    }

    /* 16 STEPS -> TWO ROWS OF 8 */

    .steps {
        width: 100%;

        display: grid;

        grid-template-columns: repeat(8, 1fr);

        gap: 7px;
    }

    .step {
        width: 100%;
        min-width: 0;

        aspect-ratio: 1 / 1;

        touch-action: manipulation;
    }

    /* Remove desktop beat separation offset */

    .step:nth-child(4n + 1) {
        margin-left: 0;
    }

    /* BOTTOM CONTROLS */

    .bottom-controls {
        width: 100%;

        grid-template-columns: 1fr;

        padding: 16px;
        gap: 18px;
    }

    .volume-control {
        max-width: none;
        width: 100%;
    }

    #masterVolume {
        width: 100%;
        height: 35px;
    }

    /* SAVE / LOAD */

    .beat-storage {
        display: grid;

        grid-template-columns: 1fr;

        gap: 10px;
    }

    #beatName {
        width: 100%;
        height: 48px;

        font-size: 16px;
    }

    #saveBeatButton,
    #loadBeatsButton,
    #clearButton {
        width: 100%;
        height: 48px;
    }

    /* SAVED BEATS */

    .saved-beats-panel {
        padding: 18px;
    }

    .saved-beat-item {
        flex-direction: column;
        align-items: stretch;
    }

    .saved-beat-actions {
        width: 100%;
    }

    .saved-beat-actions button {
        flex: 1;
        min-height: 44px;
    }
}

/* ========================================
   iOS AUDIO NOTICE
======================================== */

.ios-audio-notice {
    max-width: 1200px;
    margin: 22px auto -10px;
    padding: 14px 18px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;

    background: rgba(130, 80, 255, 0.08);
    border: 1px solid rgba(160, 110, 255, 0.35);

    font-family: inherit;
}

.ios-audio-notice[hidden] {
    display: none;
}

.ios-audio-notice-text {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ios-audio-notice strong {
    font-size: 11px;
    letter-spacing: 2px;
    white-space: nowrap;
}

.ios-audio-notice span {
    font-size: 11px;
    letter-spacing: 1px;
    opacity: 0.7;
}

#closeIosAudioNotice {
    width: 32px;
    height: 32px;

    padding: 0;
    border: 0;

    background: transparent;

    font-size: 24px;
    line-height: 1;

    cursor: pointer;
    opacity: 0.6;
}

#closeIosAudioNotice:hover {
    opacity: 1;
}

@media (max-width: 700px) {

    .ios-audio-notice {
        margin: 18px 14px 0;
        padding: 14px;
    }

    .ios-audio-notice-text {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .ios-audio-notice span {
        line-height: 1.5;
    }
}