/* AOE II Traveller - Gallery View Styles */
/* Instagram-style square photo markers with perfect center cropping */

/* Gallery Toggle Button */
.gallery-toggle {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    color: white;
    border: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.gallery-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
}

.gallery-toggle.active {
    background: linear-gradient(135deg, #10b981, #059669);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.gallery-toggle.active:hover {
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

/* Gallery Marker Styles */
.gallery-marker {
    background: transparent !important;
    border: none !important;
}

.gallery-marker-container {
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    backface-visibility: hidden;
}

.gallery-marker-container:hover,
.gallery-marker-container.hover {
    transform: scale(2) translateZ(0);
    z-index: 1001;
}

/* Square Instagram-style frame */
.gallery-photo-frame {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #fff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    position: relative;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Smaller frames for clustered markers */
.gallery-photo-frame-small {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border-width: 2px;
}

/* Gallery cluster frame */
.gallery-photo-frame-cluster {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    overflow: hidden;
    border: 3px solid #ffd700; /* Golden border for clusters */
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.5);
    position: relative;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* FIXED: Perfect center cropping for all photo orientations */
.gallery-photo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    transition: all 0.3s ease;
    will-change: transform;
    backface-visibility: hidden;
    display: block;
    flex-shrink: 0;
    /* Ensure the image fills the entire container */
    min-width: 100%;
    min-height: 100%;
}

.gallery-marker-container:hover .gallery-photo-img,
.gallery-marker-container.hover .gallery-photo-img {
    transform: scale(1.05);
}

.gallery-photo-error {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #6b7280, #9ca3af);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

.gallery-photo-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.9) 100%);
    color: white;
    padding: 4px 3px 2px 3px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 0 0 6px 6px;
}

.gallery-marker-container:hover .gallery-photo-overlay,
.gallery-marker-container.hover .gallery-photo-overlay {
    opacity: 1;
}

.gallery-photo-title {
    font-size: 0.5rem;
    font-weight: bold;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    margin-bottom: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-photo-civ {
    font-size: 0.4rem;
    opacity: 0.9;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Enhanced clustered gallery markers */
.gallery-marker-offset .gallery-marker-container {
    position: relative;
}

.gallery-marker-offset .gallery-marker-container:hover {
    transform: scale(1.8) translateZ(0);
    z-index: 1000;
}

/* Cluster marker visual distinction */
.gallery-marker-offset .gallery-photo-frame {
    border-color: #ffd700;
    border-width: 2px;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
}

.gallery-marker-offset .gallery-photo-frame-small {
    border-color: #ffd700;
    border-width: 2px;
    box-shadow: 0 3px 12px rgba(255, 215, 0, 0.4);
}

/* Photo grid container */
.gallery-photo-grid {
    width: 100%;
    height: 100%;
    display: grid;
    gap: 1px;
    background: #fff; /* Shows as grid lines */
}

/* Grid layouts */
.gallery-grid-2 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

.gallery-grid-3 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.gallery-grid-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

/* Individual photo in grid */
.gallery-grid-photo {
    overflow: hidden;
    position: relative;
}

.gallery-grid-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
}

/* Cluster count indicator */
.gallery-cluster-count {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: bold;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
}

/* Cluster hover effects */
.gallery-marker-cluster .gallery-marker-container:hover {
    transform: scale(2) translateZ(0);
    z-index: 1001;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .gallery-photo-frame {
        width: 35px;
        height: 35px;
        border-radius: 6px;
        border-width: 2px;
    }
    
    .gallery-photo-frame-small {
        width: 25px;
        height: 25px;
        border-radius: 4px;
        border-width: 1px;
    }
    
    .gallery-photo-frame-cluster {
        width: 35px;
        height: 35px;
        border-width: 2px;
    }
    
    .gallery-photo-title {
        font-size: 0.45rem;
    }
    
    .gallery-photo-civ {
        font-size: 0.35rem;
    }
    
    .gallery-cluster-count {
        width: 14px;
        height: 14px;
        font-size: 0.55rem;
        border-width: 1px;
    }
    
    .gallery-marker-container:hover,
    .gallery-marker-container.hover {
        transform: scale(1.8) translateZ(0);
    }
    
    .gallery-marker-offset .gallery-marker-container:hover {
        transform: scale(1.6) translateZ(0);
    }
}

@media (max-width: 480px) {
    .gallery-photo-frame {
        width: 30px;
        height: 30px;
        border-radius: 4px;
        border-width: 1px;
    }
    
    .gallery-photo-frame-small {
        width: 20px;
        height: 20px;
        border-radius: 3px;
        border-width: 1px;
    }
    
    .gallery-photo-frame-cluster {
        width: 30px;
        height: 30px;
        border-width: 2px;
    }
    
    .gallery-photo-title {
        font-size: 0.4rem;
    }
    
    .gallery-photo-civ {
        font-size: 0.3rem;
    }
    
    .gallery-cluster-count {
        width: 12px;
        height: 12px;
        font-size: 0.5rem;
    }
    
    .gallery-marker-container:hover,
    .gallery-marker-container.hover {
        transform: scale(1.6) translateZ(0);
    }
    
    .gallery-marker-offset .gallery-marker-container:hover {
        transform: scale(1.4) translateZ(0);
    }
}

/* High DPI Display Optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .gallery-photo-img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
    
    .gallery-photo-frame {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    }
}

/* Animation Performance Optimizations */
.gallery-marker-container {
    perspective: 1000px;
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    .gallery-marker-container,
    .gallery-photo-img,
    .gallery-photo-overlay,
    .gallery-toggle {
        transition: none !important;
        animation: none !important;
    }
    
    .gallery-marker-container:hover,
    .gallery-marker-container.hover {
        transform: scale(1.1) !important;
    }
}

/* Touch Device Optimizations */
@media (hover: none) {
    /* Always show overlays on touch devices */
    .gallery-photo-overlay {
        opacity: 0.8;
    }
    
    /* Larger touch targets on mobile */
    .gallery-photo-frame {
        min-width: 35px;
        min-height: 35px;
    }
    
    .gallery-photo-frame-small {
        min-width: 25px;
        min-height: 25px;
    }
}

/* Loading state for images */
.gallery-photo-img[src=""] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 2s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Error state for broken images */
.gallery-photo-img:not([src]) {
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-photo-img:not([src])::before {
    content: '📷';
    font-size: 1rem;
    color: #9ca3af;
}

/* Zoom animation keyframes */
@keyframes galleryZoomIn {
    from {
        transform: scale(1);
    }
    to {
        transform: scale(2);
    }
}

@keyframes galleryZoomOut {
    from {
        transform: scale(2);
    }
    to {
        transform: scale(1);
    }
}

/* Enhanced hover effects for desktop */
@media (hover: hover) and (pointer: fine) {
    .gallery-marker-container:hover {
        animation: galleryZoomIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    }
}

/* Print styles - hide gallery elements when printing */
@media print {
    .gallery-toggle,
    .gallery-marker-container {
        display: none !important;
    }
}

/* Universal fix for gallery cluster popup clicks */

.wonder-list-item {
    pointer-events: auto !important;
    position: relative !important;
    z-index: 10000 !important;
    cursor: pointer !important;
}

/* Prevent gallery overlays from interfering with popups */
.leaflet-popup-content .gallery-photo-overlay {
    display: none !important;
}

.leaflet-popup-content .gallery-marker-container {
    transform: none !important;
    z-index: auto !important;
}

.leaflet-popup-content * {
    pointer-events: auto !important;
}

/* Ensure popup content is always on top */
.leaflet-popup {
    z-index: 10000 !important;
}

.leaflet-popup-content-wrapper {
    z-index: 10001 !important;
}