@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;
}

/* A page-level sentence above the stream: same 40px inset as the title and
   the section rules, so the text column lines up with everything below it. */
.gallery-intro {
    margin: 0 40px 2.5rem;
    max-width: 46rem;
    color: var(--ink-light);
    line-height: 1.6;
}

.gallery-intro a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.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;
}

/* The order control: three words, mono, the active one inked. It sits above the
   stream and takes no more room than a caption line. */
.gallery-views {
    display: flex;
    align-items: baseline;
    gap: 0.9rem;
    margin: 0 40px 1.6rem;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-light);
}

.gallery-views-label {
    opacity: 0.6;
}

.gallery-views button {
    appearance: none;
    background: none;
    border: 0;
    padding: 0 0 0.15rem;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    color: var(--ink-light);
    cursor: pointer;
    border-bottom: 1px solid transparent;
    transition: color 120ms ease-out, border-color 120ms ease-out;
}

.gallery-views button:hover {
    color: var(--ink);
}

.gallery-views button[aria-pressed="true"] {
    color: var(--ink);
    border-bottom-color: var(--ink);
}

.gallery-views button:focus-visible {
    outline: 1px solid var(--ink);
    outline-offset: 3px;
}

/* An invented order is one stream, so the section rules step out of the way. */
.gallery[data-view="colour"] h3,
.gallery[data-view="semantic"] h3 {
    display: none;
}

@media (max-width: 640px) {
    .gallery-views {
        margin: 0 16px 1.2rem;
        gap: 0.7rem;
        flex-wrap: wrap;
    }
}

/* A page that shows a few buildings rather than a stream of pictures: one
   column, the photograph at its own proportions, capped at its source width so
   nothing is upscaled. The square crop is right for the stream and wrong for a
   building, which is taller or wider than a square. */
.gallery--feature .grid {
    grid-template-columns: 1fr;
    justify-items: center;
}

.gallery--feature .grid > li {
    width: 100%;
    max-width: 900px;
}

.gallery--feature .cell {
    aspect-ratio: auto;
}

.gallery--feature .cell img {
    height: auto;
    object-fit: contain;
}

/* The reading time sits under the title, and it carried no styling at all, so it
   hung off the left edge while everything around it was inset. */
body > section.section > .container > .page-meta {
    padding: 0 40px;
    margin: -1.5rem 0 2rem;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    color: var(--ink-light);
}

/* A building can hold several photographs. The page draws the first one and the
   rest are frames the panel walks, so they are in the document and not on it. */
.gallery .image-link[data-extra] {
    display: none;
}

/* The tile says how many there are, quietly, so a reader knows the picture is a
   set before opening it. */
.gallery--feature .cell {
    position: relative;
}

.gallery--feature .cell[data-count]::after {
    content: attr(data-count) " photos";
    position: absolute;
    right: 12px;
    bottom: 12px;
    padding: 2px 7px;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.64rem;
    letter-spacing: 0.09em;
    color: var(--ink);
    background: rgba(0, 0, 0, 0.55);
    pointer-events: none;
}
