/* ==========================================================
   Image Board styles
   ========================================================== */

:root {
    --bg: #000000;          /* page background */
    --surface: #111111;     /* empty photo tile while it loads */
    --text: #eeeeee;        /* viewer button icons */
    --accent: #00FAB3;      /* mint outline when using the keyboard */

    --edge: clamp(6px, 2vw, 24px);  /* space at the edges of the page */
    --gap: 4px;                     /* space between photos */
    --cols: 2;                      /* photos per row (changes with screen size below) */

    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
}

/* ---------- The photo grid ---------- */

.grid {
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: var(--gap);
    max-width: 1800px;
    margin: 0 auto;
    padding:
        max(var(--edge), env(safe-area-inset-top))
        max(var(--edge), env(safe-area-inset-right))
        max(var(--edge), env(safe-area-inset-bottom))
        max(var(--edge), env(safe-area-inset-left));
}

.tile {
    position: relative;
    display: block;
    aspect-ratio: 4 / 5;
    overflow: hidden;
    border-radius: 3px;
    background: var(--surface);
    cursor: zoom-in;
    -webkit-tap-highlight-color: transparent;
}

.tile img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.4s ease, transform 0.5s ease;
}

/* Photos fade in once they finish loading (only when the script is running) */
.js .tile img {
    opacity: 0;
}

.js .tile img.is-loaded {
    opacity: 1;
}

@media (hover: hover) {
    .tile:hover img {
        transform: scale(1.03);
    }
}

.tile:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- Photos per row by screen size ---------- */

@media (min-width: 560px)  { :root { --cols: 3; } }
@media (min-width: 800px)  { :root { --cols: 4; --gap: 6px; } }
@media (min-width: 1100px) { :root { --cols: 5; --gap: 8px; } }
@media (min-width: 1500px) { :root { --cols: 6; } }

/* ==========================================================
   Full-screen photo viewer
   ========================================================== */

html.viewer-open {
    overflow: hidden;
}

.viewer {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: 80px minmax(0, 1fr) 80px;
    grid-template-rows: auto minmax(0, 1fr) 24px;
    grid-template-areas:
        ".    .     close"
        "prev stage next"
        ".    .     .";
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: #000000;
    animation: viewer-in 0.2s ease-out;
}

.viewer[hidden] {
    display: none;
}

@keyframes viewer-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.viewer-stage {
    grid-area: stage;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 4px 0;
    touch-action: pan-y pinch-zoom;
}

.viewer-img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 2px;
    user-select: none;
    -webkit-user-select: none;
    transition: opacity 0.15s ease;
}

.viewer-img.is-switching {
    opacity: 0;
}

.viewer-btn {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease;
}

.viewer-btn svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.viewer-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.viewer-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.viewer-btn:disabled {
    opacity: 0.25;
    cursor: default;
}

.viewer-btn:disabled:hover {
    background: rgba(255, 255, 255, 0.08);
}

.viewer-close {
    grid-area: close;
    justify-self: center;
    margin: 12px 0;
}

.viewer-prev {
    grid-area: prev;
    place-self: center;
}

.viewer-next {
    grid-area: next;
    place-self: center;
}

/* Phone viewer: arrows sit at the bottom so they're easy to reach with a thumb */
@media (max-width: 699px) {
    .viewer {
        grid-template-columns: 72px minmax(0, 1fr) 72px;
        grid-template-rows: auto minmax(0, 1fr) auto;
        grid-template-areas:
            ".     .     close"
            "stage stage stage"
            "prev  .     next";
    }

    .viewer-close {
        margin: 8px 0;
    }

    .viewer-prev,
    .viewer-next {
        margin: 12px 0 16px;
    }
}

/* Turn off movement for people who've asked their device for less motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
