/* CSS Reset & Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-color: #1a1a2e;
    --card-bg: #16213e;
    --text-color: #eee;
    --text-muted: #aaa;
    --accent-color: #e94560;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --transition: 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    line-height: 1.6;
}

/* Header */
header {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(135deg, var(--card-bg) 0%, var(--bg-color) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

header h1 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(90deg, var(--text-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.image-count {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Main Content */
main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* No Images Message */
.no-images {
    text-align: center;
    padding: 4rem 2rem;
    background: var(--card-bg);
    border-radius: 12px;
    max-width: 500px;
    margin: 2rem auto;
}

.no-images p {
    margin-bottom: 1rem;
}

.no-images code {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
}

.folder-path {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Gallery Grid */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.25rem;
}

@media (min-width: 640px) {
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
}

/* Gallery Item */
.gallery-item {
    position: relative;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    aspect-ratio: 2 / 3; /* Poster aspect ratio */
}

.gallery-item:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 8px 30px rgba(233, 69, 96, 0.2);
}

.gallery-item:focus-within {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity var(--transition);
}

.gallery-item img.lazy {
    opacity: 0;
    background: linear-gradient(135deg, #2a2a4a 0%, #1a1a2e 100%);
}

.gallery-item img.loaded {
    opacity: 1;
}

/* Image Title Overlay */
.image-title {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2.5rem 0.75rem 0.75rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
    font-size: 0.8rem;
    color: var(--text-color);
    opacity: 0;
    transition: opacity var(--transition);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gallery-item:hover .image-title {
    opacity: 1;
}

/* Loading Skeleton Animation */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.gallery-item img.lazy:not(.loaded) {
    background: linear-gradient(90deg,
        var(--card-bg) 25%,
        rgba(255,255,255,0.05) 50%,
        var(--card-bg) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* ============================================
   LIGHTBOX STYLES
   ============================================ */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.lightbox[hidden] {
    display: flex; /* Override hidden to allow transition */
}

.lightbox.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-content {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#lightbox-image {
    max-width: 90vw;
    max-height: calc(90vh - 3rem);
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
}

.lightbox-caption {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    text-align: center;
    max-width: 90vw;
    word-break: break-word;
}

/* Lightbox Buttons */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    z-index: 1001;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
    background: var(--accent-color);
}

.lightbox-close {
    top: 1rem;
    right: 1rem;
    width: 44px;
    height: 44px;
    font-size: 2rem;
    line-height: 1;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-prev,
.lightbox-next {
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 80px;
    font-size: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-prev {
    left: 1rem;
    border-radius: 4px;
}

.lightbox-next {
    right: 1rem;
    border-radius: 4px;
}

.lightbox-prev:hover,
.lightbox-next:hover {
    transform: translateY(-50%) scale(1.05);
}

/* Hide nav buttons when only one image */
.lightbox.single-image .lightbox-prev,
.lightbox.single-image .lightbox-next {
    display: none;
}

/* Mobile Adjustments */
@media (max-width: 640px) {
    .lightbox-prev,
    .lightbox-next {
        width: 40px;
        height: 60px;
        font-size: 2rem;
    }

    .lightbox-close {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
    }

    .lightbox-caption {
        font-size: 0.85rem;
        padding: 0 1rem;
    }
}

/* Touch-friendly tap areas on mobile */
@media (hover: none) {
    .lightbox-prev,
    .lightbox-next {
        width: 25vw;
        height: 70vh;
        background: transparent;
        font-size: 2rem;
    }

    .lightbox-prev:hover,
    .lightbox-next:hover {
        background: rgba(255, 255, 255, 0.05);
    }
}

/* Accessibility - Focus Styles */
.lightbox-close:focus,
.lightbox-prev:focus,
.lightbox-next:focus,
.gallery-item:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Prevent body scroll when lightbox is open */
body.lightbox-open {
    overflow: hidden;
}

/* Smooth loading transition */
#lightbox-image {
    transition: opacity 0.2s;
}

#lightbox-image.loading {
    opacity: 0.5;
}
