/* Theme Variables */
:root {
    /* Dark theme (default) */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eee;
    --text-secondary: #888;
    --text-tertiary: #666;
    --accent-primary: #ad0a2b;
    --accent-hover: #ad1937;
    --border-color: #333;
    --border-hover: #444;
    --error-bg: #3d1f2b;
    --error-text: #ad0a2b;
}

/* Keep login and fallback controls stable on iOS Safari. */
html { -webkit-text-size-adjust: 100%; }
button, a, input, select, textarea, label { touch-action: manipulation; }
@media (max-width: 720px) {
    input, select, textarea { font-size: 16px; }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

[hidden] {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 1rem;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 0.5rem;
    overflow-x: hidden;
}

header {
    position: relative;
    text-align: center;
    margin-bottom: 2rem;
    padding-top: 3.5rem;
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.header-title {
    display: flex;
    flex-direction: column;
}

header h1 {
    font-size: 2.5rem;
    color: var(--accent-primary);
    margin-bottom: 0.5rem;
}

header h1 .version {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    vertical-align: middle;
}

header p {
    color: var(--text-secondary);
}

/* Header controls container */
.header-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
}

/* Format selector */
.format-selector {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
}

.format-selector:hover {
    border-color: var(--accent-primary);
}

.format-selector:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.search-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-form input {
    flex: 1;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    text-align: center;
    width: 100%;
}

.search-form .search-clear-btn {
    position: absolute;
    right: 0.5rem;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    border-radius: 50%;
    transition: all 0.2s;
    display: none;
    opacity: 0.6;
    width: 24px;
    height: 24px;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    min-height: 24px;
}

.search-form .search-clear-btn:hover {
    color: var(--text-primary);
    opacity: 1;
    background: transparent;
}

.search-form .search-clear-btn.visible {
    display: flex;
}

.search-form input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.search-form button {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 44px;
    min-width: 44px;
}

.search-form button:hover {
    background: var(--accent-hover);
}

.search-disabled input,
.search-disabled button {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.status {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: none;
}

.status.info {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.status.error {
    background: var(--error-bg);
    border: 1px solid var(--accent-primary);
    color: var(--error-text);
}

/* Tabs */
.search-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: -2px;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

/* Back to Albums button (shown when viewing album tracks) */
.back-to-albums-btn {
    display: none;
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.back-to-albums-btn::before {
    content: '\2190';
    margin-right: 0.5rem;
}

.back-to-albums-btn:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.results {
    display: none;
    flex-direction: column;
    gap: 0.75rem;
}

.results.active {
    display: flex;
}

.track {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    gap: 0.75rem;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, max-height 0.22s ease, padding 0.22s ease, margin 0.22s ease;
}

.track:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
}

.track.is-playing {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 0 0 1px var(--accent-primary), 0 10px 24px rgba(200, 16, 46, 0.22);
}

.track.is-removing {
    opacity: 0;
    transform: translateX(12px);
    max-height: 0;
    min-height: 0;
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
    border-width: 0;
}

.track-main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.track-cover {
    width: 80px;
    height: 80px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-tertiary);
}

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

.track-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    word-break: break-word;
}

.track-artist {
    color: var(--text-secondary);
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    word-break: break-word;
}

.track-meta {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

.track-duration {
    color: var(--text-tertiary);
}

.track-views {
    color: var(--text-tertiary);
}

/* Track actions container */
.track-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
}

/* Play button */
.play-btn {
    padding: 0;
    font-size: 1.2rem;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    min-height: 44px;
    min-width: 44px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    text-indent: 2px;
}

.play-btn:hover:not(:disabled) {
    background: var(--accent-primary);
    color: white;
    transform: scale(1.05);
}

.play-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.download-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    min-height: 44px;
    min-width: 100px;
    flex-shrink: 0;
}

.download-btn:hover:not(:disabled) {
    background: var(--accent-primary);
    color: white;
}

.download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.download-btn.already-downloaded:disabled {
    border-color: #35b86b;
    background: rgba(53, 184, 107, 0.16);
    color: #79e7a5;
    cursor: default;
    opacity: 1;
}

/* Save to Computer button variant */
.download-btn.save-btn {
    background: var(--accent-primary);
    color: white;
    animation: pulse 2s ease-in-out infinite;
}

.download-btn.save-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}

/* Albums Grid */
.albums-grid {
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.albums-grid.active {
    display: grid;
}

.album-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
}

.album-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.album-cover {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--bg-tertiary);
}

.album-info {
    padding: 1rem;
    flex: 1;
}

.album-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.album-artist {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.album-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

.album-actions {
    padding: 0 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.view-album-btn,
.download-album-btn {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.view-album-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.view-album-btn:hover:not(:disabled) {
    background: var(--accent-primary);
    color: white;
}

.download-album-btn {
    background: var(--accent-primary);
    color: white;
}

.download-album-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.view-album-btn:disabled,
.download-album-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Responsive Design - Mobile First */

/* Very small screens (< 480px) */
@media (max-width: 480px) {
    header {
        padding-top: 2.5rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .github-star {
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem;
        min-height: 36px;
    }

    .format-selector {
        flex: 1;
    }

    .search-form {
        flex-direction: column;
    }

    .search-input-wrapper {
        width: 100%;
    }

    .search-form > button[type="submit"] {
        width: 100%;
    }

    /* Fix tab overflow on mobile */
    .search-tabs {
        gap: 0;
    }

    .tab-btn {
        flex: 1;
        padding: 0.75rem 0.25rem;
        font-size: 0.8rem;
        min-width: 0;
    }
}

/* Small screens (< 640px) */
@media (max-width: 640px) {
    /* Fix tab overflow on mobile */
    .search-tabs {
        gap: 0;
    }

    .tab-btn {
        flex: 1;
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
        min-width: 0;
    }

    .albums-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.75rem;
    }

    .track {
        padding: 0.75rem;
        flex-direction: column;
        align-items: stretch;
    }

    .track-main {
        margin-bottom: 0.75rem;
    }

    .track-cover {
        width: 60px;
        height: 60px;
    }

    .track-actions {
        width: 100%;
        flex-direction: row;
        justify-content: stretch;
    }

    .play-btn {
        flex: 0 0 auto;
    }

    .download-btn {
        flex: 1;
        min-width: unset;
    }

    /* Chart tracks: override column layout to keep rank on same row as track-main */
    .chart-track.track {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }
    .chart-track .track-main {
        flex: 1 1 0;
        min-width: 0;
        margin-bottom: 0;
    }
    .chart-track .track-actions {
        flex-basis: 100%;
    }
}

/* Navidrome authentication */
.logout-form {
    display: contents;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.login-card {
    width: min(100%, 26rem);
    padding: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background: var(--bg-secondary);
    box-shadow: 0 1.25rem 3rem rgba(0, 0, 0, 0.3);
}

.login-logo {
    display: block;
    width: 3rem;
    height: 3rem;
    margin: 0 auto 1rem;
}

.login-card h1 {
    color: var(--text-primary);
    font-size: 1.65rem;
    text-align: center;
}

.login-card > p {
    margin: 0.5rem 0 1.5rem;
    color: var(--text-secondary);
    text-align: center;
}

.login-provider {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.login-provider span {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--text-primary);
    font-weight: 700;
}

.login-provider img {
    width: 1.5rem;
    height: 1.5rem;
}

.icon-btn svg {
    width: 1.15rem;
    height: 1.15rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.login-form {
    display: grid;
    gap: 1rem;
}

.login-form label {
    display: grid;
    gap: 0.4rem;
    color: var(--text-primary);
    font-weight: 600;
}

.login-form input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.55rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    font: inherit;
}

.login-form input:focus {
    border-color: var(--accent-primary);
    outline: 2px solid color-mix(in srgb, var(--accent-primary) 35%, transparent);
}

.login-form button {
    padding: 0.8rem;
}

.login-error {
    min-height: 1.25rem;
    color: var(--error-text);
    font-size: 0.9rem;
}

/* Application log tab */
.logs-section {
    padding-bottom: 2rem;
}

.log-source-tabs {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.7rem;
}

.log-source-tab {
    padding: 0.55rem 1.2rem;
    border: 1px solid #30343b;
    border-radius: 0.4rem;
    background: #17191d;
    color: #a7adb7;
    font-weight: 700;
}

.log-source-tab.active {
    border-color: var(--accent-primary);
    background: var(--accent-primary);
    color: #fff;
}

.logs-output {
    width: 100%;
    height: min(72vh, 52rem);
    margin: 0;
    padding: 1rem;
    overflow: auto;
    border: 1px solid #30343b;
    border-radius: 0.45rem;
    background: #090a0c;
    color: #e6e8eb;
    tab-size: 4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 0.78rem/1.48 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

body:has(#logs-results.active) .container {
    max-width: 1400px;
}

/* Final interface polish: dark-only UI, clearer local actions, and in-app confirmations. */
.library-explore-btn {
    padding-left: 1rem;
    padding-right: 1rem;
}

.downloads-empty {
    display: grid;
    gap: 0.3rem;
    min-height: 9rem;
    place-content: center;
    padding: 1.25rem;
    color: var(--text-secondary);
    text-align: center;
}

.downloads-empty strong {
    color: var(--text-primary);
    font-size: 1rem;
}

.downloads-empty span {
    max-width: 25rem;
    font-size: 0.88rem;
}

.confirm-modal-content {
    max-width: 27rem;
}

.confirm-modal .modal-body {
    display: grid;
    gap: 1.4rem;
}

.confirm-modal #confirm-message {
    color: var(--text-secondary);
    line-height: 1.55;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
}

.modal-actions .btn {
    min-height: 2.45rem;
    padding: 0 0.9rem;
}

/* Small to medium screens (480px - 640px) */
@media (min-width: 480px) and (max-width: 640px) {
    header {
        padding-top: 3rem;
    }
}

/* Tablet (640px - 1024px) */
@media (min-width: 640px) {
    .container {
        padding: 0 1rem;
    }

    .track {
        padding: 1.25rem;
    }

    header h1 {
        font-size: 2.5rem;
    }
}

/* Desktop (> 1024px) */
@media (min-width: 1024px) {
    body {
        padding: 2rem;
    }
}

/* Desktop - single line for cleaner look */
@media (min-width: 1024px) {
    .track-title,
    .track-artist {
        white-space: nowrap;
        text-overflow: ellipsis;
        -webkit-line-clamp: 1;
    }
}

/* GitHub Star Button - positioned at top right */
.github-star {
    position: absolute;
    top: 0;
    right: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s;
    border: 2px solid var(--border-color);
    min-height: 44px;
    z-index: 10;
}

.github-star:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

/* Queue Section */
.queue-section {
    margin: 2rem 0;
    display: none;
}

.queue-section.show {
    display: block;
}

.queue-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.queue-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.clear-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 36px;
}

.clear-btn:hover {
    background: var(--bg-primary);
    border-color: var(--border-hover);
}

.queue-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.cancel-all-btn,
.cancel-job-btn {
    padding: 0.5rem 1rem;
    min-height: 36px;
    border: 1px solid rgba(239, 68, 68, 0.55);
    border-radius: 6px;
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.cancel-all-btn:hover:not(:disabled),
.cancel-job-btn:hover:not(:disabled) {
    background: #dc2626;
    color: white;
    border-color: #dc2626;
}

.cancel-all-btn:disabled,
.cancel-job-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.queue-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.queue-empty {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Job Cards */
.job-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    transition: border-color 0.3s;
}

.job-card.queued {
    border-color: #3498db;
}

.job-card.downloading {
    border-color: #f39c12;
}

.job-card.completed {
    border-color: #2ecc71;
}

.job-card.failed {
    border-color: #e74c3c;
}

.job-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
    gap: 1rem;
}

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

.job-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.job-artist {
    color: var(--text-secondary);
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.job-status {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

.status-queued {
    background: rgba(52, 152, 219, 0.2);
    color: #3498db;
}

.status-downloading {
    background: rgba(243, 156, 18, 0.2);
    color: #f39c12;
}

.status-completed {
    background: rgba(46, 204, 113, 0.2);
    color: #2ecc71;
}

.status-failed {
    background: rgba(231, 76, 60, 0.2);
    color: #e74c3c;
}

/* Job Error */
.job-error {
    background: var(--error-bg);
    color: var(--error-text);
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    margin: 0.5rem 0;
    word-break: break-word;
}

/* Job Actions */
.download-file-btn,
.clear-job-btn,
.cancel-job-btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 0.5rem;
    margin-right: 0.5rem;
    border: none;
    min-height: 36px;
}

.download-file-btn {
    background: var(--accent-primary);
    color: white;
    text-decoration: none;
    display: inline-block;
}

.download-file-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.clear-job-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.clear-job-btn:hover {
    background: var(--bg-primary);
    border: 1px solid var(--border-hover);
}

/* Mobile Queue Adjustments */
@media (max-width: 640px) {
    .queue-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .queue-header h2 {
        font-size: 1.25rem;
    }

    .clear-btn {
        width: 100%;
    }

    .job-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .job-status {
        align-self: flex-start;
    }

    .queue-list .download-file-btn,
    .queue-list .clear-job-btn {
        width: 100%;
        margin-right: 0;
        margin-bottom: 0.25rem;
    }
}

/* Settings button - matches theme toggle style */
.icon-btn {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    transition: all 0.2s;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    border-color: var(--accent-primary);
    background: var(--bg-primary);
}

#explore-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.downloads-tab-btn {
    position: relative;
}

.library-cover {
    background: var(--bg-tertiary);
    object-fit: cover;
}

.button-spinner {
    display: inline-block;
    width: 0.85rem;
    height: 0.85rem;
    margin-right: 0.35rem;
    vertical-align: -0.12rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: button-spin 0.65s linear infinite;
}

@keyframes button-spin {
    to { transform: rotate(360deg); }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

/* Settings */
.settings-section {
    margin-bottom: 2rem;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.2rem;
}

.settings-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.settings-description a {
    color: var(--accent-primary);
    text-decoration: none;
}

.settings-description a:hover {
    text-decoration: underline;
}

.cookie-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-indicator.status-success {
    background: #22c55e;
}

.status-indicator.status-warning {
    background: #f59e0b;
}

.status-indicator.status-error {
    background: #ef4444;
}

.status-indicator.status-none {
    background: var(--text-tertiary);
}

.status-text {
    font-size: 0.95rem;
}

.cookie-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --- Explore Tab --- */

.explore-section {
    display: none;
    overflow-x: hidden;
    max-width: 100%;
}
.explore-section.active {
    display: block;
}

.explore-loading, .explore-error {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}
.explore-error {
    color: var(--error-text);
}

/* Section headers */
.explore-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.explore-section-header h2 {
    margin: 0;
    font-size: 1.25rem;
}
.explore-section-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Country selector */
.country-selector {
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
}

/* Download All button */
.download-all-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    min-height: 44px;
    min-width: 100px;
}
.download-all-btn:hover:not(:disabled) {
    background: var(--accent-primary);
    color: white;
}
.download-all-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Charts section */
.explore-charts-section {
    margin-bottom: 2rem;
}
.explore-charts-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}
.chart-tracks-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    padding: 0.5rem 0;
}

.pagination-btn {
    padding: 0.4rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--hover);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.pagination-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Chart trend indicator */
.chart-trend {
    font-size: 0.85rem;
    min-width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}
.chart-trend.trend-up { color: #22c55e; }
.chart-trend.trend-down { color: #ef4444; }
.chart-trend.trend-neutral { color: var(--text-secondary); }

/* UGC badge for non-official content */
.ugc-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    margin-left: 0.4rem;
    vertical-align: middle;
}

/* Moods & Genres section */
/* New Releases section */
.explore-new-releases-section {
    margin-bottom: 2rem;
}
.new-releases-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}
.new-release-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
}
.new-release-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}
.new-release-cover {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--bg-tertiary);
}
.new-release-info {
    padding: 0.75rem;
    flex: 1;
}
.new-release-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.new-release-artist {
    color: var(--text-secondary);
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.new-release-meta {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    margin-top: 0.25rem;
    display: flex;
    gap: 0.5rem;
}
.new-release-actions {
    padding: 0 0.75rem 0.75rem;
    display: flex;
    gap: 0.5rem;
}
.new-release-actions button {
    flex: 1;
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
}
.new-release-actions button:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}
.explicit-badge {
    display: inline-block;
    background: var(--text-tertiary);
    color: var(--bg-primary);
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0.1rem 0.3rem;
    border-radius: 2px;
    margin-left: 0.35rem;
    vertical-align: middle;
}

.explore-moods-section {
    margin-top: 1.5rem;
}
.mood-section {
    margin-bottom: 1.5rem;
}
.mood-section h2 {
    font-size: 1.15rem;
    margin: 0 0 0.75rem 0;
}
.mood-categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
}
.mood-category-card {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    text-align: center;
    font-size: 0.9rem;
    transition: background 0.15s, border-color 0.15s;
    overflow-wrap: anywhere;
    min-width: 0;
}
.mood-category-card:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

/* Mood playlists grid */
.mood-playlists-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}
.mood-playlist-card {
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    overflow: hidden;
}
.mood-playlist-thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
}
.mood-playlist-info {
    padding: 0.75rem;
}
.mood-playlist-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}
.mood-playlist-author {
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.mood-playlist-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0 0.75rem 0.75rem;
}
.mood-playlist-actions button {
    flex: 1;
    padding: 0.4rem 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
}
.mood-playlist-actions button:hover {
    border-color: var(--accent-primary);
}
.mood-playlist-actions .download-playlist-btn {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

/* Breadcrumb navigation */
.explore-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.breadcrumb-link {
    background: none;
    border: none;
    color: var(--accent-primary);
    cursor: pointer;
    padding: 0;
    font-size: inherit;
}
.breadcrumb-link:hover {
    text-decoration: underline;
}
.breadcrumb-sep {
    color: var(--text-secondary);
}
.breadcrumb-current {
    color: var(--text-primary);
    font-weight: 500;
    overflow-wrap: anywhere;
    min-width: 0;
}

/* Playlist tracks header */
.explore-playlist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.explore-playlist-header h2 {
    margin: 0;
    font-size: 1.25rem;
}
.explore-track-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.explore-tracks-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Responsive - Explore tab mobile fixes */
@media (max-width: 600px) {
    .mood-categories-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
    .mood-playlists-grid {
        grid-template-columns: 1fr;
    }

    /* Stack the section header vertically */
    .explore-section-header {
        flex-direction: column;
        align-items: stretch;
    }

    /* Allow section actions to wrap and fill width */
    .explore-section-actions {
        flex-wrap: wrap;
        width: 100%;
    }
    .explore-section-actions .country-selector {
        flex: 1 1 auto;
        min-width: 0;
    }
    .explore-section-actions .download-all-btn {
        flex: 1 1 auto;
        min-width: 0;
    }
    /* Chart trend adjustments for very small screens */
    .chart-track .chart-trend {
        min-width: 1rem;
        font-size: 0.75rem;
    }

    /* Breadcrumb may wrap on narrow screens. */
    .explore-breadcrumb {
        flex-wrap: wrap;
    }
    /* Playlist header: wrap on mobile */
    .explore-playlist-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .explore-playlist-header .explore-section-actions {
        flex-wrap: wrap;
        width: 100%;
    }
    .explore-playlist-header .explore-section-actions .download-all-btn {
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* --- Downloads Tab --- */

.downloads-section {
    display: none;
}
.downloads-section.active {
    display: block;
}

.downloads-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.downloads-header h2 {
    margin: 0;
    font-size: 1.25rem;
}
.downloads-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.downloads-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
    font-style: italic;
}

.downloads-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Missing file indicator */
.track.track-missing {
    border-style: dashed;
    opacity: 0.6;
}
.track-missing-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #ef4444;
    white-space: nowrap;
}

/* Remove button */
.remove-btn {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    min-height: 36px;
    flex-shrink: 0;
}
.remove-btn:hover:not(:disabled) {
    background: #ef4444;
    color: white;
}
.remove-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   Musicload UI refresh: calm dark collection interface, mobile-first layout.
   This section intentionally only restyles existing functionality.
   -------------------------------------------------------------------------- */
:root {
    --bg-primary: #0d0e10;
    --bg-secondary: #15171b;
    --bg-tertiary: #202329;
    --surface-raised: #1a1d22;
    --text-primary: #f6f4f1;
    --text-secondary: #a7a8ae;
    --text-tertiary: #747680;
    --accent-primary: #c8102e;
    --accent-hover: #e01b3e;
    --border-color: #2a2d33;
    --border-hover: #484c55;
    --error-bg: #2b131a;
    --error-text: #ff9aaa;
}

body {
    min-width: 320px;
    padding: 0;
    background:
        radial-gradient(circle at 86% 0%, rgba(200, 16, 46, 0.12), transparent 27rem),
        var(--bg-primary);
    letter-spacing: -0.01em;
}

.container {
    max-width: 1240px;
    padding: 0 1.5rem 3rem;
}

header {
    position: sticky;
    z-index: 20;
    top: 0;
    margin: 0 -1.5rem 1.5rem;
    padding: 1rem 1.5rem;
    text-align: left;
    background: transparent;
    backdrop-filter: none;
    border-bottom: 0;
    box-shadow: none;
}

.github-star { display: none; }

.header-content {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    max-width: 1240px;
    margin: 0 auto;
}

.header-title { flex: 0 0 auto; }
header h1 {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0;
    color: var(--text-primary);
    font-size: 1.18rem;
    letter-spacing: -0.04em;
}
header h1 .brand-mark {
    display: block;
    width: 1.7rem;
    height: 1.7rem;
    flex: 0 0 auto;
}
header h1 .version, header p { display: none; }

.header-controls {
    justify-content: flex-end;
    gap: 0.4rem;
    width: auto;
}

.format-selector, .icon-btn {
    min-height: 2.45rem;
    height: 2.45rem;
    border: 1px solid transparent;
    border-radius: 0.55rem;
    background: transparent;
    color: var(--text-secondary);
    box-shadow: none;
}
.format-selector {
    order: -1;
    padding: 0 0.55rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-color: var(--border-color);
}
.icon-btn { min-width: 2.45rem; font-size: 1rem; }
.icon-btn:hover, #explore-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-hover);
    color: var(--text-primary);
    transform: none;
}

#explore-btn, #library-btn, #listenbrainz-btn, #downloads-btn {
    width: auto;
    min-width: auto;
    padding: 0 0.72rem;
    font-size: 0;
}
#explore-btn::after, #library-btn::after, #listenbrainz-btn::after, #downloads-btn::after {
    font-size: 0.83rem;
    font-weight: 650;
    letter-spacing: 0;
}
#explore-btn::after { content: "Explore"; }
#library-btn::after { content: "Library"; }
#listenbrainz-btn::after { content: "ListenBrainz"; }
#downloads-btn::after { content: "Downloads"; }
.search-form {
    max-width: 720px;
    margin: 1.7rem auto 1.35rem;
    gap: 0.55rem;
}
.search-input-wrapper::before {
    content: "⌕";
    position: absolute;
    z-index: 1;
    left: 1rem;
    color: var(--text-tertiary);
    font-size: 1.2rem;
    pointer-events: none;
}
.search-form input {
    min-height: 3.2rem;
    padding: 0.75rem 2.8rem 0.75rem 2.85rem;
    text-align: left;
    border: 1px solid var(--border-color);
    border-radius: 0.8rem;
    background: var(--bg-secondary);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.14);
}
.search-form input::placeholder { color: var(--text-tertiary); }
.search-form input:focus {
    border-color: rgba(200, 16, 46, 0.9);
    box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.15);
}
.search-form button[type="submit"] {
    min-height: 3.2rem;
    padding: 0.75rem 1.15rem;
    border-radius: 0.75rem;
    background: var(--accent-primary);
    font-size: 0.9rem;
}
.search-form button[type="submit"]:hover { background: var(--accent-hover); }
.search-form .search-clear-btn { right: 0.8rem; }

.status {
    max-width: 720px;
    margin: 0 auto 1.2rem;
    border-radius: 0.7rem;
}

.search-tabs { justify-content: center; gap: 0.25rem; }
.tab-btn {
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
}
.tab-btn.active, .tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

.explore-section, .downloads-section, .results, .albums-grid { animation: musicload-enter 220ms ease-out; }
@keyframes musicload-enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.explore-section-header, .downloads-header, .queue-header {
    margin: 1.5rem 0 1rem;
    padding: 0;
    border: 0;
}
.explore-section-header h2, .downloads-header h2, .queue-header h2,
.explore-section h2, .library-header h2 {
    font-size: clamp(1.35rem, 2.5vw, 1.75rem);
    letter-spacing: -0.04em;
}
.explore-section-actions { gap: 0.45rem; }

.track, .album-card, .queue-item, .explore-card, .mood-card, .mood-playlist-card {
    border: 1px solid var(--border-color);
    border-radius: 0.85rem;
    background: var(--bg-secondary);
}
.track {
    min-height: 5.7rem;
    padding: 0.65rem;
    gap: 0.9rem;
    box-shadow: none;
}
.track:hover {
    border-color: var(--border-hover);
    background: var(--surface-raised);
    transform: none;
    box-shadow: 0 12px 28px rgba(0,0,0,0.16);
}
.track.is-playing { box-shadow: 0 0 0 1px var(--accent-primary), 0 14px 32px rgba(200, 16, 46, 0.18); }
.track-cover { width: 4.35rem; height: 4.35rem; border-radius: 0.6rem; }
.track-title { font-size: 0.98rem; }
.track-artist { color: var(--text-secondary); }
.track-meta { font-size: 0.78rem; }
.track-actions { gap: 0.45rem; }
.play-btn {
    min-width: 2.45rem;
    min-height: 2.45rem;
    border: 1px solid var(--border-color);
    border-radius: 0.55rem;
    background: transparent;
    color: var(--text-primary);
}
.play-btn:hover:not(:disabled) {
    border-color: var(--accent-primary);
    background: rgba(200, 16, 46, 0.12);
    color: #fff;
    transform: none;
}
.download-btn, .download-all-btn, .library-explore-btn,
.clear-btn, .cancel-all-btn, .remove-btn, .clear-job-btn, .cancel-job-btn {
    min-height: 2.45rem;
    border: 1px solid var(--accent-primary);
    border-radius: 0.55rem;
    background: transparent;
    color: #ff526c;
    font-size: 0.82rem;
    font-weight: 650;
}
.download-btn:hover:not(:disabled), .download-all-btn:hover,
.library-explore-btn:hover, .clear-btn:hover, .cancel-all-btn:hover,
.remove-btn:hover:not(:disabled), .clear-job-btn:hover, .cancel-job-btn:hover {
    border-color: var(--accent-hover);
    background: rgba(200, 16, 46, 0.13);
    color: #fff;
}

.albums-grid { grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: 1rem; }
.album-card { overflow: hidden; }
.album-card:hover { border-color: var(--border-hover); transform: none; box-shadow: 0 16px 32px rgba(0,0,0,0.18); }
.album-cover { border-radius: 0; }
.album-info { padding: 0.85rem; }
.album-title { font-size: 0.94rem; }
.album-actions { padding: 0 0.85rem 0.85rem; }

.queue-section, .library-header, .explore-playlist, .charts-section {
    padding: 1.05rem;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    background: rgba(21, 23, 27, 0.78);
}
.queue-header { margin-top: 0; }
.queue-header-actions { gap: 0.45rem; }

.mini-player {
    right: 1.5rem;
    bottom: 1.5rem;
    min-width: 265px;
    padding: 0.7rem 0.75rem 0.7rem 1rem;
    border: 1px solid var(--border-hover);
    border-radius: 0.9rem;
    background: rgba(23, 25, 29, 0.94);
    box-shadow: 0 18px 45px rgba(0,0,0,0.38);
    backdrop-filter: blur(16px);
}
.mini-player-toggle {
    background: var(--accent-primary);
    color: white;
    border-radius: 50%;
}
.mini-player-stop { border-radius: 0.45rem; }

.mobile-nav { display: none; }

@media (max-width: 720px) {
    body { padding-bottom: calc(5.9rem + env(safe-area-inset-bottom)); }
    .container { padding: 0 0.9rem 1rem; }
    header {
        position: relative;
        margin: 0 -0.9rem 0.65rem;
        padding: max(0.85rem, env(safe-area-inset-top)) 0.9rem 0.75rem;
        background: transparent;
        backdrop-filter: none;
        border-bottom: 0;
        box-shadow: none;
    }
    .header-content { gap: 0.5rem; }
    header h1 { font-size: 1.1rem; }
    #explore-btn, #library-btn, #listenbrainz-btn, #downloads-btn { display: none; }
    .format-selector { display: none; }
    #cookies-btn { min-width: 2.2rem; min-height: 2.2rem; height: 2.2rem; }
    .search-form { margin: 0.75rem 0 1rem; }
    .search-form button[type="submit"] { min-width: 3.2rem; padding: 0.75rem; font-size: 0; }
    .search-form button[type="submit"]::after { content: "Search"; font-size: 0.78rem; }
    .search-tabs { margin-bottom: 1rem; }
    .explore-section-header, .downloads-header, .queue-header { margin: 1.1rem 0 0.75rem; }
    .queue-section, .library-header, .explore-playlist, .charts-section { padding: 0.8rem; border-radius: 0.8rem; }
    .track { align-items: center; min-height: 4.8rem; padding: 0.55rem; gap: 0.6rem; }
    .track-cover { width: 3.55rem; height: 3.55rem; }
    .track-title { -webkit-line-clamp: 1; }
    .track-artist { -webkit-line-clamp: 1; font-size: 0.82rem; }
    .track-meta { display: none; }
    .play-btn { min-width: 2.25rem; min-height: 2.25rem; }
    .download-btn { min-width: auto; padding: 0 0.7rem; min-height: 2.25rem; font-size: 0.76rem; }
    .albums-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
    .album-info { padding: 0.65rem; }
    .album-actions { padding: 0 0.65rem 0.65rem; }
    .album-actions button { width: 100%; }
    .mini-player { left: 0.9rem; right: 0.9rem; bottom: calc(4.8rem + env(safe-area-inset-bottom)); min-width: 0; }
    .mobile-nav {
        position: fixed;
        z-index: 30;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 0.15rem;
        left: 0;
        right: 0;
        bottom: 0;
        min-height: calc(4.7rem + env(safe-area-inset-bottom));
        padding: 0.45rem 0.45rem calc(0.45rem + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border-color);
        background: rgba(15, 16, 19, 0.96);
        backdrop-filter: blur(16px);
    }
    .mobile-nav.mobile-nav-three {
        grid-template-columns: repeat(3, 1fr);
    }
    .mobile-nav.mobile-nav-four {
        grid-template-columns: repeat(4, 1fr);
    }
    .mobile-nav.mobile-nav-two {
        grid-template-columns: repeat(2, 1fr);
    }
    .mobile-nav-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.18rem;
        border: 0;
        border-radius: 0.65rem;
        background: transparent;
        color: var(--text-tertiary);
        font-size: 0.64rem;
        font-weight: 650;
    }
    .mobile-nav-icon { font-size: 1.28rem; line-height: 1; }
    .mobile-nav-btn.active { color: #ff405d; background: rgba(200, 16, 46, 0.1); }

    /* Keep local album art anchored to the same left edge on every row. */
    #library-tracks-list .track {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
    }
    #library-tracks-list .track-main {
        width: 100%;
        min-width: 0;
        margin-bottom: 0;
    }
    #library-tracks-list .library-cover {
        justify-self: start;
    }
    #library-tracks-list .track-actions {
        width: auto;
        justify-content: flex-end;
    }
}

@media (min-width: 721px) and (max-width: 980px) {
    .container { max-width: 900px; }
    .albums-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Unified action controls and persistent playback control. */
.library-delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 4.6rem;
    height: auto;
    min-height: 2.45rem;
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--accent-primary);
    border-radius: 0.55rem;
    background: transparent;
    color: #ff526c;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 650;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}
.library-delete-btn:hover:not(:disabled) {
    border-color: var(--accent-hover);
    background: rgba(200, 16, 46, 0.15);
    color: #fff;
}
.library-delete-btn:disabled { opacity: 0.55; cursor: wait; }

/* Shared active-download feedback for desktop and installed/mobile layouts. */
#downloads-btn.download-active,
.mobile-nav-btn.download-active {
    color: #fff;
    border-color: #ff526c;
    background: rgba(200, 16, 46, 0.22);
    animation: download-button-glow 1.35s ease-in-out infinite;
}
@keyframes download-button-glow {
    0%, 100% { box-shadow: 0 0 0 rgba(255, 64, 93, 0.08); }
    50% { box-shadow: 0 0 1.25rem rgba(255, 64, 93, 0.68); }
}

/* The original button remains in place; only its label and fill change. */
.download-btn.inline-download-progress {
    position: relative;
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    cursor: pointer;
    opacity: 1;
}
.download-btn.inline-download-progress::before {
    content: attr(data-progress-details);
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.28rem);
    width: max-content;
    max-width: 12rem;
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.1;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.button-progress-fill {
    position: absolute;
    inset: 0 auto 0 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(200, 16, 46, 0.58), var(--accent-primary));
    transition: width 0.35s ease;
}
.button-progress-label {
    position: relative;
    z-index: 1;
}
.progress-action-btn {
    position: relative;
    overflow: hidden;
    min-width: 7rem;
    border: 1px solid var(--accent-primary);
    background: var(--bg-tertiary);
    color: #fff;
}
.job-state {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
    max-width: 48%;
}
.job-state .job-status { align-self: flex-end; }
.job-progress-details {
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 0.72rem;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

@media (prefers-reduced-motion: reduce) {
    #downloads-btn.download-active,
    .mobile-nav-btn.download-active { animation: none; }
}

@media (max-width: 640px) {
    .job-header {
        flex-direction: row;
        align-items: flex-start;
    }
    .job-state { max-width: 52%; }
    .download-btn.inline-download-progress::before {
        max-width: 9rem;
        font-size: 0.62rem;
    }
}

.mini-player {
    position: fixed;
    z-index: 40;
    display: grid;
    place-items: center;
    width: 3.7rem;
    min-width: 3.7rem;
    height: 3.7rem;
    min-height: 3.7rem;
    padding: 0;
    overflow: hidden;
    border: 1px solid #f04b62;
    border-radius: 50%;
    background: var(--accent-primary);
    box-shadow: 0 12px 32px rgba(200, 16, 46, 0.42);
}
.mini-player[hidden] { display: none !important; }
.mini-player-info, .mini-player-stop { display: none !important; }
.mini-player-toggle {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #fff;
    font-size: 1.15rem;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}
.mini-player-toggle:hover { background: rgba(255, 255, 255, 0.16); }

@media (max-width: 720px) {
    .mini-player {
        left: auto;
        right: 1rem;
        bottom: calc(5.25rem + env(safe-area-inset-bottom));
        width: 3.45rem;
        min-width: 3.45rem;
        height: 3.45rem;
        min-height: 3.45rem;
    }
}

/* Mobile adjustments for downloads */
@media (max-width: 640px) {
    .downloads-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .downloads-list .track-actions .download-file-btn {
        flex: 0 0 auto;
        width: auto;
        text-align: center;
        margin: 0;
    }
    .downloads-list .track-actions .remove-btn {
        flex: 1 1 0;
        min-width: 0;
    }
}

/* Optional per-account ListenBrainz explorer. */
.listenbrainz-section { display: none; }
.listenbrainz-section.active { display: block; }
.listenbrainz-header,
.listenbrainz-playlist-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin: 1.25rem 0 1rem;
}
.listenbrainz-header h2,
.listenbrainz-playlist-heading h3 { margin: 0; }
.listenbrainz-header p,
.listenbrainz-playlist-heading span {
    margin: 0.3rem 0 0;
    color: var(--text-secondary);
    font-size: 0.82rem;
}
.listenbrainz-settings-form {
    display: flex;
    flex: 0 1 28rem;
    gap: 0.5rem;
}
.listenbrainz-settings-form input,
.listenbrainz-settings-form select {
    min-width: 0;
    min-height: 2.45rem;
    flex: 1;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.55rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.listenbrainz-settings-form input[type="text"] { flex: 1; }
.listenbrainz-settings-form select { flex: 0 0 7.2rem; }
.listenbrainz-settings-form input[type="time"] { flex: 0 0 7.2rem; }
.listenbrainz-auto-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-height: 2.45rem;
    padding: 0 0.55rem;
    border: 1px solid var(--border-color);
    border-radius: 0.55rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.78rem;
}
.listenbrainz-auto-toggle input { flex: 0 0 auto; width: auto; min-height: auto; }
.listenbrainz-settings-form button {
    min-height: 2.45rem;
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--accent-primary);
    border-radius: 0.55rem;
    background: transparent;
    color: #ff526c;
    cursor: pointer;
    font-weight: 650;
}
.listenbrainz-settings-form button.is-saving {
    cursor: wait;
    background: rgba(200, 16, 46, 0.16);
}
.listenbrainz-settings-form button.is-saved {
    border-color: #35b86b;
    background: rgba(53, 184, 107, 0.16);
    color: #79e7a5;
}

/* Keep hover geometry stable so moving the pointer onto a control cannot retrigger hover. */
button:hover,
.download-file-btn:hover,
.github-star:hover {
    transform: none;
}
button:active,
.download-file-btn:active {
    transform: translateY(1px);
}
.listenbrainz-empty {
    padding: 3rem 1rem;
    color: var(--text-secondary);
    text-align: center;
}
.listenbrainz-countdown {
    margin: -0.4rem 0 1rem;
    color: var(--text-secondary);
    font-size: 0.78rem;
    text-align: right;
}

@media (max-width: 720px) {
    .listenbrainz-header,
    .listenbrainz-playlist-heading {
        align-items: stretch;
        flex-direction: column;
    }
    .listenbrainz-settings-form { flex-basis: auto; width: 100%; }
    .listenbrainz-settings-form { flex-wrap: wrap; }
    .listenbrainz-settings-form input[type="text"] { flex-basis: 100%; }
    .listenbrainz-settings-form select { flex: 1 1 7rem; }
    .listenbrainz-settings-form input[type="time"] { flex: 1 1 7rem; }
    .listenbrainz-countdown { text-align: left; }
    .listenbrainz-playlist-heading .download-all-btn { width: 100%; }
}
