/* ===== Overlay Styles ===== */
#fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: calc(100vh - 80px);
    background: #000;
    z-index: 1500;
    display: none; /* Physically remove from hit-test tree when inactive */
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overflow-y: auto; /* Enable page scroll */
}
#fullscreen-overlay.active {
    display: flex !important;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.overlay-bg-blur {
    position: absolute;
    top: -150px; left: -150px; right: -150px; bottom: -150px;
    background: #000; /* Base color fallback */
    background-size: 160% 200%;
    background-position: 50% 50%;
    filter: blur(25px) brightness(0.25);
    z-index: 0;
    transform: translateZ(0) scale(1.1);
    pointer-events: none;
    backface-visibility: hidden;
    contain: layout size;
}

/* ===== Side Panels ===== */
.overlay-queue-panel,
.overlay-lyrics-panel {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
    transition: width 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

.overlay-queue-panel {
    width: 310px;
    min-width: 0;
    background: linear-gradient(to right, rgba(0,0,0,0.85) 0%, rgba(10,10,10,0.5) 100%);
    border-right: 1px solid rgba(255,255,255,0.06);
    z-index: 1;
}
.overlay-lyrics-panel {
    width: 340px;
    min-width: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.85) 0%, rgba(10,10,10,0.5) 100%);
    position: relative;
    z-index: 1;
}
.overlay-lyrics-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 35px 20px 40px;
}
.overlay-lyrics-content {
    padding: 0 !important; /* Managed by wrapper */
}

/* Collapsed state */
.overlay-queue-panel.collapsed,
.overlay-lyrics-panel.collapsed {
    width: 0 !important;
    opacity: 0;
    padding: 0 !important;
    pointer-events: none;
    border: none;
}

/* Panel header — fixed, never scrolls */
.overlay-panel-header {
    flex-shrink: 0;
    padding: 22px 16px 10px; /* Increased top padding to prevent edge clipping */
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.overlay-panel-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
}

.overlay-copy-lyrics.floating {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff; /* Ensure white for visibility */
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 1001;
    backdrop-filter: blur(5px);
}
.overlay-copy-lyrics.floating:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
    border-color: rgba(255,255,255,0.3);
}
.overlay-copy-lyrics svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.5;
    stroke: #fff; /* Explicit color */
}

.lyric-date-overlay {
    display: block;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.3);
    margin-bottom: 20px;
    font-style: italic;
}

/* ===== Lyrics Content ===== */
.overlay-lyrics-content {
    flex: 1;
    overflow-y: visible; /* Page scroll instead of box scroll */
    color: #bbb;
    font-size: 0.92rem;
    line-height: 1.7;
    padding: 14px 18px 20px;
    white-space: normal;
    word-wrap: break-word;
}
.overlay-lyrics-content::-webkit-scrollbar { width: 5px; }
.overlay-lyrics-content::-webkit-scrollbar-track { background: rgba(255,255,255,0.04); }
.overlay-lyrics-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 3px; }

/* ===== Queue List ===== */
.overlay-queue-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin: 0;
    padding: 8px 10px;
    list-style: none;
}
.overlay-queue-list::-webkit-scrollbar { width: 5px; }
.overlay-queue-list::-webkit-scrollbar-track { background: rgba(255,255,255,0.04); }
.overlay-queue-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 3px; }

.overlay-queue-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 5px;
    background: rgba(255,255,255,0.02);
    cursor: grab;
    transition: background 0.2s;
    user-select: none;
    /* Performance: Skip rendering for off-screen queue items */
    content-visibility: auto;
    contain-intrinsic-size: 0 52px;
}
.overlay-queue-item:active { cursor: grabbing; }
.overlay-queue-item:hover { background: rgba(255,255,255,0.07); }
.overlay-queue-item.dragging { opacity: 0.5; background: rgba(255,255,255,0.1); }
.overlay-queue-item.active-play {
    background: rgba(46, 204, 113, 0.1);
    border-left: 3px solid var(--icon-active);
    padding-left: 7px;
}

.queue-grip {
    color: #555;
    cursor: grab;
    padding-right: 10px;
    display: flex;
    align-items: center;
}
.queue-meta {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.queue-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.overlay-queue-item.active-play .queue-title { color: var(--icon-active); }
.queue-artist {
    font-size: 0.68rem;
    color: #777;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Center Art Panel */
.overlay-art-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around; /* Distribute art and meta evenly */
    padding: 60px 20px 20px;
    box-sizing: border-box;
    position: relative;
    min-width: 0;
    z-index: 1;
}

.overlay-art-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    position: relative; /* Anchor for absolute children */
    aspect-ratio: 1/1; /* Native sizing */
}

.overlay-art-controls {
    position: absolute;
    top: 15px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 14px;
    z-index: 5;
}

.overlay-toggle {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--icon, #888);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.overlay-toggle:hover {
    background: rgba(255,255,255,0.15);
    color: var(--icon-hover, #fff);
}
.overlay-toggle.active {
    background: rgba(46,204,113,0.15);
    border-color: var(--icon-active);
    color: var(--icon-active);
}

/* Art image — fills as much space as possible */
.overlay-art {
    position: absolute; /* Crossfade stack */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: auto;
    height: auto;
    max-width: min(90%, 550px);
    max-height: 90%; 
    aspect-ratio: 1/1;
    object-fit: contain;
    box-shadow: 0 10px 60px rgba(0,0,0,0.8);
    background: transparent; 
    transition: opacity 0.5s ease, max-width 0.3s ease, max-height 0.3s ease;
    opacity: 0;
    pointer-events: none;
}
.overlay-art.active {
    opacity: 1;
    pointer-events: auto;
}

/* Dynamic art sizing when panels collapse */
#fullscreen-overlay:has(.overlay-queue-panel.collapsed) .overlay-art,
#fullscreen-overlay:has(.overlay-lyrics-panel.collapsed) .overlay-art {
    max-width: min(90%, 750px);
}
#fullscreen-overlay:has(.overlay-queue-panel.collapsed):has(.overlay-lyrics-panel.collapsed) .overlay-art {
    max-width: min(95%, 900px);
}

/* Track info below art */
.overlay-track-info {
    margin-top: 20px;
    text-align: center;
    max-width: 700px;
    width: 100%;
    flex-shrink: 0;
    min-height: 100px; /* Ensure space for title + waveform */
}
.overlay-track-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}
.overlay-track-artist {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 2px;
    font-weight: 500;
}
.overlay-track-album {
    font-size: 0.9rem;
    color: #aaa;
    margin-bottom: 2px;
}

/* Waveform Seekbar */
.overlay-waveform-container {
    margin: 15px auto 0 auto;
    position: relative;
    width: 0; /* Dynamic from JS */
    height: 44px;
    cursor: pointer;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    transition: background 0.2s, height 0.2s, opacity 0.3s;
    display: none !important; /* Default OFF */
}
#fullscreen-overlay.waveform-on .overlay-waveform-container {
    display: block !important;
}
.overlay-waveform-container:hover {
    background: rgba(255, 255, 255, 0.06);
}

#overlay-waveform-canvas {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 1;
}
.overlay-waveform-progress {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 100%;
    transform: scaleX(0);
    transform-origin: left;
    will-change: transform;
    background: linear-gradient(to right, var(--accent), #fff);
    mix-blend-mode: overlay;
    opacity: 0.7;
    z-index: 2;
    pointer-events: none;
}
.overlay-waveform-clicker {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10;
}

/* ===== Mobile ===== */
@media (max-width: 1100px) {
    #fullscreen-overlay {
        display: none; /* Inherit default hidden state */
        flex-direction: column;
        overflow-y: auto;
        height: calc(100vh - 85px);
        background: #000 !important; /* Solid black for OLED/Performance */
        padding-top: 2px !important;
    }
    
    .overlay-bg-blur {
        display: none !important; /* Disable expensive filters on mobile */
    }
    
    .overlay-art-panel {
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 0 10px 0; /* Zero panel padding */
        box-sizing: border-box;
        text-align: center;
        justify-content: flex-start !important; /* Prevent distribution of space */
    }
    
    .overlay-art-controls {
        position: relative;
        top: 0 !important; /* Neutralize desktop top: 15px */
        display: flex;
        justify-content: center;
        flex-wrap: wrap; 
        gap: 6px; 
        margin-top: 0 !important; 
        margin-bottom: 4px !important; /* Space between toolbar and art 4px */
        width: 100%;
        z-index: 100;
    }
    
    .overlay-art-container {
        display: flex;
        flex: none !important; /* Neutralize desktop flex: 1 */
        margin: 0 auto 4px !important; /* Space between art and title 4px */
        width: 100%;
        max-width: 300px;
        aspect-ratio: 1/1; 
        position: relative;
    }
    
    .overlay-art {
        position: absolute; 
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 100%;
        height: 100%;
        object-fit: contain; 
        box-shadow: none;
        border-radius: 0;
        background: transparent !important; 
        opacity: 0;
        transition: opacity 0.5s ease;
        pointer-events: none;
        max-width: none; 
        max-height: none; 
    }
    
    .overlay-art.active {
        opacity: 1;
        pointer-events: auto;
    }
    
    .overlay-toggle { 
        width: 44px; 
        height: 44px; 
        background: rgba(30,30,30,0.95);
        border: 1px solid rgba(255,255,255,0.1);
    }
    
    .overlay-track-info {
        margin-top: 0; 
        margin-bottom: 8px; /* Slightly more space before lyrics panel start */
        width: 100%;
        text-align: center;
        min-height: 60px; /* Reserve space for title/album on mobile */
    }
    
    .overlay-track-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 2px; }
    .overlay-track-artist { font-size: 1rem; color: var(--accent); margin-bottom: 2px; font-weight: 500; }
    .overlay-track-album { font-size: 0.9rem; opacity: 0.8; margin-bottom: 0; }
    .overlay-waveform-container { display: none !important; }

    .overlay-lyrics-panel, .overlay-queue-panel {
        display: flex;
        flex-direction: column;
        width: 100%;
        border: none;
        border-top: 1px solid rgba(255,255,255,0.08);
        background: transparent; 
        flex: none; /* Allows natural content height, prevents cutoff */
    }
    
    .overlay-lyrics-content, .overlay-queue-list {
        overflow-y: visible;
        padding: 10px 15px 20px; /* Gutted top padding */
    }
    
    .overlay-queue-panel.collapsed, .overlay-lyrics-panel.collapsed {
        display: none !important;
    }
    
    .queue-title { font-size: 0.85rem; }
}
