body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f0f0f0;
}

.gallery {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin: 20px;
}

.gallery-item {
    flex: 1 1 calc(25% - 20px); /* Four items per row with spacing */
    margin: 10px;
    cursor: pointer;
    max-width: calc(25% - 20px); /* Maximum width for larger screens */
}

.gallery-item img {
    object-fit: contain;
    width: 100%;
    height: 350px;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.popup {
    display: none; /* Initially hidden */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 1000; /* Make sure it's on top */
}

.popup img {
    max-width: 74%;
    height: 50%;
    margin-bottom: 20px;
    margin-top: 50px;
    object-fit: contain;
}

.close {
    color: white;
    position: absolute;
    top: 120px;
    right: 30px;
    font-size: 30px;
    cursor: pointer;
}

.popup h2, .popup p {
    color: white;
    text-align: center;
    margin: 5px 0;
    max-width: 90%; /* Limit width of text */
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .gallery-item {
        flex: 1 1 calc(50% - 20px); /* Two items per row */
        max-width: calc(50% - 20px);
    }
}

@media (max-width: 480px) {
    .gallery-item {
        flex: 1 1 100%; /* One item per row */
        max-width: 100%;
    }

    .close {
        font-size: 24px; /* Smaller close button on mobile */
    }

    .popup h2, .popup p {
        font-size: 16px; /* Smaller text on mobile */
    }

    .popup img {
        max-width: 50%;
        height: auto;
        margin-bottom: 20px;
    }
}
