* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

html, body {
    font-family: 'EB Garamond', Georgia, serif;
    background: #f2f2f2;
    padding: 0;
    margin: 0;
    height: 100%;
}

/* Tile height variable - viewport divided by 3, minus header */
:root {
    --header-height: 48px;
    --tile-height: calc((100vh - var(--header-height)) / 3.25);
    --image-padding: 20px;
}

/* Header Banner */
.gallery-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.gallery-header a {
    font-family: Georgia, 'EB Garamond', serif;
    font-style: italic;
    font-size: 18px;
    color: #8B3A3A; /* Spice red / paprika */
    text-decoration: none;
    letter-spacing: 0.02em;
}

.gallery-header a:hover {
    color: #6d2d2d;
}

.gallery-header .gallery-title {
    font-family: Georgia, 'EB Garamond', serif;
    font-style: italic;
    font-size: 18px;
    color: #1a1a1a;
    letter-spacing: 0.02em;
}

.gallery-header .gallery-title:hover {
    color: #1a1a1a;
}

/* Grid toggle button */
.grid-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.grid-toggle img {
    width: 16px;
    height: 16px;
    opacity: 0.5;
    transition: opacity 0.15s ease;
}

.grid-toggle:hover img {
    opacity: 1;
}

/* ================================
   Grid Overlay
   ================================ */
.grid-overlay {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: #f2f2f2;
    z-index: 50;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.grid-overlay.active {
    opacity: 1;
    visibility: visible;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 16px;
    max-width: 800px;
    margin: 0 auto;
}

.grid-thumbnail {
    aspect-ratio: 1 / 1;
    padding: 0;
    border: none;
    background: #fff;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.grid-thumbnail:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.grid-thumbnail:active {
    transform: scale(0.98);
}

.grid-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

/* Tablet and Desktop: 4 columns */
@media (min-width: 600px) {
    .grid-container {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
        padding: 24px;
    }
}

/* Gallery Container */
.gallery {
    position: absolute;
    bottom: 0;
    width: 100%;
    left: 0;
    top: 0;
}

/* Shift gallery down when header is present */
.gallery-header + .grid-overlay + .gallery,
.gallery-header + .gallery {
    top: var(--header-height);
}

/* Base tile styling - UNIFORM HEIGHT */
.gallery .tile {
    background: #fff;
    max-width: 620px;
    margin: 0 auto;
    width: 90%;
    border-bottom: 1px solid #e8e8e8;
    height: var(--tile-height);
}

/* Image tiles */
.gallery .tile.image-tile {
    padding: var(--image-padding) 0;
    overflow: hidden;
    position: relative;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery .tile.image-tile img {
    width: 100%;
    height: calc(var(--tile-height) - var(--image-padding) * 2);
    max-height: calc(var(--tile-height) - var(--image-padding) * 2);
    object-fit: contain;
    object-position: center;
    display: block;
}

/* Split image tiles for tall artwork */
.gallery .tile.image-tile.split-top,
.gallery .tile.image-tile.split-bottom {
    height: var(--tile-height);
    padding: 0;
    overflow: hidden;
    display: flex;
    align-items: flex-start;
}

.gallery .tile.image-tile.split-top {
    padding-top: var(--image-padding);
    border-bottom: none;
}

.gallery .tile.image-tile.split-bottom {
    padding-bottom: var(--image-padding);
}

.gallery .tile.image-tile.split-top img,
.gallery .tile.image-tile.split-bottom img {
    width: 100%;
    height: calc(var(--tile-height) * 2 - var(--image-padding) * 2); /* Total height minus top and bottom padding */
    max-height: none;
    object-fit: contain;
    object-position: center top;
}

/* Clip to show only top half */
.gallery .tile.image-tile.split-top img {
    clip-path: inset(0 0 50% 0);
}

/* Clip to show only bottom half, then pull it up */
.gallery .tile.image-tile.split-bottom img {
    clip-path: inset(50% 0 0 0);
    margin-top: calc(var(--image-padding) - var(--tile-height));
}

/* Caption tiles */
.gallery .tile.caption-tile {
    height: var(--tile-height);
    padding: 20px 40px;
    text-align: center;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.caption-content {
    display: inline-block;
    text-align: left;
}

/* Date styling - saffron/cardamom tone */
.caption-date {
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    font-size: 11px;
    letter-spacing: 0.12em;
    color: #C4941A; /* Saffron gold */
    margin-bottom: 6px;
    text-transform: uppercase;
}

/* Title styling - spice red, Georgia italic */
.caption-title {
    font-family: Georgia, 'EB Garamond', serif;
    font-style: italic;
    font-size: 20px;
    font-weight: 400;
    color: #8B3A3A; /* Spice red / paprika */
    line-height: 1.3;
    margin-bottom: 8px;
    letter-spacing: 0.01em;
}

/* Location styling - black, left aligned */
.caption-location {
    font-family: 'EB Garamond', Georgia, serif;
    font-size: 13px;
    color: #1a1a1a;
    font-style: normal;
    letter-spacing: 0.02em;
}

.caption-location::before {
    content: '(';
}

.caption-location::after {
    content: ')';
}

/* Separator between artworks - applied via JS to tiles after the first artwork */
.gallery .tile.artwork-start {
    border-top: 1px dashed #ccc;
    margin-top: 40px;
}

/* First tile spacing */
.gallery .tile:first-child {
    margin-top: 20px;
}

/* Last tile bottom spacing */
.gallery .tile:last-child {
    margin-bottom: 20px;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    :root {
        --header-height: 42px;
    }
    
    .gallery-header a {
        font-size: 16px;
    }
    
    .gallery-header .gallery-title {
        font-size: 16px;
    }
    
    .grid-toggle {
        margin-left: 5px;
    }
    
    .grid-toggle img {
        width: 14px;
        height: 14px;
    }
    
    .gallery .tile.caption-tile {
        padding: 16px 24px;
    }
    
    .caption-date {
        font-size: 10px;
    }
    
    .caption-title {
        font-size: 17px;
    }
    
    .caption-location {
        font-size: 12px;
    }
}

@media (max-width: 400px) {
    :root {
        --header-height: 38px;
    }
    
    .gallery-header a {
        font-size: 15px;
    }
    
    .gallery-header .gallery-title {
        font-size: 15px;
    }
    
    .grid-toggle {
        margin-left: 4px;
    }
    
    .grid-toggle img {
        width: 12px;
        height: 12px;
    }
    
    .gallery .tile {
        width: 95%;
    }
    
    .caption-title {
        font-size: 15px;
    }
}
