/* --- FONT AND ROOT VARIABLES --- */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
    --font-family: 'Poppins', sans-serif;

    /* Light Theme */
    --bg-primary-light: #f0f4f8;
    --bg-secondary-light: #ffffff;
    --text-primary-light: #1e293b;
    --text-secondary-light: #64748b;
    --border-light: #e2e8f0;
    --accent-blue-light: #3b82f6;
    --accent-blue-dark-light: #2563eb;
    --shadow-light: 0 4px 15px rgba(0, 0, 0, 0.05);
    --drag-overlay-light: rgba(59, 130, 246, 0.1);

    /* Dark Theme */
    --bg-primary-dark: #0f172a;
    --bg-secondary-dark: #1e293b;
    --text-primary-dark: #e2e8f0;
    --text-secondary-dark: #94a3b8;
    --border-dark: #334155;
    --accent-blue-dark: #60a5fa;
    --accent-blue-dark-dark: #3b82f6;
    --shadow-dark: 0 4px 20px rgba(0, 0, 0, 0.2);
    --drag-overlay-dark: rgba(96, 165, 250, 0.1);
}

/* --- THEME SETUP --- */
body {
    background-color: var(--bg-primary-light);
    color: var(--text-primary-light);
    transition: background-color 0.3s ease, color 0.3s ease;
}

html.dark body {
    --bg-primary: var(--bg-primary-dark);
    --bg-secondary: var(--bg-secondary-dark);
    --text-primary: var(--text-primary-dark);
    --text-secondary: var(--text-secondary-dark);
    --border: var(--border-dark);
    --accent-blue: var(--accent-blue-dark);
    --accent-blue-dark: var(--accent-blue-dark-dark);
    --shadow: var(--shadow-dark);
    --drag-overlay: var(--drag-overlay-dark);
}

html:not(.dark) body {
    --bg-primary: var(--bg-primary-light);
    --bg-secondary: var(--bg-secondary-light);
    --text-primary: var(--text-primary-light);
    --text-secondary: var(--text-secondary-light);
    --border: var(--border-light);
    --accent-blue: var(--accent-blue-light);
    --accent-blue-dark: var(--accent-blue-dark-light);
    --shadow: var(--shadow-light);
    --drag-overlay: var(--drag-overlay-light);
}


/* --- BASE & MOBILE-FIRST STYLES (< 768px) --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    font-size: 16px;
    overflow: hidden; /* Prevent scrollbars on the body itself */
}

#offline-indicator {
    position: fixed;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #ef4444;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    z-index: 1000;
    transition: bottom 0.5s ease;
}

#offline-indicator.visible {
    bottom: 20px;
}

/* Main app container uses Flexbox for layout */
#app-container {
    display: flex;
    flex-direction: column; /* Stack sidebar and main content vertically on mobile */
    height: 100vh;
    background-color: var(--bg-primary);
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* --- SIDEBAR (Mobile) --- */
#sidebar {
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-secondary);
    flex-shrink: 0; /* Prevent sidebar from shrinking */
    max-height: 45vh; /* Limit height on mobile to ensure player is visible */
}

#sidebar.drag-over .playlist-container {
    border-color: var(--accent-blue);
    background-color: var(--drag-overlay);
}

.sidebar-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.header-main h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-blue);
}

#location-info {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

#location-info span:not(:last-child)::after {
    content: '•';
    margin: 0 0.4rem;
}

.search-container {
    padding: 0 1rem 0.5rem;
    position: relative;
}

#search-bar {
    width: 100%;
    padding: 0.6rem 2.2rem 0.6rem 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#search-bar:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px var(--drag-overlay);
}

.search-clear-btn {
    position: absolute;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    padding: 0.25rem;
}

.search-clear-btn.visible {
    opacity: 1;
}

.playlist-controls {
    padding: 0.5rem 1rem;
}

.playlist-container {
    flex-grow: 1; /* Allow playlist to take up remaining space in sidebar */
    overflow-y: auto;
    padding: 0 1rem 1rem;
    transition: background-color 0.2s ease;
}

.playlist-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.3s ease;
    margin-bottom: 0.5rem;
    border: 1px solid transparent;
}

.playlist-item:hover {
    background-color: rgba(0,0,0,0.05);
}
html.dark .playlist-item:hover {
    background-color: rgba(255,255,255,0.1);
}

.playlist-item.active {
    background-color: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue-dark);
}

.playlist-item.active .playlist-artist {
    color: rgba(255, 255, 255, 0.8);
}

.playlist-album-art {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    margin-right: 1rem;
    object-fit: cover;
    flex-shrink: 0;
}

.playlist-track-info { overflow: hidden; }
.playlist-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.playlist-artist { font-size: 0.875rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color 0.2s ease; }

.drop-zone-text {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 1rem;
    transition: border-color 0.2s ease, color 0.2s ease;
}

#sidebar.drag-over .drop-zone-text {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

/* --- MAIN CONTENT (Mobile) --- */
#main-content {
    flex-grow: 1; /* This is key: it fills the remaining vertical space */
    display: flex;
    flex-direction: column;
    justify-content: center; /* Center player UI vertically */
    padding: 1rem;
    overflow-y: auto;
    min-height: 0; /* A flexbox fix to prevent content from overflowing its container */
}

#player-ui {
    padding-top: 20%;
    flex-grow: 1; /* Allow player UI to take up available space */
    width: 100%;
    margin: 0 auto;
    max-width: 450px; /* Max width for larger screens */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

/* Responsive Album Art */
.album-art-container {
    position: relative;
    overflow: hidden;
    top: 0; /* Reset top to 0 */
    width: 80%; /* Scales with the viewport width */
    max-width: 100%; /* But won't get larger than this on bigger phones */
    aspect-ratio: 1 / 1; /* Maintains a perfect square */
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    flex-shrink: 0;
    margin-bottom: 0.5rem;
}

.album-art {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.track-info {
    text-align: center;
    flex-shrink: 0;
}

#track-title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
#track-artist { font-size: 0.8rem; color: var(--text-secondary); }

/* --- CONTROLS --- */
.progress-container, .player-controls, .extra-controls {
    width: 100%;
    flex-shrink: 0;
}

.progress-container { display: flex; flex-direction: column; gap: 0.5rem; }
.time-display { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-secondary); }
.player-controls { display: flex; justify-content: center; align-items: center; gap: 1rem; }
.extra-controls { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.volume-control { display: flex; align-items: center; gap: 0.5rem; flex-grow: 1; max-width: 200px; }
.volume-control svg { color: var(--text-secondary); }

/* --- BUTTONS & INPUTS --- */
.btn-primary {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.btn-primary:hover { background-color: var(--accent-blue-dark); }
.btn-primary:active { transform: scale(0.98); }

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.icon-btn:hover { color: var(--text-primary); background-color: rgba(0,0,0,0.05); }
html.dark .icon-btn:hover { background-color: rgba(255,255,255,0.1); }
.icon-btn.active { color: var(--accent-blue); }

#play-pause-btn {
    background-color: var(--accent-blue);
    color: white;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.4);
    transition: all 0.2s ease;
}
#play-pause-btn:hover { background-color: var(--accent-blue-dark); color: white; transform: scale(1.05); }
#play-pause-btn:active { transform: scale(1); }
#play-pause-btn .pause-icon { display: none; }
#play-pause-btn.playing .play-icon { display: none; }
#play-pause-btn.playing .pause-icon { display: block; }

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 5px;
    outline: none;
    cursor: pointer;
    transition: background 0.2s ease;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-blue);
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    transition: transform 0.2s ease, background-color 0.2s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* --- THEME TOGGLE --- */
.theme-switcher { position: relative; }
.theme-switcher .moon { display: none; }
html.dark .theme-switcher .sun { display: none; }
html.dark .theme-switcher .moon { display: block; }

/* --- ENHANCER BUTTON --- */
.enhancer-checkbox { display: none; }
.btn-enhancer {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    background-color: var(--border);
    color: var(--text-secondary);
    transition: all 0.3s ease;
}
.btn-enhancer svg { transition: all 0.3s ease; }
.enhancer-checkbox:checked + .btn-enhancer {
    background-color: var(--accent-blue);
    color: white;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}
html.dark .enhancer-checkbox:checked + .btn-enhancer {
    box-shadow: 0 0 15px rgba(96, 165, 250, 0.4);
}

/* --- ENTRANCE ANIMATIONS --- */
[data-animate] {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

[data-animate].in-view {
    opacity: 1;
    transform: translateY(0);
}


/* --- TABLET STYLES (min-width: 768px) --- */
@media (min-width: 768px) {
    #app-container {
        flex-direction: row; /* Switch to side-by-side layout */
    }

    #sidebar {
        width: 320px; /* Give sidebar a fixed width */
        height: 100vh;
        max-height: 100vh;
        border-right: 1px solid var(--border);
        border-bottom: none;
    }

    .sidebar-header { padding: 1.5rem; }
    .header-main h1 { font-size: 1.5rem; }
    #location-info { font-size: 0.75rem; }
    .search-container { padding: 0 1.5rem 1rem; }
    .playlist-controls { padding: 0 1.5rem 1rem; }
    .playlist-container { padding: 0 1.5rem 1.5rem; }

    #main-content {
        padding: 2rem;
    }

    #player-ui {
        gap: 1.5rem;
    }

    .album-art-container {
        width: 100%;
        max-width: 350px; /* Allow thumbnail to be larger */
        margin-bottom: 0;
    }

    #track-title { font-size: clamp(1.25rem, 4vw, 1.5rem); } /* Fluid typography */
    #track-artist { font-size: clamp(0.9rem, 2vw, 1rem); }

    .player-controls { gap: 1.5rem; }
    #play-pause-btn { width: 64px; height: 64px; }
}

/* --- DESKTOP STYLES (min-width: 1025px) --- */
@media (min-width: 1025px) {
    #sidebar {
        width: 350px; /* Slightly wider sidebar for desktop */
    }

    .album-art-container {
        max-width: 400px; /* Even larger thumbnail for big screens */
    }

    #track-title { font-size: 1.75rem; }
}


