/* Gallery Page Styling */
:root {
    /* Patterned after index.html */
    --bg-color: #fafafa;
    --text-color: #222;
    --accent-color: #6e46be;
    /* matching index.html link color */
    --tile-bg: #fff;
    --font-main: 'Verdana', sans-serif;
    /* matching index.html */
}

/* Reset & Base */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    overflow: hidden;
}

/* Back Button */
.back-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 100;
    color: #555;
    font-size: 1.5rem;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.8);
    padding: 8px 12px;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.back-btn:hover {
    background: #fff;
    color: var(--accent-color);
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

/* Infinite Scroll Container */
.gallery-viewport {
    width: 100vw;
    height: 100vh;
    overflow: auto;
    cursor: grab;
    /* Hide scrollbars */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.gallery-viewport::-webkit-scrollbar {
    display: none;
}

.gallery-viewport:active {
    cursor: grabbing;
}

/* The Grid Canvas */
.gallery-canvas {
    /* Force a huge canvas to ensure multiple screens worth of content in all directions */
    font-size: 0;
    /* remove spacing artifacts */
    min-width: 300vw;
    min-height: 300vh;
    display: block;
    /* Regular block flow */
    box-sizing: border-box;
    padding: 50px;
}

.gallery-grid {
    display: grid;
    /* Auto-fill columns across the entire 300vw width */
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    grid-auto-rows: 260px;
    grid-auto-flow: dense;
    gap: 20px;

    /* Fill the huge canvas */
    width: 100%;
    height: 100%;
}

/* Gallery Item / Tile - varied sizing classes */
.gallery-item {
    position: relative;
    background-color: var(--tile-bg);
    border-radius: 4px;
    /* slighter radius for cleaner look */
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    /* subtle shadow in light mode */
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s ease;

    /* For entrance */
    opacity: 0;
    animation: fadeIn 0.8s ease-out forwards;
}

/* Size Variants - IMPORTANT: these rely on the grid-auto-rows/cols logic */
.w-2 {
    grid-column: span 2;
}

.h-2 {
    grid-row: span 2;
}

/* w-3 is tricky if columns are responsive, but okay on large grids */
.w-3 {
    grid-column: span 3;
}

.gallery-item:hover {
    transform: scale(1.02);
    z-index: 10;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.6s ease;
}

.gallery-item:hover img {
    transform: scale(1.08);
    /* slight zoom */
}

/* Text Overlay - keeping it dark for readability on images, but cleaner */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    /* darker tint overall on hover? Or gradient? */
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.3) 50%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 25px;
}

.gallery-item:hover .overlay {
    opacity: 1;
}

.overlay h3 {
    margin: 0 0 6px 0;
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    transform: translateY(15px);
    transition: transform 0.3s ease;
}

.overlay p {
    margin: 0;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.9);
    transform: translateY(15px);
    transition: transform 0.3s ease 0.05s;
}

.gallery-item:hover .overlay h3,
.gallery-item:hover .overlay p {
    transform: translateY(0);
}

/* Entrance Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
        scale: 0.95;
    }

    to {
        opacity: 1;
        transform: translateY(0);
        scale: 1;
    }
}

/* Staggered delays */
.gallery-item:nth-child(1) {
    animation-delay: 0.05s;
}

.gallery-item:nth-child(2) {
    animation-delay: 0.1s;
}

.gallery-item:nth-child(3) {
    animation-delay: 0.15s;
}

.gallery-item:nth-child(4) {
    animation-delay: 0.2s;
}

.gallery-item:nth-child(5) {
    animation-delay: 0.25s;
}

.gallery-item:nth-child(6) {
    animation-delay: 0.3s;
}

.gallery-item:nth-child(7) {
    animation-delay: 0.35s;
}

/* ... generic for rest */
.gallery-item:nth-child(n+8) {
    animation-delay: 0.4s;
}