:root {
  --text: #414958;
  --muted: #777;
  --line: #eee;
  --nav-height: 65px;
  --cascade: min(80vw, 500px);
}

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

html { scroll-behavior: smooth; scroll-padding-top: var(--nav-height); }

body {
  margin: 0;
  font-family: "Lato", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: #fff;
}

a { color: inherit; }

.container { width: min(960px, 100% - 30px); margin: 0 auto; }

/* Header */

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 40px 80px;
  /* Leaves room for the menu bar and its borders, so it shows at the bottom of the
     first screen. */
  min-height: calc(100vh - var(--nav-height) - 2px);
  min-height: calc(100svh - var(--nav-height) - 2px);
  padding: 40px 15px;
  /* On short windows the reflection would otherwise run into the next section. */
  overflow: clip;
  background: #fff;
  /* Keeps the floor behind the images but in front of this background. */
  isolation: isolate;
  position: relative;
  /* Height of the images above the reflecting surface. */
  --lift: 60px;
}

/* The floor, from the menu bar back to its far edge. The script moves its top edge to
   the far edge. */
.floor-plane {
  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(#f6f6f6, #fbfbfb 100vh);
}

.hero h1 {
  margin: 0;
  font-weight: 100;
  font-size: 40px;
  color: var(--muted);
  text-transform: uppercase;
}

.tagline {
  margin: 5px 0 0 3px;
  font-weight: 300;
  color: #444;
  text-transform: uppercase;
}

.cascade {
  position: relative;
  width: var(--cascade);
  height: var(--cascade);
}

/* The title's reflection in the floor, placed by the script. Seen through the glass, so it
   sits under the seams, and faint like the images' reflection. */
.text-reflection {
  position: absolute;
  z-index: -1;
  top: 0;
  margin: 0;
  pointer-events: none;
  filter: blur(0.4px);
  /* Even across the title and subtitle, which is only a short way down the floor. */
  opacity: 0.15;
}

/* Seams between the glass floor panels, drawn by the script. */
.floor {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
}

.floor-back { z-index: -1; }

/* The reflection is a real mirrored copy of the bottom half of the tiles, so its
   perspective can converge on the viewer's eye rather than on its own middle. */
.reflection {
  /* Spare room around the tiles, so the mask doesn't cut off tiles that stick out
     mid-flip or the edges of the blur. */
  --bleed: 20px;
  position: absolute;
  top: calc(100% + var(--gap, 2 * var(--lift)));
  left: 0;
  width: 100%;
  box-sizing: content-box;
  padding: var(--bleed);
  margin: calc(-1 * var(--bleed));
  pointer-events: none;
  filter: blur(0.5px);
  /* Strongest next to the surface, falling away quickly then slowly, like a glossy floor. */
  --fade: linear-gradient(
    rgb(0 0 0 / 0.22) var(--bleed),
    rgb(0 0 0 / 0.1) calc(var(--bleed) + var(--cascade) / 10),
    rgb(0 0 0 / 0.034) calc(var(--bleed) + var(--cascade) / 4),
    transparent calc(var(--bleed) + var(--cascade) / 2)
  );
  -webkit-mask-image: var(--fade);
  mask-image: var(--fade);
}

/* Blurs the reflection more the further it is from the surface. */
.reflection > .blur {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(3px);
  -webkit-mask-image: linear-gradient(transparent calc(var(--bleed) - 40px), #000 calc(var(--bleed) + var(--cascade) / 4));
  mask-image: linear-gradient(transparent calc(var(--bleed) - 40px), #000 calc(var(--bleed) + var(--cascade) / 4));
}

.reflection > .flip {
  position: absolute;
  inset: var(--bleed);
  transform: scaleY(-1);
}

.reflection .tiles {
  position: absolute;
  inset: 0;
}

.cascade > img,
.cascade > .tiles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Hide all but the first image until the script has built the tiles. */
.cascade > img:not(:first-child) { visibility: hidden; }

.tiles {
  display: grid;
  /* The script sets the viewer's distance and eye point. */
  perspective: var(--distance, 2600px);
  perspective-origin: var(--eye-x, 50%) var(--eye-y, 50%);
}

@property --angle {
  syntax: "<angle>";
  inherits: true;
  initial-value: 180deg;
}

.tile {
  position: relative;
  background-repeat: no-repeat;
  backface-visibility: hidden;
  /* Overlap neighbours slightly. Animated tiles get soft edges, which would otherwise
     show thin lines of background between them. */
  transform: rotateY(var(--angle)) scale(1.02);
  transition: --angle var(--duration, 800ms) var(--easing, ease-in-out) var(--delay, 0ms);
}

/* Darken tiles as they turn edge-on, as if lit from the viewer's side. */
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #000;
  opacity: calc((1 - cos(var(--angle))) * 0.5);
}

.tiles:first-of-type .tile { --angle: 0deg; }
.tiles:first-of-type { z-index: 2; }

/* Navigation */

.navbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fff;
  border-block: 1px solid var(--line);
}

.navbar .container {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 35px;
  min-height: var(--nav-height);
}

.navbar-logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .2em;
  color: #222;
}

.navbar ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0 35px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.navbar a,
.navbar .divider {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
  text-decoration: none;
  color: #222;
}

.navbar a:hover { color: #33c3f0; }

/* Sections */

main section {
  padding: 60px 0;
  border-top: 1px solid var(--line);
}

main section:first-child { border-top: 0; }

h2 {
  margin: 0 0 30px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
}

h3 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 400;
}

h3 a { text-decoration: none; }

p { margin: 0 0 12px; }

.split {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 40px;
  align-items: start;
}

.cv { margin: 24px 0; font-size: 13px; }
.cv dt { margin-top: 12px; }
.cv dd { margin: 0; }

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 12px;
}

.links a {
  padding-left: 5px;
  border-left: 1px solid #bbb;
  text-decoration: none;
}

.links a:hover { text-decoration: underline; }

.avatar {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  object-fit: cover;
}

.project {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 30px;
  align-items: center;
  margin: 40px 0;
}

.project.has-video { grid-template-columns: 170px 1fr 280px; }

.brand { display: block; margin: 0 0 20px; }

.photo {
  width: 360px;
  height: auto;
  border-radius: 4px;
}

/* Key figures, in one row */
.facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 20px 0;
  padding: 0;
  list-style: none;
}

.facts strong {
  display: block;
  font-size: 22px;
  font-weight: 300;
}

.facts span {
  display: block;
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* A logo beside its text */
.beside {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 30px;
  align-items: center;
}

/* Publications */
.pubs {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
}

.pubs li {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.pubs a { text-decoration: none; }
.pubs a:hover { text-decoration: underline; }

.pubs .venue {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

/* Smaller cards for earlier projects */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 30px;
}

.card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  margin-bottom: 12px;
}

.card h3 { font-size: 17px; }
.card p { font-size: 13px; }

/* Embeds */

.video {
  position: relative;
  aspect-ratio: 16 / 9;
}

.video iframe,
.players iframe {
  width: 100%;
  border: 0;
}

.video iframe { position: absolute; inset: 0; height: 100%; }

.players {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 20px;
}

/* Before and after comparison: drag to move the divide between the two pictures */
.compare-figure { margin: 10px 0 0; }

.compare {
  --pos: 50%;
  position: relative;
  cursor: ew-resize;
  /* Horizontal drags move the divide; vertical ones still scroll the page. */
  touch-action: pan-y;
  user-select: none;
}

.compare img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.compare .after {
  position: absolute;
  inset: 0;
  clip-path: inset(0 0 0 var(--pos));
}

.compare::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos);
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 4px rgb(0 0 0 / 0.6);
}

.compare::after {
  content: "\2039\00a0\203A";
  position: absolute;
  top: 50%;
  left: var(--pos);
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.55);
  box-shadow: 0 0 6px rgb(0 0 0 / 0.4);
  color: #fff;
  font-size: 18px;
  line-height: 30px;
  text-align: center;
}

/* Kept for keyboard use, but hidden: the picture itself is the control. */
.compare input {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.compare:has(input:focus-visible) { outline: 2px solid #33c3f0; outline-offset: 2px; }

.compare-figure figcaption {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

/* Sections hidden until asked for */
.more summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
}

.more[open] summary { margin-bottom: 20px; }

/* Pages other than the homepage */
.page-header { padding: 50px 0 20px; }

.page-header .back {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2em;
  text-transform: uppercase;
  text-decoration: none;
  color: #222;
}

.page-header h1 {
  margin: 24px 0 8px;
  font-size: 40px;
  font-weight: 100;
  color: var(--muted);
  text-transform: uppercase;
}

.hack {
  display: grid;
  grid-template-columns: minmax(0, 420px) 1fr;
  gap: 30px;
  align-items: start;
  padding: 40px 0;
  border-top: 1px solid var(--line);
}

.hack-media img,
.hack-media iframe {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 12 / 5;
  object-fit: cover;
  border: 0;
}

.hack-media .fit {
  object-fit: contain;
  background: #f4f4f4;
}

.hack h3 a:hover { text-decoration: underline; }

.hack .gone {
  font-size: 12px;
  color: var(--muted);
}

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

/* Footer */

footer {
  padding: 60px 15px 50px;
  background: #535353;
  color: #808080;
  text-align: center;
  font-size: 10px;
}

.footer-title {
  margin-bottom: 20px;
  font-size: 15px;
  color: #a8a8a8;
}

/* Narrow screens */

@media (max-width: 760px) {
  .split,
  .project,
  .project.has-video,
  .players {
    grid-template-columns: 1fr;
  }

  .split .avatar { order: -1; }
  .avatar { justify-self: center; }
  .navbar .container,
  .navbar ul { gap: 0 18px; }
  .navbar-logo { display: none; }
  /* One line of links that scrolls sideways, so the bar keeps its height. */
  .navbar .container { flex-wrap: nowrap; }
  .navbar ul {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    /* Fade the right edge, a hint that more links scroll into view. */
    -webkit-mask-image: linear-gradient(to right, #000 85%, transparent);
    mask-image: linear-gradient(to right, #000 85%, transparent);
  }
  .navbar li { flex: none; }
  .navbar .divider { display: none; }
  .hero h1 { font-size: min(40px, 8.5vw); }
  .hack {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .beside {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .beside img { width: 78px; height: auto; }
  .photo { width: 100%; }
}

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