@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500&family=JetBrains+Mono:ital,wght@0,400;1,400&display=swap");

:root {
    color-scheme: light dark;

    --paper: #f5f2eb;
    --paper-dark: #ebe7dc;
    --ink: #1a1a1a;
    --ink-light: #6b6b6b;
    --rule: rgba(26, 26, 26, 0.12);
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #171614;
        --paper-dark: #100f0e;
        --ink: #f2f0ec;
        --ink-light: #a09a91;
        --rule: rgba(242, 240, 236, 0.14);
    }
}

/* The canvas is painted from the root element, and the body below carries the
   same colour, so the reader never sees two shades of the page background. */
html {
    background: var(--paper);
}

body {
    max-width: none;
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

/* The stream runs edge to edge, so the page chrome carries its own margin. */
body > section.section > .container > h1 {
    padding: 0 40px;
    font-weight: 500;
    font-size: 2rem;
    letter-spacing: -0.015em;
    margin: 64px 0 32px;
}

.gallery h3 {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-weight: 400;
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-light);
    margin: 3.5rem 40px 1.1rem;
    padding-bottom: 0.7rem;
    border-bottom: 1px solid var(--rule);
    display: flex;
    align-items: baseline;
    gap: 1rem;
}

.gallery h3::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--rule);
    transform: translateY(-0.25em);
}

.gallery h3:first-of-type {
    margin-top: 0;
}

/* The stream: square tiles packed edge to edge, so the pictures are the page and
   no gutter, border or caption block takes room from them. */
.gallery .grid {
    list-style: none;
    margin: 0 0 3rem;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0;
    content-visibility: auto;
    contain-intrinsic-size: auto 900px;
}

.gallery .grid > li {
    position: relative;
    background: var(--paper-dark);
    min-width: 0;
    overflow: hidden;
    /* The app links here as `#<slug>`; keep the tile clear of the fixed
       back link so a jump does not land under it. */
    scroll-margin-top: 3.5rem;
}

.gallery .cell {
    aspect-ratio: 1;
    background: var(--paper-dark);
    padding: 0;
    overflow: hidden;
}

.gallery .image-link {
    display: block;
    width: 100%;
    height: 100%;
    color: inherit;
    text-decoration: none;
}

.gallery .image-link:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: -4px;
}

.gallery .cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 500ms ease;
}

.gallery .grid > li:hover .cell img {
    transform: scale(1.04);
}

/* The caption sits on the picture, over a scrim, and comes up when the tile is
   pointed at or reached by the keyboard. It is not hit-testable, so a click
   anywhere on the tile still opens the picture. */
.gallery .meta {
    position: absolute;
    inset: auto 0 0 0;
    padding: 36px 12px 10px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0));
    opacity: 0;
    transition: opacity 180ms ease;
    pointer-events: none;
}

.gallery .grid > li:hover .meta,
.gallery .grid > li:focus-within .meta {
    opacity: 1;
}

/* The site's keyboard cursor is a data attribute, not focus, so it needs its own
   rule: walking the gallery with j and k has to name the picture it is on, the
   same way the pointer does. */
.gallery .grid > li[data-nav-cursor="true"] .meta {
    opacity: 1;
}

.gallery .meta .title {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.25;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
    /* Break a long title evenly rather than leaving one word on its own line. */
    text-wrap: balance;
}

.gallery .meta .sub {
    margin: 4px 0 0;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-style: italic;
    font-size: 0.7rem;
    letter-spacing: 0.01em;
    color: rgba(255, 255, 255, 0.78);
    line-height: 1.35;
    text-wrap: balance;
}

/* A finger has no hover, so on a touch screen the caption sits on the tile the
   whole time. There it has to earn its room: smaller type and a shallower
   scrim, so the picture keeps most of the tile it is on. */
@media (hover: none) {
    .gallery .meta {
        opacity: 1;
        padding: 16px 8px 6px;
    }
    .gallery .meta .title {
        font-size: 0.7rem;
        line-height: 1.2;
    }
    .gallery .meta .sub {
        margin-top: 2px;
        font-size: 0.6rem;
        line-height: 1.2;
    }
}

/* Phones. Two columns of squares, so a tile is about the size it is on a
   desktop, and the page chrome gives back the room it was holding. */
@media (max-width: 640px) {
    body > section.section > .container > h1 {
        padding: 0 16px;
        font-size: 1.4rem;
        /* Clear of the fixed back link, which ends 36px down. */
        margin: 40px 0 20px;
    }
    .gallery h3 {
        margin: 2rem 16px 0.7rem;
        padding-bottom: 0.55rem;
        font-size: 0.72rem;
        letter-spacing: 0.14em;
    }
    .gallery .grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    footer {
        padding: 0 16px;
    }
}

footer {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-light);
    margin-top: 4rem;
    padding: 0 40px;
}

footer hr {
    border: none;
    border-top: 1px solid var(--rule);
}

footer a {
    color: var(--ink-light);
    text-decoration: none;
}

footer a:hover {
    color: var(--ink);
}

/* The keyboard cursor hugs the tile. Tiles sit flush against each other, so an
   outset ring would land on the picture beside it. */
.gallery .grid > li[data-nav-cursor="true"] {
    outline-offset: -3px;
}
