/* Global Resets */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Base Body Styles */
body {
    font-family: var(--font-family-player, 'Arial', sans-serif);
    background-color: #1a1a1a; /* Dark background for the page */
    color: var(--player-text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden; /* Prevent body scrollbars */
    user-select: none; /* Prevent text selection within player */
}

/* CSS Variables for Skinnability (Default Skin - Classic Winamp Grey) */
:root {
    /* Main Player Colors */
    --player-bg: #2d2d2d; /* Main background for windows */
    --player-border: #000; /* Outer border of the main container */
    --player-text: #c0c0c0; /* General text color */
    --player-accent: #00ff00; /* Green display text, active states */
    --player-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5); /* Drop shadow for container */

    /* 3D Border Effects */
    --border-light: rgba(255, 255, 255, 0.2); /* Light side of 3D border */
    --border-dark: rgba(0, 0, 0, 0.5); /* Dark side of 3D border */

    /* Buttons (General) */
    --button-bg: #808080;
    --button-text: #000;
    --button-hover-bg: #a0a0a0;
    --button-active-bg: #606060;

    /* Input/Display Fields */
    --input-bg: #000;
    --input-text: var(--player-accent); /* Green text on black background */

    /* Window Header */
    --window-header-bg: #1a1a1a;
    --window-header-text: #c0c0c0;
    --window-control-bg: #606060;
    --window-control-hover-bg: #808080;
    --window-control-active-bg: #404040;

    /* Playlist Specific */
    --playlist-item-bg: transparent;
    --playlist-item-hover-bg: rgba(255, 255, 255, 0.1);
    --playlist-item-active-bg: rgba(255, 255, 255, 0.2);
    --playlist-item-playing-bg: #000080; /* Dark blue for playing item */
    --playlist-item-playing-text: #ffffff; /* White text for playing item */

    /* Scrollbar */
    --scrollbar-thumb-color: var(--button-bg);
    --scrollbar-track-color: var(--player-bg);

    /* Layout */
    --player-window-gap: 4px; /* Gap between windows in the main container */
    --font-family-player: 'Arial', sans-serif; /* Can be overridden by a pixel font */
}

/* Main WebAmp Container */
/* This container acts as the desktop for the Winamp windows */
#webamp-container {
    background-color: var(--player-bg);
    border: 1px solid var(--player-border);
    box-shadow: var(--player-shadow);
    color: var(--player-text);
    display: flex;
    flex-direction: column; /* Windows stack vertically by default */
    gap: var(--player-window-gap);
    padding: var(--player-window-gap);
    position: relative; /* For absolute positioning of draggable windows */
    /* resize: both; */ /* Disabled for now, as individual windows are meant to be resizable */
    overflow: hidden; /* Hide overflow if windows are positioned outside */
    min-width: 275px; /* Winamp classic width */
    max-width: 90vw;
    min-height: 116px; /* Main player height */
    max-height: 90vh;
    font-family: var(--font-family-player);
}

/* Individual Player Windows (Main, Playlist, EQ) */
.window {
    background-color: var(--player-bg);
    border-top: 1px solid var(--border-light);
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-dark);
    border-bottom: 1px solid var(--border-dark);
    padding: 2px; /* Inner padding for the window content area */
    display: flex;
    flex-direction: column;
    position: absolute; /* Allows independent dragging and positioning */
    top: 0; /* Default position, will be set by JS */
    left: 0; /* Default position, will be set by JS */
    z-index: 10; /* Default z-index */
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3); /* Shadow for individual windows */
}

/* Window Header (Title Bar) */
.window-header {
    background-color: var(--window-header-bg);
    color: var(--window-header-text);
    height: 16px; /* Classic Winamp header height */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
    font-size: 0.7em;
    cursor: grab; /* Indicates draggable */
    margin-bottom: 2px; /* Gap between header and content */
}

.window-header:active {
    cursor: grabbing;
}

.window-title {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.window-controls {
    display: flex;
    gap: 2px;
}

/* Window Control Buttons (Minimize, Maximize, Close) */
.window-controls button {
    width: 12px; /* Small, square buttons */
    height: 12px;
    background-color: var(--window-control-bg);
    border-top: 1px solid var(--border-light);
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-dark);
    border-bottom: 1px solid var(--border-dark);
    cursor: pointer;
    font-size: 0.6em; /* Smaller font for symbols */
    color: var(--window-header-text);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.1s ease;
    outline: none;
}

.window-controls button:hover {
    background-color: var(--window-control-hover-bg);
}

.window-controls button:active {
    background-color: var(--window-control-active-bg);
    border-top: 1px solid var(--border-dark);
    border-left: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

/* Specific button symbols (can be replaced with background images for authenticity) */
.minimize-button::before { content: '_'; }
.maximize-button::before { content: '[]'; }
.close-button::before { content: 'X'; }


/* Main Player Window */
#main-player {
    width: 275px; /* Classic Winamp width */
    height: 116px; /* Classic Winamp height */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Center initially */
    z-index: 11; /* Higher z-index for main player */
}

#main-player .window-content {
    display: flex;
    flex-direction: column;
    height: calc(100% - 18px); /* Account for header height + margin */
    justify-content: space-between;
}

/* Display Area (Track Info, Visualizer) */
#display-area {
    background-color: var(--input-bg);
    color: var(--input-text);
    border-top: 1px solid var(--border-dark);
    border-left: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 2px 4px;
    height: 50px; /* Approx height for display area */
    font-size: 0.8em;
    overflow: hidden;
}

#current-track-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    height: 16px; /* Single line */
}

#visualizer-canvas {
    width: 100%;
    height: 30px; /* Space for visualizer */
    background-color: rgba(0, 0, 0, 0.3); /* Slightly transparent background */
    border-top: 1px solid var(--border-light);
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-dark);
    border-bottom: 1px solid var(--border-dark);
}

/* Time Display */
#time-display {
    background-color: var(--input-bg);
    color: var(--input-text);
    border-top: 1px solid var(--border-dark);
    border-left: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    padding: 2px 4px;
    font-size: 0.8em;
    text-align: right;
    margin-top: 2px;
}

/* Controls Area (Buttons, Volume, Modes) */
#controls {
    display: flex;
    flex-wrap: wrap; /* Allow controls to wrap if space is tight */
    gap: 2px;
    margin-top: 2px;
}

/* Generic Control Buttons */
.control-button, .action-button {
    background-color: var(--button-bg);
    color: var(--button-text);
    border-top: 1px solid var(--border-light);
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-dark);
    border-bottom: 1px solid var(--border-dark);
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.8em;
    text-transform: uppercase;
    outline: none;
    transition: background-color 0.1s ease;
    min-width: 30px; /* Ensure buttons have minimum size */
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.control-button:hover, .action-button:hover {
    background-color: var(--button-hover-bg);
}

.control-button:active, .action-button:active {
    background-color: var(--button-active-bg);
    border-top: 1px solid var(--border-dark);
    border-left: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

/* Specific button sizes/styles */
#prev-button, #play-button, #pause-button, #stop-button, #next-button {
    width: 40px; /* Wider playback buttons */
}
#play-button::before { content: '▶'; }
#pause-button::before { content: '||'; }
#stop-button::before { content: '■'; }
#prev-button::before { content: '«'; }
#next-button::before { content: '»'; }

/* Volume Controls */
#volume-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-grow: 1; /* Allows volume controls to take available space */
}

#volume-slider {
    -webkit-appearance: none; /* Override default slider styles */
    appearance: none;
    width: 100%;
    height: 8px; /* Slimmer slider */
    background: var(--input-bg);
    outline: none;
    border-top: 1px solid var(--border-dark);
    border-left: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    margin: 0;
}

/* Slider Thumb (Handle) */
#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--player-accent); /* Green thumb */
    border: 1px solid var(--player-accent); /* Small border */
    cursor: grab;
}

#volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: var(--player-accent);
    border: 1px solid var(--player-accent);
    cursor: grab;
}

#mute-button {
    width: 40px; /* Small mute button */
}
#mute-button::before { content: '🔇'; } /* Mute symbol */

/* Playback Modes (Shuffle, Repeat) */
#playback-modes {
    display: flex;
    gap: 2px;
}

#shuffle-button, #repeat-button {
    width: 60px; /* Wider buttons for text */
    font-size: 0.7em;
}

/* Active state for shuffle/repeat */
#shuffle-button.active, #repeat-button.active {
    background-color: var(--player-accent);
    color: var(--button-bg);
    border-top: 1px solid var(--border-dark);
    border-left: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

/* Add Files Button */
#add-files-button {
    margin-top: 5px;
    width: auto; /* Auto width based on content */
    align-self: flex-start; /* Align to the start of the flex container */
}

/* Playlist Window */
#playlist-window {
    width: 275px; /* Same width as main player for alignment */
    height: 200px; /* Example height, can be resized */
    top: calc(50% + 116px/2 + var(--player-window-gap)); /* Below main player */
    left: 50%;
    transform: translateX(-50%); /* Center below */
    display: flex;
    flex-direction: column;
    resize: vertical; /* Allow vertical resizing */
    min-height: 100px;
    overflow: hidden; /* Hide content overflow, playlist UL will scroll */
}

#playlist-window .window-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Ensure UL takes full height and scrolls */
}

#playlist {
    list-style: none;
    flex-grow: 1;
    overflow-y: auto; /* Enable scrolling for long playlists */
    font-size: 0.8em;
    padding: 2px 0; /* Padding for list items */
}

#playlist li {
    padding: 2px 5px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background-color: var(--playlist-item-bg);
    color: var(--player-text);
    transition: background-color 0.1s ease;
}

#playlist li:hover {
    background-color: var(--playlist-item-hover-bg);
}

#playlist li.playing {
    background-color: var(--playlist-item-playing-bg);
    color: var(--playlist-item-playing-text);
}

/* Custom Scrollbar for Playlist */
#playlist::-webkit-scrollbar {
    width: 8px; /* Width of the scrollbar */
}

#playlist::-webkit-scrollbar-track {
    background: var(--scrollbar-track-color); /* Color of the track */
    border-left: 1px solid var(--border-dark);
    border-top: 1px solid var(--border-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
}

#playlist::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb-color); /* Color of the scroll thumb */
    border-top: 1px solid var(--border-light);
    border-left: 1px solid var(--border-light);
    border-right: 1px solid var(--border-dark);
    border-bottom: 1px solid var(--border-dark);
}

#playlist::-webkit-scrollbar-thumb:hover {
    background-color: var(--button-hover-bg);
}

/* Equalizer Window (Placeholder) */
#equalizer-window {
    width: 275px;
    height: 116px; /* Same height as main player */
    top: calc(50% - 116px/2 - var(--player-window-gap)); /* Above main player */
    left: calc(50% + 275px/2 + var(--player-window-gap)); /* To the right of main player */
    z-index: 9; /* Lower z-index */
    display: none; /* Hidden by default until implemented in JS */
}

#equalizer-window .window-content {
    height: calc(100% - 18px); /* Account for header height + margin */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.9em;
    color: var(--player-text);
}

/* Drag and Drop Feedback */
#webamp-container.drag-over {
    border: 1px dashed var(--player-accent);
    box-shadow: 0 0 10px var(--player-accent);
}

/* Tooltips (Basic styling for title attribute) */
[title]:hover::after {
    content: attr(title);
    position: absolute;
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 0.7em;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none; /* Allow clicks through the tooltip */
    transform: translateY(5px); /* Offset from cursor */
}

/* Basic Responsiveness / Mini-player consideration */
@media (max-width: 768px) {
    body {
        min-height: auto;
        align-items: flex-start;
        padding: 10px;
    }

    #webamp-container {
        width: 100%;
        max-width: 100%;
        min-width: unset;
        height: auto;
        max-height: unset;
        flex-direction: column;
        padding: 5px;
        gap: 5px;
    }

    /* Stack windows vertically and make them take full width */
    .window {
        position: relative; /* Change to relative for stacking */
        width: 100%;
        left: 0;
        top: auto;
        transform: none; /* Remove centering transform */
        margin-bottom: var(--player-window-gap); /* Add gap between stacked windows */
    }

    #main-player {
        height: auto; /* Allow height to adjust */
        min-height: 116px;
    }

    #playlist-window {
        height: auto;
        min-height: 150px; /* Ensure playlist is visible */
        resize: vertical;
    }

    #equalizer-window {
        display: none; /* Hide EQ on small screens by default */
    }

    #controls {
        justify-content: center; /* Center controls */
    }
}

/* Placeholder for the initial index.html content to be hidden (if any before JS loads) */
body > h1, body > p {
    display: none;
}