/* ── Design Tokens ── */
:root {
    --bg-primary: #121212;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-hover: #2a2a4a;
    --bg-active: #0f3460;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-green: #4ecca3;
    --accent-red: #ff6b6b;
    --border: #2a2a3a;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: grid;
    grid-template-rows: auto 1fr;
    grid-template-columns: 1fr 1fr;
    min-height: 100vh;
    padding-bottom: 90px;
}

/* ── Header ── */
header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#selectFolder {
    padding: 8px 18px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
#selectFolder:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* ── YouTube Player ── */
#youtube-player-shell {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: min(420px, calc(100vw - 48px));
    aspect-ratio: 16 / 9;
    background: #000;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 90;
}

#youtube-player-shell[hidden] {
    display: none;
}

#youtubePlayer,
#youtubePlayer iframe {
    width: 100%;
    height: 100%;
}

/* ── Player Bar ── */
#player-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    z-index: 100;
}

/* ── Seek Bar ── */
#seekBar {
    position: absolute;
    top: -2px;
    left: 0;
    right: 0;
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    margin: 0;
    padding: 0;
    z-index: 1;
    transition: height 0.15s, top 0.15s;
}
#seekBar:hover { height: 6px; top: -3px; }

#seekBar::-webkit-slider-runnable-track {
    height: 100%;
    background: var(--border);
    border-radius: 2px;
}
#seekBar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 0; height: 0;
    transition: all 0.15s;
}
#seekBar:hover::-webkit-slider-thumb {
    width: 12px; height: 12px;
    background: var(--accent);
    border-radius: 50%;
    margin-top: -4px;
}
#seekBar::-moz-range-track {
    height: 100%;
    background: var(--border);
    border: none;
    border-radius: 2px;
}
#seekBar::-moz-range-thumb {
    width: 0; height: 0;
    border: none;
    background: transparent;
    transition: all 0.15s;
}
#seekBar:hover::-moz-range-thumb {
    width: 12px; height: 12px;
    background: var(--accent);
    border-radius: 50%;
}

/* ── Now Playing ── */
#now-playing {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    min-width: 0;
}
#nowPlaying {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#nowPlayingScore {
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Transport Controls ── */
#transport-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.transport-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, transform 0.15s, background-color 0.2s;
    position: relative;
}
.transport-btn:hover { color: #fff; background: var(--bg-hover); }
.transport-btn:active { transform: scale(0.9); }

/* Play/Pause button — larger and accented */
.play-btn {
    width: 48px;
    height: 48px;
    background: var(--accent);
    color: #fff;
    font-size: 20px;
}
.play-btn:hover { background: var(--accent-hover); color: #fff; }

/* CSS-drawn play triangle */
.play-btn::before {
    content: '';
    display: block;
    width: 0; height: 0;
    border-style: solid;
    border-width: 9px 0 9px 16px;
    border-color: transparent transparent transparent #fff;
    margin-left: 3px;
}
/* CSS-drawn pause bars */
.play-btn.is-playing::before {
    width: 14px; height: 18px;
    border: none;
    border-left: 4px solid #fff;
    border-right: 4px solid #fff;
    margin-left: 0;
}

/* CSS-drawn prev/next icons */
#previous::before {
    content: '';
    display: block;
    width: 0; height: 0;
    border-style: solid;
    border-width: 7px 12px 7px 0;
    border-color: transparent currentColor transparent transparent;
}
#previous::after {
    content: '';
    display: block;
    width: 3px; height: 14px;
    background: currentColor;
    margin-left: -1px;
}
#next::before {
    content: '';
    display: block;
    width: 3px; height: 14px;
    background: currentColor;
    margin-right: -1px;
}
#next::after {
    content: '';
    display: block;
    width: 0; height: 0;
    border-style: solid;
    border-width: 7px 0 7px 12px;
    border-color: transparent transparent transparent currentColor;
}

/* ── Vote Controls ── */
#vote-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.vote-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.upvote-btn:hover {
    color: var(--accent-green);
    border-color: var(--accent-green);
    background: rgba(78, 204, 163, 0.1);
}
.downvote-btn:hover {
    color: var(--accent-red);
    border-color: var(--accent-red);
    background: rgba(255, 107, 107, 0.1);
}
.vote-btn:active { transform: scale(0.85); }

@keyframes vote-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.25); }
    100% { transform: scale(1); }
}
.vote-pulse { animation: vote-pulse 0.3s ease; }

/* ── Hidden audio ── */
audio { display: none; }

/* ── Popover ── */
#folder-select-popover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 3em 4em;
    text-align: center;
    box-shadow: var(--shadow);
}
#folder-select-popover::backdrop {
    background: rgba(0, 0, 0, 0.7);
}
#folder-select-popover p {
    font-size: 16px;
    margin-bottom: 20px;
    color: var(--text-secondary);
}
#folder-select-popover button {
    padding: 10px 28px;
    border-radius: 24px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
#folder-select-popover button:hover {
    background: var(--accent-hover);
}

/* ── Responsive ── */
@media (max-width: 768px) {
    body {
        grid-template-columns: 1fr;
        padding-bottom: 80px;
    }
    header { padding: 10px 16px; }
    #player-bar {
        padding: 0 12px;
        gap: 8px;
        height: 72px;
    }
    #now-playing { display: none; }
    #player-bar {
        grid-template-columns: 1fr auto;
    }
    #vote-controls { justify-content: flex-start; }
}
