* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --bg-gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-dark: #0f0f23;
    --card-bg: rgba(15, 15, 35, 0.85);
    --text-primary: #fff;
    --text-secondary: rgba(255, 255, 255, 0.8);
    --text-muted: rgba(255, 255, 255, 0.6);
    --border-color: rgba(102, 126, 234, 0.3);
    --hover-bg: rgba(255, 255, 255, 0.12);
    --active-bg: rgba(102, 126, 234, 0.35);
    --track-bg: rgba(255, 255, 255, 0.2);
}

body.light-theme {
    --primary-color: #5568d3;
    --secondary-color: #6c5ce7;
    --bg-gradient-1: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    --bg-dark: #f5f5f5;
    --card-bg: rgba(255, 255, 255, 0.95);
    --text-primary: #2d3436;
    --text-secondary: rgba(45, 52, 54, 0.9);
    --text-muted: rgba(45, 52, 54, 0.7);
    --border-color: rgba(85, 104, 211, 0.2);
    --hover-bg: rgba(85, 104, 211, 0.1);
    --active-bg: rgba(85, 104, 211, 0.2);
    --track-bg: rgba(85, 104, 211, 0.25);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #1a1a3e 100%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s ease, color 0.3s ease;
}

body.light-theme {
    background: var(--bg-gradient-1);
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: 15px;
    padding: 30px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

h1 {
    font-size: 2.5em;
    background: var(--bg-gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

h2 {
    font-size: 1.5em;
    margin: 25px 0 15px 0;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
    color: var(--text-primary);
    transition: color 0.3s ease, border-color 0.3s ease;
}

.theme-toggle {
    padding: 10px 16px;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    background: var(--primary-color);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.search-bar {
    margin: 20px 0;
    position: relative;
    max-width: 400px;
}

.search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1em;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    transition: color 0.2s ease;
}

.search-clear:hover {
    color: var(--primary-color);
}

#search {
    width: 100%;
    max-width: 400px;
    padding: 12px 15px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    font-size: 1em;
    transition: all 0.3s ease;
}

#search:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.3);
}

#search::placeholder {
    color: var(--text-muted);
}

body.light-theme #search {
    background: rgba(0, 0, 0, 0.05);
}

body.light-theme #search:focus {
    background: rgba(0, 0, 0, 0.08);
}

audio {
    display: none;
    /* Keep element logically bound but layout hidden as custom controls are drawn */
}

.now-playing-card {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    padding: 20px;
    margin: 20px 0;
    display: flex;
    align-items: center;
    gap: 20px;
    animation: slideIn 0.4s ease;
    transition: background 0.3s ease, border-color 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.album-art-container {
    position: relative;
    flex-shrink: 0;
}

.album-art {
    width: 120px;
    height: 120px;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--primary-color);
    object-fit: cover;
    transition: transform 0.5s ease;
}

.album-art.playing {
    animation: albumRotate 20s linear infinite;
}

@keyframes albumRotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.playing-indicator {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: flex;
    gap: 3px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 10px;
    border-radius: 20px;
}

.playing-indicator.hidden {
    display: none;
}

.playing-indicator .bar {
    width: 3px;
    height: 12px;
    background: var(--primary-color);
    border-radius: 2px;
    animation: barPulse 0.6s ease-in-out infinite;
}

.playing-indicator .bar:nth-child(2) {
    animation-delay: 0.1s;
}

.playing-indicator .bar:nth-child(3) {
    animation-delay: 0.2s;
}

@keyframes barPulse {

    0%,
    100% {
        height: 12px;
        background: var(--primary-color);
    }

    50% {
        height: 20px;
        background: var(--secondary-color);
    }
}

.now-playing-info {
    flex: 1;
}

.now-playing-title {
    font-size: 1.3em;
    font-weight: 700;
    margin-bottom: 5px;
    color: var(--text-primary);
}

.now-playing-artist {
    font-size: 1em;
    color: var(--text-secondary);
}

.keyboard-shortcuts {
    text-align: center;
    padding: 10px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    margin: 15px 0;
    border-left: 4px solid var(--primary-color);
    color: var(--text-secondary);
}

.song {
    cursor: pointer;
    padding: 12px 15px;
    margin: 8px 0;
    background: rgba(255, 255, 255, 0.05);
    border-left: 4px solid transparent;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.25s ease;
}

.song:hover {
    background: var(--hover-bg);
    border-left-color: var(--primary-color);
    transform: translateX(3px);
}

.song.active {
    background: var(--active-bg);
    border-left-color: var(--primary-color);
    box-shadow: inset 0 0 8px rgba(102, 126, 234, 0.2);
}

.song-info {
    text-align: left;
    flex: 1;
}

.song-title {
    font-weight: 600;
    font-size: 1.1em;
    margin-bottom: 3px;
    color: var(--text-primary);
}

.song-artist {
    font-size: 0.9em;
    color: var(--text-muted);
}

.song-duration {
    font-size: 0.85em;
    color: var(--text-muted);
    margin: 0 10px;
    min-width: 40px;
    text-align: right;
}

.song-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.queue-section {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.queue {
    max-height: 250px;
    overflow-y: auto;
}

.queue-item {
    padding: 10px 12px;
    margin: 6px 0;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95em;
    border-left: 3px solid var(--primary-color);
    transition: all 0.2s ease;
    cursor: pointer;
}

.queue-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(3px);
}

.queue-item-index {
    font-weight: 700;
    color: var(--primary-color);
    min-width: 25px;
}

.queue-item-info {
    flex: 1;
    margin: 0 10px;
}

.queue-item-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.queue-item-artist {
    font-size: 0.85em;
    color: var(--text-muted);
}

.queue-item-duration {
    font-size: 0.85em;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: 10px;
}

.recently-played {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.recent-item {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.recent-item:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.25);
}

.recent-item-cover {
    width: 100%;
    height: 120px;
    border-radius: 8px;
    object-fit: cover;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
}

.recent-item-title {
    font-weight: 600;
    font-size: 0.9em;
    margin-bottom: 3px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-item-artist {
    font-size: 0.8em;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-item-time {
    font-size: 0.75em;
    color: var(--text-muted);
    margin-top: 5px;
    display: block;
}

.playlist {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 20px;
    padding: 10px;
    border-radius: 10px;
}

.favorite-btn,
.download-btn {
    cursor: pointer;
    font-size: 1.2em;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s ease;
    background: none;
    border: none;
    padding: 5px 10px;
}

.favorite-btn:hover {
    color: gold;
    transform: scale(1.2);
}

.download-btn:hover {
    color: var(--primary-color);
    transform: scale(1.2);
}

.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.control-btn {
    padding: 12px 20px;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    font-weight: 600;
    font-size: 0.95em;
    transition: all 0.3s ease;
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.control-btn.active-toggle {
    border-color: #fff;
    box-shadow: 0 0 12px var(--primary-color);
}

.control-btn:active {
    transform: translateY(0);
}

.progress-control,
.volume-control {
    margin: 25px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.progress-control label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 1.05em;
    color: var(--text-primary);
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 15px;
}

.volume-label-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.05em;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    outline: none;
}

.volume-label-btn:hover {
    color: var(--primary-color);
}

#progress,
#volume {
    width: 100%;
    max-width: 400px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--track-bg);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    outline: none;
    cursor: pointer;
    transition: background 0.3s ease, border-color 0.3s ease;
}

#progress::-webkit-slider-thumb,
#volume::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(102, 126, 234, 0.5);
}

#progress::-moz-range-thumb,
#volume::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(102, 126, 234, 0.5);
}

#time-display {
    display: inline-block;
    margin-top: 10px;
    font-size: 0.95em;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Custom Scrollbar Styles for lists */
.playlist::-webkit-scrollbar,
.queue::-webkit-scrollbar {
    width: 6px;
}

.playlist::-webkit-scrollbar-track,
.queue::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
}

.playlist::-webkit-scrollbar-thumb,
.queue::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    h1 {
        font-size: 1.8em;
    }

    h2 {
        font-size: 1.2em;
    }

    .now-playing-card {
        flex-direction: column;
        text-align: center;
        padding: 15px;
    }

    .album-art {
        width: 100px;
        height: 100px;
    }

    .controls {
        flex-direction: column;
    }

    .control-btn {
        width: 100%;
    }

    #search {
        max-width: 100%;
    }

    #progress,
    #volume {
        max-width: 100%;
    }

    .playlist {
        max-height: 300px;
    }

    .song {
        flex-wrap: wrap;
        gap: 10px;
    }

    .song-info {
        flex: 1 0 100%;
    }

    .song-actions {
        flex: 1;
        justify-content: flex-start;
    }

    .song-duration {
        margin: 5px 0 0 0;
        text-align: left;
    }

    .recently-played {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 15px;
    }

    h1 {
        font-size: 1.5em;
    }

    h2 {
        font-size: 1.1em;
    }

    .now-playing-card {
        padding: 12px;
    }

    .album-art {
        width: 80px;
        height: 80px;
    }

    .now-playing-title {
        font-size: 1.1em;
    }

    .now-playing-artist {
        font-size: 0.9em;
    }

    .song {
        padding: 10px;
        font-size: 0.9em;
    }

    .control-btn {
        padding: 10px 15px;
        font-size: 0.9em;
    }

    .theme-toggle {
        padding: 8px 12px;
        font-size: 0.85em;
    }

    .favorite-btn,
    .download-btn {
        font-size: 1em;
    }

    .keyboard-shortcuts {
        font-size: 0.8em;
        padding: 8px;
    }

    .recently-played {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 10px;
    }

    .queue-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .queue-item-duration {
        align-self: flex-end;
    }
}