:root {
    --bg-0: #0b0b0b;
    --bg-1: #0d0d0d;
    --bg-2: #111111;
    --bg-3: #121212;
    --bg-4: #151515;
    --bg-5: #171717;
    --bg-6: #1a1a1a;
    --bg-7: #202020;
    --bg-8: #222222;
    --bg-9: #242424;
    --bg-10: #262626;
    --bg-11: #2a2a2a;
    --bg-12: #333333;
    --bg-13: #3a3a3a;
    --bg-14: #444444;
    --bg-15: #4b4b4b;
    --bg-16: #4c3f18;
    --bg-17: #5a4b1f;

    --text-0: #ffffff;
    --text-1: #dfffe6;
    --text-2: #b2b2b2;
    --text-3: #aaa;
    --text-4: #a9a9a9;
    --text-5: #9d9d9d;
    --text-6: #9a9a9a;
    --text-7: #8f8f8f;

    --border-0: #1d1d1d;
    --border-1: #222222;
    --border-2: #242424;
    --border-3: #252525;
    --border-4: #2a2a2a;
    --border-5: #2b2b2b;
    --border-6: #345240;

    --shadow-0: rgba(0, 0, 0, 0.12);
    --shadow-1: rgba(0, 0, 0, 0.18);
    --shadow-2: rgba(0, 0, 0, 0.22);
    --shadow-3: rgba(0, 0, 0, 0.35);
    --shadow-4: rgba(0, 0, 0, 0.70);
    --inset-0: rgba(255, 255, 255, 0.03);
    --inset-1: rgba(255, 255, 255, 0.04);
    --inset-2: rgba(255, 255, 255, 0.06);

    --overlay-0: rgba(0, 0, 0, 0);
    --overlay-1: rgba(0, 0, 0, 0.15);
    --overlay-2: rgba(0, 0, 0, 0.35);
    --overlay-3: rgba(0, 0, 0, 0.70);
    --overlay-4: rgba(0, 0, 0, 0.80);

    --line-0: rgba(255, 255, 255, 0.12);
    --line-1: rgba(255, 255, 255, 0.14);
    --line-2: rgba(255, 255, 255, 0.35);

    --focus-0: rgba(255, 255, 255, 0.04);

    --spinner-track: #444444;
    --spinner-head: #ffffff;

    --track-selected: #262626;
    --track-hover: #2a2a2a;
    --toggle-on: #24382a;
    --toggle-on-border: #345240;
    --toggle-on-text: #dfffe6;

    --placeholder: rgba(255, 255, 255, 0.12);
    --placeholder-inner: rgba(255, 255, 255, 0.35);

    --transition-fast: 0.14s ease;
    --transition-medium: 0.18s ease;
    --transition-panel: 0.20s ease;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: var(--bg-2);
    color: var(--text-0);
    text-align: center;
    opacity: 0;
    transition: opacity var(--transition-panel);
}

.app {
    display: flex;
    height: 100vh;
    min-height: 0;
}

.left,
.right {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.left {
    width: 20%;
    min-width: 220px;
    background: var(--bg-1);
    border-right: 1px solid var(--border-1);
}

.right {
    width: 40%;
    min-width: 320px;
    border-left: 1px solid var(--border-1);
}

.middle {
    width: 40%;
    min-height: 0;
}

#playbackControl,
.search-box,
.lyrics-box,
.lastfm-bar,
.modal-content {
    background: var(--bg-6);
    border: 1px solid var(--border-4);
    border-radius: 10px;
    box-shadow: inset 0 1px 0 var(--inset-0), 0 10px 22px var(--shadow-0);
}

#playbackControl {
    margin: 10px 10px 0;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    overflow: hidden;
}

#albumArtWrap {
    position: relative;
    width: 100%;
    max-width: 250px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

#albumArtWrap img {
    display: block;
    width: 100%;
    max-width: 250px;
    aspect-ratio: 1 / 1;
    height: auto;
    object-fit: cover;
    border-radius: 10px;
}

#albumLoadingOverlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-2);
    border-radius: 10px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-medium);
}

#albumArtWrap.loading #albumLoadingOverlay {
    opacity: 1;
    pointer-events: auto;
}

#albumArtWrap.loading img {
    filter: brightness(0.65) blur(1px);
}

#player {
    display: none;
}

.title {
    font-weight: 700;
    word-break: break-word;
}

.author,
.meta,
.lyrics-subtitle,
.empty-state,
.settings-row small,
.lastfm-nowplaying,
#currentTimeLabel,
#durationLabel {
    color: var(--text-3);
}

.author {
    font-size: 13px;
}

.info {
    min-width: 0;
    flex: 1;
    font-size: 13px;
}

.meta {
    font-size: 12px;
}

.control-timebar,
.volume-row {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.control-timebar input,
.volume-row input {
    width: 100%;
}

.control-timebar div,
.volume-row div {
    white-space: nowrap;
    padding: 4px;
    border-radius: 5px;
    font-size: 16px;
}

.control-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    width: 100%;
}

.control-buttons button,
.drag-handle,
.playlist-save-btn,
.delete-playlist-btn,
.delete-track-btn,
.add-to-playlist,
.settings-actions-btn,
.lastfm-actions button,
.utility-settings,
#modalPlaylists button,
.modal-content > button,
.modal-content #createPlaylistBtn {
    border: none;
    cursor: pointer;
    color: var(--text-0);
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast),
        box-shadow var(--transition-fast),
        filter var(--transition-fast),
        opacity var(--transition-fast);
}

.control-buttons button,
.drag-handle,
.playlist-save-btn,
.delete-playlist-btn,
.delete-track-btn,
.add-to-playlist,
.settings-actions-btn,
.lastfm-actions button,
.utility-settings {
    background: var(--bg-6);
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
    box-shadow: inset 0 1px 0 var(--inset-0);
}

.control-buttons button {
    width: 100%;
    aspect-ratio: 1 / 1;
    font-family: monospace;
    font-size: 18px;
    background: var(--bg-11);
}

.control-buttons button:hover,
.drag-handle:hover,
.playlist-save-btn:hover,
.add-to-playlist:hover,
.settings-actions-btn:hover,
.utility-settings:hover,
.lastfm-toggle:hover {
    background: var(--bg-13);
    transform: translateY(-1px);
}

.control-buttons button.active-toggle {
    background: var(--bg-16);
}

.control-buttons button.active-toggle:hover {
    background: var(--bg-17);
}

#playlistList,
.playlist-list,
.middle,
#results {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    margin: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    background: var(--bg-6);
    border: 1px solid var(--border-4);
    border-radius: 10px;
    box-shadow: inset 0 1px 0 var(--inset-0), 0 10px 22px var(--shadow-0);
    scrollbar-width: thin;
    scrollbar-color: var(--bg-13) transparent;
}

.playlist-row,
.video {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--bg-7);
    border: 1px solid var(--border-4);
    border-radius: 12px;
    cursor: pointer;
    box-shadow: inset 0 1px 0 var(--inset-1);
}

.playlist-row:hover,
.video:hover {
    background: var(--track-hover);
    border-color: var(--border-5);
}

.playlist-row.active,
.video.selected {
    background: var(--track-selected);
    border-color: var(--border-5);
}

.video.dragging {
    opacity: 0.5;
}

.playlist-item {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--overlay-0);
    border: none;
    border-radius: 10px;
    text-align: left;
}

.playlist-item:hover,
.playlist-item.active {
    background: var(--overlay-0);
}

.playlist-item-name {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-weight: 600;
}

.playlist-actions,
.lastfm-actions,
.settings-actions {
    display: flex;
    flex-shrink: 0;
    gap: 0;
}

.drag-handle,
.playlist-save-btn,
.delete-playlist-btn,
.delete-track-btn,
.add-to-playlist,
.settings-actions-btn,
.lastfm-actions button,
.utility-settings {
    width: 40px;
    height: 40px;
}

.utility-settings {
    height: 100%;
    width: auto;
    margin-left: 10px;
    aspect-ratio: 1 / 1;
    border: 1px solid var(--border-4);
    background: var(--bg-6);
}

.settings-actions-btn {
    width: 50%;
    background: var(--bg-11);
}

.delete-playlist-btn:hover,
.delete-track-btn:hover {
    background: var(--bg-12);
}

.lastfm-toggle.active {
    background: var(--toggle-on);
    border-color: var(--toggle-on-border);
    color: var(--toggle-on-text);
}

.lastfm-toggle.active:hover {
    background: var(--toggle-on);
    border-color: var(--toggle-on-border);
}

.middle .video,
.playlist-row,
.drag-handle {
    cursor: grab;
}

.middle .video:active,
.playlist-row:active,
.drag-handle:active {
    cursor: grabbing;
}

.action-left {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.action-middle {
    border-radius: 0;
    border-left: 1px solid var(--border-0);
    border-right: 1px solid var(--border-0);
}

.action-right {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: 1px solid var(--border-0);
}

.playlist-drop-placeholder {
    height: 12px;
    margin: 0 6px;
    border-radius: 999px;
    background: var(--placeholder);
    box-shadow: inset 0 0 0 1px var(--line-1);
}

.playlist-drop-placeholder::after {
    content: "";
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--placeholder-inner);
}

.track-cover-btn {
    position: relative;
    width: 54px;
    height: 54px;
    padding: 0;
    border: none;
    background: var(--overlay-0);
    overflow: hidden;
    flex-shrink: 0;
    cursor: pointer;
    border-radius: 10px;
}

.track-cover-btn img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.track-cover-btn .play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-0);
    font-size: 18px;
    opacity: 0;
    pointer-events: none;
    background: var(--overlay-0);
}

.track-cover-btn:hover img {
    filter: brightness(0.55);
}

.track-cover-btn:hover .play-overlay {
    opacity: 1;
}

.search-box {
    margin: 10px 10px 12px;
    height: 64px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: height var(--transition-panel);
}

.search-box.loading {
    height: 128px;
}

.search-box.open {
    height: 400px;
}

.search-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    padding: 10px;
    background: var(--bg-6);
}

.search-header input {
    flex: 1;
    width: auto;
    padding: 10px;
    border: none;
    outline: none;
    border-radius: 8px 0 0 8px;
    background: var(--bg-2);
    color: var(--text-0);
    font-size: 16px;
}

.search-header button {
    padding: 10px 14px;
    border: none;
    background: var(--bg-2);
    color: var(--text-3);
    cursor: pointer;
    font-size: 16px;
}

.search-header button:hover {
    background: var(--bg-1);
}

.search-btn.search {
    border-radius: 0;
}

.search-btn.clear {
    border-radius: 0 8px 8px 0;
    border-left: 1px solid var(--border-1);
}

#results {
    margin: 0;
    border: none;
    opacity: 0;
    transform: translateY(10px);
    transition:
        opacity var(--transition-fast),
        transform var(--transition-fast);
}

.search-box.open #results {
    opacity: 1;
    transform: translateY(0);
}

.search-box.loading .loader {
    padding: 10px 0;
}

.loader {
    height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader::after,
.mini-spinner {
    content: "";
    width: 18px;
    height: 18px;
    border: 3px solid var(--spinner-track);
    border-top-color: var(--spinner-head);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.mini-spinner {
    width: 22px;
    height: 22px;
}

.lyrics-box {
    flex: 1;
    min-height: 0;
    margin: 0 10px 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    text-align: left;
    position: relative;
}

.lyrics-box.loading .lyrics-content {
    opacity: 0.18;
}

.lyrics-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-1);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-medium);
    z-index: 2;
}

.lyrics-box.loading .lyrics-loading-overlay {
    opacity: 1;
    pointer-events: auto;
}

.lyrics-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-3);
}

.lyrics-title {
    font-weight: 700;
    font-size: 14px;
}

.lyrics-subtitle {
    font-size: 12px;
}

.lyrics-content {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    white-space: pre-wrap;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-13) transparent;
}

.lyrics-line {
    min-height: 1.45em;
    padding: 4px 0;
    color: var(--text-6);
    line-height: 1.45;
    cursor: pointer;
}

.lyrics-line.active {
    color: var(--text-0);
    font-weight: 700;
    transform: translateX(4px);
}

.lyrics-empty {
    padding: 2px 0;
    color: var(--text-3);
    font-size: 14px;
}

.thumb {
    position: relative;
    flex-shrink: 0;
}

.thumb img {
    display: block;
    width: 120px;
    height: 70px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--thumb-bg, var(--bg-8));
}

.duration {
    position: absolute;
    right: 4px;
    bottom: 4px;
    padding: 2px 5px;
    border-radius: 3px;
    background: var(--overlay-4);
    font-size: 11px;
}

.lastfm-box {
    margin: 0 10px 12px;
    display: flex;
    flex-direction: row;
}

.lastfm-bar {
    width: 100%;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 12px 12px 14px;
    overflow: hidden;
}

.lastfm-bar input {
    flex: 1;
    min-width: 0;
    padding: 0 14px;
    border: none;
    outline: none;
    background: var(--overlay-0);
    color: var(--text-0);
    font-size: clamp(0.92rem, 0.8vw, 1rem);
}

.lastfm-status-area {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
}

.lastfm-label {
    color: var(--text-7);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.lastfm-status {
    color: var(--text-0);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
}

.lastfm-nowplaying {
    font-size: 12px;
    line-height: 1.35;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--overlay-3);
}

.modal-content {
    width: min(340px, calc(100vw - 32px));
    padding: 20px;
    text-align: left;
}

.modal-content h3 {
    margin-top: 0;
}

.modal-content input {
    width: 100%;
    margin-top: 10px;
    padding: 8px;
    border: none;
    border-radius: 8px;
    background: var(--bg-3);
    color: var(--text-0);
}

#modalPlaylists,
.settings-grid {
    display: grid;
    gap: 8px;
    max-height: 220px;
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-13) transparent;
}

#modalPlaylists button,
.modal-content > button,
.modal-content #createPlaylistBtn {
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    background: var(--bg-12);
    border-radius: 8px;
}

#modalPlaylists button:hover,
.modal-content > button:hover,
.modal-content #createPlaylistBtn:hover {
    background: var(--bg-14);
}

.modal-content.settings-content {
    gap: 10px;
}

.settings-grid {
    gap: 12px;
}

.settings-field {
    display: grid;
    gap: 6px;
}

.settings-field label {
    font-size: 12px;
    color: var(--text-4);
    font-weight: 700;
}

.settings-field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-5);
    border-radius: 10px;
    background: var(--bg-3);
    color: var(--text-0);
    outline: none;
}

.settings-field input:focus {
    border-color: var(--bg-15);
    box-shadow: 0 0 0 3px var(--focus-0);
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border-2);
    background: var(--bg-4);
}

.settings-row div {
    width: 100%;
}

.settings-row input {
    width: 24px;
    margin: 10px;
    aspect-ratio: 1 / 1;
}

.empty-state {
    padding: 14px;
    font-size: 14px;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--overlay-0);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-13);
    border-radius: 10px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#mobileTabPlaylist,
#mobileTabLyrics,
.mobile-tabs {
    display: none;
}

@media (max-width: 860px) {
    * {
        box-sizing: border-box;
    }

    html,
    body {
        width: 100%;
        min-height: 100%;
        overflow-x: hidden;
        overflow-y: auto;
    }

    body {
        text-align: left;
        -webkit-tap-highlight-color: transparent;
    }

    .app {
        display: flex;
        flex-direction: column;
        width: 100%;
        min-height: 100dvh;
        height: auto;
    }

    .left,
    .middle,
    .right {
        width: 100%;
        min-width: 0;
    }

    .left {
        order: 1;
        background: none;
        border: none;
    }

    .right {
        display: contents;
    }

    .search-box,
    .middle,
    .lyrics-box,
    .lastfm-box,
    .mobile-tabs {
        width: calc(100% - 20px);
        margin-left: 10px;
        margin-right: 10px;
    }

    .search-box {
        order: 4;
        margin: 0 10px 0 10px;
        border-radius: 14px;
        overflow: hidden;
    }

    .mobile-tabs {
        order: 2;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px;
        margin-top: 10px;
        border-radius: 14px;
        background: var(--bg-6);
        border: 1px solid var(--border-4);
        box-shadow: inset 0 1px 0 var(--inset-0), 0 10px 22px var(--shadow-0);
    }

    .mobile-tabs label {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 42px;
        padding: 0 12px;
        border: 1px solid var(--border-4);
        border-radius: 12px;
        background: var(--bg-7);
        color: var(--text-3);
        font-weight: 700;
        font-size: 13px;
        cursor: pointer;
        user-select: none;
        white-space: nowrap;
        transition:
            background-color 0.14s ease,
            border-color 0.14s ease,
            color 0.14s ease;
    }

    .mobile-tabs label:hover {
        background: var(--bg-11);
        color: var(--text-0);
    }

    #mobileTabPlaylist,
    #mobileTabLyrics {
        position: absolute;
        left: -9999px;
        width: 1px;
        height: 1px;
        opacity: 0;
        pointer-events: none;
    }

    #mobileTabPlaylist:checked ~ .app .mobile-tabs label[for="mobileTabPlaylist"],
    #mobileTabLyrics:checked ~ .app .mobile-tabs label[for="mobileTabLyrics"] {
        background: var(--bg-10);
        border-color: var(--border-5);
        color: var(--text-0);
    }

    #mobileTabLyrics:checked ~ .app .playlist-list,
    #mobileTabLyrics:checked ~ .app .middle,
    #mobileTabLyrics:checked ~ .app .search-box {
        display: none;
    }

    #mobileTabPlaylist:checked ~ .app .playlist-list,
    #mobileTabPlaylist:checked ~ .app .search-box {
        display: flex;
    }

    #mobileTabPlaylist:checked ~ .app .lyrics-box {
        display: none;
    }

    #mobileTabLyrics:checked ~ .app .lyrics-box {
        display: flex;
    }

    .playlist-list {
        order: 3;
        display: flex;
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        padding: 10px;
        scroll-snap-type: x proximity;
        align-items: stretch;
    }

    .playlist-list .playlist-row {
        flex: 0 0 auto;
        min-width: 220px;
        width: max-content;
        scroll-snap-align: start;
    }

    .playlist-list .playlist-item {
        flex: 1;
        min-width: 0;
    }


    .middle {
        order: 5;
        display: flex;
        flex-direction: column;
        gap: 8px;
        height: auto;
        max-height: 70dvh;
        overflow-y: auto;
        overflow-x: hidden;
        margin: 10px;
        padding: 10px;
        border-radius: 14px;
        box-shadow: none;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    .lyrics-box {
        order: 5;
        display: none;
        flex-direction: column;
        height: auto;
        max-height: 70dvh;
        overflow-y: auto;
        overflow-x: hidden;
        margin-top: 10px;
        padding: 0;
        border-radius: 14px;
        box-shadow: none;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }
    .lastfm-bar {
        width: 100%;
        flex: 1;
    }

    .utility-settings {
        min-width: 80px;
        height: auto;
        aspect-ratio: 1/1;
    }

    .lastfm-box {
        order: 6;
        display: flex;
    }
}