:root,
:root[data-theme="dark"] {
    --bg: #0e1014;
    --bg-2: #15181f;
    --bg-3: #1d212b;
    --bg-hover: #252a36;
    --border: #2a2f3b;
    --text: #e8eaf0;
    --muted: #9aa3b2;
    --accent: #8b5cf6;
    --accent-2: #a78bfa;
    --danger: #ef4444;
    --like: #f43f5e;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

:root[data-theme="light"] {
    --bg: #f5f6f8;
    --bg-2: #ffffff;
    --bg-3: #eceef2;
    --bg-hover: #e2e5ec;
    --border: #d8dce4;
    --text: #1c2230;
    --muted: #5c6575;
    --accent: #7c3aed;
    --accent-2: #8b5cf6;
    --danger: #dc2626;
    --like: #e11d48;
    --shadow: 0 8px 30px rgba(20, 24, 40, 0.12);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    min-height: 100vh;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1px 6px;
}

.app {
    display: grid;
    grid-template-columns: 230px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    color: var(--text);
    font-size: 19px;
    font-weight: 700;
    margin-bottom: 22px;
}
.brand:hover { text-decoration: none; color: var(--accent-2); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
    color: var(--muted);
    padding: 9px 12px;
    border-radius: 8px;
    font-weight: 500;
}
.nav-link:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--bg-3); color: var(--accent-2); }

.sidebar-bottom {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding-bottom: 110px;
}

.topbar {
    padding: 14px 26px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2);
    position: sticky;
    top: 0;
    z-index: 5;
}

.search input {
    width: min(480px, 100%);
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    padding: 9px 16px;
    outline: none;
}
.search input:focus { border-color: var(--accent); }

.content { padding: 24px 26px; }

.page-title { font-size: 26px; margin: 0 0 6px; }
.section { margin-top: 28px; }
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.section-title { font-size: 19px; margin: 0 0 12px; }
.count { font-size: 14px; font-weight: 400; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}

.card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    color: var(--text);
    min-width: 0;
}
.card:hover { text-decoration: none; background: var(--bg-hover); }
.card-cover-wrap { position: relative; }
.card-cover {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    background: var(--bg-3);
}
.cover-artist, .cover-playlist {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 44px;
    font-weight: 700;
    color: var(--accent-2);
    background: linear-gradient(135deg, var(--bg-3), var(--bg-hover));
}
.cover-playlist { color: var(--muted); }
.card-title {
    margin-top: 8px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card-sub {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.play-overlay {
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
    box-shadow: var(--shadow);
}
.card-cover-wrap:hover .play-overlay { opacity: 1; }
.play-overlay:hover { background: var(--accent-2); }

.details-head {
    display: flex;
    gap: 22px;
    align-items: center;
    margin-bottom: 10px;
}
.details-cover {
    width: 180px;
    height: 180px;
    border-radius: 14px;
    object-fit: cover;
    background: var(--bg-3);
    flex-shrink: 0;
}
.details-cover.big { display: flex; align-items: center; justify-content: center; font-size: 64px; color: var(--accent-2); }

.btn {
    border: 1px solid var(--border);
    background: var(--bg-3);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 14px;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); text-align: left; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; align-items: center; }

.icon-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.icon-btn.liked { color: var(--like); }

.song-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}
.song-table th {
    text-align: left;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.song-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.song-row:hover { background: var(--bg-hover); }
.cell-title { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.col-num { text-align: right; font-variant-numeric: tabular-nums; }
.col-play { width: 44px; }
.col-like { width: 44px; }
.col-add { width: 110px; }

.add-to-playlist {
    background: var(--bg-3);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 6px;
    font-size: 12px;
    max-width: 110px;
}

.inline-form {
    display: flex;
    gap: 10px;
    margin: 14px 0;
}
.inline-form input {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 12px;
    min-width: 260px;
    outline: none;
}
.inline-form input:focus { border-color: var(--accent); }

.empty-state {
    background: var(--bg-2);
    border: 1px dashed var(--border);
    border-radius: 12px;
    padding: 34px;
    text-align: center;
    color: var(--muted);
    margin-top: 18px;
}

.token-reveal {
    background: var(--bg-2);
    border: 1px solid var(--accent);
    border-radius: 10px;
    padding: 14px 16px;
    margin: 14px 0;
}
.token-value {
    display: block;
    word-break: break-all;
    font-size: 13px;
    color: var(--accent-2);
    background: var(--bg-3);
    padding: 8px 10px;
    border-radius: 6px;
    margin-top: 6px;
}

/* Player */
.player {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    align-items: center;
    gap: 16px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    padding: 10px 18px;
    box-shadow: var(--shadow);
}
.player.hidden { display: none; }
.player-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.player-cover {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg-3);
    flex-shrink: 0;
}
.player-meta { min-width: 0; }
.player-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-artist { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-center { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.player-controls { display: flex; align-items: center; gap: 14px; }
.play-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
}
.play-btn:hover { background: var(--accent-2); color: #fff; }
.player-progress { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 560px; }
.time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 38px; text-align: center; }
.bar {
    flex: 1;
    height: 6px;
    background: var(--bg-3);
    border-radius: 999px;
    cursor: pointer;
    position: relative;
}
.fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 999px;
}
.player-right { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.player-right input[type="range"] { width: 90px; accent-color: var(--accent); }
.vol-icon { font-size: 14px; }

.queue {
    position: absolute;
    right: 12px;
    bottom: 76px;
    width: 320px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 6px;
}
.queue.hidden { display: none; }
.queue-item {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
}
.queue-item:hover { background: var(--bg-hover); }
.queue-item.current { background: var(--bg-3); color: var(--accent-2); }
.queue-item .q-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.queue-item .q-artist { color: var(--muted); font-size: 12px; white-space: nowrap; }

.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 999px;
    z-index: 100;
    box-shadow: var(--shadow);
}
.toast.hidden { display: none; }

/* Login */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 34px 30px;
    width: min(380px, 92vw);
    box-shadow: var(--shadow);
}
.login-brand { margin: 0 0 4px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 12px;
    outline: none;
}
.login-card input:focus { border-color: var(--accent); }

@media (max-width: 800px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
    }
    .brand { margin-bottom: 0; margin-right: 12px; }
    .sidebar-bottom { margin-top: 0; flex-direction: row; flex-wrap: wrap; }
    .player { grid-template-columns: 1fr; gap: 6px; }
    .player-right { justify-content: flex-start; }
}

/* Song context menu */
.ctx-menu {
    position: fixed;
    z-index: 1000;
    min-width: 200px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 6px;
    display: flex;
    flex-direction: column;
}

.ctx-item {
    background: transparent;
    border: none;
    color: var(--text);
    text-align: left;
    font-size: 14px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

.ctx-item:hover { background: var(--bg-hover); }
.ctx-label { color: var(--muted); cursor: default; }
.ctx-label:hover { background: transparent; }

/* YouTube import form */
.yt-import input { flex: 1; min-width: 0; }

/* Edit song form */
.edit-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 520px;
    margin-top: 18px;
}

.edit-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.edit-form input {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 12px;
    font-size: 15px;
    outline: none;
}

.edit-form input:focus { border-color: var(--accent); }
.edit-form-row { display: flex; gap: 12px; }
.edit-form-row label { flex: 1; }

@media (max-width: 640px) {
    .edit-form-row { flex-direction: column; gap: 14px; }
}
