/* --- THEME VARIABLES (DARK MODE ONLY) --- */
:root {
    --primary-bg: #121212;
    --secondary-bg: #1e1e1e;
    --tertiary-bg: #2a2a2a; /* Slightly lighter for elements within secondary */
    --text-color: #e0e0e0;
    --text-muted-color: #a0a0a0;
    --header-color: #ffffff;
    --accent-color: #4dabf7; /* Primary accent blue */
    --accent-hover-color: #228be6; /* Darker blue for hover */
    --shadow-color: rgba(0, 0, 0, 0.4);
    --border-color: #3a3a3a;
    --light-border-color: #555; /* For subtle borders */
    --button-bg: var(--tertiary-bg);
    --button-bg-hover: var(--border-color);
    --button-primary-bg: var(--accent-color);
    --button-primary-bg-hover: var(--accent-hover-color);
    --select-bg: var(--secondary-bg);
    --select-border: var(--border-color);
    --select-arrow: var(--text-color);
    --modal-overlay-bg: rgba(0, 0, 0, 0.7);
}

/* --- BASIC SETUP --- */
body {
    font-family: "Roboto", sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-color);
    margin: 0;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- HEADER --- */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    background-color: var(--secondary-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 8px var(--shadow-color);
    padding: 0;

    .header-inner-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        max-width: 1400px;
        margin: 0 auto;
        padding: 0.75rem 1rem; /* Slightly reduced vertical padding */
        position: relative;
    }

    .header-left {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        flex-grow: 1;
        min-width: 0;
    }

    .header-center {
        flex-grow: 2;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
        position: relative;
        min-width: 0;
    }

    .band-selector-wrapper {
        display: flex;
        gap: 0.75rem;
        align-items: center;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
    }

    .header-right {
        flex-shrink: 0;
        display: flex;
        gap: 0.75rem;
        align-items: center;
    }

    .header-title {
        font-size: clamp(0.9rem, 2.5vw, 1.3rem);
        font-weight: 700;
        margin: 0;
        color: var(--header-color);
        white-space: normal; /* Allow text to wrap */
        line-height: 1.1;
    }

    .header-select {
        appearance: none;
        background-color: var(--select-bg);
        border: 1px solid var(--select-border);
        color: var(--text-color);
        padding: 0.5rem 2.2rem 0.5rem 1rem; /* Increased right padding for arrow */
        border-radius: 6px;
        font-size: 0.95rem;
        cursor: pointer;
        background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="%23e0e0e0"><path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z" clip-rule="evenodd" /></svg>');
        background-repeat: no-repeat;
        background-position: right 0.75rem center;
        background-size: 1.2rem;
        transition: border-color 0.2s ease, box-shadow 0.2s ease;
        flex-grow: 1;
        min-width: 150px; 

        &:hover {
            border-color: var(--accent-color);
        }

        &:focus {
            outline: none;
            border-color: var(--accent-color);
            box-shadow: 0 0 0 3px rgba(77, 171, 247, 0.5);
        }
    }

    .header-button {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        background-color: var(--button-bg);
        border: 1px solid var(--border-color);
        color: var(--text-color);
        padding: 0.5rem 1rem;
        border-radius: 6px;
        cursor: pointer;
        font-weight: 500;
        white-space: nowrap;
        transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;

        &:hover {
            background-color: var(--button-bg-hover);
            border-color: var(--accent-color);
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }

        &:focus {
            outline: none;
            box-shadow: 0 0 0 3px rgba(77, 171, 247, 0.5);
        }

        &.primary {
            background-color: var(--button-primary-bg);
            border-color: var(--button-primary-bg);
            color: #fff;

            &:hover {
                background-color: var(--button-primary-bg-hover);
                border-color: var(--button-primary-bg-hover);
            }
        }
    }

    .icon-button {
        padding: 0;
        width: 38px;
        height: 38px;
        justify-content: center;
        border-radius: 50%;
        font-size: 1.1rem;
        flex-shrink: 0;

        svg {
            width: 20px;
            height: 20px;
            fill: currentColor;
        }
    }

    .chevron-icon {
        transition: transform 0.2s ease-in-out;
    }

    .header-button.expanded .chevron-icon {
        transform: rotate(180deg);
    }
}


/* --- OVERLAY STYLES FOR RANKINGS --- */
.album-key-list-container {
    position: absolute;
    top: 100%;
    /* Use fixed sizing on desktop so it doesn't squish */
    width: 600px;
    max-width: 90vw; /* Ensure it fits on smaller screens */
    
    /* Center absolute element */
    left: 50%;
    transform: translateX(-50%) translateY(0);
    
    background-color: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-top: none;
    box-shadow: 0 10px 26px var(--shadow-color);
    padding: 1rem;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    opacity: 1;
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
    pointer-events: auto;
    box-sizing: border-box;
    z-index: 1001;

    &.hidden {
        opacity: 0;
        /* Keep centered X, move up Y */
        transform: translateX(-50%) translateY(-10px);
        pointer-events: none;
    }
}


/* --- ALBUM RANKING LIST --- */
.album-key-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;

    li {
        display: flex;
        align-items: center;
        font-size: 1em;
        font-weight: 500;
        gap: 8px;
        flex-wrap: wrap;
        border: 2px solid var(--border-color);
        padding: 10px;
        border-radius: 10px;
        background-color: var(--tertiary-bg);
        transition: transform 0.2s ease, box-shadow 0.2s ease;

        &:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
        }

        &.no-albums {
            justify-content: center;
            color: var(--text-muted-color);
            font-style: italic;
            padding: 20px;
        }
    }

    .key-color-swatch {
        width: 14px; 
        height: 14px; 
        border-radius: 4px;
        flex-shrink: 0;
        border: 1px solid rgba(255, 255, 255, 0.1); 
    }

    .rank-number {
        font-weight: 700;
        min-width: 1.5em;
        text-align: left;
        color: var(--accent-color);
    }

    .album-name {
        flex-grow: 1;
        color: var(--header-color);
        max-width: 55vw;
    }

    .album-stats-wrapper {
        display: flex;
        gap: 16px;
        margin-left: auto;
    }

    .album-stat {
        display: flex;
        flex-direction: column;
        align-items: center;
        min-width: 50px;
    }

    .stat-value {
        font-weight: 700;
        font-size: 1.1em;
        color: var(--header-color);
    }

    .stat-label {
        font-size: 0.75em;
        color: var(--text-muted-color);
        text-transform: uppercase;
        white-space: nowrap;
        letter-spacing: 0.05em; 
    }
}

/* --- RESPONSIVE HEADER & CONTENT --- */
@media (max-width: 768px) {
    .app-header {
        .header-inner-content {
            flex-direction: row; 
            flex-wrap: wrap;
            padding: 0.5rem;
        }

        .header-left {
            order: 1;
            flex: 1 1 auto; 
            margin-right: 0.5rem;
        }
        
        .header-right {
            order: 2;
            flex: 0 0 auto;
        }

        .header-center {
            order: 3;
            width: 100%; /* Force new line */
            margin-top: 0.5rem;
        }

        .band-selector-wrapper {
            width: 100%;
            gap: 0.5rem;
        }

        .header-select, 
        .band-selector-wrapper .header-button {
            flex: 1; 
            width: auto;
            min-width: 0; 
        }
    }

    .album-key-list-container {
        /* On mobile, take up most of width */
        width: 750px; 
        left: 0;
        max-width: 95vw;
        transform: translateX(-50%) translateY(0);
        
        &.hidden {
            transform: translateX(-50%) translateY(-10px);
        }
    }

    .album-key-list {
        max-height: calc(100vh - 250px);
        overflow-y: auto;
        padding-right: 5px;

        li {
            .album-stats-wrapper {
                flex-basis: 100%;
                margin-left: 0;
                justify-content: flex-start;
                padding-left: 30px;
                margin-top: 4px;
                gap: 10px;
            }
            .album-stat {
                min-width: unset;
            }
        }
    }
}
@media (max-width: 1200px) { 
 .album-key-list-container {
    width: 1100px;
    max-width: 95vw;
    left:0;
 }
}

/* --- MODAL STYLES --- */
.modal {
    background: var(--secondary-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 15px 40px var(--shadow-color);
    width: 90%;
    max-width: 650px; 
    padding: 2rem;
    line-height: 1.6;
    max-height: 90vh;
    overflow-y: auto;

    &::backdrop {
        background: var(--modal-overlay-bg);
        backdrop-filter: blur(4px);
    }

    h2 {
        color: var(--header-color);
        margin-top: 0;
        margin-bottom: 1.2rem;
        font-size: 1.5rem;
    }

    h3 {
        margin-top: 1.8rem;
        color: var(--accent-color);
        font-size: 1.2rem;
    }

    ul {
        padding-left: 20px;
        margin-bottom: 1rem;
        list-style: disc;
    }

    li {
        margin-bottom: 0.6rem;
    }

    .modal-textarea,
    .modal-input {
        width: 100%;
        background-color: var(--primary-bg);
        color: var(--text-color);
        border: 1px solid var(--border-color);
        border-radius: 6px;
        margin: 1.2rem 0;
        padding: 0.85rem;
        font-family: 'Roboto Mono', monospace; 
        font-size: 1em;
        box-sizing: border-box;
        transition: border-color 0.2s ease, box-shadow 0.2s ease;

        &:focus {
            outline: none;
            border-color: var(--accent-color);
            box-shadow: 0 0 0 3px rgba(77, 171, 247, 0.5);
        }
    }

    .modal-textarea {
        height: 180px; 
        resize: vertical;
    }
    
    .modal-section {
        margin-bottom: 2rem;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 1.5rem;
    }
    
    .modal-section:last-of-type {
        border-bottom: none;
        margin-bottom: 0;
    }
    
    .modal-section h3 {
        margin-top: 0;
        font-size: 1.1rem;
        color: var(--text-color);
        font-weight: 700;
    }

    input[type="number"]::-webkit-inner-spin-button,
    input[type="number"]::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }

    input[type="number"] {
        -moz-appearance: textfield;
    }

    .modal-actions {
        display: flex;
        justify-content: flex-end;
        gap: 1rem;
        margin-top: 1.5rem;
    }

    .modal-button {
        background-color: var(--button-bg);
        border: 1px solid var(--border-color);
        color: var(--text-color);
        padding: 0.7rem 1.4rem;
        border-radius: 6px;
        cursor: pointer;
        font-weight: 500;
        transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;

        &:hover {
            background-color: var(--button-bg-hover);
            border-color: var(--accent-color);
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }

        &:focus {
            outline: none;
            box-shadow: 0 0 0 3px rgba(77, 171, 247, 0.5);
        }

        &.primary {
            background-color: var(--button-primary-bg);
            border-color: var(--button-primary-bg);
            color: #fff;

            &:hover {
                background-color: var(--button-primary-bg-hover);
                border-color: var(--button-primary-bg-hover);
            }
        }
    }
}


/* --- MAIN CONTENT & TILES --- */
.container {
    max-width: 1400px;
    margin: 0 auto;
    /* Reduced horizontal padding on mobile for more space */
    padding: 30px clamp(4rem, 5vw, 70px); 
}

.song-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;

    .song-tile {
        display: flex;
        align-items: center;
        background-color: var(--secondary-bg);
        padding: 10px;
        border-radius: 8px;
        box-shadow: 0 2px 5px var(--shadow-color);
        border: 1px solid var(--border-color);
        border: 6px solid var(--album-color, var(--accent-color));
        cursor: grab;
        user-select: none;
        transition: transform 0.25s ease-in-out, box-shadow 0.25s ease-in-out;
        position: relative;
        border-width:2px 6px;

        &:hover {
            box-shadow: 0 4px 10px var(--shadow-color);
            transform: translateY(-3px);
        }

        &:focus {
            outline: none;
            box-shadow: 0 0 0 3px var(--accent-color), 0 4px 10px var(--shadow-color);
        }
    }

    .song-number {
        font-size: 1.05em;
        font-weight: 700;
        color: var(--accent-color);
        margin-right: 12px;
        text-align: right;
        flex-shrink: 0;
    }

    .song-info {
        flex-grow: 1;
        min-width: 0;
    }

    .song-title {
        font-weight: 700;
        font-size: 1em;
        line-height: 1.1em;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: var(--header-color);
    }

    .song-album {
        font-size: 0.85em;
        line-height: .9em;
        color: var(--text-muted-color);
        font-style: italic;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-top: 2px; 
    }

    /* --- Play Link/Button Styles --- */
    .play-link {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background-color: var(--tertiary-bg); 
        color: var(--accent-color); 
        border: 1px solid var(--border-color);
        transition: all 0.2s ease;
        margin-left: 10px;
        flex-shrink: 0;
        text-decoration: none; 
        cursor: pointer;

        &:hover {
            background-color: var(--accent-color);
            color: #fff;
            transform: scale(1.1);
            box-shadow: 0 0 8px rgba(77, 171, 247, 0.6);
            border-color: var(--accent-color);
        }

        svg {
            width: 14px;
            height: 14px;
            fill: currentColor;
            margin-left: 2px;
        }
    }
}


/* --- SORTABLEJS & ACCESSIBILITY --- */
/* The item currently selected/being dragged */
.sortable-chosen {
    cursor: grabbing;
    /* 1. Make background solid so text doesn't blend with background */
    background-color: var(--secondary-bg); 
    
    /* 2. Add the Outline (High contrast blue) */
    outline: 3px solid var(--accent-color);
    
    /* 3. Add a shadow to lift it up visually */
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    
    /* 4. Ensure it sits on top of neighbors */
    z-index: 1000; 
    opacity: 1 !important;
}

.sortable-ghost {
    opacity: 0.4;
    background-color: var(--accent-color);
    border: 2px dashed var(--header-color);
    border-left: 6px dashed var(--header-color); 
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}