/* --- Gallery General --- */
.hidden {
    display: none !important; /* Utility class to hide elements */
}

/* Make sure the main content area has some base padding */
.gallery-section .container {
    padding-top: 1rem;
    padding-bottom: 2rem;
}

#gallery-container {
    padding-top: 40px;
    padding-bottom: 40px;
}

#gallery-container h1 {
    text-align: center;
    margin-bottom: 40px;
    font-size: 2.5rem;
    font-weight: 700;
}

/* --- Category Grid --- */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

.category-card {
    position: relative;
    aspect-ratio: 1 / 1; /* Creates a perfect square */
    overflow: hidden;
    cursor: pointer;
    background-color: #e0e0e0; /* Placeholder color */
}

.category-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease-out;
}

.category-card:hover img {
    transform: scale(1.1);
}

.category-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0);
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: background-color 0.4s ease-out;
}

.category-card:hover .category-overlay {
    background-color: rgba(0, 0, 0, 0.6);
}

.category-overlay .category-name {
    color: white;
    font-size: 1.8rem;
    font-weight: 700;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.category-card:hover .category-overlay .category-name {
    opacity: 1;
    transform: translateY(0);
}

.category-image-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
}


/* --- Image View --- */
#image-view .back-button {
    background: #333;
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 30px;
    transition: background-color 0.3s;
}

#image-view .back-button:hover {
    background-color: #4CAF50;
    color: black;
}

#image-view .category-description {
    margin-bottom: 40px;
    padding: 20px;
    background-color: #f9f9f9;
}

#image-view .category-description h2 {
    margin-top: 0;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
}

.image-grid .image-card {
    overflow: hidden;
    position: relative;
    border-radius: 0px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.image-grid .image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.image-grid .image-card:hover img {
    transform: scale(1.05);
}

.image-card {
    aspect-ratio: 1 / 1;
    overflow: hidden;
    cursor: pointer;
    background-color: #f0f0f0;
}

.image-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s;
}

.image-card:hover img {
    opacity: 0.8;
}

/* --- Lightbox --- */
.lightbox {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
}

.lightbox-content {
    max-width: 55vw;
    max-height: 70vh;
    animation: lightbox-zoom 0.5s ease;
}

@keyframes lightbox-zoom {
    from { transform: scale(0.8); }
    to { transform: scale(1); }
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.lightbox-close:hover {
    color: #ccc;
}

.lightbox-caption {
    text-align: center;
    color: #ccc;
    padding: 20px 0;
    font-size: 1.2rem;
    position: absolute;
    bottom: 15px;
    width: 80%;
    left: 10%;
}

#category-description {
    max-width: 800px;
    margin: 0 auto 2rem auto; /* Centered with bottom margin */
    padding: 20px;
    font-size: 1.1rem;
    line-height: 1.6;
    color: #555;
    text-align: center; /* Default to center alignment */
    background-color: #f9f9f9;
    border-radius: 5px;
}

#category-description h2 {
    margin-top: 0;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.gallery-section .gallery-header {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    margin-top: 2rem; /* Add space from the topbar */
    margin-bottom: 2rem;
    min-height: 40px; /* Ensure space is reserved */
}

.category-title-header {
    text-align: center;
    margin: 0;
    font-size: 2rem;
    color: #333;
    /* This will be positioned in the center by the flex container */
}

.back-btn {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    text-decoration: none;
    background-color: #f0f0f0;
    color: #333;
    padding: 8px 16px;
    border-radius: 5px;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.back-btn:hover {
    background-color: #e0e0e0;
    color: #4CAF50;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.gallery-intro-text {
    text-align: center;
    margin-bottom: 30px;
    color: #666;
    font-style: italic;
}

/* This is the view for a single category's images */
#image-view {
    display: block; /* Ensures it takes up block-level space */
    padding: 20px 0;
    background-color: #f9f9f9;
    border-radius: 5px;
}

#gallery-container-realizacje {
    padding-bottom: 50px;
}

#category-description {
    padding-bottom: 20px;
}

/* New styles for realizations.html to enforce square aspect ratio */
.realization-item {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1; /* Enforce a square shape */
    overflow: hidden;
    border-radius: 0px;
    background-color: #f0f0f0; /* Placeholder color */
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.realization-item img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; /* Crop to fit without distorting */
    transition: transform 0.3s ease;
}

.realization-item:hover img {
    transform: scale(1.05);
}


/* --- Responsive and Mobile Specific Styles --- */
@media (max-width: 768px) {
    /* Mobile-specific styles for gallery */

    main {
        margin-top: 10px !important;
        padding-bottom: 80px;
    }

    .gallery-section .gallery-header {
        flex-direction: column;
        align-items: flex-start; /* Align items to the start */
        margin-bottom: 1rem;
        margin-top: 0; /* Move content higher on mobile */
    }

    .gallery-section .container {
        padding-bottom: 0;
    }

    /* Reposition back button to be subtle in the top-left */
    .back-btn {
        margin-top: 12.5px;
        position: relative;
        transform: none;
        padding: 6px 12px;
        font-size: 0.8rem;
        margin-bottom: 1rem; /* Space between button and title */
        width: fit-content; /* Don't stretch full width */
        order: 1; /* Order it before the title */
    }

    #back-to-home-btn {
        order: 1;
    }
    
    #back-to-galleries-btn {
        order: 1;
    }

    /* Center the main titles */
    .category-title-header, 
    #gallery-main-title {
        align-self: center;
        margin-top: 5px;
        order: 2; /* Appear after the button */
        font-size: 1.8rem; /* Slightly smaller title on mobile */
    }

    /* 2-column grid for categories on mobile */
    .category-grid, .image-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .lightbox-content {
        max-width: 90vw;
        max-height: 70vh;
    }

    #category-description {
        padding: 15px;
        font-size: 1rem;
    }

    /* --- New Mobile Category Card Styles --- */

    /* 1. Disable hover effects for touch devices */
    .category-card:hover img {
        transform: none;
    }

    .category-card:hover .category-overlay {
        background-color: transparent;
    }

    /* 2. Position the text container at the bottom */
    .category-card .category-overlay {
        justify-content: center; /* Center bar horizontally */
        align-items: flex-end; /* Align bar to the bottom */
    }

    /* 3. Make the category name into the bar and center its text */
    .category-overlay .category-name {
        opacity: 1;
        transform: none;
        background: rgba(0, 0, 0, 0.45);
        color: white;
        font-weight: 600;
        
        /* Text Scaling and Layout */
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        text-align: center;
        font-size: clamp(0.75rem, 4vw, 1rem); /* Responsive font size */

        /* Sizing and Centering */
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 25%; /* Reduced height */
        padding: 0 5px;
        box-sizing: border-box;
    }
}


@media (hover: none) {
    .category-card:hover img {
        transform: scale(1); /* Disable zoom on devices that can't hover */
    }
    .category-card:hover .category-overlay {
        background-color: rgba(0,0,0,0); /* Disable overlay on non-hover devices */
    }
     .back-btn:hover {
        background-color: #333; /* Revert hover for touch */
    }
}