/* ==========================================================================
   Tokens
   Raw scale (--text-*, --space-*) → semantic aliases → utility classes.
   Components use aliases and classes only.
   ========================================================================== */

:root {
  /* Raw type scale */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-md: 1.25rem;
  --text-lg: 1.375rem;
  --text-xl: clamp(1.5rem, 1.3rem + 0.8vw, 1.875rem);
  --text-2xl: clamp(1.875rem, 1.5rem + 1.4vw, 2.5rem);
  --text-3xl: clamp(2.25rem, 1.7rem + 2.2vw, 3.5rem);
  --text-4xl: clamp(2.75rem, 1.9rem + 3.4vw, 4.75rem);
  --text-5xl: clamp(3.25rem, 1.9rem + 5.6vw, 7.5rem);

  /* Raw spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;
  --space-9: 6rem;
  --space-10: 8rem;

  /* Semantic type aliases */
  --display: var(--text-5xl);
  --heading-01: var(--text-4xl);
  --heading-02: var(--text-3xl);
  --heading-03: var(--text-2xl);
  --heading-04: var(--text-xl);
  --heading-05: var(--text-lg);
  --intro: var(--text-xl);
  --lead: var(--text-md);
  --body: var(--text-md);
  --body-md: var(--text-base);
  --body-sm: var(--text-sm);
  --meta: var(--text-xs);

  /* Semantic spacing aliases */
  /* Fluid layout up to --max-width. One side margin for text and images; steps up at 48rem and 75rem, then grows to keep content within --max-width */
  --gutter: var(--space-5);
  /* How far images and hairlines run out past the text into the side margin */
  --bleed: min(calc(var(--gutter) / 2), calc(var(--space-8) / 2));
  --section-gap: var(--space-9);
  --stack-sm: var(--space-3);
  --stack: var(--space-5);
  --stack-lg: var(--space-7);

  /* Layout */
  --max-width: 62.5rem; /* 1000px: content and side margins together */
  --content-width: 56.25rem; /* 900px: case study copy, centred under the images */
  --measure: 65ch;
  --measure-intro: 46ch;
  --thumb-width: 20rem;
  --rule: 1px;

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --reveal-distance: var(--space-6);
  --reveal-duration: 0.9s;

  /* Type */
  --font-sans: "Fira Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;

  /* Colour */
  --color-page: #ffffff;
  --color-bg: var(--color-page);
  --color-surface: #ffffff;
  --color-text: #141414;
  --color-text-muted: #5c5c58;
  /* Dividers: black at low opacity on light backgrounds (case studies switch to white on dark ones) */
  --color-border: rgb(0 0 0 / 0.12);
  /* Tint behind rows of two or more gallery images: dark on light pages (case studies on a dark
     page colour switch it to a light one) */
  --color-overlay: rgb(0 0 0 / 0.03);
  --color-accent: #2f4bff;
  --color-accent-contrast: #ffffff;
  /* White: header and labels sitting on images */
  --color-invert: #ffffff;
  /* Darkening behind the next-project title, so it reads over a light image */
  --color-scrim: rgb(0 0 0 / 0.65);
  /* Dark text for use over pale images */
  --color-ink: #141414;

  --nav-height: 3.5rem;
  /* Case study hero height: 16:9 (3:2 on mobile), never taller than the screen. The next
     project's peek uses the same so it lands exactly. */
  --hero-height: min(56.25vw, 100vh);

  color-scheme: light;
}

@media (max-width: 47.99rem) {
  :root {
    --hero-height: min(66.667vw, 100vh);
    /* Tighter gaps between the header, intro and project list (case studies set their own) */
    --section-gap: var(--space-7);
  }
}

@media (min-width: 48rem) {
  :root {
    --gutter: max(var(--space-7), calc((100vw - var(--max-width)) / 2));
  }
}

@media (min-width: 75rem) {
  :root {
    /* Past --max-width the margin grows, so text, images and the fixed header stay aligned */
    --gutter: max(var(--space-8), calc((100vw - var(--max-width)) / 2));
  }
}

/* ==========================================================================
   Base
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

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

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Selected text is the page inverted: text colour behind, page colour on top. Case studies swap
   both tokens, so it follows their light or dark colours. */
::selection {
  background: var(--color-text);
  color: var(--color-bg);
}

main {
  flex: 1;
}

img,
svg,
video {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
  text-decoration-thickness: var(--rule);
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--color-accent);
}

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

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -100%;
  padding: var(--space-2) var(--space-4);
  background: var(--color-text);
  color: var(--color-bg);
}

.skip-link:focus {
  top: var(--space-2);
}

/* ==========================================================================
   Type utilities — one class per semantic alias
   ========================================================================== */

.display,
.heading-01,
.heading-02,
.heading-03,
.heading-04,
.heading-05 {
  font-weight: 600;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.display {
  font-size: var(--display);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.heading-01 {
  font-size: var(--heading-01);
  line-height: 1;
  letter-spacing: -0.035em;
}

.heading-02 {
  font-size: var(--heading-02);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.heading-03 {
  font-size: var(--heading-03);
  line-height: 1.15;
}

.heading-04 {
  font-size: var(--heading-04);
  line-height: 1.25;
}

.heading-05 {
  font-size: var(--heading-05);
  font-weight: 500;
  line-height: 1.3;
}

/* Large first-person statement paragraphs */
.intro {
  font-size: var(--intro);
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.02em;
  max-width: var(--measure-intro);
  text-wrap: pretty;
}

.lead {
  font-size: var(--lead);
  line-height: 1.5;
  color: var(--color-text-muted);
  text-wrap: pretty;
}

.body {
  font-size: var(--body);
  line-height: 1.6;
}

.body-md {
  font-size: var(--body-md);
  line-height: 1.5;
}

.body-sm {
  font-size: var(--body-sm);
  line-height: 1.5;
}

.meta {
  font-size: var(--meta);
  line-height: 1.4;
  color: var(--color-text-muted);
}

.muted {
  color: var(--color-text-muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Link that recedes until hovered */
.subtle-link {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.subtle-link:hover {
  color: var(--color-text);
}

/* Unstyled list with a relaxed rhythm */
.plain-list {
  padding: 0;
  list-style: none;
}

.plain-list > li + li {
  margin-top: var(--space-2);
}

/* Columns with a hairline under each item. Set --columns inline for more than two. */
.plain-list--columns {
  display: grid;
  column-gap: var(--stack);
}

.plain-list--columns > li {
  padding-block: var(--space-2);
  border-bottom: var(--rule) solid var(--color-border);
}

.plain-list--columns > li + li {
  margin-top: 0;
}

@media (min-width: 48rem) {
  .plain-list--columns {
    grid-template-columns: repeat(var(--columns, 2), minmax(0, 1fr));
  }
}

/* Token / code names: mono at meta size, case preserved */
.token {
  font-family: var(--font-mono);
  font-size: var(--meta);
  line-height: 1.4;
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

/* Scroll reveal: only once ScrollReveal has opted in, so content is visible without JS */
.reveal-ready [data-reveal] {
  opacity: 0;
  translate: 0 var(--reveal-distance);
  transition:
    opacity var(--reveal-duration) var(--ease-out) calc(var(--reveal-delay, 0s) + var(--reveal-extra, 0s)),
    translate var(--reveal-duration) var(--ease-out) calc(var(--reveal-delay, 0s) + var(--reveal-extra, 0s));
}

.reveal-ready [data-reveal].is-revealed {
  opacity: 1;
  translate: none;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.container {
  width: 100%;
  padding-inline: var(--gutter);
}

.section {
  padding-block: var(--section-gap);
}

.section + .section {
  padding-top: 0;
}

/* Extra room under the last block of a case study, before the footer */
.case > .section:last-child {
  padding-bottom: calc(var(--section-gap) * 2);
}

.stack > * + * {
  margin-top: var(--stack);
}

.stack-sm > * + * {
  margin-top: var(--stack-sm);
}

.stack-lg > * + * {
  margin-top: var(--stack-lg);
}

.measure {
  max-width: var(--measure);
}


/* Label column + content column, divided from what's above by a hairline */
.split {
  position: relative;
  display: grid;
  gap: var(--stack);
  padding-top: var(--stack);
}

/* The hairline is its own layer so it can draw in from the left */
.split::before {
  content: '';
  position: absolute;
  top: 0;
  left: calc(var(--gutter) - var(--bleed));
  right: calc(var(--gutter) - var(--bleed));
  height: var(--rule);
  background: var(--color-border);
  transform-origin: left;
}

.reveal-ready .split::before {
  transform: scaleX(0);
  transition: transform 1.4s var(--ease-out) var(--reveal-delay, 0s);
}

.reveal-ready .split.is-revealed::before {
  transform: none;
}

@media (min-width: 48rem) {
  .split {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    gap: var(--stack-lg);
  }
}

/* ==========================================================================
   Components
   ========================================================================== */

/* Nav */
/* Scrolls away with the page */
.nav {
  height: var(--nav-height);
}

.nav__inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--stack);
}

.nav__brand {
  color: var(--color-text);
  font-weight: 400;
}

/* Footer */
.footer {
  padding-block: var(--space-6);
}

/* Case studies have no footer: they end on the next project */
html:has(.case) .footer {
  display: none;
}

.footer__inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--stack-sm);
}

.footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  padding: 0;
  list-style: none;
}

/* Plain links: no underline, and the colour stays the text colour on hover too */
.footer__links a,
.footer__links a:hover {
  color: inherit;
  text-decoration: none;
}

/* Section header */
.section-header {
  font-size: var(--body-sm);
  font-weight: 400;
  line-height: 1.5;
  color: var(--color-text-muted);
}

/* Close button on case studies: a black square with a white cross, pinned to the top right
   corner of the screen */
.back-link {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  background: var(--color-ink);
  text-decoration: none;
  view-transition-name: back-link;
}

.back-link svg {
  stroke: var(--color-invert);
}

/* Comes in on its own once the page is there: a soft fade and rise in size. Only when arriving
   from the home list; between projects it stays put. When the hero grows in from the list, it
   waits for that to land. */
html:not([data-no-hero-enter]) .back-link {
  animation: close-in 0.7s var(--ease-out) 0.3s backwards;
}

html[data-hero-morph]:not([data-no-hero-enter]) .back-link {
  animation-delay: 1s;
}

@keyframes close-in {
  from {
    opacity: 0;
    scale: 0.8;
  }
}

@media (prefers-reduced-motion: reduce) {
  .back-link {
    animation: none;
  }
}

/* The name is left off case study pages */
html:has(.case) .nav__brand {
  visibility: hidden;
}

/* Case study hero: full width at --hero-height, running up under the header.
   It stays pinned while the content below scrolls up over it. */
.case-hero {
  position: sticky;
  top: 0;
  /* Explicit stacking: the content sections below sit above the hero (z-index 1). Left to
     source order, Safari on iOS can paint the zoomed hero over them. */
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--hero-height);
  margin-top: calc(var(--nav-height) * -1);
  overflow: hidden;
}

/* Content sections sit over the pinned hero, so they need to cover it */
.case > .section {
  position: relative;
  z-index: 1;
  background: var(--color-bg);
}

.case-hero__media {
  flex: none;
  width: 100%;
  height: 100%;
  view-transition-name: project-hero;
}

.case-hero__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* As the page scrolls over the pinned hero, the picture zooms in (20% by the time it is
   covered; the hero's edges clip it, so no gaps show). Driven by the scroll position, so it
   needs no script; browsers without scroll-driven animations simply leave it still. */
@supports (animation-timeline: scroll()) {
  .case-hero__media img {
    animation: hero-zoom linear both;
    animation-timeline: scroll(root block);
    animation-range: 0 var(--hero-height);
  }

  @media (prefers-reduced-motion: reduce) {
    .case-hero__media img {
      animation: none;
    }
  }
}

@keyframes hero-zoom {
  to {
    scale: 1.2;
  }
}

/* Where there is no thumbnail to morph from (touch and narrow screens), the hero enters by
   itself when you arrive from the list: it wipes down from the top edge while settling in
   from slightly zoomed. */
@media not all and (hover: hover) and (pointer: fine) and (min-width: 48rem) {
  html:not([data-no-hero-enter]) .case-hero__media {
    transform-origin: top;
    animation: hero-enter 1s var(--ease-out) backwards;
  }
}

@keyframes hero-enter {
  from {
    clip-path: inset(0 0 100% 0);
    transform: translateY(-6%) scale(1.1);
  }

  to {
    clip-path: inset(0);
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .case-hero .case-hero__media {
    animation: none;
  }
}

/* Page navigations: only the project thumbnail morphs into the hero; the rest swaps instantly */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
}

::view-transition-group(project-hero) {
  /* Above the page, under the close button (10) */
  z-index: 5;
  animation-duration: 1s;
  /* Even in and out: no lunge at the start, no crawl at the end */
  animation-timing-function: cubic-bezier(0.55, 0, 0.1, 1);
}

/* One picture does the whole move, so there is no cross-fade and nothing see-through.
   Opening a project: the sharp hero is shrunk down to the thumbnail's size and grows from
   there, rather than stretching up a small thumbnail. Going back, the hero shrinks into the
   row. Both ends are the same 16:9 picture, so the start and end frames match. */
::view-transition-old(project-hero),
::view-transition-new(project-hero) {
  width: 100%;
  height: 100%;
  object-fit: cover;
  mix-blend-mode: normal;
  animation: none;
  opacity: 1;
}

/* The old picture stays on screen under the new one until the new page has painted, so nothing
   goes blank while it loads (scrolling on from one project to the next, or opening from the list).
   Opening from the list, the thumbnail itself is the start of the move and grows with the box,
   so the picture scales instead of being revealed through a small window. The hero (already
   cropped to the screen) only fades in over it late, once it is nearly full size. */

html[data-hero-morph]::view-transition-new(project-hero) {
  animation: vt-fade-in 0.5s ease-in-out 0.45s both;
}

/* Opening a project from the list: the list stays on screen while the hero grows over it,
   and the project page fades in slowly underneath as the hero grows, so nothing disappears. */
html[data-hero-morph]::view-transition-old(root),
html[data-hero-morph]::view-transition-new(root) {
  mix-blend-mode: normal;
}

html[data-hero-morph]::view-transition-new(root) {
  animation: vt-fade-in 0.8s var(--ease-in-out) 0.3s both;
}

/* Returning to the list: one continuous zoom from the hero down into its row, while the
   case study around it cross-fades out */
html[data-returning]::view-transition-group(project-hero) {
  animation-duration: 0.9s;
}

html[data-returning]::view-transition-old(project-hero) {
  display: block;
}

html[data-returning]::view-transition-new(project-hero) {
  display: none;
}

/* On phones the list has no thumbnail to zoom into, so the hero has nothing to land on. Left to
   itself it would sit on top, fully opaque, and then vanish when the transition ends. Fade it
   out with the rest of the page instead. */
html[data-returning]::view-transition-old(project-hero):only-child {
  animation: vt-fade-out 0.45s var(--ease-out) both;
}

html[data-returning]::view-transition-old(root) {
  animation: vt-fade-out 0.45s var(--ease-out) both;
  mix-blend-mode: normal;
}

html[data-returning]::view-transition-new(root) {
  mix-blend-mode: normal;
}

@keyframes vt-fade-out {
  to {
    opacity: 0;
  }
}

/* Layers during a page transition, lowest to highest: the page (header included), the
   morphing hero, then the close button. */
::view-transition-group(back-link) {
  z-index: 10;
}

/* The Back link: between two case studies it is on both pages, so it just stays put. It only
   fades when it is arriving (from the list) or leaving (to the list). */
::view-transition-old(back-link) {
  animation: none;
  opacity: 0;
  mix-blend-mode: normal;
}

::view-transition-new(back-link) {
  animation: none;
  mix-blend-mode: normal;
}

::view-transition-old(back-link):only-child {
  opacity: 1;
  animation: vt-fade-out 0.2s var(--ease-out) both;
}

@keyframes vt-fade-in {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(project-hero) {
    animation: none;
  }

  ::view-transition-old(back-link),
  ::view-transition-new(back-link) {
    animation: none;
  }
}

/* Project list */
.project-list__items {
  /* Hairlines run wider than the text; rows pad back in so the text stays on the margin */
  margin-inline: calc(var(--bleed) * -1);
  padding: 0;
  list-style: none;
}

.project-list__row {
  padding-inline: var(--bleed);
  display: block;
  padding-block: var(--space-5);
  border-top: var(--rule) solid var(--color-border);
  text-decoration: none;
  transition: color 0.2s;
}

/* Phones and touch: each row carries its own thumbnail, which grows into the hero */
.project-list__thumb {
  display: block;
  width: 100%;
  /* Same proportions as the case study hero (3:2 on phones), so the picture grows and shrinks
     without its crop changing at the end of the move */
  aspect-ratio: 16 / 9;
  object-fit: cover;
  margin-bottom: var(--space-3);
}

@media (max-width: 47.99rem) {
  .project-list__thumb {
    aspect-ratio: 3 / 2;
  }
}

@media (min-width: 48rem) and (hover: hover) and (pointer: fine) {
  .project-list__thumb {
    display: none;
  }
}

.project-list__title {
  display: block;
  font-weight: 400;
  transition: opacity 0.2s;
}

.project-list__items > li:first-child .project-list__row {
  padding-top: 0;
  border-top: 0;
}

.project-list__row:hover,
.project-list__row:focus-visible,
.project-list__row:hover > *,
.project-list__row:focus-visible > * {
  color: var(--color-text);
}

@media (hover: hover) and (pointer: fine) {
  /* Only the titles dim; the dividers stay as they are */
  .project-list__items:hover .project-list__row:not(:hover) .project-list__title {
    opacity: 0.35;
  }
}

.project-list {
  position: relative;
}

/* Follows the cursor; position is set from script */
.project-list__preview {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  width: var(--thumb-width);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  pointer-events: none;
  will-change: transform;
  opacity: 0;
  scale: 0.96;
  transition: opacity 0.4s, scale 0.7s cubic-bezier(0.22, 1, 0.36, 1),
    aspect-ratio 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

@media (min-width: 48rem) and (hover: hover) and (pointer: fine) {
  .project-list__preview {
    display: block;
  }
}

.project-list__preview.is-visible {
  opacity: 1;
  scale: 1;
}

/* Inner layer, shifted against the motion for parallax */
.project-list__frame {
  position: absolute;
  inset: 0;
  will-change: transform;
}

.project-list__preview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  visibility: hidden;
}

.project-list__preview img.is-active {
  visibility: visible;
  z-index: 2;
}

.project-list__preview img.is-prev {
  visibility: visible;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  .project-list__row,
  .project-list__preview {
    transition: none;
  }
}

/* Prose (rendered markdown) */
.prose {
  max-width: var(--measure);
}

.prose > * + * {
  margin-top: var(--stack);
}

.prose h2 {
  font-size: var(--heading-05);
  line-height: 1.3;
  font-weight: 500;
  letter-spacing: -0.015em;
  margin-top: var(--stack-lg);
}

.prose h3 {
  font-size: var(--body);
  line-height: 1.5;
  font-weight: 500;
  margin-top: var(--stack-lg);
}

.prose > :first-child {
  margin-top: 0;
}

.prose ul,
.prose ol {
  padding-left: var(--space-5);
}

/* Case study — proportions follow the Kus Studio case study layout */
.case {
  --section-gap: var(--space-8);
}

/* Same size and weight as the project links on the home page */
.case-title {
  /* Same centred column as the copy below; fills its width instead of balancing short lines */
  width: 100%;
  max-width: var(--content-width);
  margin-inline: auto;
  margin-bottom: var(--stack);
  font-weight: 400;
  text-wrap: pretty;
}

/* Text sections are a single column, full width, with no hairline above */
.case .split {
  padding-top: 0;
}

/* Copy is a narrower column than the image sections, centred under them */
.case .split > * {
  width: 100%;
  max-width: var(--content-width);
  margin-inline: auto;
}

.case .split::before {
  display: none;
}

@media (min-width: 48rem) {
  .case .split {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--stack);
  }
}

.services-list > li {
  font-size: var(--body-md);
  line-height: 1.5;
  padding-block: var(--space-3);
}

/* A hairline above the first row too: the first item on small screens (one column), the first
   three from 48rem (three columns) */
.services-list > li:first-child {
  border-top: var(--rule) solid var(--color-border);
}

@media (min-width: 48rem) {
  .services-list > li:nth-child(-n + 3) {
    border-top: var(--rule) solid var(--color-border);
  }
}

/* Gallery: rows of images, 1200px at most (the 1000px content width plus 100px each side on wide
   screens), flat corners */
.gallery {
  --gallery-gap: var(--space-5);
  /* Padding inside tinted rows of two or more images */
  --gallery-pad: var(--gallery-gap);
  display: grid;
  gap: var(--gallery-gap);
}

@media (min-width: 48rem) {
  .gallery {
    --gallery-gap: var(--space-7);
    --gallery-pad: 5rem; /* 80px */
  }
}

@media (min-width: 75rem) {
  .gallery {
    margin-inline: -6.25rem; /* 100px: content 1000px -> images 1200px */
  }
}

/* One row per single image, pair or row of three */
.gallery__section {
  display: grid;
  gap: var(--gallery-gap);
  align-items: start;
}

/* Pairs and rows of three sit side by side from 48rem */
@media (min-width: 48rem) {
  .gallery__section {
    grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  }
}

/* Below that they become a side-swipe row: the first image fills most of the width and the
   next peeks in from the right, snapping one image at a time */
@media (max-width: 47.99rem) {
  .gallery__section--multi {
    display: flex;
    overflow-x: auto;
    /* Horizontal only: left as auto it also scrolls vertically (by a few px), which catches
       up-and-down swipes that start over a row */
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: var(--gallery-pad);
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .gallery__section--multi::-webkit-scrollbar {
    display: none;
  }

  .gallery__section--multi > figure {
    flex: 0 0 78%;
    scroll-snap-align: start;
  }
}

/* A row at one height: each image is as wide as its proportions need. Below 48rem it is the
   side-swipe row, with every image at the same set height instead of a share of the width. */
@media (max-width: 47.99rem) {
  .gallery__section--row > figure {
    flex: 0 0 auto;
  }

  .gallery .gallery__section--row img {
    width: auto;
    max-width: none;
    height: 14rem;
  }
}

@media (min-width: 48rem) {
  .gallery__section--row {
    display: flex;
  }

  .gallery__section--row > figure {
    flex: var(--ratio) 1 0;
    min-width: 0;
  }
}

/* Two or more images: padded and tinted. A single image runs full width with neither. */
.gallery__section--multi {
  padding: var(--gallery-pad);
  background: var(--color-overlay);
}

/* A very slight lift for each image in those rows (the phone frame carries it for phones) */
.gallery__section--multi img:not(.phone img),
.gallery__section--multi .phone {
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.03), 0 4px 14px rgb(0 0 0 / 0.03);
}

/* Mobile screenshots sit in a plain white device shape: just the outline, no notch or
   buttons. The one place on the site with rounded corners. */
.phone {
  --phone-pad: 0.625rem; /* 10px */
  --phone-radius: var(--space-5);
  padding: var(--phone-pad);
  background: var(--color-invert);
  border-radius: var(--phone-radius);
}

.gallery .phone img {
  border-radius: calc(var(--phone-radius) - var(--phone-pad));
}

.gallery__embed {
  display: block;
  width: 100%;
  height: var(--embed-height, 47.5rem); /* stacked layout on narrow screens */
  border: 0;
}

/* The embedded page switches to its wide layout at 992px of its own width, which the gallery
   reaches at a 68rem window */
@media (min-width: 68rem) {
  .gallery__embed {
    height: var(--embed-height, 27.5rem);
  }
}

.gallery img {
  display: block;
  width: 100%;
  height: auto;
}

.gallery figcaption {
  margin-top: var(--space-2);
}



/* Next project: its hero peeks in below the footer. Script lifts it to fill the screen. */
.next-hero {
  --peek: 30vh;
  position: relative;
  /* Above the case study sections (z-index 1), so it rises over them, not under */
  z-index: 2;
  height: var(--peek);
}

.next-hero__backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  /* Fades from this page's colour to the next project's as the hero rises (--p runs 0 to 1), so
     the colour is already right when that page opens */
  background: color-mix(in srgb, var(--next-bg) calc(var(--p, 0) * 100%), var(--color-bg));
  opacity: 0;
  pointer-events: none;
}

.next-hero__link {
  display: block;
  height: 100%;
  text-decoration: none;
}

/* Shows only the top of the hero; script grows it upward as it rises */
.next-hero__layer {
  position: relative;
  height: 100%;
  overflow: hidden;
  will-change: transform, height;
}

.next-hero__media {
  width: 100%;
  height: var(--hero-height);
}

.next-hero__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Darkens the top of the peek, behind the title; fades out as the hero rises, so the hero
   that opens next has none */
.next-hero__scrim {
  position: absolute;
  inset: 0 0 auto;
  height: var(--peek);
  background: linear-gradient(var(--color-scrim) 55%, transparent);
  pointer-events: none;
}

.next-hero__text {
  position: absolute;
  top: var(--space-6);
  left: var(--gutter);
  right: var(--gutter);
  display: grid;
  gap: var(--space-1);
  color: var(--color-invert);
}

/* The title runs the full width of the content area rather than the intro measure */
.next-hero__text .intro {
  max-width: none;
}

/* Design system page */
.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: var(--stack);
}

.swatch__chip {
  height: var(--space-9);
  border: var(--rule) solid var(--color-border);
  margin-bottom: var(--space-2);
}

.type-specimen {
  display: grid;
  gap: var(--space-2);
  padding-block: var(--stack);
  border-bottom: var(--rule) solid var(--color-border);
}

@media (min-width: 48rem) {
  .type-specimen {
    grid-template-columns: 12rem minmax(0, 1fr);
    align-items: baseline;
  }
}

.space-bar {
  height: var(--space-4);
  background: var(--color-accent);
}

.space-row {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  align-items: center;
  gap: var(--stack-sm);
}
