:root {
    --app-bg: #0d0d0d;
    --button-lighter: #262626;
    --button-normal: #141414;
    --button-darker: #0b0b0b;
    --button-hover: #3a3a3a;
    --box-bg: #171717;
    --box-item-bg: #222222;
    --box-item-hover: #2a2a2a;
    --box-item-selected: #303030;
    --text-normal: #ffffff;
    --text-darker: #aaaaaa;
    --border: #222222;
    --button-delete: #861313;
    --button-toggle: #325d5d;
    --button-toggle-lighter: #4d8f8f;

    --transparent: rgba(0, 0, 0, 0);
    --overlay-light: rgba(0, 0, 0, 0.40);
    --overlay-dark: rgba(0, 0, 0, 0.80);

    --spinner-track: #444444;
    --spinner-head: #ffffff;

    --transition-fast: 0.14s ease;
    --transition-medium: 0.18s ease;
    --transition-panel: 0.20s ease;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: var(--app-bg);
    color: var(--text-normal);
}

.app {
    display: flex;
    height: 100vh;
    min-height: 0;
}

.left,
.middle,
.right {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.left {
    width: 20%;
    border-right: 1px solid var(--border);
}

.middle {
    width: 40%;
}

.right {
    width: 40%;
    border-left: 1px solid var(--border);
}

#playbackControl,
.search-box,
.lyrics-box,
.lastfm-bar,
.modal-content {
    background: var(--box-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
}

#playbackControl {
    margin: 10px 10px 0;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    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-light);
    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-darker);
}

.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%;
}
.search-btn,
.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-normal);
    background: var(--button-normal);
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast),
        filter var(--transition-fast),
        opacity var(--transition-fast);
}

.search-btn {
    background: var(--button-darker);
    aspect-ratio: 1 / 1;
    height: 64px;
}
.control-buttons button {
    width: 100%;
    max-height: 64px;
    aspect-ratio:1;
    font-family: monospace;
    font-size: 16pt;
    background: var(--button-lighter);
}

.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(--button-hover);
    transform: translateY(-1px);
}

.control-buttons button.active-toggle {
    background: var(--button-toggle);
}

.control-buttons button.active-toggle:hover {
    background: var(--button-toggle-lighter);
}

.playlist-list,
#playlistView,
#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(--box-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.playlist-row,
.video {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--box-item-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
}

.playlist-row:hover,
.video:hover {
    background: var(--box-item-hover);
    border-color: var(--border);
}

.playlist-row.active,
.video.selected {
    background: var(--box-item-selected);
    border-color: var(--border);
}

.video.dragging {
    opacity: 0.5;
}

.playlist-item {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--transparent);
    border: none;
    border-radius: 10px;
    text-align: left;
}

.playlist-item:hover,
.playlist-item.active {
    background: var(--transparent);
}

.playlist-item-name {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-weight: 600;
}
.search-actions,
.playlist-actions,
.lastfm-actions,
.settings-actions {
    display: flex;
    flex-shrink: 0;
    gap: 0;
}

.search-actions {
    margin: 10px;
}

.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);
    background: var(--button-normal);
}

.settings-actions-btn {
    width: 50%;
    background: var(--button-darker);
}

.delete-playlist-btn:hover,
.delete-track-btn:hover {
    background: var(--button-delete);
}

.lastfm-toggle.active {
    background: var(--button-toggle);
    color: var(--te);
}

.lastfm-toggle.active:hover {
    background: var(--button-toggle-lighter);
}

.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);
}

.action-right {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: 1px solid var(--border);
}

.playlist-drop-placeholder {
    height: 5px;
    margin: 0 6px;
    border-radius: 10px;
    background: var(--button-lighter);
}

.playlist-drop-placeholder::after {
    content: "";
    display: block;
    height: 100%;
}

.track-cover-btn {
    position: relative;
    width: 54px;
    height: 54px;
    padding: 0;
    border: none;
    background: var(--transparent);
    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-normal);
    font-size: 18px;
    opacity: 0;
    pointer-events: none;
    background: var(--transparent);
}

.track-cover-btn:hover img {
    filter: brightness(0.55);
}

.track-cover-btn:hover .play-overlay {
    opacity: 1;
}

.search-box {
    margin: 10px;
    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-box.loading .search-header .action-right,
.search-box.open .search-header .action-right {
    border-bottom-right-radius: 0;
    transition: var(--transition-panel);
}
    
.search-box.loading .search-header,
.search-box.open .search-header {
    border: none;
    border-bottom: 1px solid var(--border);
}

.search-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    padding: 0;
    align-items: center;
}

.search-header input {
    flex: 1;
    width: auto;
    height: 64px;
    padding: 10px;
    border: none;
    outline: none;
    border-radius: 10px 0 0 10px;
    background: var(--box-bg);
    color: var(--text-normal);
    font-size: 16px;
}

.search-header button:hover {
    background: var(--bg-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-light);
    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: 10px;
    border-bottom: 1px solid var(--border);
}

.lyrics-title {
    font-weight: 700;
    font-size: 14px;
}

.lyrics-subtitle {
    font-size: 12px;
}

.lyrics-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    white-space: pre-wrap;
}

.lyrics-line {
    min-height: 1.45em;
    padding: 4px 0;
    color: var(--text-darker);
    line-height: 1.45;
    cursor: pointer;
}

.lyrics-line.active {
    color: var(--text-normal);
    font-weight: 700;
    transform: translateX(4px);
}

.lyrics-empty {
    padding: 2px 0;
    color: var(--text-darker);
    font-size: 14px;
}

.thumb {
    position: relative;
    flex-shrink: 0;
}

.thumb img {
    display: block;
    width: 120px;
    height: 70px;
    object-fit: cover;
    border-radius: 10px;
    background: var(--box-item-bg);
}

.duration {
    position: absolute;
    right: 4px;
    bottom: 4px;
    padding: 2px 5px;
    border-radius: 10px;
    background: var(--overlay-dark);
    font-size: 11px;
}

.lastfm-box {
    margin: 0 10px 10px;
    display: flex;
    flex-direction: row;
}

.lastfm-bar {
    width: 100%;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    overflow: hidden;
}

.lastfm-status-area {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
}

.lastfm-label {
    color: var(--text-darker);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.lastfm-status {
    color: var(--text-normal);
    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-dark);
}

.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: 10px;
    background: var(--button-normal);
    color: var(--text-normal);
}

#modalPlaylists,
.settings-grid {
    display: grid;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 4px;
}

#modalPlaylists button,
.modal-content > button,
.modal-content #createPlaylistBtn {
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    background: var(--box-item-bg);
    border-radius: 10px;
}

#modalPlaylists button:hover,
.modal-content > button:hover,
.modal-content #createPlaylistBtn:hover {
    background: var(--button-hover);
}

.modal-content.settings-content {
    gap: 10px;
}

.settings-grid {
    gap: 10px;
}

.settings-field {
    display: grid;
    gap: 6px;
}

.settings-field label {
    font-size: 10px;
    color: var(--text-darker);
    font-weight: 700;
}

.settings-field input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--button-normal);
    color: var(--text-normal);
    outline: none;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--box-bg);
}

.settings-row div {
    width: 100%;
}

.settings-row input {
    width: 24px;
    margin: 10px;
    aspect-ratio: 1 / 1;
}

.empty-state {
    padding: 10px;
    font-size: 14px;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--transparent);
}

::-webkit-scrollbar-thumb {
    background: var(--button-hover);
    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;
    }

    .control-buttons button {
        font-size: 24pt;
    }

    .search-box,
    #playlistView,
    .lyrics-box,
    .lastfm-box,
    .mobile-tabs {
        width: calc(100% - 20px);
        margin-left: 10px;
        margin-right: 10px;
    }

    .search-box {
        order: 5;
        margin: 0 10px 10px 10px;
        border-radius: 0 0 10px 10px;
        overflow: hidden;
    }

    .middle {
        order: 4;
    }
    .mobile-tabs {
        order: 2;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px;
        margin: 10px 10px 0 10px;
        border-radius: 10px 10px 0 0;
        background: var(--box-bg);
        border: 1px solid var(--border);
        border-bottom: none;
    }

    .mobile-tabs label {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 42px;
        padding: 0 10px;
        border: 1px solid var(--border);
        border-radius: 10px;
        background: var(--box-item-bg);
        color: var(--text-darker);
        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(--button-hover);
        color: var(--text-normal);
    }

    #mobileTabPlaylist,
    #mobileTabLyrics {
        display: none;
    }

    #mobileTabPlaylist:checked ~ .app .mobile-tabs label[for="mobileTabPlaylist"],
    #mobileTabLyrics:checked ~ .app .mobile-tabs label[for="mobileTabLyrics"] {
        background: var(--box-item-selected);
        border-color: var(--border);
        color: var(--text-normal);
    }

    #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;
        margin: 0 10px;
        border-radius: 0;
        border-bottom: 0;
    }

    .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;
    }

    .search-header .action-right {
        border-top-right-radius: 0;
    }

    #playlistView {
        order: 5;
        display: flex;
        flex-direction: column;
        gap: 8px;
        height: auto;
        max-height: 70dvh;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 10px;
        border-radius: 0;
        margin: 0 10px;
        border-bottom: 0;
        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: 0;
        padding: 0;
        border-radius: 0 0 10px 10px;
        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;
    }
}
