/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    will-change: scroll-position;
}

/* Header */
header {
    text-align: center;
    padding: 2rem 1rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

header p {
    font-size: 1.2rem;
    color: #7f8c8d;
}

.reference-link {
    margin-top: 1rem;
}

.reference-link a {
    display: inline-block;
    background: linear-gradient(135deg, #4267B2 0%, #365899 100%);
    color: white;
    text-decoration: none;
    padding: 0.8rem 1.5rem;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(66, 103, 178, 0.3);
}

.reference-link a:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(66, 103, 178, 0.4);
    background: linear-gradient(135deg, #365899 0%, #4267B2 100%);
}

/* Main container */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Gallery container */
#gallery-container {
    display: grid;
    gap: 2rem;
}

/* Category section */
.category {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.category:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.category-title {
    font-size: 1.8rem;
    color: #2c3e50;
    margin-bottom: 1rem;
    text-align: center;
    border-bottom: 3px solid #e74c3c;
    padding-bottom: 0.5rem;
}

.category-note {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 10px;
    margin-bottom: 1.5rem;
    border-left: 4px solid #e74c3c;
    font-style: italic;
    color: #555;
}

/* Image grid */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.image-item {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.image-item:hover, .image-item:active {
    transform: scale(1.05);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.image-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    pointer-events: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

.image-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    color: white;
    padding: 1rem;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.image-item:hover .image-overlay {
    transform: translateY(0);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(5px);
}

.modal-content {
    margin: 2% auto;
    display: flex;
    max-width: 95%;
    max-height: 95%;
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    position: relative;
}

.close {
    position: absolute;
    top: 15px;
    right: 25px;
    color: white;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1002;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.close:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* Navigation arrows */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    z-index: 1002;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    user-select: none;
}

.nav-arrow:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: translateY(-50%) scale(1.1);
}

.nav-arrow:active {
    transform: translateY(-50%) scale(0.95);
}

.nav-arrow.prev {
    left: 20px;
}

.nav-arrow.next {
    right: 20px;
}

.nav-arrow:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-arrow:disabled:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: translateY(-50%) scale(1);
}

#modal-image {
    flex: 2;
    max-width: 70%;
    height: auto;
    object-fit: contain;
    max-height: 100%;
    transition: opacity 0.3s ease;
}

/* Image counter */
.image-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 1002;
}

/* Touch gestures for mobile */
.modal-content {
    touch-action: pan-y;
}

#modal-image {
    touch-action: none;
}

#modal-info {
    flex: 1;
    padding: 2rem;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

#modal-title {
    font-size: 1.5rem;
    color: #2c3e50;
    margin-bottom: 1rem;
    border-bottom: 2px solid #e74c3c;
    padding-bottom: 0.5rem;
}

#modal-description {
    font-size: 1.1rem;
    color: #555;
    line-height: 1.8;
}

/* Loading animation */
.loading {
    text-align: center;
    padding: 2rem;
    font-size: 1.2rem;
    color: #7f8c8d;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #e74c3c;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive design */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    header p {
        font-size: 1rem;
    }
    
    .category-title {
        font-size: 1.4rem;
    }
    
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 0.8rem;
    }
    
    .image-item img {
        height: 120px;
    }
    
    .modal-content {
        flex-direction: column;
        max-width: 100%;
        max-height: 100%;
        margin: 0;
        border-radius: 0;
    }
    
    #modal-image {
        max-width: 100%;
        flex: none;
        max-height: 60vh;
    }
    
    #modal-info {
        flex: none;
        padding: 1rem;
        max-height: 40vh;
        overflow-y: auto;
    }
    
    .close {
        top: 10px;
        right: 15px;
        width: 40px;
        height: 40px;
        font-size: 28px;
    }
    
    .nav-arrow {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .nav-arrow.prev {
        left: 10px;
    }
    
    .nav-arrow.next {
        right: 10px;
    }
    
    .image-counter {
        bottom: 10px;
        font-size: 12px;
        padding: 6px 12px;
    }
    
    /* Mobile touch improvements */
    .image-item {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    
    .category {
        padding: 1rem;
    }
    
    .category-note {
        padding: 0.8rem;
        font-size: 0.9rem;
    }
    
    .reference-link a {
        font-size: 0.9rem;
        padding: 0.6rem 1.2rem;
    }
    
    /* Better mobile scrolling */
    body {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Prevent zoom on double tap */
    * {
        touch-action: manipulation;
    }
    
    .modal {
        touch-action: manipulation;
    }
}

@media (max-width: 480px) {
    header {
        padding: 1.5rem 0.5rem;
    }
    
    header h1 {
        font-size: 1.8rem;
    }
    
    main {
        padding: 0 0.5rem;
    }
    
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.5rem;
    }
    
    .image-item img {
        height: 100px;
    }
    
    .category-title {
        font-size: 1.2rem;
    }
    
    #modal-info {
        padding: 0.8rem;
    }
    
    #modal-title {
        font-size: 1.2rem;
    }
    
    #modal-description {
        font-size: 0.9rem;
    }
}
