/* Hide jam session status text on mobile */
@media (max-width: 600px) {
    .jam-status-text, #jam-status-text {
        display: none !important;
    }
}

:root {
    --main-bg: #2d0036;
    --sidebar-bg: #3d0066;
    --accent: #a259ff;
    --accentdark: #8528ff;
    --text: #fff;
    --card-bg: #3d0066;
    --card-hover: #a259ff22;
    /* Gradient used for songbar / play icons */
    --bg-gradient: linear-gradient(90deg,#3d0066 60%,#a259ff 100%);
}

/* Remove blue outline/focus ring from all interactive elements */
* {
    -webkit-tap-highlight-color: transparent;
    outline: none !important;
}

button:focus,
input:focus,
select:focus,
textarea:focus,
a:focus,
[role="button"]:focus {
    outline: none !important;
    box-shadow: none !important;
}

/* Download button for Windows installer - uses app accent colors */
.download-win-btn {
    background: linear-gradient(90deg, var(--accent) 0%, var(--accentdark) 100%);
    color: #fff;
    border: none;
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(162,89,255,0.16);
    display: inline-block;
    min-width: 220px;
    text-align: center;
}
.download-win-btn:hover { transform: translateY(-1px); }

/* Container for download buttons (centers them and keeps spacing) */
.download-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    margin-top: 18px;
    flex-wrap: wrap;
}

/* On small screens we stack the buttons vertically */
@media (max-width: 720px) {
    .download-buttons { flex-direction: column; gap: 12px; }
    .download-win-btn { min-width: 180px; padding: 12px 16px; }
}

/* Make jam info box smaller on mobile */
@media (max-width: 600px) {
    #jam-info, .jam-info {
        font-size: 0.95em !important;
        padding: 8px 10px !important;
        min-height: 38px !important;
        max-height: 56px !important;
        border-radius: 10px !important;
        margin-bottom: 8px !important;
        box-shadow: 0 2px 10px rgba(0,0,0,0.18) !important;
    }
    #jam-info h3, .jam-info h3 {
        font-size: 1em !important;
        margin-bottom: 4px !important;
    }
    #jam-info .jam-details, .jam-info .jam-details {
        font-size: 0.92em !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        flex-direction: row !important;
    }
    #jam-info .jam-actions, .jam-info .jam-actions {
        margin-top: 4px !important;
        font-size: 0.92em !important;
        padding: 4px 8px !important;
    }
}

/* Spotify Import Form Styling */
#spotifyForm {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

#spotifyUrl {
    background: #282828;
    border: 2px solid #3d0066;
    border-radius: 12px;
    padding: 14px 18px;
    color: #fff;
    font-size: 15px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    transition: all 0.3s ease;
}

#spotifyUrl:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(162, 89, 255, 0.15);
    background: #1a1a1a;
}

#spotifyUrl::placeholder {
    color: #888;
}

#spotifyForm button[type="submit"] {
    background: linear-gradient(90deg, var(--accent) 0%, var(--accentdark) 100%);
    color: #fff;
    border: none;
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(162, 89, 255, 0.3);
    transition: all 0.3s ease;
}

#spotifyForm button[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(162, 89, 255, 0.4);
}

#spotifyForm button[type="submit"]:active {
    transform: translateY(0);
}

/* Android button: no extra left margin needed when using flex gap */
.download-android-btn { margin-left: 0; }

html, body {
    /* Prevent any scrolling on the page */
    overflow: hidden;
    height: 100%;
}
body {
    margin: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: linear-gradient(180deg, #3d0066 0%, #1a0033 100%);
    background-attachment: fixed;
    color: var(--text);
    height: 100vh;
    display: flex;
    /* allow narrow/mobile widths */
    min-width: 320px;
    /* allow the body to span the full viewport so inner containers can stretch */
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
}
.sidebar {
    width: 220px;
    min-width: 220px;
    max-width: 220px;
    background: rgba(61, 0, 102, 0.3);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
         width: 100%;
    min-height: 100vh;
    box-shadow: 2px 0 8px #0002;
}
.sidebar h1 {
    font-size: 1.6em;
    color: var(--accent);
    margin-bottom: 40px;
}
/* Logo image styling: used in sidebar and headers */
.sidebar .logo {
    width: 160px;
    height: auto;
    margin-bottom: 20px;
}
.header .logo, .header-logo {
    height: 56px;
    width: auto;
    display: inline-block;
    vertical-align: middle;
}
.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.sidebar nav a {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    padding: 8px 24px;
    border-radius: 8px;
    transition: background 0.2s;
    cursor: pointer;
}
.sidebar nav a.active {
    background: var(--accent);
    color: #fff;
}
.sidebar nav a:hover {
    background: var(--card-hover);
    color: var(--accent);
}
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 48px 64px;
    /* Disable vertical scrolling inside main */
    overflow: hidden;
    min-width: 600px;
    max-width: 1200px;
}

/* Hide the internal scrollbar on .main while preserving scroll capability
   This prevents a second scrollbar appearing next to the profile button. */
.main {
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none; /* Firefox */
}
.main::-webkit-scrollbar {
    display: none; /* Safari and Chrome */
    width: 0;
    height: 0;
}
.header {
    font-size: 2em;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 24px;
}
#searchForm {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
}
#songName {
    flex: 1;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    font-size: 1em;
    background: #fff;
    color: #333;
}
button[type="submit"] {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 24px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}
button[type="submit"]:hover {
    background: #7c3aed;
}
#main-search {
    /* make search area a column so results can grow and scroll */
    display: flex;
    flex-direction: column;
    height: calc(100vh - 160px); /* leave space for header/padding */
}

#results {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: flex-start;
    /* Allow only results area to scroll vertically; prevent horizontal scroll */
    overflow-y: auto;
    overflow-x: hidden;
    /* Let results expand inside the search area and become scrollable */
    flex: 1 1 auto;
    max-height: 100%;
    box-sizing: border-box;
    /* keep a small right padding so vertical scrollbar doesn't overlap actions */
    padding-right: 12px;
}
/* #video-list placeholder removed; specific rules exist below */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 1px 8px #0002;
    padding: 10px 12px;
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    transition: box-shadow 0.18s, background 0.18s;
}
.card:hover {
    background: var(--card-hover);
    box-shadow: 0 4px 24px #0004;
}
.card-thumb, .card img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}
.card .title {
    font-weight: 700;
    font-size: 0.95rem;
    margin: 0 0 4px 0;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card .author {
    font-size: 0.85rem;
    color: #cfcfcf;
}
.card .duration {
    font-size: 0.85rem;
    color: #bfbfbf;
}
.card audio {
    width: 100%;
    margin-top: 10px;
}
.card .yt-download-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.14s;
    display: inline-flex;
    align-items: center;
}
.card .yt-download-btn:active {
    background: #7c3aed;
}

.container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Playlist list inside Library: allow scrolling only for the playlist list column */
#playlist-ui #playlist-list {
    overflow-y: auto;
    max-height: calc(70vh - 160px);
    padding-right: 8px;
}
/* Make playlist view scrollable and ensure flex containers allow shrinking */
#library-main {
    display: flex;
    flex-direction: column;
    min-height: 0; /* allow children with overflow:auto to shrink correctly */
}
#playlist-view {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
    padding-right: 12px;
    box-sizing: border-box;
}

/* Keep the playlist header fixed at the top of the playlist view and only allow
   the song list to scroll. The header is non-scrolling with flex:0 and the
   songs container handles overflow. */
#playlist-view { display: flex; flex-direction: column; }
.playlist-header { 
    flex: 0 0 auto; 
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.playlist-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}
.playlist-header-left h2 {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.playlist-header-right {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}
.playlist-btn {
    background: #a259ff;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
}
.playlist-btn:hover {
    background: #8528ff;
}

/* Mobile optimizations for playlist header */
@media (max-width: 720px) {
    .playlist-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .playlist-header-left {
        width: 100%;
    }
    .playlist-header-right {
        width: 100%;
        justify-content: space-between;
    }
    .playlist-btn {
        flex: 1;
        justify-content: center;
        padding: 10px 8px;
        font-size: 0.85em;
    }
    .playlist-btn-text {
        display: none;
    }
    .playlist-btn-icon {
        font-size: 1.2em;
    }
}

.playlist-songs { flex: 1 1 auto; overflow-y: auto; min-height: 0; padding-top: 12px; -webkit-overflow-scrolling: touch; }

/* Ensure the library container has a constrained height so inner areas can scroll
   Even when the global page scrolling is disabled (html/body { overflow: hidden }),
   these scrollable children will work if their heights are constrained. */
#library-spotify {
    /* reserve space for header/padding and the bottom songbar */
    height: calc(100vh - 160px);
    display: flex;
    flex-direction: row;
}

/* Constrain the main area and playlist view so they show internal scrollbars when needed */
#library-main {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
}
#playlist-view {
    max-height: calc(100vh - 240px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* When the mobile playlist-open state hides the sidebar, give the library-spotify
   full available height so the playlist view can still scroll. */
#library-spotify.playlist-open {
    height: calc(100vh - 88px);
}
.sidebar {
    width: 240px;
    min-width: 240px;
    max-width: 240px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 0;
    height: 100vh;
    box-shadow: 2px 0 8px #0002;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 10;
}
.sidebar h1 {
    font-size: 1.6em;
    color: var(--accent);
    margin-bottom: 40px;
}
.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
    align-items: center;
}
.sidebar nav a {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    padding: 10px 32px;
    border-radius: 8px;
    transition: background 0.2s;
    cursor: pointer;
    width: 80%;
    text-align: center;
    margin-bottom: 8px;
}
.sidebar nav a.active {
    background: var(--accent);
    color: #fff;
}
.sidebar nav a:hover {
    background: var(--card-hover);
    color: var(--accent);
}
.main {
    margin-left: 240px; /* space for fixed sidebar */
    /* use full remaining width (viewport minus sidebar) */
    width: calc(100% - 240px);
    max-width: none;
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 48px 64px;
    overflow: hidden;
    min-width: 0;
    height: 100vh;
}
.header {
    font-size: 2em;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 24px;
}
#searchForm {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
}
#songName {
    flex: 1;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    font-size: 1em;
    background: #fff;
    color: #333;
}
button[type="submit"] {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 24px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}
button[type="submit"]:hover {
    background: #7c3aed;
}
#results {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: flex-start;
}
#video-list {
    /* Render results as a vertical compact list (Spotify-like)
       Each .card becomes a horizontal row with thumbnail | meta | actions */
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

/* Ensure cards don't overflow the viewport and their inner columns can shrink */
.card {
    overflow: hidden;
}
.card-meta { min-width: 0; }

/* Actions column: keep a fixed compact width and allow truncation */
.card-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    justify-content: center;
    flex-shrink: 0;
    width: 110px; /* reserve space for duration + button */
}
.card-actions .duration { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .yt-download-btn { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 480px) {
    /* Reserve extra right padding so scrollbar does not cover buttons */
    #results { padding-right: 64px; }
    .card-actions { width: 76px; }
    .card-thumb, .card img { width: 44px; height: 44px; }
    .card { padding-right: 8px; }
    .card .yt-download-btn { padding: 6px 8px; font-size: 0.78rem; }
}

/* Make the search results area visually full-bleed (ignore .main horizontal padding)
   so the list and its scrollbar align with the page edges inside the main content. */
#results.full-bleed {
    /* .main has 48px vertical and 64px horizontal padding; undo horizontal padding */
    margin-left: -64px;
    width: calc(100% + 128px);
    padding-left: 64px;
    padding-right: 64px;
    box-sizing: border-box;
}

#video-list .card {
    align-items: center;
    padding: 8px 12px;
}

/* Meta column (title + author) takes remaining space */
.card-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 auto;
}

.card-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    justify-content: center;
    flex-shrink: 0;
}

.card-actions .duration { margin-bottom: 4px; }
#music-bar {
    background: linear-gradient(90deg,#3d0066 60%,#a259ff 100%) !important;
    box-shadow: 0 -2px 12px #0004;
    padding: 0 32px !important;
    height: 90px !important;
    display: flex;
    align-items: center;
     /* keep music bar above the mobile bottom nav so both are usable */
     /* Raised to sit above .mobile-nav (which uses ~20050) so music controls
         remain fully interactive while the nav stays at the very bottom. */
     z-index: 20060;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    overflow: hidden;
}
#music-bar-thumb {
    width: 64px !important;
    height: 64px !important;
    border-radius: 8px;
    margin-right: 32px !important;
    object-fit: cover;
    box-shadow: 0 2px 8px #0006;
    flex-shrink: 0;
}
#music-bar-title {
    color: #fff;
    font-weight: bold;
    font-size: 1.3em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#music-bar-author {
    color: #ccc;
    font-size: 1em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#music-bar-controls {
    flex: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
}
#music-bar-play {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 48px !important;
    height: 48px !important;
    font-size: 2em !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px #0006;
    transition: background 0.2s;
    flex-shrink: 0;
}
#music-bar-play:hover {
    background: #7c3aed;
}

/* Make sure the play/pause icon is always visible.
   Use a solid-color fallback first, and only enable gradient-filled text
   when the browser supports background-clip:text. This avoids the brief
   invisible/flicker behaviour on unsupported browsers. */
#music-bar-play {
    /* fallback visible color */
    color: var(--accent);
    background: none;
    -webkit-text-fill-color: initial;
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
    #music-bar-play {
        /* make the play/pause character filled with the gradient */
        color: transparent; /* hide fallback color so background-clip:text shows through */
        background: var(--bg-gradient);
        -webkit-background-clip: text;
        background-clip: text;
        /* WebKit requires this to make the text transparent for the clip to show */
        -webkit-text-fill-color: transparent;
    }
}

/* For the small songbar button: allow the SVG play/pause to inherit a solid color matching the gradient's mid tone */
.play-btn {
    /* fallback color for SVGs that use currentColor */
    color: #a259ff; /* uses the accent as a middle-ground match */
}
#music-bar-progress-container {
    flex: 1;
    min-width: 120px;
    max-width: 700px;
    width: 100%;
    height: 8px;
    background: #fff2;
    border-radius: 4px;
    position: relative;
    box-shadow: 0 1px 4px #0002;
}
#music-bar-progress {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    width: 0%;
    position: absolute;
    top: 0;
    left: 0;
    transition: width 0.2s;
}
#music-bar-time {
    color: #fff;
    font-size: 1em;
    width: 80px;
    text-align: center;
    flex-shrink: 0;
}
#music-bar-volume {
    width: 100px !important;
    flex-shrink: 0;
    accent-color: var(--accentdark);
}

/* Improved Add to Playlist button (search result cards) */
.add-playlist-btn {
    display: inline-flex !important; /* override any inline block */
    align-items: center;
    gap: 8px;
    background: linear-gradient(90deg, var(--accent) 0%, var(--accentdark) 100%) !important;
    color: #fff !important;
    border: none !important;
    padding: 8px 12px !important;
    border-radius: 10px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    margin-top: 8px !important;
    box-shadow: 0 6px 20px rgba(162,89,255,0.18) !important;
    transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease !important;
    font-size: 0.95rem !important;
}
.add-playlist-btn:hover { transform: translateY(-2px); }
.add-playlist-btn:active { transform: translateY(0); }
.add-playlist-btn::before {
    content: '+'; /* plain plus sign */
    display: inline-block;
    font-size: 14px;
    line-height: 1;
    width: 18px;
    height: 18px;
    text-align: center;
    color: rgba(255,255,255,0.95);
    background: rgba(255, 255, 255, 0);
    border-radius: 4px;
}

/* Back button default: hidden on all sizes; shown explicitly in mobile .playlist-open state below */
.playlist-back-btn { display: none; }

/* Search result card layout fixes: ensure content never overflows horizontally */
.card{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    width:100%;
    box-sizing:border-box;
    min-width:0; /* allows flex children to shrink below their content width */
}
.card-thumb{ flex-shrink:0; width:64px; height:64px; object-fit:cover; border-radius:8px; }
.card-meta{ display:flex; flex-direction:column; gap:4px; flex:1 1 auto; min-width:0; }
.card-meta .title, .card-meta .author{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.card-actions{ display:flex; flex-direction:column; align-items:flex-end; gap:8px; flex:0 0 auto; min-width:72px; max-width:140px; box-sizing:border-box; }
.card-actions .duration{ color: rgba(255,255,255,0.85); font-size:0.9rem; flex-shrink:0; }
.card-actions .yt-download-btn, .card-actions .add-playlist-btn{ white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:140px; }

/* Make the action area more compact on very small screens so buttons don't push layout */
@media (max-width: 480px){
    .card{ gap:8px; }
    .card-thumb{ width:48px; height:48px; }
    .card-meta .title{ font-size:0.95rem; }
    .card-actions{ min-width:56px; max-width:110px; align-items:flex-end; }
    .card-actions .yt-download-btn, .card-actions .add-playlist-btn{ padding:6px 8px !important; font-size:0.82rem !important; }
    /* If needed, allow the actions to wrap under the meta on the smallest screens */
    .card{ flex-wrap:nowrap; }
}

/* Playlist modal (overrides inline styles from JS) */
#playlist-modal {
    position: fixed !important;
    inset: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: rgba(0,0,0,0.55) !important;
    z-index: 9999 !important;
}
#playlist-modal > div {
    /* style the inner box (JS creates a div without a class) */
    background: #0f0b12 !important; /* dark card to match site */
    color: #fff !important;
    width: min(680px, 92vw) !important;
    max-height: 78vh !important;
    border-radius: 12px !important;
    box-shadow: 0 12px 48px rgba(0,0,0,0.5) !important;
    padding: 18px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    overflow: hidden !important;
}
#playlist-modal > div h3 {
    margin: 0 0 6px 0 !important;
    color: var(--accent) !important;
    font-size: 1.15rem !important;
}

/* Playlist buttons inside the modal. JS adds plain buttons; override their inline styles */
#playlist-modal > div > button {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px !important;
    width: 100% !important;
    padding: 10px 12px !important;
    margin: 6px 0 !important;
    border-radius: 10px !important;
    border: none !important;
    background: linear-gradient(90deg, var(--accent) 0%, var(--accentdark) 100%) !important;
    color: #fff !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    box-shadow: 0 8px 24px rgba(162,89,255,0.12) !important;
    text-align: left !important;
}

/* Make the last button (Cancel) look like a secondary action */
#playlist-modal > div > button:last-of-type {
    background: transparent !important;
    color: #ddd !important;
    border: 1px solid rgba(255,255,255,0.06) !important;
    font-weight: 600 !important;
}

/* Provide a scrollable list area if many playlists exist */
#playlist-modal > div { position: relative; }
#playlist-modal > div .playlist-list { overflow: auto; max-height: calc(78vh - 140px); }

/* Small thumbnail inside playlist buttons if provided by backend (JS doesn't add but safety) */
#playlist-modal > div > button img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; margin-right: 12px; }

/* ----------------------
   Mobile / Responsive
   ---------------------- */
@media (max-width: 1024px) {
    /* Hide desktop sidebar and use mobile nav earlier for tablets and phones */
    .sidebar { display: none !important; }
    .main { margin-left: 0 !important; width: 100% !important; padding: 20px !important; }
    body { min-width: 320px; }
    /* Adjust header and search form */
    .header { font-size: 1.4rem; margin-bottom: 14px; }
    #searchForm { flex-direction: column; gap: 8px; }
    #songName { width: 100%; padding: 10px; }
    button[type="submit"] { width: auto; align-self: flex-end; }
    /* Results should fill mobile width and have larger hit area */
    #results { padding-left: 0; padding-right: 0; }
    #video-list { gap: 8px; }
    .card { padding: 8px 10px; gap: 10px; }
    .card-thumb, .card img { width: 48px; height: 48px; }
    .card .title { font-size: 0.95rem; }
    .card .author { font-size: 0.8rem; }
    .card-actions { align-items: flex-end; min-width: 60px; }
    .card .yt-download-btn { padding: 6px 8px; font-size: 0.85rem; }

    /* Make the results visually full-bleed on small screens */
    #results.full-bleed { margin-left: 0; width: 100%; padding-left: 0; padding-right: 0; }

    /* Library sidebar should collapse to full width on smaller screens - override inline width */
    #library-sidebar { width: 100% !important; box-sizing: border-box; }

    /* Music bar smaller on mobile */
    #music-bar { height: 72px !important; padding: 0 12px !important; }
    #music-bar-thumb { width: 52px !important; height: 52px !important; margin-right: 12px !important; }
    #music-bar-play { width: 40px !important; height: 40px !important; font-size: 1.3em !important; }

    /* Mobile nav: fixed bottom bar */
    .mobile-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 56px; background: rgba(43, 0, 48, 0.85); backdrop-filter: blur(10px); box-shadow: 0 -4px 18px rgba(0,0,0,0.4); z-index: 13002; align-items: center; justify-content: space-around; }
    /* Place the music bar above the mobile nav so both are reachable. Keep the mobile nav on top so its buttons remain tappable. */
     /* Ensure mobile nav has a clearly higher stacking context than the music bar
         and that the music bar is offset by the nav height plus any safe-area inset
         (handles iPhone/Android cutouts). Use larger z-index so nothing else accidentally
         covers the nav. */
      .mobile-nav { z-index: 20050 !important; pointer-events: auto !important; }
      /* Place music bar above the mobile nav and offset it by the nav height so
          the nav remains at the bottom but does not overlap the music controls. */
      #music-bar { bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important; z-index: 20060 !important; pointer-events: auto !important; }
    .mobile-nav .m-nav-btn { background: transparent; border: none; color: #fff; font-weight: 700; padding: 12px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; min-width: 48px; min-height: 48px; }
    .mobile-nav .m-nav-btn.active { background: rgba(162,89,255,0.18); color: var(--accent); }
    .mobile-nav .m-nav-btn svg { display: block; }

    /* Make sure main content has bottom padding so content isn't hidden behind mobile nav */
    .main { padding-bottom: 88px !important; }
}

/* Move profile button into the top-right corner on small screens */
@media (max-width: 720px) {
    #profile-btn {
        position: fixed !important;
        top: 8px !important;
        right: 8px !important;
        width: 44px !important;
        height: 44px !important;
        padding: 0 !important;
        box-shadow: 0 2px 10px rgba(0,0,0,0.45) !important;
        z-index: 13000 !important;
    }
    #profile-btn img, #profile-btn-img {
        width: 100% !important;
        height: 100% !important;
        left: 0 !important;
        top: 0 !important;
        display: block !important;
        border-radius: 50% !important;
    }
    /* Slightly reduce right padding of main so the button doesn't overlap content */
    .main { padding-right: 60px !important; }
}

/* Additional responsive polish for smaller screens */
@media (max-width: 720px) {
    /* Library: stack sidebar and main, make playlist UI full width */
    #library-spotify { flex-direction: column; }
    #library-sidebar { width: 100% !important; min-width: 0; max-height: 220px; overflow:auto; padding: 12px; }
    #library-main { width: 100%; padding: 12px; }
    #playlist-view { padding: 0; }
    /* Playlist cards should be touch-friendly and full width */
    .playlist-card { padding: 10px; border-radius: 10px; }
    /* Reduce header size */
    .header { font-size: 1.3rem; }
    /* Tighten up spacing for results and cards */
    #video-list { gap: 8px; }
    .card { padding: 8px 10px; }
}

/* Make the playlist list fill the mobile viewport and allow the opened playlist to take over the screen */
@media (max-width: 720px) {
    #library-spotify { display:flex; flex-direction:column; height: calc(100vh - 132px); /* account for bottom nav (56px) + songbar (68px) + padding */ }
    #library-sidebar { flex: 0 0 auto; max-height: none; overflow:auto; }
    #library-main { flex: 1 1 auto; overflow:auto; padding-bottom: 8px; }
    /* When a playlist is opened on mobile, hide the sidebar and let the main area fill the viewport */
    #library-spotify.playlist-open #library-sidebar { display:none !important; }
    #library-spotify.playlist-open #library-main { width:100% !important; padding-bottom: 0; }
    /* Playlist view should use all available space */
    #playlist-view { max-height: none; height: 100%; }
    /* Back button in playlist header (mobile) */
    .playlist-back-btn { display:none; }
    #library-spotify.playlist-open .playlist-back-btn { display:inline-flex; align-items:center; gap:8px; background:transparent; border:none; color:var(--text); padding:8px 10px; border-radius:8px; cursor:pointer; font-weight:700; margin-right:8px; }
}

@media (max-width: 480px) {
    /* smaller offsets for extra-small screens */
    #library-spotify { height: calc(100vh - 132px); /* same as larger mobile */ }
    #library-spotify.playlist-open .playlist-back-btn { padding:6px 8px; font-size:0.95rem; }
}

@media (max-width: 480px) {
    /* Very small screens: increase touch targets and stack details */
    #searchForm { gap: 10px; }
    #songName { padding: 12px; font-size: 1rem; }
    button[type="submit"] { padding: 10px 14px; font-size: 1rem; }
    .card .title { font-size: 0.93rem; }
    .card .author { font-size: 0.8rem; }
    /* Playlist modal full width */
    #playlist-modal > div { width: calc(100vw - 28px) !important; padding: 12px !important; }
    /* Profile menu position fix for mobile */
    #profile-menu-popup { left: 8px !important; right: 8px !important; top: 72px !important; }
    /* Reduce main padding even more */
    .main { padding: 16px !important; padding-bottom: 96px !important; }
}

/* Forms, buttons and inputs - make them scale nicely */
input, textarea, select, button { font-family: inherit; }
input[type="text"], input[type="password"], textarea { width: 100%; box-sizing: border-box; }

/* Helpful utility for hiding elements on mobile */
.hide-on-mobile { display: none; }

@media (min-width: 901px) {
    /* hide mobile nav on desktop */
    .mobile-nav { display: none !important; }
}

