:root {
  --bg: #0e0f11;
  --surface: #17191c;
  --line: #2b2e33;
  --text: #f1efea;
  --muted: #a3a29c;
  --gutter: clamp(16px, 4vw, 56px);
  color-scheme: dark;
}

* { box-sizing: border-box; scrollbar-width: none; }
::-webkit-scrollbar { display: none; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Helvetica, Arial, "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a { color: inherit; }
img { display: block; width: 100%; height: 100%; object-fit: cover; }
ul { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 13px; font-weight: 500; letter-spacing: 0.04em; color: var(--muted); }

:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

/* Top bar */
.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 24px;
  padding: 18px var(--gutter);
  background: linear-gradient(rgb(14 15 17 / 0.85), rgb(14 15 17 / 0));
}
.topbar a { text-decoration: none; font-size: 13px; }
.topbar a:hover { text-decoration: underline; text-underline-offset: 4px; }
.topbar nav { display: flex; gap: 24px; flex-shrink: 0; }

/* Opening image */
.hero { position: relative; height: 100svh; min-height: 520px; overflow: hidden; }
.hero-media { position: absolute; inset: 0; }
/* Sharp at the top, then increasingly blurred towards the bottom.
   A ready-blurred copy of the image: much lighter to scroll past than a live blur. */
.hero-media::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("images/destrier-night-03-blur.jpg") center / cover;
  -webkit-mask-image: linear-gradient(transparent 55%, #000 85%);
  mask-image: linear-gradient(transparent 55%, #000 85%);
  pointer-events: none;
}
/* Fades the image out into the page background. */
.hero::after {
  content: "";
  position: absolute;
  inset: 50% 0 0;
  background: linear-gradient(rgb(14 15 17 / 0), var(--bg) 92%);
  pointer-events: none;
}
.hero-text { position: absolute; z-index: 1; left: var(--gutter); right: var(--gutter); bottom: clamp(28px, 6vw, 64px); }
.hero h1 { font-size: clamp(30px, 4.5vw, 60px); font-weight: 500; line-height: 1.05; letter-spacing: -0.015em; }
.hero-role { margin-top: 14px; }

/* Work */
.work { padding: clamp(56px, 9vw, 120px) var(--gutter) 0; }
.work-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(36px, 5vw, 64px) clamp(16px, 2.5vw, 32px); margin-top: 24px; }
.project { margin: 0; min-width: 0; }
.project.wide { grid-column: 1 / -1; }
.project-open { display: block; width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.project-open:disabled { cursor: default; }
.project-media { aspect-ratio: 16 / 9; overflow: hidden; background: var(--surface); }
.project.half .project-media { aspect-ratio: 4 / 3; }
.project-media img { transition: transform 500ms ease; }
.project-open:hover .project-media img { transform: scale(1.015); }
.project-caption { display: flex; justify-content: space-between; gap: 24px; padding-top: 12px; }
.project-caption h3 { font-size: 15px; font-weight: 500; }
.project-role { color: var(--muted); font-size: 13px; }
.project-tools { flex-shrink: 0; color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }

/* Shown until the image file exists */
.slot {
  display: grid;
  place-content: center;
  width: 100%;
  height: 100%;
  padding: 16px;
  background: linear-gradient(150deg, #24272c, #131417);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  overflow-wrap: anywhere;
}
.hero-media .slot { padding-bottom: 30vh; }

/* About */
.about { padding: clamp(72px, 10vw, 136px) var(--gutter) clamp(56px, 8vw, 96px); }
.about-text { margin-top: 24px; max-width: 34ch; font-size: clamp(20px, 2.4vw, 30px); line-height: 1.3; }
.about-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--line); }
.about-facts h3 { font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 10px; }
.about-facts span { display: block; color: var(--muted); font-size: 13px; }
.about-facts li + li { margin-top: 4px; }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; overflow: hidden; overscroll-behavior: none; background: rgb(8 9 10); animation: viewer-fade 160ms ease; }
@keyframes viewer-fade { from { opacity: 0; } }
.viewer[hidden] { display: none; }
.viewer figure { margin: 0; width: 100%; }
/* Three screen-wide slides: previous, current and next. Only the track moves. */
.viewer-track { position: relative; height: calc(100svh - 52px); cursor: grab; touch-action: pinch-zoom; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; will-change: transform; }
.viewer-track:active { cursor: grabbing; }
.viewer-slide { position: absolute; inset: 0; display: flex; justify-content: center; padding: 16px clamp(16px, 6vw, 80px) 0; will-change: transform; }
.viewer-slide.before { transform: translateX(-100%); }
.viewer-slide.after { transform: translateX(100%); }
.viewer-slide img, .viewer-slide video, .viewer-slide iframe { display: block; width: 100%; max-width: 1520px; height: 100%; border: 0; object-fit: contain; }
.viewer-slide img { pointer-events: none; } /* Keeps iOS from lifting the image on a long press. */
.viewer img[hidden], .viewer video[hidden], .viewer iframe[hidden], .viewer-clips[hidden] { display: none; }
/* Five clips on one page: two above three. The sizes match the still shown while paging. */
.viewer-clips { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: 425fr 282fr; gap: 6px; align-self: center; width: min(100%, 1520px, calc((100svh - 68px) * 2.126)); aspect-ratio: 1520 / 715; }
.viewer-clips video { grid-column: span 2; max-width: none; min-height: 0; object-fit: cover; pointer-events: none; }
.viewer-clips video:nth-child(-n + 2) { grid-column: span 3; }
.viewer figcaption { padding-top: 10px; color: var(--muted); font-size: 13px; text-align: center; transition: opacity 160ms ease; }
.viewer button { position: absolute; z-index: 1; transition: opacity 160ms ease; width: 48px; height: 48px; border: 0; background: none; color: var(--text); font-size: 34px; line-height: 1; cursor: pointer; }
.viewer-close { top: 8px; right: 8px; }
.viewer-prev { left: 4px; }
.viewer-next { right: 4px; }
.viewer-nav[hidden] { display: none; }
/* Touch screens only: sound for the film, placed on its corner by main.js. */
.viewer .viewer-sound { top: 0; left: 0; display: grid; place-items: center; padding: 0; }
.viewer .viewer-sound[hidden] { display: none; }
.viewer-sound svg { width: 30px; height: 30px; padding: 6px; border-radius: 50%; background: rgb(0 0 0 / 0.6); }
.viewer-sound.on .sound-off, .viewer-sound:not(.on) .sound-on { display: none; }
.viewer .viewer-sound.moving { opacity: 0; }
/* Touch screens only: appears on a tap, placed on the film by main.js. */
.viewer-progress { position: absolute; z-index: 1; top: 0; left: 0; display: flex; align-items: center; height: 32px; cursor: pointer; touch-action: none; transition: opacity 160ms ease; }
.viewer-progress[hidden] { display: none; }
.viewer-progress span { display: block; width: 100%; height: 3px; border-radius: 2px; background: linear-gradient(var(--text), var(--text)) left / var(--played, 0%) 100% no-repeat rgb(241 239 234 / 0.3); }
.viewer-progress.moving, body.viewer-dismissing .viewer-progress { opacity: 0; }
body.viewer-open { overflow: hidden; }
/* Once the viewer covers it, the page has no need to be drawn. */
body.viewer-open main { animation: page-away 0s 160ms forwards; }
@keyframes page-away { to { visibility: hidden; } }
/* While pulling down or closing: the page shows through, and only the image stays. */
body.viewer-dismissing main { animation: none; }
body.viewer-dismissing .viewer-slide.before, body.viewer-dismissing .viewer-slide.after { visibility: hidden; }
body.viewer-dismissing .viewer figcaption, body.viewer-dismissing .viewer button { opacity: 0; }

/* Wider side margins on a computer. The viewer keeps its own margins. */
@media (min-width: 761px) {
  :root { --gutter: max(9vw, calc(50vw - 780px)); }
  /* The image stays the same size and is centred on the screen. main.js places the caption. */
  .viewer-track { height: calc(100svh - 68px); }
  .viewer-slide { padding-top: 0; }
  .viewer figcaption { position: absolute; top: calc(100svh - 17px); left: 56px; right: 56px; padding-top: 0; transform: translateY(-50%); pointer-events: none; }
}

/* Half-width cards get too narrow for the title and details side by side. */
@media (max-width: 1100px) {
  .project.half .project-caption { flex-direction: column; gap: 2px; }
  .project.half .project-tools { text-align: left; }
}

@media (max-width: 760px) {
  .hero { height: 115vw; min-height: 0; } /* Short enough to keep the whole car in frame. */
  /* Same layout as on a computer: wide projects lead, half projects sit in pairs. */
  .work-grid { column-gap: 12px; row-gap: 32px; }
  .project-caption { flex-direction: column; gap: 2px; }
  .project-tools { text-align: left; white-space: normal; }
  .project.half .project-caption { padding-top: 8px; }
  .project.half .project-caption h3 { font-size: 13px; line-height: 1.35; }
  .project.half .project-role, .project.half .project-tools { font-size: 11px; line-height: 1.4; }
  /* Columns as on a computer, two instead of three to fit the width. */
  /* About sits in a narrower block on the left, in smaller type. */
  .about-text { max-width: 270px; font-size: 15px; line-height: 1.45; }
  /* The line above runs the full width; the columns keep to the left. */
  .about-facts { grid-template-columns: repeat(2, minmax(0, 127px)); gap: 24px 16px; margin-top: 36px; padding-top: 20px; font-size: 13px; line-height: 1.45; }
  .about-facts h3, .about-facts span { font-size: 11px; }
  #contact-block { grid-column: 1 / -1; } /* The email address needs the full width. */
  .viewer-nav { top: auto; bottom: 4px; }
  .viewer-clips { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: 405fr 201fr 201fr; gap: 4px; width: min(100%, calc((100svh - 68px) * 0.883)); aspect-ratio: 720 / 815; }
  .viewer-clips video, .viewer-clips video:nth-child(-n + 2) { grid-column: span 1; }
  .viewer-clips video:first-child { grid-column: span 2; }
}

/* An upright phone: the arrows and caption sit in one row, halfway between a wide image
   and the bottom of the screen, and always clear of the tallest (4:5) images. */
@media (max-width: 760px) and (orientation: portrait) {
  .viewer { --nav-y: max(81svh, calc(50svh + 62.5vw + 12px)); }
  .viewer-slide { padding-top: 0; }
  .viewer-nav { top: var(--nav-y); bottom: auto; transform: translateY(-50%); }
  .viewer figcaption { position: absolute; top: var(--nav-y); left: 56px; right: 56px; padding-top: 0; transform: translateY(-50%); pointer-events: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .project-media img { transition: none; }
  .viewer { animation: none; }
}

/* Save as PDF: one landscape page per project */
@media print {
  @page { size: A4 landscape; margin: 0; }
  :root { --bg: #fff; --text: #111; --muted: #555; --line: #ccc; }
  body { font-size: 12pt; }
  .topbar, .viewer { display: none; }
  .hero { height: 210mm; min-height: 0; break-after: page; color: #fff; }
  .hero::after { background: linear-gradient(rgb(0 0 0 / 0), rgb(0 0 0 / 0.8)); }
  .work { padding: 0; }
  .work > h2 { display: none; }
  .work-grid { display: block; margin: 0; }
  .project { height: 210mm; padding: 10mm; break-after: page; break-inside: avoid; }
  .project-media, .project.half .project-media { aspect-ratio: auto; height: 172mm; }
  .project-open:hover .project-media img { transform: none; }
  .about { padding: 18mm; break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
