/* ====================================================
   GLOBAL & LAYOUT STYLES
   ==================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background: #ececec;
}

.gallery-section {
    width: 90%;
    max-width: 1200px;
    margin: auto;
    padding: 60px 0;
}

/* ====================================================
   GALLERY HEADING (Auto-scaling text)
   ==================================================== */
.gallery-heading {
    text-align: center;
    margin-bottom: 40px;
}

.gallery-heading h1 {
    color: #003366;
    font-size: clamp(28px, 4vw, 40px); /* Scales font smoothly on mobile */
    font-weight: 700;
}

.gallery-heading p {
    color: #428840;
    margin-top: 10px;
    font-size: clamp(14px, 1.5vw, 18px);
}

/* ====================================================
   GALLERY GRID & ITEMS (Fixed vertical-shifting)
   ==================================================== */
.gallery-container {
    display: grid;
    /* Uses dynamic auto-fit with a safer min-width for columns */
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 25px;
}

.gallery-item {
    overflow: hidden;
    border-radius: 15px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0,0,0,.12);
    height: 280px; /* Fixed height for uniform grids on desktop */
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,.18);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover; /* Prevents stretching of pictures */
    transition: transform 0.5s ease;
}

.gallery-item:hover img {
    transform: scale(1.08); /* Smoother hover effect */
}

/* ====================================================
   LIGHTBOX MODULE (Optimized for all touches)
   ==================================================== */
#lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.92); /* Darker backdrop for focus */
    z-index: 99999;
}

#lightbox img {
    max-width: 90%;
    max-height: 80%; /* Safe zone for close button */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.close {
    position: absolute;
    top: 25px;
    right: 25px;
    color: white;
    font-size: 40px;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s ease;
    z-index: 100000;
}

.close:hover {
    color: #ff3333;
}

/* ====================================================
   RESPONSIVE MEDIA QUERIES (Anti-wrapping mechanism)
   ==================================================== */

@media (max-width: 768px) {
    .gallery-section {
        width: 95%; /* More horizontal space on smaller screens */
        padding: 40px 0;
    }

    .gallery-container {
        grid-template-columns: repeat(2, 1fr); /* Forces clean 2-columns (no huge cards) */
        gap: 15px;
    }

    .gallery-item {
        height: 200px; /* Reduced card height for proportional mobile ratios */
        border-radius: 10px;
    }

    .close {
        top: 20px;
        right: 20px;
        font-size: 35px; /* Easily tappable button size on mobile */
    }
}

@media (max-width: 480px) {
    .gallery-container {
        grid-template-columns: repeat(2, 1fr); /* Retains 2-column view to prevent giant vertical cards */
        gap: 10px;
    }

    .gallery-item {
        height: 150px; /* Perfectly aligned small device block height */
    }

    #lightbox img {
        max-width: 95%;
        max-height: 75%;
    }
}