/* =========================================================
   Custom Project Fonts
   ========================================================= */
@font-face {
    font-family: 'Swiss721BT-med';
    src: url('/fonts/Swiss721BT-Medium.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Swiss721BT-lt';
    src: url('/fonts/Swiss721BT-Light.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

/* public/styles.css */

:root {
    --off-white: #fdfaf0;
    --page-bg: #fdfaf0;
    --ink: #1d1d1b;
    --ink-soft: #6a665c;
    --backdrop: rgba(92, 92, 92, 0.94);
    --dissolve: 350ms;
    --gap: 8px;
    /* every tile is locked to this shape */
    --tile-ratio: 3 / 2;
    /* photos per row */
    --grid-columns: 3;
}

* {
    box-sizing: border-box;
}

html {
    /* reserves the scrollbar track so locking scroll can't reflow the grid */
    scrollbar-gutter: stable;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--page-bg);
    color: var(--ink);
    font-family: "Swiss721BT-med", Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* scroll lock while the viewer is open */
body.viewer-open {
    overflow: hidden;
}

.masthead {
    padding: 4rem 2rem 2rem;
    max-width: 1600px;
    margin: 0 auto;
}

.masthead h1 {
    margin: 0;
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    letter-spacing: 0.02em;
}

.masthead p {
    margin: 0.5rem 0 0;
    color: var(--ink-soft);
}

/* --- UNIFORM 3:2 GRID, FIXED COLUMN COUNT --- */

.grid {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem 2rem 5rem;
    display: grid;
    /* minmax(0, 1fr) stops a wide thumb from forcing the track past its share */
    grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr));
    /* tiles size themselves from the ratio, never from the row height */
    align-items: start;
    gap: var(--gap);
}

.tile {
    appearance: none;
    border: none;
    background: var(--off-white);
    padding: 0;
    margin: 0;
    cursor: pointer;
    overflow: hidden;
    /* block + relative: a button's intrinsic content sizing can't win here */
    display: block;
    position: relative;
    /* every image, portrait or landscape, renders in the same landscape box */
    aspect-ratio: var(--tile-ratio);
    /* the grid must not stretch the tile past its ratio */
    align-self: start;
    /* stops a large intrinsic image size from blowing out the 1fr track */
    min-width: 0;
    min-height: 0;
    /* animate transform only, so hovering never triggers a full repaint */
    transition: transform 200ms ease;
}

.tile:hover,
.tile:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
    outline: none;
}

.tile img {
    /* out of flow: the 3:2 box is the single source of truth for tile size */
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    /* centre-crop into the 3:2 frame */
    object-fit: cover;
    object-position: center;
    display: block;
    opacity: 0;
    transition: opacity 300ms ease;
}

.tile img.loaded {
    opacity: 1;
}

.empty-state {
    text-align: center;
    color: var(--ink-soft);
    padding: 0 2rem 4rem;
}

/* --- VIEWER (dissolve in / out) --- */

.viewer {
    position: fixed;
    inset: 0;
    z-index: 50;
    /* flex centring + padding + scroll fallback: the card cannot land offscreen */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(12px, 2.5vw, 40px);
    overflow: auto;
    overscroll-behavior: contain;
    background: var(--backdrop);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    will-change: opacity;
    /* visibility flips only after the fade-out finishes */
    transition: opacity var(--dissolve) ease, visibility 0s linear var(--dissolve);
}

/* mobile browsers: match the visible viewport, not the ideal one */
@supports (height: 100dvh) {
    .viewer {
        height: 100dvh;
    }
}

.viewer.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity var(--dissolve) ease, visibility 0s;
}

.viewer-card {
    position: relative;
    flex: 0 0 auto;
    margin: auto;
    /* sized against the padded overlay box, so it always fits or scrolls */
    width: min(1600px, 100%);
    height: min(1040px, 100%);
    background: var(--off-white);
    padding: clamp(1.25rem, 2.5vw, 2.5rem);
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(240px, 24%, 400px);
    /* the row must be constrained or tall images overflow at natural size */
    grid-template-rows: minmax(0, 1fr);
    gap: clamp(1.25rem, 2.5vw, 2.5rem);
}

.viewer-close {
    position: absolute;
    top: 1.5rem;
    right: 1.75rem;
    width: 44px;
    height: 44px;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink);
    z-index: 3;
}

.viewer-close svg {
    width: 100%;
    height: 100%;
    display: block;
}

.viewer-close svg path {
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.viewer-close:hover,
.viewer-close:focus-visible {
    color: var(--ink-soft);
    outline: none;
}

/* both layers occupy the same cell, so portrait and landscape behave the same */
.viewer-figure {
    position: relative;
    margin: 0;
    display: grid;
    /* explicit minmax(0, 1fr) tracks: without these the implicit auto row takes
       its minimum from the image's intrinsic height and pushes past the card */
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.viewer-layer {
    grid-area: 1 / 1;
    width: 100%;
    height: 100%;
    /* image must never contribute a size larger than its cell */
    max-width: 100%;
    max-height: 100%;
    min-width: 0;
    min-height: 0;
    object-fit: contain;
    display: block;
}

.viewer-layer.placeholder {
    opacity: 0;
    transition: opacity 150ms ease;
}

.viewer-layer.placeholder.shown {
    opacity: 1;
}

.viewer-layer.full {
    opacity: 0;
    transition: opacity 300ms ease;
}

.viewer-layer.full.loaded {
    opacity: 1;
}

/* the original could not be fetched; the thumbnail stays up behind this */
.viewer-card.full-failed .viewer-figure::after {
    content: 'Original unavailable';
    position: absolute;
    left: 50%;
    bottom: 0.75rem;
    transform: translateX(-50%);
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    color: var(--off-white);
    background: rgba(29, 29, 27, 0.8);
    pointer-events: none;
}

/* --- EXPOSURE DETAILS CARD --- */

.exif-card {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding-bottom: 2.5rem;
    min-width: 0;
    min-height: 0;
}

.exif-card h2 {
    margin: 0 0 1.25rem;
    font-size: clamp(1.4rem, 2.2vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.exif-list {
    margin: 0;
    display: grid;
    gap: 0.3rem;
}

.exif-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: baseline;
}

/* titles */
.exif-row dt {
    font-family: "Swiss721BT-lt", Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    font-size: clamp(0.95rem, 1.3vw, 1.2rem);
    color: var(--ink);
}

.exif-row dd {
    margin: 0;
    font-size: clamp(0.95rem, 1.3vw, 1.2rem);
    color: var(--ink-soft);
    text-align: right;
    overflow-wrap: anywhere;
}

/* --- MOBILE: stack image over details --- */

@media (max-width: 820px) {
    :root {
        /* 4-up below this width leaves tiles too small to read */
        --grid-columns: 2;
    }

    .masthead {
        padding: 2.5rem 1rem 1.5rem;
    }

    .grid {
        padding: 1rem 1rem 3rem;
    }

    .viewer {
        padding: 10px;
    }

    .viewer-card {
    position: relative;
    flex: 0 0 auto;
    margin: auto;
    /* sized against the padded overlay box, so it always fits or scrolls */
    width: min(1600px, 100%);
    height: min(1040px, 100%);
    /* backstop in case the percentage branch fails to resolve */
    max-height: 100%;
    /* nothing inside the card may paint past its edge */
    overflow: hidden;
    background: var(--off-white);
    padding: clamp(1.25rem, 2.5vw, 2.5rem);
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(240px, 24%, 400px);
    /* the row must be constrained or tall images overflow at natural size */
    grid-template-rows: minmax(0, 1fr);
    gap: clamp(1.25rem, 2.5vw, 2.5rem);
}

    .viewer-close {
        top: 0.5rem;
        right: 0.5rem;
        width: 38px;
        height: 38px;
    }

    .exif-card {
        justify-content: flex-start;
        padding-bottom: 0;
    }

    .exif-card h2 {
        margin-bottom: 0.75rem;
    }
}

@media (max-width: 480px) {
    :root {
        --grid-columns: 1;
    }
}

/* respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {

    .viewer,
    .viewer-layer,
    .tile,
    .tile img {
        transition: none;
    }
}