:root {
    --color-white: rgba(255, 255, 255, 1);
    --color-black: rgba(0, 0, 0, 1);
    --color-cream-50: rgba(252, 252, 249, 1);
    --color-cream-100: rgba(255, 255, 253, 1);
    --color-gray-200: rgba(245, 245, 245, 1);
    --color-gray-300: rgba(167, 169, 169, 1);
    --color-gray-400: rgba(119, 124, 124, 1);
    --color-slate-500: rgba(98, 108, 113, 1);
    --color-teal-500: rgba(33, 128, 141, 1);
    --color-teal-600: rgba(29, 116, 128, 1);
    --color-charcoal-700: rgba(31, 33, 33, 1);
    --color-charcoal-800: rgba(38, 40, 40, 1);

    --focus-ring: 0 0 0 3px rgba(33, 128, 141, 0.4);
}

* {
    box-sizing: border-box;
}

html {
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    color: var(--color-charcoal-700);
    background-color: var(--color-cream-50);
    -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: dark) {
    html {
        color: var(--color-gray-200);
        background-color: var(--color-charcoal-700);
    }
}

body {
    margin: 0;
    padding: 0;
}

.gallery-container {
    position: relative;
    width: 100%;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--color-cream-50);
}

@media (prefers-color-scheme: dark) {
    .gallery-container {
        background: var(--color-charcoal-700);
    }
}

.gallery-title {
    position: fixed; /* fixed seems the way to go */
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 0.15em;
    color: rgba(0, 0, 0, 0.08);
    pointer-events: none;
    z-index: 1;
    user-select: none;
    text-transform: uppercase;
    white-space: nowrap;
    margin-left: 8px;
}

@media (prefers-color-scheme: dark) {
    .gallery-title {
        color: rgba(255, 255, 255, 0.08);
    }
}

.masonry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    grid-auto-rows: auto;
    gap: 1px;
    padding: 1px;
    margin: 0;
    background: var(--color-gray-200);
}

@media (prefers-color-scheme: dark) {
    .masonry-grid {
        background: var(--color-charcoal-800);
    }
}

@media (min-width: 768px) {
    .masonry-grid {
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    }
}

@media (min-width: 1024px) {
    .masonry-grid {
        grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    }
}

@media (min-width: 1440px) {
    .masonry-grid {
        grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    }
}

.gallery-item {
    position: relative;
    overflow: hidden;
    background: var(--color-white);
    aspect-ratio: 4 / 3;
    cursor: pointer;
    transition: all 200ms cubic-bezier(0.16, 1, 0.3, 1);
    transform: translateZ(0);
}

@media (prefers-color-scheme: dark) {
    .gallery-item {
        background: var(--color-charcoal-800);
    }
}

.gallery-item:hover {
    /* transform: scale(1.1); */
    z-index: 1000;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: all 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

.gallery-item:hover img {
    filter: brightness(0.85);
}

.gallery-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0) 60%);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    opacity: 0;
    transition: opacity 200ms cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 10;
}

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

.gallery-info {
    color: var(--color-white);
    font-size: 0.75rem;
    line-height: 1.4;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.gallery-info-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
}

.gallery-info-details {
    font-size: 0.7rem;
    opacity: 0.9;
    margin-bottom: 0.2rem;
}

.gallery-info-exif {
    font-size: 0.65rem;
    opacity: 0.8;
    font-family: 'Monaco', 'Menlo', monospace;
    max-height: 2.8rem;
    overflow: hidden;
}

.modal-gallery {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    backdrop-filter: blur(2px);
    animation: fadeIn 200ms ease-out;
}

.modal-gallery.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content-wrapper {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    animation: slideUp 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-image {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 0;
}

.modal-details {
    color: var(--color-white);
    text-align: center;
    max-width: 600px;
    font-size: 0.85rem;
}

.modal-details h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.3rem;
    font-weight: 600;
}

.modal-details p {
    margin: 0 0 0.5rem 0;
    line-height: 1.5;
}

.modal-details-exif {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.4;
    margin-top: 1rem;
    text-align: left;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.75rem;
    border-radius: 4px;
}

.modal-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 200ms ease;
    z-index: 1001;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 200ms ease;
    z-index: 1001;
}

.modal-nav:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%) scale(1.1);
}

.modal-nav.prev {
    left: 1.5rem;
}

.modal-nav.next {
    right: 1.5rem;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--color-slate-500);
    font-size: 1rem;
}

.error {
    padding: 2rem;
    color: var(--color-charcoal-700);
    background: rgba(255, 100, 100, 0.1);
    border-left: 4px solid rgba(255, 100, 100, 0.5);
    border-radius: 4px;
    margin: 1rem;
}

@media (prefers-color-scheme: dark) {
    .error {
        color: var(--color-gray-200);
    }
}
