/* Gallery Modal */
#gallery-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: flex;
    font-family: 'minecraft', monospace;
    color: white;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#gallery-modal.active {
    opacity: 1;
    pointer-events: auto;
}

#gallery-sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    width: 42px;
    height: 34px;
    border-radius: 6px;
    border: 1px solid #333;
    background: #1a1a1a;
    cursor: pointer;
    gap: 3px;
    flex-shrink: 0;
    position: relative;
    z-index: 1004;
}

#gallery-sidebar-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: #cfcfcf;
}

#gallery-sidebar-scrim {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    display: none;
    z-index: 1001;
}

/* Sidebar */
#gallery-sidebar {
    width: 250px;
    background-color: #111;
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    flex-shrink: 0;
}

.gallery-nav-item {
    padding: 10px 15px;
    cursor: pointer;
    border-radius: 5px;
    margin-bottom: 5px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.gallery-nav-item:hover {
    background-color: #222;
}

.gallery-nav-item.active {
    background-color: #333;
    font-weight: bold;
}

/* Main Content Area */
#gallery-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* Header / Toolbar */
#gallery-toolbar {
    padding: 1rem;
    padding-right: 4rem; /* Make room for absolute close button */
    border-bottom: 1px solid #333;
    display: flex;
    gap: 1rem;
    align-items: center;
    background-color: #111;
}

#gallery-toolbar select, 
#gallery-toolbar input {
    background-color: #222;
    color: white;
    border: 1px solid #444;
    padding: 5px 10px;
    border-radius: 4px;
    font-family: inherit;
}

/* Grid */
#gallery-grid {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 1.5rem;
    max-width: 80%;
    margin: 0 auto;
    align-content: start; /* Prevent rows from stretching to fill height */
    grid-auto-rows: max-content; /* Ensure rows assume content height */
}

/* Gallery Item Card */
.gallery-item {
    background-color: #1a1a1a;
    border-radius: 8px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    border: 1px solid #333;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    height: auto; /* Allow it to grow */
    min-height: 280px; /* Ensure space for image + details */
}

/* ... hover effects ... */
.gallery-item:hover {
    transform: translateY(-5px) scale(1.02);
    border-color: #00ffcc;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5), 0 0 15px rgba(0, 255, 204, 0.2);
    z-index: 10;
}

.gallery-preview {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    background-color: #000;
    flex-shrink: 0; /* Don't shrink the image */
    image-rendering: pixelated; /* Optimize for scaling up low-res art */
}

.gallery-info {
    padding: 10px;
    flex-grow: 1; /* Take remaining space */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.gallery-title {
    font-weight: bold;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 1rem;
    color: #fff;
}

.gallery-artist {
    color: #888;
    font-size: 0.9em;
}

.gallery-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
}

.gallery-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #666;
    transition: color 0.2s;
    font-size: 1.2em;
}

.gallery-btn:hover {
    color: white;
}

.gallery-btn.hearted {
    color: #ff4444;
}

/* Playlist specific styles */
.playlist-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: #222;
    margin-bottom: 10px;
    border-radius: 4px;
}

/* Close Button */
#gallery-close {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 2rem;
    cursor: pointer;
    z-index: 1003;
    color: #888;
}

#gallery-close:hover {
    color: white;
}

/* Scrollbar */
#gallery-grid::-webkit-scrollbar {
    width: 8px;
}
#gallery-grid::-webkit-scrollbar-track {
    background: #111;
}
#gallery-grid::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}
#gallery-grid::-webkit-scrollbar-thumb:hover {
    background: #555;
}

@media only screen and (max-width: 900px) {
    #gallery-grid {
        max-width: 100%;
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

@media only screen and (max-width: 768px) {
    #gallery-modal {
        overflow: hidden;
    }

    #gallery-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: min(85vw, 320px);
        transform: translateX(-110%);
        transition: transform 0.3s ease;
        z-index: 1002;
        box-shadow: 8px 0 24px rgba(0, 0, 0, 0.5);
    }

    #gallery-modal.sidebar-open #gallery-sidebar {
        transform: translateX(0);
    }

    #gallery-sidebar-toggle {
        display: inline-flex;
    }

    #gallery-sidebar-scrim {
        display: block;
    }

    #gallery-modal.sidebar-open #gallery-sidebar-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    #gallery-toolbar {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    #gallery-filters {
        flex: 1 1 100%;
        flex-wrap: wrap;
    }

    #gallery-toolbar select,
    #gallery-toolbar input {
        flex: 1 1 100%;
        min-width: 0;
    }

    #gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        max-width: 100%;
        padding: 0.75rem;
        gap: 1rem;
    }

    #gallery-pagination {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}
