/* ==========================================================================
   HOME PAGE layout, after context/layouts/base-design.png (1280 wide) and
   base-design-V2.png for the header, gridlines and navigation.
   Colours and type come from the design system. The staggered headline and
   its gridlines break the system on purpose.

   --u is one pixel of the 1280 design, scaled to the current page width.
   --h is the same for the first screen, but also shrinks on short windows so
   the company logos stay above the fold.
   ========================================================================== */

body { padding: 0; overflow-x: clip; }

.frame {
  --u: calc(100cqi / 1280);
  --columns: 5;                          /* the layout sits on five columns */
  container-type: inline-size;
  position: relative;
  isolation: isolate;                    /* keeps the line layers inside the page */
  background: var(--color-bg);           /* solid, so crossing lines can blend */
  max-width: var(--page-width);
  margin: 0 auto;

  /* First screen: heights of everything around the headline */
  --fold-header: 94px;
  --fold-trusted: 94px;                  /* "Trusted by" and one row of logos */
  --fold-extra: 0px;                     /* the button, when under the headline */
  --fold-gap: var(--space-32);           /* clear space left below the logos */
  --fold-others: calc(var(--fold-header) + var(--fold-trusted) + var(--fold-extra) + var(--fold-gap));
  /* headline unit: follows the width, limited by height (never below 0.6px for that) */
  --h: max(min(var(--u), (100svh - var(--fold-others)) / 455), min(var(--u), 0.6px));
  --lines: calc(279 * var(--h));         /* three headline lines */
  /* space above and below the headline: as designed if there is room */
  --room: calc(100svh - var(--fold-others) - var(--lines));
  --pad-top: clamp(var(--space-40), var(--room) * 0.54, 190 * var(--h));
  --pad-bottom: clamp(var(--space-32), var(--room) * 0.46, 160 * var(--h));
  --shift: calc((100cqi - 1280 * var(--h)) / 2);   /* keeps the headline centred */
}

.five {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  column-gap: var(--grid-gutter);
  padding-inline: var(--page-margin);
}

.hero-action[hidden] { display: none; }

/* ---------- Fading gridlines ---------- */
/* The two side lines frame the page and fade out above the case studies.
   The three inner lines only mark the navigation columns. */
.guides {
  position: absolute;
  inset: 0 0 auto;
  z-index: -2;
  height: calc(var(--fold-others) + var(--pad-top) + var(--lines) + var(--pad-bottom));
  pointer-events: none;
}
.guides > .five { height: 100%; }
.guides i { display: block; width: var(--line-1); background: linear-gradient(180deg, var(--color-gridline), transparent); }
.guides i:nth-child(2) { grid-column: 3; grid-row: 1; height: 170px; }
.guides i:nth-child(3) { grid-column: 4; grid-row: 1; height: 170px; }
.guides i:nth-child(4) { grid-column: 5; grid-row: 1; height: 170px; }
.guides i:nth-child(1),
.guides i:nth-child(5) { grid-row: 1; height: 100%; }
.guides i:nth-child(1) { grid-column: 1; }
.guides i:nth-child(5) { grid-column: 5; justify-self: end; }

/* ---------- Header ---------- */
.site-header { position: relative; align-items: start; height: 94px; }
.site-header .gridline { top: 93px; }
.logo { grid-column: 1 / span 2; justify-self: start; margin-top: 44px; position: relative; z-index: 1; }
.logo img { display: block; width: 135px; height: 56px; }
.site-nav {
  --nav-top: 57px;                       /* space between the window top and the links */
  --current: 0;                          /* the page you are on: 0, 1 or 2 */
  --item: var(--current);                /* where the indicator is */
  position: relative;
  grid-column: 3 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: var(--grid-gutter);
  margin-top: var(--nav-top);
}
.site-nav a {
  position: relative;
  align-content: end;                    /* one-line labels sit on the same last line as two-line ones */
  outline: var(--line-2) solid transparent;
  color: var(--color-text-body);
  text-transform: uppercase;
  font-size: var(--font-size-16);
  font-weight: var(--weight-medium);
  line-height: 20px;
  text-decoration: underline transparent var(--line-1);
  text-underline-offset: var(--underline-offset);
  transition: color var(--hover-fade), text-decoration-color var(--hover-fade);
}
.site-nav a:hover, .site-nav a:focus-visible { color: var(--color-text); }
.site-nav a:focus-visible { text-decoration-color: currentColor; }
/* each link can be pointed at anywhere in its column, up to the window top,
   including the gutter, so the indicator never drops back between links */
.site-nav a::after { content: ""; position: absolute; inset: calc(-1 * var(--nav-top)) calc(-1 * var(--grid-gutter)) 0 0; }

/* Pagination indicator: half a column wide. Mark the current page's link with
   aria-current="page" (or data-current); it slides to a hovered or focused link. */
.site-nav::before {
  content: "";
  position: absolute;
  top: calc(-1 * var(--nav-top));
  left: 0;
  z-index: 1;
  width: calc((100% - 2 * var(--grid-gutter)) / 6);
  height: var(--line-8);
  border-radius: 0 0 var(--radius-8) var(--radius-8);
  background: var(--color-accent);
  opacity: 0;
  transform: translateX(calc(var(--item) * (200% + var(--grid-gutter))));
  transition: transform var(--hover-fade), opacity var(--hover-fade);
  pointer-events: none;
}
.site-nav:has([aria-current], [data-current], a:hover, a:focus-visible)::before { opacity: 1; }
/* Opening wipe: uncovered from the left behind a hard edge, like Keynote's Wipe */
@keyframes wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.fade-ready .site-nav[data-wipe]::before { clip-path: inset(0 100% 0 0); }
.fade-ready .site-nav[data-wipe].wipe-in::before {
  animation: wipe var(--wipe-duration) var(--wipe-ease) calc(var(--appear-delay) + var(--step, 0) * var(--sequence-gap)) both;
}
@media print { .fade-ready .site-nav[data-wipe]::before { clip-path: none; } }
.site-nav:has(a:nth-of-type(2):is([aria-current], [data-current])) { --current: 1; }
.site-nav:has(a:nth-of-type(3):is([aria-current], [data-current])) { --current: 2; }
.site-nav:has(a:nth-of-type(1):is(:hover, :focus-visible)) { --item: 0; }
.site-nav:has(a:nth-of-type(2):is(:hover, :focus-visible)) { --item: 1; }
.site-nav:has(a:nth-of-type(3):is(:hover, :focus-visible)) { --item: 2; }
@media (prefers-reduced-motion: reduce) { .site-nav::before { transition: none; } }

/* ---------- Mobile menu (scripts/menu.js) ---------- */
.menu-toggle { display: none; }
@media (max-width: 560px) {
  .has-menu .frame { --fold-header: 96px; }
  .has-menu .logo { grid-column: 1 / span 3; grid-row: 1; z-index: 21; }
  .has-menu .menu-toggle {
    --button-pad-x: var(--space-8); --button-icon: var(--icon-24); --button-icon-stroke: var(--icon-stroke-24);
    display: inline-flex; grid-column: 4 / -1; grid-row: 1; justify-self: end; z-index: 21;
    margin-top: calc(var(--space-24) + var(--space-8));
  }
  .has-menu .site-nav { display: none; }
  .has-menu.menu-open { overflow: hidden; }
  .has-menu.menu-open .site-nav {
    position: absolute; inset: 0 0 auto; z-index: 20;
    grid-area: auto;                       /* span the whole header, margins included */
    display: flex; flex-direction: column;
    height: 100vh; height: 100dvh; overflow: auto;
    margin: 0; padding: calc(var(--space-128) - var(--space-8)) var(--space-24) var(--space-40);
    background: var(--color-bg);
  }
  .has-menu .site-nav::before { display: none; }
  /* the links are not part of the opening fade here: they show when the menu opens */
  .has-menu .site-nav a {
    opacity: 1; animation: none;
    display: flex; align-items: center; gap: var(--space-16);
    padding-block: var(--space-24);
    border-bottom: var(--line-1) solid var(--color-divider);
    font-size: var(--font-size-32); line-height: var(--leading-heading);
  }
  .has-menu .site-nav a::after { content: none; }
  .has-menu .site-nav a br { display: none; }
  .has-menu .site-nav a:is([aria-current], [data-current])::after {
    content: ""; position: static; width: var(--space-32); height: var(--line-8); margin-left: auto;
    border-radius: var(--radius-8); background: var(--color-accent);
  }
}

/* ---------- Hero: staggered headline ---------- */
.hero { position: relative; padding: var(--pad-top) 0 var(--pad-bottom); }
.hero h1 {
  margin: 0;
  font-size: calc(96 * var(--h));
  line-height: calc(93 * var(--h));
}
.hero .line { display: block; position: relative; white-space: nowrap; }
.hero .line > span { display: inline-block; margin-left: calc(var(--shift) + var(--offset)); }
.hero .line-1 { --offset: calc(192 * var(--h)); }
.hero .line-2 { --offset: calc(455 * var(--h)); }
.hero .line-3 { --offset: calc(316 * var(--h)); color: var(--color-text-highlight); }
/* each gridline sits on the line's baseline */
.hero .line .gridline { top: calc(79.7 * var(--h)); }
.hero-action { position: absolute; left: calc(var(--shift) + 848 * var(--h)); top: calc(var(--pad-top) + 173 * var(--h) - 52px); }

/* ---------- Trusted by ---------- */
.trusted { display: grid; justify-items: center; gap: 36px; padding-inline: var(--page-margin); }
.trusted ul { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 74px; margin: 0; padding: 0; list-style: none; }
.trusted img { display: block; }

/* ---------- Case studies ---------- */
/* where a link lands, the heading sits --anchor-space below the top of the window */
:root { --anchor-space: var(--space-64); }
@media (max-width: 560px) { :root { --anchor-space: var(--space-40); } }
.work { margin-top: 60px; padding-top: var(--space-16); scroll-margin-top: calc(var(--anchor-space) - var(--space-16)); }
.work > h2 { font-weight: var(--weight-medium); }
.work > h2 { padding-inline: var(--page-margin); margin-bottom: calc(var(--space-16) + var(--space-4)); }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--grid-gutter); padding-inline: var(--page-margin); }
.tile { position: relative; isolation: isolate; overflow: hidden; aspect-ratio: 723 / 1153; background: var(--color-card); }
/* square below: rounded corners would leave a faint outline on the black */
.tile.radius-96 { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.tile-image { position: absolute; inset: 0; z-index: -1; width: 100%; height: 100%; object-fit: cover; }
/* the pictures are pale at the bottom, so the words sit on their own shade */
.tile-text {
  position: absolute; inset: auto -1px -1px; display: grid; gap: var(--space-8);   /* 1px over, so no sliver of picture shows */
  min-height: 70%; align-content: end;               /* how far up the shade reaches */
  padding: var(--space-128) var(--space-40) var(--space-40);
  background: linear-gradient(transparent, rgb(0 0 0 / 0.78) 44%, var(--neutral-1000) 82%);   /* solid, so the card has no bottom edge */
}
.tile-logo { display: block; justify-self: start; max-width: 100%; height: auto; margin-block: var(--space-4) var(--space-8); }
/* white on the shade in either theme */
.tile-text p, .tile-text h3 { margin: 0; color: var(--neutral-0); }
.tile-text .tile-year { font-size: var(--font-size-16); font-weight: var(--weight-regular); line-height: var(--leading-body); color: var(--neutral-250); }
.work > h2 { text-align: center; font-size: var(--text-page-heading); margin-bottom: var(--space-64); }
@media (max-width: 560px) { .work > h2 { margin-bottom: var(--space-40); } }
.tile-text h3 { font-size: var(--text-heading); line-height: var(--leading-heading); font-weight: var(--weight-medium); text-wrap: balance; }

/* ---------- Sections under the case studies ---------- */
.section { margin-top: var(--space-128); padding-inline: var(--page-margin); scroll-margin-top: var(--anchor-space); }
.section > h2 { margin-bottom: calc(var(--space-16) + var(--space-4)); font-weight: var(--weight-medium); }
.section .table { --table-columns: var(--columns); }
.lead { font-weight: var(--weight-medium); }

/* Past projects: year, project and role have set widths so each description
   stays on one line; company takes the rest */
@media (min-width: 1000px) {
  #past-projects .table tr { grid-template-columns: minmax(0, 1fr) 7rem 21rem 12rem; }
  #past-projects .table .col-2 { grid-column: auto; }
  /* Appearances: a media column wide enough for all its links on one line */
  #appearances .table tr { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) 5.5rem 26.5rem; }
  #appearances .table .col-2 { grid-column: auto; }
  #appearances .table .cell-links { column-gap: var(--space-16); }
}
@media (min-width: 1040px) {
  /* centred on columns two to five, but never narrower than the text needs */
  #past-projects > *, #appearances > * { width: max(920px, calc((100% - 5 * var(--grid-gutter)) / 6 * 4 + 3 * var(--grid-gutter))); margin-inline: auto; }
}
/* too narrow for one line across: rows stack, as they do on phones */
@media (min-width: 761px) and (max-width: 999px) {
  #past-projects .table thead, #appearances .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  #past-projects .table tr, #appearances .table tr { grid-template-columns: minmax(0, 1fr) auto; row-gap: var(--space-4); }
  #past-projects .table td, #appearances .table td { grid-column: 1 / -1; }
  #past-projects .table td:first-child, #appearances .table td:first-child { grid-column: 1; }
  #past-projects .table .cell-aside, #appearances .table .cell-aside { grid-column: 2; grid-row: 1; }
  #appearances .table .cell-links { column-gap: var(--space-16); margin-top: var(--space-8); }
}

@media (max-width: 760px) {
  #appearances .table .cell-links { column-gap: var(--space-16); }   /* fits the links across a phone */
}

/* About Karl: photo on the left, heading and text beside it */
.headshot { display: block; width: 100%; height: auto; }
.about { overflow-x: clip; }              /* the photo starts off to the side as it slides in */
.about-text { display: grid; gap: var(--space-24); align-content: start; }
.about-text h2 { font-weight: var(--weight-medium); }
.about-text p { max-width: 62ch; text-wrap: pretty; }
.nowrap { white-space: nowrap; }
.about-text .lead { max-width: 640px; }
@media (min-width: 761px) {
  .about { display: grid; grid-template-columns: repeat(var(--columns), minmax(0, 1fr)); column-gap: var(--grid-gutter); align-items: center; }
  .about > .about-side { grid-column: 1 / 3; }
  .about > .about-text { grid-column: 3 / -1; }
}
@media (min-width: 1040px) {
  .about { grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr)); }
  .about > .about-side { grid-column: 2 / 4; }
  .about > .about-text { grid-column: 4 / 6; }
}

.contact { padding-bottom: var(--space-64); text-align: center; }
/* the line runs edge to edge, and the footer ends flush with the bottom of the page */
.site-footer { position: relative; z-index: 2; margin-top: var(--space-64); padding: var(--space-16) var(--page-margin); border-top: var(--line-1) solid var(--color-divider); background: var(--color-bg); text-align: center; }
.site-footer p { margin: 0; color: var(--color-footer-text); }
.contact-text { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; gap: var(--space-16); width: 100%; max-width: 760px; margin-inline: auto; }
.contact-text p { text-wrap: pretty; }
.contact-text .lead { text-wrap: balance; }
.contact-actions {
  display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-16); margin-top: var(--space-16);
  /* the pair may reach past a narrow column, evenly on both sides, to stay on one line */
  width: max-content; max-width: calc(100cqi - 2 * var(--page-margin));
}
/* Get in touch: two empty columns on each side, or one until two columns are
   wide enough to keep the button labels on one line */
@media (min-width: 1040px) {
  .contact { display: grid; grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr)); column-gap: var(--grid-gutter); }
  .contact > * { grid-column: 2 / 6; }
}
@media (min-width: 1240px) { .contact > * { grid-column: 3 / 5; } }

@media (max-width: 760px) {
  .headshot { max-width: 320px; margin: 0 auto var(--space-32); }
}
@media (max-width: 560px) {
  .section { margin-top: var(--space-64); }
}

/* ---------- Smaller screens: centred headline, button underneath ---------- */
@media (max-width: 1039px) {
  .frame {
    --fold-extra: calc(var(--space-32) + 52px);
    /* centred, there is room to keep the headline at 48px or more */
    --h: max(min(var(--u), (100svh - var(--fold-others)) / 455), 0.5px);
  }
  .hero h1 { text-align: center; }
  .hero .line > span { margin-left: 0; }          /* no stagger */
  .hero-action { position: static; margin: var(--space-32) var(--page-margin) 0; display: flex; justify-content: center; }
}

/* ---------- Case studies: narrower screens ---------- */
@media (max-width: 1239px) { .tile-text h3 { font-size: var(--font-size-24); } }
@media (max-width: 1039px) {
  .tile-text { padding: var(--space-128) var(--space-24) var(--space-24); }
}
@media (min-width: 761px) and (max-width: 899px) {   /* three narrow tiles */
  .tile-text { padding: var(--space-128) var(--space-16) var(--space-24); }
  .tile-text h3 { font-size: var(--font-size-16); }
  .tile-logo { zoom: 0.75; }
  .tile.radius-96 { --r: var(--radius-32); }          /* the big corner would cut into the words */
}
@media (max-width: 760px) {              /* one tile per row */
  .tiles { grid-template-columns: minmax(0, 480px); justify-content: center; }
}

/* Logos: one row on tablet, two by two when narrower */
@media (max-width: 899px) { .trusted ul { gap: var(--space-24) var(--space-40); } }
@media (max-width: 760px) {
  .frame { --fold-trusted: 152px; }       /* logos two by two */
  .trusted ul { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); justify-items: center; width: 100%; max-width: 400px; column-gap: var(--space-16); }
  .trusted li { min-width: 0; }
  .trusted img { max-width: 100%; height: auto; }
}

/* ---------- Mobile ---------- */
@media (max-width: 560px) {
  .frame {
    --fold-header: 152px;
    --fold-trusted: 134px;
    --fold-gap: var(--space-16);
    --lines: calc(3 * min(var(--font-size-48), 13vw));
    --room: calc(100svh - var(--fold-others) - var(--lines));
    --pad-top: clamp(var(--space-24), var(--room) / 2, var(--space-64));
    --pad-bottom: var(--pad-top);
  }
  .site-header { height: auto; row-gap: var(--space-24); padding-bottom: var(--space-8); }
  .logo { grid-column: 1 / -1; margin-top: var(--space-24); }
  .site-nav { grid-column: 1 / -1; margin-top: 0; --nav-top: var(--space-16); }
  .site-header .gridline { top: auto; bottom: 0; }
  .guides { display: none; }

  .hero { padding-inline: var(--page-margin); }
  .hero h1 { font-size: min(var(--font-size-48), 13vw); line-height: 1; }
  .hero .line .gridline { top: 0.846em; margin-inline: calc(-1 * var(--page-margin)); }   /* hero is inset here */
  .hero-action { margin: var(--space-32) 0 0; }

  .trusted { gap: var(--space-24); }
  .work { margin-top: var(--space-40); }

}

/* no button under the headline, so no room kept for it above the fold */
.frame:has(.hero-action[hidden]) { --fold-extra: 0px; }

/* ---------- Phones: the first screen ends with the logos ---------- */
@media (max-width: 560px) {
  /* the headline takes the spare height, which keeps "Work" below the fold.
     242px = header, "Trusted by" with two rows of logos, and a little room */
  .hero { display: flex; flex-direction: column; justify-content: center; min-height: calc(100svh - 242px); }
  .work > h2 { font-size: var(--font-size-24); }
}
