:root {
    --text-color: #3a3d36;
    --text-light: #f0f1f1;
    --background: #f4f1e9;
    --surface: #ffffffa8;
    --accent-color: #7b8266;
    --accent-dark: #6a7058;
    --border-color: #7b826637;
    --shadow-color: rgba(0,0,0,0.1);
    --loader-color: var(--accent-dark);
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background);
    background-image: url('https://images.unsplash.com/photo-1597769914294-87d8516e1336?q=80&w=2070');
    background-size: cover;
    background-attachment: fixed;
    color: var(--text-color);
    padding-bottom: 90px; /* Space for the bottom player */
    margin: 0;
}

/* --- Track Change Animation --- */
.ply-album-art, .ply-track-details {
    transition: opacity 0.3s ease-in-out;
}

/* --- Player Container (Desktop) --- */
#audio-player-container {
    position: fixed;
    bottom: 0; /* Changed from top to bottom */
    left: 0;
    width: 100%;
    height: 90px;
    background-color: var(--surface);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 1000;
    display: flex;
    align-items: center;
    padding: 0 30px;
    box-sizing: border-box;
    border-top: 1px solid var(--border-color); /* Changed from border-bottom */
    transition: transform 0.3s ease-in-out;
}

.ply-player-content {
    width: 100%;
    display: grid;
    grid-template-columns: 300px 1fr auto;
    align-items: center;
    gap: 20px;
}

/* --- Track Info --- */
.ply-track-info-container {
    display: flex;
    align-items: center;
    gap: 15px;
    overflow: hidden;
    min-width: 0;
}
.ply-album-art {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}
.ply-track-details h3, .ply-track-details p {
    margin: 0;
    font-weight: 500;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ply-track-details p {
    font-size: 0.9rem;
    color: var(--accent-dark);
}

/* --- Controls Block --- */
.ply-controls-wave-block {
    display: flex;
    align-items: center;
    gap: 20px;
    width: 100%;
}
.ply-controls-main {
    display: flex;
    align-items: center;
    gap: 15px;
}
.ply-control-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.ply-control-btn:hover {
    color: var(--accent-dark);
    background-color: var(--border-color);
}
.ply-control-btn.active {
    color: var(--text-color);
    background-color: var(--border-color);
}

.ply-play-btn {
    background-color: var(--accent-color);
    color: var(--background);
    width: 50px;
    height: 50px;
    font-size: 1.4rem;
}
.ply-play-btn:hover {
    background-color: var(--accent-dark);
    transform: scale(1.05);
    color: #fff;
}
.ply-waveform-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
}
.ply-time {
    font-size: 0.85rem;
    color: var(--text-color);
    min-width: 40px;
    text-align: center;
}
#desktop-waveform-wrapper, #modal-waveform-wrapper {
    width: 100%;
    height: 60px;
    cursor: pointer;
}

/* --- Extra Controls --- */
.ply-extra-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-self: end;
}
#playlist-btn { font-size: 1.6rem; }

/* --- Playlist Panel --- */
#playlist-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 420px;
    height: 100vh;
    background-color: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--border-color);
    z-index: 1003;
    transition: right 0.4s ease-in-out;
    display: flex;
    flex-direction: column;
}
#playlist-panel.active { right: 0; }
.ply-playlist-header {
    padding: 20px 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}
.ply-playlist-header h3 { margin: 0; }
#playlist-list-container {
    overflow-y: auto;
    flex-grow: 1;
    padding: 10px 15px 10px 25px;
}
.ply-playlist-song {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.ply-playlist-song:hover { background-color: var(--border-color); }
.ply-playlist-song.playing {
    background-color: var(--accent-color);
    color: #fff;
}
.ply-playlist-song.playing .ply-playlist-song-artist { color: var(--text-light); }
.ply-playlist-song-art {
    width: 50px;
    height: 50px;
    border-radius: 6px;
    object-fit: cover;
}
.ply-playlist-song-details {
    overflow: hidden;
    flex-grow: 1;
}
.ply-playlist-song-details h5 { margin: 0; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ply-playlist-song-details p { margin: 0; font-size: 0.8rem; color: var(--accent-dark); }

/* --- Mini Visualizer in Playlist --- */
.ply-mini-visualizer {
    display: none;
    margin-left: auto;
    align-items: center;
    gap: 2px;
    height: 16px;
}
.ply-playlist-song.playing .ply-mini-visualizer {
    display: flex;
}
.ply-mini-visualizer .ply-bar {
    width: 3px;
    height: 100%;
    background-color: var(--text-light);
    animation: ply-mini-level-anim 1.2s infinite ease-in-out alternate;
    transform-origin: bottom;
}
.ply-mini-visualizer .ply-bar:nth-child(2) { animation-delay: -1.0s; }
.ply-mini-visualizer .ply-bar:nth-child(3) { animation-delay: -0.8s; }
@keyframes ply-mini-level-anim {
    from { transform: scaleY(0.2); }
    to { transform: scaleY(1); }
}

/* Custom scrollbar */
#playlist-list-container::-webkit-scrollbar { width: 8px; }
#playlist-list-container::-webkit-scrollbar-track { background: transparent; }
#playlist-list-container::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
#playlist-list-container::-webkit-scrollbar-thumb:hover { background-color: var(--accent-color); }


/* --- Loader --- */
.ply-waveform-loader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgb(251 250 247 / 35%);
    z-index: 5;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    backdrop-filter: blur(10px);
}
.ply-waveform-loader.loading {
    opacity: 1;
    visibility: visible;
}
.ply-loader-bar-container {
    display: flex;
    gap: 4px;
    height: 40px;
    align-items: center;
}
.ply-loader-bar {
    width: 5px;
    height: 10px;
    background-color: var(--loader-color);
    animation: ply-loader-anim 1.2s infinite ease-in-out;
    border-radius: 2px;
}
.ply-loader-bar:nth-child(2) { animation-delay: -1.1s; }
.ply-loader-bar:nth-child(3) { animation-delay: -1.0s; }
.ply-loader-bar:nth-child(4) { animation-delay: -0.9s; }
@keyframes ply-loader-anim {
    0%, 40%, 100% { transform: scaleY(0.4); }
    20% { transform: scaleY(1.0); }
}

/* --- Page Content --- */
.ply-page-content {
    padding: 40px 20px;
    max-width: 900px;
    margin: 40px auto;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 var(--shadow-color);
}

/* --- Mobile Player --- */
#mobile-player-bar, #now-playing-modal { display: none; }

/* --- Responsiveness --- */
@media (max-width: 1024px) {
    .ply-player-content { grid-template-columns: 250px 1fr auto; }
    .ply-controls-main { gap: 10px; }
    .ply-controls-wave-block { gap: 15px; }
}

@media (max-width: 768px) {
    body { padding-top: 20px; padding-bottom: 75px; } /* Adjusted for mobile bar */
    #audio-player-container { transform: translateY(100%); } /* Hide by moving down */

    /* FIX: Make preloader background transparent on mobile */
    .ply-waveform-loader {
        background-color: transparent;
    }

    #mobile-player-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        bottom: 0; left: 0;
        width: 100%; height: 75px;
        background: var(--surface);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        border-top: 1px solid var(--border-color);
        z-index: 1000;
        padding: 0 15px;
        box-sizing: border-box;
        cursor: pointer;
    }
    .ply-mobile-track-info { display: flex; align-items: center; gap: 12px; overflow: hidden; }
    .ply-mobile-track-info .ply-album-art {
        width: 50px;
        height: 50px;
        border-radius: 50%;
    }
    .ply-mobile-controls { display: flex; align-items: center; gap: 20px; }
    .ply-mobile-controls .ply-play-btn { width: 45px; height: 45px; font-size: 1.2rem; }
    .ply-mobile-controls .ply-control-btn { font-size: 1.5rem; }

    #now-playing-modal {
        position: fixed;
        top: 100%; left: 0;
        width: 100%; height: 100%;
        background: var(--background);
        z-index: 1002;
        transition: top 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        padding: 30px;
        box-sizing: border-box;
        color: var(--text-color);
    }
    #now-playing-modal.active { top: 0; }
    .ply-now-playing-header { width: 100%; display: flex; justify-content: space-between; align-items: center; }
    .ply-now-playing-header .ply-control-btn { font-size: 1.5rem; }

    /* FIX: Album art spinning logic */
    #now-playing-album-art {
        width: 70vw; max-width: 300px;
        height: 70vw; max-height: 300px;
        border-radius: 50%;
        object-fit: cover;
        box-shadow: 0 10px 40px rgba(0,0,0,0.2);
        transition: opacity 0.3s ease-in-out; /* Removed transform transition to let animation handle it */
        animation: spin 30s linear infinite; /* Apply animation property */
        animation-play-state: paused; /* Start in a paused state */
    }
    @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

    .ply-now-playing-details { text-align: center; transition: opacity 0.3s ease-in-out;}
    .ply-now-playing-details h2 { margin: 15px 0 5px; font-size: 1.5rem; }
    .ply-now-playing-details p { margin: 0; font-size: 1rem; color: var(--accent-dark); }
    .ply-now-playing-waveform-container { width: 100%; }
    .ply-now-playing-waveform-container .ply-waveform-container { margin: 15px 0; }
    .ply-now-playing-controls {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 10px;
    }
    .ply-now-playing-controls .ply-play-btn { width: 65px; height: 65px; font-size: 2rem; }
    .ply-now-playing-controls .ply-control-btn { font-size: 1.5rem; }

    #playlist-panel {
        width: 100%; height: 100%;
        top: 0; border-left: none;
    }
    #close-playlist-btn {
        position: absolute; top: 15px; right: 20px;
        font-size: 1.8rem; display: block;
        z-index: 10;
    }
}