/* Design tokens, taken from the Figma file (1442px frame, 10px margin and gutter, 12 columns). */
:root {
  --unit: 10px;
  --gap: var(--unit);
  --margin: var(--unit);

  --text: 15px;
  --lh-tight: 0.92;
  --lh-body: 1.11;
  --tracking: -0.15px;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --weight: 300;

  --header-h: 300px;
  --header-h-about: 331px; /* Figma: about text starts at y=351 */
  --nav-gap: 5px;
  --tile-gap: 10px;
  --tile-pad: 20px;
  --control-gap: 4px;
  --arrow-w: 50px;

  --color-bg: #ffffff;
  --color-fg: #000000;
  --color-ph: #d9d9d9;
  --color-skeleton: #e6e6e6;
  --hover-opacity: 0.4;

  --fade: 400ms;
  --leave: 200ms;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --parallax: 0.4; /* hero moves at 60% of scroll speed */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--color-bg); }

body {
  font-family: var(--font);
  font-weight: var(--weight);
  font-size: var(--text);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking);
  color: var(--color-fg);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
p, h1 { font-size: inherit; font-weight: inherit; text-box: trim-both cap alphabetic; }
img, iframe { display: block; }

/* Page: 12 column grid, every direct child places itself with grid-column. */
.page {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--margin);
  align-content: start;
}

/* ---------- header ---------- */

.header {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  height: var(--header-h);
  align-items: start;
}
.header--about { height: var(--header-h-about); }
.header__name { grid-column: 1 / 5; white-space: nowrap; }
.header__detail { white-space: nowrap; }
.header > .header__detail { grid-column: 5 / 9; }
.header__end { grid-column: 9 / 13; display: flex; justify-content: space-between; align-items: start; }

.nav { display: flex; flex-direction: column; gap: var(--nav-gap); align-items: start; }
.nav__link { text-box: trim-both cap alphabetic; }

/* Hover: name, nav links and Prev/Next fade. */
.header__name a:hover, .nav__link:hover, .control:hover { opacity: var(--hover-opacity); }

/* ---------- images ---------- */

.ph { background: var(--color-ph); width: 100%; height: 100%; }
img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- home ---------- */

.hero { grid-column: 1 / -1; display: block; aspect-ratio: var(--r, 1.5); }

.tiles {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  row-gap: var(--gap);
}
.tile { grid-column: span 4; display: flex; flex-direction: column; gap: var(--tile-gap); padding-bottom: var(--tile-pad); }
.tile__image { aspect-ratio: 3 / 2; }
.tile__title { width: 100%; }

/* ---------- project ---------- */

.controls {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  align-items: start;
}
.control { display: flex; align-items: center; gap: var(--control-gap); white-space: nowrap; }
.control svg { width: var(--arrow-w); height: auto; flex: none; }
.control span { text-box: trim-both cap alphabetic; }
.control--prev { grid-column: 1 / 3; justify-self: start; }
.controls__title { grid-column: 5 / 9; white-space: nowrap; }
.control--next { grid-column: 11 / 13; justify-self: end; }

.main { grid-column: 1 / -1; aspect-ratio: var(--r, 1.5); }
.main--video iframe { width: 100%; height: 100%; border: 0; }

/* Bento rows: each row is its own 12 column grid matching the page grid. */
.row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  row-gap: var(--gap);
  align-items: start;
}
.cell { aspect-ratio: var(--r, 1.5); }
.row--full .cell { grid-column: 1 / -1; }
.row--halves .cell { grid-column: span 6; }
.row--thirds .cell { grid-column: span 4; }
.row--single .cell { grid-column: span 6; }

/* Tall: the portrait fills the height of two stacked landscapes plus the gap between them. */
.row--tall { grid-template-rows: auto auto; }
.row--tall .cell--stack { grid-column: span 6; }
.row--tall .cell--tall { grid-row: 1 / 3; aspect-ratio: auto; align-self: stretch; position: relative; }
.row--tall .cell--tall > * { position: absolute; inset: 0; }
.row--tall-left .cell--tall { grid-column: 1 / 7; }
.row--tall-left .cell--stack { grid-column: 7 / 13; }
.row--tall-right .cell--tall { grid-column: 7 / 13; }
.row--tall-right .cell--stack { grid-column: 1 / 7; }
.row--tall-right .cell--stack:nth-child(2) { grid-row: 1; }
.row--tall-right .cell--stack:nth-child(3) { grid-row: 2; }

/* ---------- about ---------- */

/* About copy is centered in the viewport; it shares the first grid row with the header. */
.page--about { min-height: 100vh; grid-template-rows: minmax(0, 1fr); }
.page--about .header { grid-row: 1; }
/* Centered on the grid, vertically centered in the window. Takes more columns as the window narrows. */
.about { grid-column: 6 / 8; grid-row: 1; align-self: center; line-height: var(--lh-body); }
/* Width stays roughly 355-540px: more columns as the window narrows. Odd spans sit half a column left of center. */
@media (max-width: 2200px) { .about { grid-column: 5 / 8; } }
@media (max-width: 1600px) { .about { grid-column: 5 / 9; } }
@media (max-width: 1200px) { .about { grid-column: 4 / 9; } }
@media (max-width: 1000px) { .about { grid-column: 4 / 10; } }
@media (max-width: 800px)  { .about { grid-column: 3 / 10; } }
@media (max-width: 700px)  { .about { grid-column: 3 / 11; } }
.about p { text-box: none; }
.about p + p { margin-top: calc(var(--text) * var(--lh-body)); }

/* ---------- contact ---------- */

/* Same column and centring as the About copy. Fields are bare: a label, the text, a hairline below. */
.contact__slot { position: relative; }
.contact p + .contact__slot { margin-top: calc(var(--text) * var(--lh-body) * 2); }
.contact__form { display: grid; row-gap: calc(var(--text) * var(--lh-body)); }
/* After sending, the form keeps its space (so nothing moves) and the confirmation sits where it began.
   The confirmation lives in the slot, not the form's grid, so it can't add a track. */
.contact--sent .contact__form { visibility: hidden; }
.contact__sent { position: absolute; top: 0; left: 0; margin: 0; }
.js .contact__sent { animation: fade-in var(--fade) var(--ease) backwards; }
.field { display: grid; row-gap: var(--nav-gap); text-box: none; }
.field input, .field textarea {
  font: inherit; letter-spacing: inherit; line-height: var(--lh-body); color: inherit;
  width: 100%; background: none; border: 0; border-bottom: 1px solid var(--color-fg); border-radius: 0;
  padding: 0 0 var(--nav-gap); outline: none;
}
.field input:focus-visible, .field textarea:focus-visible { box-shadow: 0 1px 0 var(--color-fg); }
.field textarea { resize: none; min-height: calc(var(--text) * var(--lh-body) * 6); }
.field--hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.contact__actions { display: flex; gap: var(--tile-pad); align-items: baseline; text-box: none; }
.contact__send { font: inherit; letter-spacing: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.contact__send:hover { opacity: var(--hover-opacity); }
.contact__send:disabled { opacity: var(--hover-opacity); cursor: default; }

/* ---------- motion ---------- */

/* Skeleton: every image box is a flat grey until its image has loaded. */
.hero, .tile__image, .main, .cell { background: var(--color-skeleton); }
.js img { opacity: 0; transition: opacity var(--fade) var(--ease); }
.js img.is-loaded { opacity: 1; }

/* Arriving: the header fades in only on the first visit, then stays put between pages.
   Text (project name, prev/next, about copy) fades in; image boxes show their skeleton at once
   and each image fades in over its box. Coming from prev/next, the buttons stay as they were. */
@keyframes fade-in { from { opacity: 0; } }
/* "backwards" holds opacity 0 through any delay and releases after, so hover styles still apply. */
.js.first-visit .header, .js .controls__title, .js .control, .js .about { animation: fade-in var(--fade) var(--ease) backwards; }
.js .control { animation-delay: 80ms; }
.js.keep-controls .control { animation: none; }

/* Leaving: content fades out, the header stays. Between projects the prev/next buttons stay too. */
.is-leaving .hero, .is-leaving .tiles, .is-leaving .main, .is-leaving .row, .is-leaving .about, .is-leaving .controls__title,
.is-leaving:not(.is-leaving--keep-controls) .control { opacity: 0; transition: opacity var(--leave) var(--ease); }

/* Home parallax: the hero is pushed down as you scroll, the tiles slide up over it. */
.page--home .hero { position: relative; z-index: 0; will-change: transform; }
.page--home .tiles { position: relative; z-index: 1; background: var(--color-bg); margin-top: calc(-1 * var(--gap)); padding-top: var(--gap); }

@media (prefers-reduced-motion: reduce) {
  .js img { opacity: 1; transition: none; }
  .js .header, .js .controls__title, .js .control, .js .about { animation: none; }
  .page--home .hero { transform: none !important; }
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  :root { --header-h: 200px; --header-h-about: 200px; }
  /* Header collapses to two columns: name and details stacked left, nav right. */
  .header { grid-template-columns: 1fr auto; grid-template-rows: auto auto auto; row-gap: calc(var(--text) * var(--lh-tight) + var(--nav-gap)); align-content: start; }
  .header__name { grid-column: 1; grid-row: 1; }
  .header > .header__detail { grid-column: 1; grid-row: 2; }
  .header__end { display: contents; }
  .header__end .header__detail { grid-column: 1; grid-row: 3; }
  .header__end .nav { grid-column: 2; grid-row: 1 / 4; }

  .tile { grid-column: span 6; }
  .controls__title { grid-column: 3 / 11; justify-self: center; }
}

@media (max-width: 600px) {
  :root { --header-h: 160px; --header-h-about: 160px; }
  .tile { grid-column: 1 / -1; }
  .row--halves .cell, .row--thirds .cell, .row--single .cell,
  .row--tall .cell--stack, .row--tall .cell--tall { grid-column: 1 / -1; }
  .row--tall { grid-template-rows: none; }
  .row--tall .cell--tall { grid-row: auto; aspect-ratio: var(--r, 0.75); position: static; }
  .row--tall .cell--tall > * { position: static; }
  .row--tall-right .cell--stack:nth-child(2), .row--tall-right .cell--stack:nth-child(3) { grid-row: auto; }
  .controls__title { grid-column: 4 / 10; }
  .control--prev { grid-column: 1 / 4; }
  .control--next { grid-column: 10 / 13; }
  .control svg { width: 30px; }
  /* Phone: copy flows below the header at full width. */
  .page--about { min-height: 0; grid-template-rows: none; }
  .about { grid-column: 1 / -1; grid-row: auto; align-self: start; }
}
