/* ─── Sheet ────────────────────────────────────────────────

   The A4 CV carried onto the screen. A side title of fitted type runs up the
   left edge; everything else sits in a nine-column content block beside it.
   Ink, one grey and a paper tint; the cv-a4 blue is spent only on
   interaction (hover, focus, selection).

   Vertical rhythm: a 20 px line (--line-height) with 10 px half-steps. Text, small
   text and the larger sizes all take line heights that are multiples of the
   half-step, and rules are subtracted from the padding that follows them so
   they never push the grid off. */

/* ─── Reset ────────────────────────────────────────────── */

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

ol,
ul {
  list-style: none;
}

h1,
h2,
h3,
h4,
h5,
h6,
button {
  font: inherit;
  color: inherit;
}

p{
  max-width: 65ch;
}

/* One weight throughout; hierarchy comes from size, rules and grey. */
strong,
b {
  font-weight: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

img,
video,
iframe {
  display: block;
  max-width: 100%;
  border: 0;
}

/* ─── Tokens ───────────────────────────────────────────── */

:root {
  --paper: #fff;
  --ink: #3d3d3d;
  --grey: #77766f;
  --image-background: #efeee9;
  --accent: #3c3cff;

  --margin: clamp(16px, 2.2vw, 40px);
  --gutter: clamp(12px, 1.2vw, 20px);
  --rule-thin: 1px;
  --rule-thick: 3px;

  --line-height: 20px;
  --space-small: 10px;
  --space-medium: 20px;
  --space-large: 40px;
  --space-between-projects: 60px;
  --space-between-sections: 80px;

  --text-small: 12px;
  --text-normal: 15px;
  --text-large: clamp(22px, 1rem + 1.3vw, 36px);
  --text-title: clamp(26px, 1rem + 1.7vw, 44px);

  /* The side title takes two of twelve columns on every page, so the content
     edge never moves; a long title just runs thinner inside it. */
  --side-column: calc((100vw - var(--margin) * 2 - var(--gutter) * 11) / 6 + var(--gutter));
}

/* Line heights rounded up to the half-step, so large type stays on grid. */
@supports (line-height: round(up, 1em, 10px)) {
  :root {
    --line-height-large: round(up, 1.12em, var(--space-small));
    --line-height-title: round(up, 1em, var(--space-small));
  }
}

::selection {
  background: var(--accent);
  color: var(--paper);
}

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

/* ─── Page ─────────────────────────────────────────────── */

html {
  scroll-behavior: smooth;
  max-width: 1920px;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Sheet", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: var(--text-normal);
  line-height: var(--line-height);
  font-variant-numeric: tabular-nums;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.page {
  display: grid;
  grid-template-columns: var(--side-column) minmax(0, 1fr);
  column-gap: var(--gutter);
  min-height: 100svh;
  padding: var(--margin);
}

.align-right {
  text-align: right;
}

a:hover,
a[aria-current]:hover {
  color: var(--accent);
}

/* ─── Side title ───────────────────────────────────────── */

/* Set bottom-to-top like a book spine and held in view while the content
   scrolls. sheet.js fits it to the viewport height, its depth capped at the
   width of the column. */
.side-title {
  position: sticky;
  top: var(--margin);
  align-self: start;
  display: flex;
  align-items: flex-end;
  height: calc(100svh - var(--margin) * 2);
  overflow: hidden;
}

.side-title span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: clamp(64px, 12vh, 200px);
  line-height: 0.9;
  letter-spacing: -0.03em;
  white-space: nowrap;
  margin-left: -0.04em;
}

/* ─── Content column ───────────────────────────────────── */

.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main {
  flex: 1;
  padding-bottom: var(--space-between-sections);
}

.grid9,
.site-header,
.site-footer,
.project-pager,
.project-item,
.table-row {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  column-gap: var(--gutter);
}

/* ─── Site header + footer ─────────────────────────────── */

/* The header is navigation, so it reads at text size; the footer stays
   small. */
.site-footer {
  font-size: var(--text-small);
}

.site-header > :nth-child(1),
.site-footer > :nth-child(1) {
  grid-column: 1 / span 2;
}

.site-header > :nth-child(2),
.site-footer > :nth-child(2) {
  grid-column: 3 / span 3;
}

.site-header > :nth-child(3),
.site-footer > :nth-child(3) {
  grid-column: 6 / span 2;
}

.site-header > :nth-child(4),
.site-footer > :nth-child(4) {
  grid-column: 8 / span 2;
}

.site-header {
  padding-bottom: calc(var(--space-small) - var(--rule-thin));
  border-bottom: var(--rule-thin) solid var(--ink);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--space-medium);
}

.site-header a,
.site-footer {
  color: var(--grey);
}

.site-header a[aria-current] {
  color: var(--ink);
}

.site-footer {
  padding-top: calc(var(--space-small) - var(--rule-thin));
  border-top: var(--rule-thin) solid var(--ink);
}

/* ─── Intro text + info row ────────────────────────────── */

.intro-text {
  padding-top: var(--space-large);
  font-size: var(--text-large);
  line-height: var(--line-height-large, 1.2);
  letter-spacing: -0.015em;
}

.intro-text p {
  display: inline;
}

.info-row {
  display: grid;
  grid-template-columns: repeat(var(--count, 3), minmax(0, 1fr));
  column-gap: var(--gutter);
  padding-top: calc(var(--space-small) - var(--rule-thick));
  border-top: var(--rule-thick) solid var(--ink);
}

.info-row dt,
.row-year,
.row-subtitle,
.section-heading span + span,
.project-header {
  color: var(--grey);
}

.info-row dt {
  font-size: var(--text-small);
}

.info-row a,
.project-link,
.project-more,
.prose a {
  text-decoration: underline;
  text-decoration-thickness: var(--rule-thin);
  text-underline-offset: 0.2em;
}

/* ─── Sections ─────────────────────────────────────────── */

.section {
  margin-top: var(--space-between-sections);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: var(--gutter);
  padding: calc(var(--space-small) - var(--rule-thick)) 0 var(--space-medium);
  border-top: var(--rule-thick) solid var(--ink);
}

.section-heading span + span {
  text-align: right;
}

/* ─── Project list (home) ──────────────────────────────── */

.project-item {
  padding: calc(var(--space-small) - var(--rule-thin)) 0 var(--space-between-projects);
  border-top: var(--rule-thin) solid var(--ink);
}

.project-item:first-child {
  padding-top: 0;
  border-top: 0;
}

.project-item:last-child {
  padding-bottom: 0;
}

/* Title on its own line; year, type and link follow on one grey line. */
.project-header {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--space-medium);
}

.project-title {
  order: -1;
  flex-basis: 100%;
  font-size: var(--text-title);
  line-height: var(--line-height-title, 1);
  letter-spacing: -0.03em;
  color: var(--ink);
  padding-bottom: var(--space-small);
}

.project-link {
  margin-left: auto;
  color: var(--ink);
}

.project-summary {
  grid-column: 1 / span 4;
  grid-row: 2;
  margin-top: var(--space-medium);
  padding-right: var(--gutter);
}

.project-summary > * + * {
  margin-top: var(--space-small);
}

.project-more {
  display: inline-block;
}

.project-media {
  grid-column: 5 / -1;
  grid-row: 2;
  margin-top: var(--space-medium);
}

/* ─── Media ────────────────────────────────────────────── */

.media {
  overflow: hidden;
}

.media img,
.media video,
.media iframe {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

iframe[src*="youtube"] {
  aspect-ratio: 16 / 9;
}

.media-uncropped img,
.media-uncropped video {
  object-fit: contain;
}

.project-cover .media {
  aspect-ratio: 16 / 9;
}

.project-cover:not(:empty) {
  margin-top: var(--space-large);
}

/* ─── Tag filter + project table (index) ───────────────── */

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-medium);
  padding-top: var(--space-large);
  font-size: var(--text-small);
  color: var(--grey);
}

.tag-filter a[aria-current] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: var(--rule-thin);
  text-underline-offset: 0.2em;
}

.tag-filter + .section {
  margin-top: var(--space-large);
}

.table-row {
  padding: calc(var(--space-small) - var(--rule-thin)) 0 var(--space-medium);
  border-top: var(--rule-thin) solid var(--ink);
}

.project-table > :first-child {
  padding-top: 0;
  border-top: 0;
}

.project-table > :last-child {
  padding-bottom: 0;
}

.row-year {
  grid-column: 1 / span 2;
}

.row-title {
  grid-column: 3 / span 3;
  padding-right: var(--gutter);
}


.row-summary {
  grid-column: 6 / span 3;
}

.row-thumbnail {
  grid-column: 9;
  align-self: start;
}

.row-thumbnail img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--image-background);
}

.table-row:hover h3 a {
  color: var(--accent);
}

/* ─── Prose (blocks, layouts) ──────────────────────────── */

/* Running text keeps a seven-column measure; figures use all nine. */
.prose > :is(p, ul, ol, blockquote, h2, h3, h4, h5, h6) {
  max-width: calc((100% - var(--gutter) * 8) / 9 * 7 + var(--gutter) * 6);
}

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


.prose > :is(h2, h3, h4):not(:first-child) {
  margin-top: var(--space-large);
}

.prose > :is(h2, h3, h4) + * {
  margin-top: 0;
}

.prose ul {
  list-style: "– ";
  padding-left: 1em;
}

.prose blockquote {
  font-size: var(--text-large);
  line-height: var(--line-height-large, 1.2);
  letter-spacing: -0.015em;
}

.prose figure img,
.prose figure video,
.prose .video iframe {
  width: 100%;
  height: auto;
  background: var(--image-background);
}

.prose .video {
  display: block;
}

.prose .video iframe {
  aspect-ratio: 16 / 9;
}

.prose figcaption,
.image-grid figcaption {
  padding-top: var(--space-small);
  font-size: var(--text-small);
  color: var(--grey);
}

.prose-large {
  padding-top: var(--space-large);
  font-size: var(--text-large);
  line-height: var(--line-height-large, 1.2);
  letter-spacing: -0.015em;
}

/* Layout columns come in twelfths, so they get a twelve-column grid. */
.layout-row {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gutter);
  row-gap: var(--line-height);
  margin-top: var(--space-between-sections);
}

.intro-text + .layout-row,
.main > :first-child:is(.layout-row, .section) {
  margin-top: var(--space-large);
}

.layout-row > .prose {
  grid-column: span var(--span, 12);
}

.layout-row > .prose > * {
  max-width: none;
}

/* ─── Image grid ───────────────────────────────────────── */

.image-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gutter);
}

.image-grid .full-width {
  grid-column: 1 / -1;
}

.image-grid img {
  width: 100%;
  height: auto;
  background: var(--image-background);
}

/* ─── Project pager ────────────────────────────────────── */

.project-pager {
  margin-top: var(--space-between-sections);
  padding-top: calc(var(--space-small) - var(--rule-thick));
  border-top: var(--rule-thick) solid var(--ink);
}

.project-pager > * {
  grid-column: span 3;
}

.project-pager span {
  display: block;
  font-size: var(--text-small);
  color: var(--grey);
}

/* ─── Colour wash ──────────────────────────────────────── */

/* With the wash option on (html.has-colour-wash), the page starts on
   paper and drifts through the cv-a4 colours, each mixed far down towards
   white, across the full length of the page. Scroll-driven where
   supported; sheet.js scrubs the same keyframes elsewhere. */
:root {
  --wash-lime: color-mix(in oklab, #c6ff3d 22%, var(--paper));
  --wash-pink: color-mix(in oklab, #ff9ad5 22%, var(--paper));
  --wash-sky: color-mix(in oklab, #8fd3ff 22%, var(--paper));
  --wash-amber: color-mix(in oklab, #ffb31a 22%, var(--paper));
  --wash-lilac: color-mix(in oklab, #b9a8ff 22%, var(--paper));
}

@keyframes wash {
  0% { background-color: var(--paper); }
  20% { background-color: var(--wash-lime); }
  40% { background-color: var(--wash-pink); }
  60% { background-color: var(--wash-sky); }
  80% { background-color: var(--wash-amber); }
  100% { background-color: var(--wash-lilac); }
}

.has-colour-wash {
  background-color: var(--paper);
  animation: wash 1s linear paused both;
  animation-delay: calc(var(--scroll, 0) * -0.999s);
}

.has-colour-wash body {
  background: transparent;
}

@supports (animation-timeline: scroll()) {
  .has-colour-wash {
    animation-play-state: running;
    animation-delay: 0s;
    animation-duration: auto;
    animation-timeline: scroll(root block);
  }
}

@media (prefers-reduced-motion: reduce) {
  .has-colour-wash {
    animation: none;
  }
}

/* ─── Small screens ────────────────────────────────────── */

/* The side title turns to sit across the top, fitted to the width; the content
   block keeps its grid but stacks what no longer fits side by side. */
@media (max-width: 60rem) {
  .page {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    row-gap: var(--space-medium);
  }

  .side-title {
    position: static;
    height: auto;
    align-items: flex-start;
  }

  .side-title span {
    writing-mode: horizontal-tb;
    transform: none;
    line-height: 0.8;
    margin-left: -0.03em;
    padding-bottom: 0.12em;
  }

  .site-header,
  .site-footer {
    row-gap: var(--space-small);
  }

  .site-header > :nth-child(n),
  .site-footer > :nth-child(n) {
    grid-column: span 5;
  }

  .site-header > :nth-child(2n),
  .site-footer > :nth-child(2n) {
    grid-column: 6 / span 4;
    text-align: right;
    justify-content: flex-end;
  }

  .info-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: var(--space-medium);
  }

  .info-row dd {
    overflow-wrap: anywhere;
  }

  .project-summary,
  .project-media {
    grid-column: 1 / -1;
    grid-row: auto;
    padding-right: 0;
  }

  .project-link {
    margin-left: 0;
  }

  .row-year {
    grid-column: 1 / span 3;
  }

  .row-title {
    grid-column: 4 / -1;
    padding-right: 0;
  }

  .row-summary {
    grid-column: 4 / -1;
    padding-top: var(--space-small);
  }

  .row-thumbnail {
    display: none;
  }

  .prose > :is(p, ul, ol, blockquote, h2, h3, h4, h5, h6) {
    max-width: none;
  }

  .layout-row > .prose {
    grid-column: 1 / -1;
  }

  .image-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .project-pager > * {
    grid-column: span 9;
  }

  .project-pager > * + * {
    padding-top: var(--space-small);
  }

  .project-pager .align-right {
    text-align: left;
  }
}

/* On the narrowest phones half the width is too little for an email address;
   the first column shrinks to its content and the second takes the rest. */
@media (max-width: 380px) {
  .info-row {
    grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  }
}
