/* Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f8f9fa;
    color: #111;
    -webkit-font-smoothing: antialiased;
}

/* Navigation Bar */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background-color: #ffffff;
    border-bottom: 1px solid #eaeaec;
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #333;
}

/* Header */
.portfolio-header {
    text-align: center;
    padding: 60px 20px 50px;
}

.portfolio-header h1 {
    font-size: 24px;
    font-weight: 500;
    margin-bottom: 12px;
    letter-spacing: -0.5px;
}

.portfolio-header p {
    font-size: 14px;
    color: #555;
    margin-bottom: 16px;
}

.contact-link {
    font-size: 14px;
    color: #111;
    text-decoration: none;
    font-weight: 500;
}

.contact-link:hover {
    text-decoration: underline;
}

/* Masonry Gallery Layout */
.gallery-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px 60px;
    
    /* CSS Columns handle the masonry effect */
    column-count: 3;
    column-gap: 24px;
}

.gallery-container img {
    width: 100%;
    display: block;
    margin-bottom: 24px;
    border-radius: 2px;
    /* Prevents images from splitting across columns */
    break-inside: avoid; 
}

/* Responsive Breakpoints */
@media (max-width: 900px) {
    .gallery-container {
        column-count: 2;
    }
}

@media (max-width: 600px) {
    .gallery-container {
        column-count: 1;
        padding: 0 16px 40px;
    }
}

/* --- Optimized Lightbox CSS for Smooth Transitions --- */

.gallery-container img {
    cursor: pointer;
    transition: opacity 0.2s ease-in-out;
}

.gallery-container img:hover {
    opacity: 0.85;
}

/* Lightbox Modal Overlay */
.lightbox {
    /* Critical Change: Use opacity and visibility instead of display: none */
    display: flex; 
    flex-direction: column; /* Stacks children vertically */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    
    /* Pre-animation state (hidden) */
    opacity: 0;
    visibility: hidden;
    
    /* Defines the animation curve. 0.3s is 'quick but smooth'. */
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

/* Target State (When Lightbox is Active) */
.lightbox.active {
    opacity: 1;
    visibility: visible;
}

/* Enlarged image styling with added scale animation */
.lightbox-content {
    /* 1. Constraint (Existing, ensures it fits the viewport) */
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    
    /* 2. Frame Styling (The New Additions) */
    background-color: #ffffff; /* Sets the frame color */
    
    /* Creates the gap between the image edge and the shadow. 
       Adjust this number (e.g., 10px, 30px) for a thinner/thicker mat. */
    padding: 40px; 
    
    /* Optional slight corner rounding */
    border-radius: 4px; 
    
    /* 3. Shadow adjustment (Existing, but made slightly sharper) */
    box-shadow: 0 16px 48px rgba(0,0,0,0.85);
    
    /* 4. Utilities (Existing) */
    user-select: none;
    
    /* 5. Animation (Existing from previous step) */
    transform: scale(0.95);
    transition: transform 0.3s ease-in-out;
}

/* Scale image up when active */
.lightbox.active .lightbox-content {
    transform: scale(1);
}

/* --- New Rules for the Caption --- */
.lightbox-caption {
    margin-top: 20px;
    color: #ffffff;
    text-align: center;
    max-width: 800px;
    padding: 0 20px;
    
    /* Animation matching the image */
    transform: translateY(10px);
    transition: transform 0.3s ease-in-out;
}

.lightbox.active .lightbox-caption {
    transform: translateY(0);
}

.lightbox-caption h3 {
    margin: 0 0 5px 0;
    font-size: 1.25rem;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.lightbox-caption p {
    margin: 0;
    font-size: 0.95rem;
    color: #b3b3b3;
    font-weight: 300;
    line-height: 1.4;
}

/* --- Lightbox Navigation Arrows --- */
.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(0, 0, 0, 0.4); /* Semi-transparent background */
    color: #ffffff;
    border: none;
    font-size: 2rem;
    padding: 16px 20px;
    cursor: pointer;
    z-index: 1010;
    user-select: none;
    transition: background-color 0.2s ease-in-out;
    border-radius: 4px;
}

@media (hover: hover) {
    .nav-btn:hover {
        background-color: rgba(0, 0, 0, 0.9);
    }
}

/* Responsive adjustments for Mobile (Screens smaller than 768px) */
@media (max-width: 767px) {
    .lightbox-content {
        max-height: 60vh; /* Shrinks the image to make room for text */
        padding: 15px;    /* Slightly tighter frame for small screens */
    }

    .lightbox-caption {
        margin-top: 15px;
        max-width: 90vw;  /* Allows text to use more horizontal space */
    }

    .lightbox-caption h3 {
        font-size: 1.1rem;
    }

    .lightbox-caption p {
        font-size: 0.85rem;
    }
    
    /* Optional: Hide the side arrows on mobile to reduce clutter, 
       since we added swipe support */
    .nav-btn {
        display: none; 
    }
}

.prev-btn {
    left: 20px;
}

.next-btn {
    right: 20px;
}

/* Ensure the image sits below the buttons */
.lightbox-content {
    z-index: 1005; 
}

/* Close Button */
.close-btn {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #ffffff;
    font-size: 40px;
    font-weight: 100;
    cursor: pointer;
    user-select: none;
    z-index: 1001;
    line-height: 1;
}

.close-btn:hover {
    color: #cccccc;
}