/**
 * FlexPress Gallery Styles
 */

/* Gallery Container */
.episode-gallery {
    margin: 2rem 0;
    padding: 1rem 0;
}

/* Gallery Grid */
.gallery-grid {
    display: grid;
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Gallery Items */
.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    background: transparent;
    aspect-ratio: 1 / 1; /* Force square aspect ratio for thumbnails */
}

/* Fallback for older browsers that don't support aspect-ratio */
@supports not (aspect-ratio: 1 / 1) {
    .gallery-item {
        height: 0;
        padding-bottom: 100%; /* Creates 1:1 aspect ratio */
    }
    
    .gallery-item .gallery-link,
    .gallery-item .gallery-preview-last,
    .gallery-item .gallery-preview-cta {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* Gallery Links */
.gallery-link {
    display: block;
    text-decoration: none;
    color: inherit;
    position: relative;
    overflow: hidden;
}

.gallery-link:hover {
    text-decoration: none;
}

/* Gallery Images */
.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.gallery-link:hover img {
    transform: scale(1.05);
}

/* Gallery Captions */
.gallery-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    color: #fff;
    padding: 1rem;
    font-size: 0.9rem;
    line-height: 1.4;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-link:hover .gallery-caption {
    opacity: 1;
}

/* Responsive Grid Columns */
@media (min-width: 576px) {
    .gallery-grid[data-columns="2"] {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .gallery-grid[data-columns="3"] {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .gallery-grid[data-columns="4"] {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .gallery-grid[data-columns="5"] {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .gallery-grid[data-columns="3"] {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .gallery-grid[data-columns="4"] {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .gallery-grid[data-columns="5"] {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 992px) {
    .gallery-grid[data-columns="4"] {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .gallery-grid[data-columns="5"] {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1200px) {
    .gallery-grid[data-columns="5"] {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* Lightbox Styles */
.gallery-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}

.gallery-lightbox.active {
    display: flex;
}

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

.lightbox-image {
    max-width: 100%;
    max-height: calc(90vh - 4rem); /* Account for caption space */
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    display: block;
    transition: opacity 0.3s ease;
}

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

.lightbox-caption {
    color: #fff;
    margin-top: 1rem;
    font-size: 1.1rem;
    line-height: 1.4;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 2rem;
    padding: 1rem 0.5rem;
    cursor: pointer;
    transition: background 0.3s ease;
    border-radius: 4px;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-prev {
    left: 1rem;
}

.lightbox-next {
    right: 1rem;
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    padding: 0.5rem;
    cursor: pointer;
    transition: background 0.3s ease;
    border-radius: 4px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-counter {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

/* Loading States */
.gallery-loading {
    text-align: center;
    padding: 2rem;
    color: #666;
}

.gallery-loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-top-color: #0073aa;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 0.5rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Empty State */
.gallery-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
    font-style: italic;
}

.gallery-empty::before {
    content: '📷';
    font-size: 3rem;
    display: block;
    margin-bottom: 1rem;
}

/* Accessibility */
.gallery-item:focus-within {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.gallery-link:focus {
    outline: none;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .gallery-item {
        border: 2px solid #000;
    }
    
    .gallery-caption {
        background: rgba(0, 0, 0, 1);
        border-top: 2px solid #fff;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .gallery-item,
    .gallery-item img,
    .gallery-caption {
        transition: none;
    }
    
    .gallery-item:hover {
        transform: none;
    }
    
    .gallery-link:hover img {
        transform: none;
    }
    
    .gallery-link:hover .gallery-caption {
        opacity: 1;
    }
}

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

/* Gallery Preview Mode Styles */
.gallery-preview-last {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    display: block;
    text-decoration: none;
    color: inherit;
}

.gallery-preview-cta {
    transition: all 0.3s ease;
}

.gallery-preview-cta:hover {
    text-decoration: none;
    color: inherit;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.gallery-preview-last img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: all 0.3s ease;
}

.gallery-preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.3s ease;
}

.gallery-preview-overlay:hover {
    background: rgba(0, 0, 0, 0.9);
}

.preview-overlay-content {
    text-align: center;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.remaining-count {
    font-size: 3rem;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
    margin: 0 0 0.5rem 0;
    line-height: 1;
    transition: all 0.3s ease;
}

.cta-hint {
    font-size: 0.875rem;
    color: #fff;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 500;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
    transition: all 0.3s ease;
}

/* Preview mode hover effects */
.gallery-preview-cta:hover img {
    transform: scale(1.08);
    filter: blur(2px);
}

.gallery-preview-cta:hover .gallery-preview-overlay {
    background: rgba(0, 0, 0, 0.9);
}

.gallery-preview-cta:hover .remaining-count {
    transform: scale(1.15);
    color: #ffd700;
    text-shadow: 0 2px 15px rgba(255, 215, 0, 0.5);
}

.gallery-preview-cta:hover .cta-hint {
    opacity: 1;
    color: #ffd700;
    transform: translateY(-2px);
    text-shadow: 0 1px 8px rgba(255, 215, 0, 0.3);
}

/* Responsive adjustments for preview overlay */
@media (max-width: 991px) {
    .remaining-count {
        font-size: 2.5rem;
    }
    
    .cta-hint {
        font-size: 0.8rem;
    }
}

@media (max-width: 767px) {
    .remaining-count {
        font-size: 2rem;
    }
    
    .cta-hint {
        font-size: 0.75rem;
    }
}

@media (max-width: 479px) {
    .remaining-count {
        font-size: 1.5rem;
        margin-bottom: 0.25rem;
    }
    
    .cta-hint {
        font-size: 0.7rem;
        letter-spacing: 0.5px;
    }
}

/* Mobile Lightbox Adjustments */
@media (max-width: 768px) {
    .lightbox-content {
        max-width: 95vw;
        max-height: 95vh;
        padding: 1rem;
    }
    
    .lightbox-image {
        max-height: calc(95vh - 6rem); /* More space for caption on mobile */
    }
    
    .lightbox-caption {
        font-size: 1rem;
        margin-top: 0.5rem;
    }
    
    .lightbox-nav {
        font-size: 1.5rem;
        padding: 0.5rem 0.25rem;
    }
    
    .lightbox-close {
        width: 35px;
        height: 35px;
        font-size: 1.25rem;
    }
    
    .lightbox-counter {
        font-size: 0.8rem;
        padding: 0.25rem 0.75rem;
    }
}

@media (max-width: 480px) {
    .lightbox-content {
        max-width: 98vw;
        max-height: 98vh;
        padding: 0.5rem;
    }
    
    .lightbox-image {
        max-height: calc(98vh - 5rem);
    }
    
    .lightbox-caption {
        font-size: 0.9rem;
    }
}

/* Print Styles */
@media print {
    .episode-gallery {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem;
    }
    
    .gallery-caption {
        opacity: 1;
        background: rgba(0, 0, 0, 0.1);
        color: #000;
    }
    
    /* Hide preview overlay in print */
    .gallery-preview-overlay {
        display: none;
    }
}
