:root {
  --paper: #f4f5f3;
  --ink: #16181c;
  --graphite: #6b7079; /* 4.6:1 on paper: secondary text stays readable */
  --rule: rgba(22, 24, 28, 0.14);
  --signal: #2f3bd6;

  --sans: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --gutter: clamp(20px, 3.2vw, 44px);
  --name-size: 16vw; /* set by scramble.js so the name spans the viewport */
  --tag-size: 8vw;
}

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

html {
  scroll-behavior: smooth;
  scrollbar-gutter: stable; /* page width is identical while scroll is locked during boot */
}

html.is-loading {
  overflow: hidden;
}

/* The real name appears only when the loader's glyph row lands on it. */
html:not(.is-named) .hero__name {
  visibility: hidden;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

p,
dd {
  text-wrap: pretty; /* avoids one-word last lines */
}

h1,
h2,
h3 {
  text-wrap: balance;
}

::selection {
  background: rgba(47, 59, 214, 0.16);
}

h1,
h2,
h3,
p,
dl,
dd,
ul {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

.nowrap {
  white-space: nowrap;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  text-decoration-color: rgba(22, 24, 28, 0.32);
  transition: text-decoration-color 0.15s;
}

a:hover {
  text-decoration-color: currentColor;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Hero ------------------------------------------------------------------ */

.hero {
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 320px; /* landscape phones: the hero is exactly one screen tall */
  overflow: hidden;
}

.hero__stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  touch-action: pan-y;
}

.hero__stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hero__stage.is-hover {
  cursor: grab;
}

.hero__stage.is-dragging {
  cursor: grabbing;
}

/* Copy sits above the canvas but lets pointer events fall through to the badge. */
.hero__copy,
.hero__hint {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.hero__copy a {
  pointer-events: auto;
}

.hero__copy {
  top: var(--gutter);
  left: var(--gutter);
  right: var(--gutter);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

/* --badge-clear (set by badge.js) is the half-width the straps or card occupy around
   the centre line, so the corner copy never runs underneath them. */
/* Corner copy grows a little on big monitors (≈17px at 1440 wide, ≈20px at 2560). */
.hero__intro {
  max-width: min(22em, calc(50% - var(--badge-clear, 0px)));
  font-size: clamp(16px, 0.3vw + 12.7px, 21px);
  line-height: 1.5;
  letter-spacing: -0.01em;
}

.hero__intro a {
  display: block;
  width: fit-content;
  margin-top: 12px;
  font-weight: 500;
}

.hero__school {
  max-width: min(18em, calc(50% - var(--badge-clear, 0px)));
  text-align: right;
  color: var(--graphite);
  font-size: clamp(15px, 0.28vw + 12px, 19px);
  line-height: 1.5;
}

.hero__hint {
  right: var(--gutter);
  bottom: calc(var(--name-size) * 1.12);
  color: var(--graphite);
  font-size: clamp(13px, 0.2vw + 10.2px, 16px);
}

.hero__name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--name-size) * 0.04);
  z-index: 0;
  padding-inline: calc(var(--gutter) * 0.5);
  font: 500 var(--name-size) / 1.1 var(--mono);
  height: calc(var(--name-size) * 1.1); /* keeps the box when the name layer is hidden */
  letter-spacing: 0;
  white-space: pre;
  pointer-events: none;
  user-select: none;
}

.name-layer,
.name-line {
  display: block;
}

.name-layer[hidden] {
  display: none;
}

/* Two tagline rows occupy the same box as the one-row name. */
.name-layer--tag {
  position: absolute;
  left: calc(var(--gutter) * 0.5);
  right: calc(var(--gutter) * 0.5);
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--tag-size);
  line-height: 1.1;
}

.glyph.is-code {
  color: var(--signal);
}

/* Sections ---------------------------------------------------------------- */

.work,
.contact {
  padding: clamp(72px, 11vw, 160px) var(--gutter);
}

.section-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 26rem);
  gap: 24px 48px;
  align-items: end;
  margin-bottom: clamp(40px, 6vw, 80px);
}

.section-head h2 {
  font: 600 clamp(44px, 6.4vw, 92px) / 1 var(--sans);
  letter-spacing: -0.045em;
}

.section-head p {
  color: var(--graphite);
  max-width: 24rem;
  font-size: 17px;
  line-height: 1.5;
}

/* Work list */

.project {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr) minmax(0, 15rem);
  gap: 12px 40px;
  padding: 32px 0 40px;
  border-top: 1px solid var(--rule);
}

.project:last-child {
  border-bottom: 1px solid var(--rule);
}

.project__year {
  color: var(--graphite);
  font-family: var(--mono);
  font-size: 14px;
  padding-top: 6px;
}

.project__title {
  font: 600 clamp(26px, 2.8vw, 38px) / 1.1 var(--sans);
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}

.project__summary {
  max-width: 36rem;
  line-height: 1.65;
}

.project__role {
  margin-top: 8px;
  color: var(--graphite);
}

.project__links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  margin-top: 16px;
}

.project__image {
  display: block;
  width: 100%;
  max-width: 38rem;
  height: auto;
  margin-top: 24px;
  border-radius: 6px;
  background: #e9eae7;
}

.project__stack {
  display: flex;
  flex-wrap: wrap;
  align-content: start;
  gap: 6px;
}

.project__stack li {
  padding: 2px 9px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  font: 400 13px/1.6 var(--mono);
}

.work__empty {
  padding: 32px 0;
  border-block: 1px solid var(--rule);
  color: var(--graphite);
}

.work__empty a {
  color: var(--ink);
}

/* Contact */

.contact {
  padding-bottom: var(--gutter);
}

.contact__list {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
}

.contact__list dt,
.contact__list dd {
  padding: 18px 0;
  border-top: 1px solid var(--rule);
}

.contact__list dt {
  color: var(--graphite);
  font: 400 13px/1.6 var(--mono);
  padding-top: 24px;
}

.contact__list dd {
  font: 500 clamp(22px, 3vw, 40px) / 1.2 var(--sans);
  letter-spacing: -0.03em;
  overflow-wrap: anywhere;
}

.contact__list dd a {
  text-underline-offset: 6px;
}

.contact__fine {
  margin-top: clamp(64px, 10vw, 140px);
  color: var(--graphite);
  font-size: 13px;
}

/* Loader -------------------------------------------------------------------- */

.loader {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--paper);
  transition: background-color 0.7s ease 0.35s;
}

.loader.is-revealing {
  background-color: rgba(244, 245, 243, 0);
  pointer-events: none;
}

/* Same box as .hero__name, shrunk to the centre of the screen. Revealing removes the
   offset and scale, so the row flies down and lands exactly on the giant name. */
.loader__row {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--name-size) * 0.04);
  height: calc(var(--name-size) * 1.1);
  padding-inline: calc(var(--gutter) * 0.5);
  font: 500 var(--name-size) / 1.1 var(--mono);
  color: var(--signal);
  white-space: pre;
  translate: 0 calc(-50dvh + var(--name-size) * 0.59 - 20px);
  scale: var(--loader-scale, 0.16);
  transition:
    translate 1.1s cubic-bezier(0.7, 0, 0.2, 1),
    scale 1.1s cubic-bezier(0.7, 0, 0.2, 1);
}

.loader.is-revealing .loader__row {
  translate: 0 0;
  scale: 1;
}

.loader__cell {
  display: inline-block;
  vertical-align: top;
  height: 1.1em;
  overflow: hidden;
}

.loader__strip {
  display: block;
  white-space: pre-line;
  animation: loader-flicker 1.2s steps(20) infinite;
}

@keyframes loader-flicker {
  to {
    transform: translateY(-100%);
  }
}

.loader__status {
  position: absolute;
  left: 50%;
  top: calc(50% + 28px);
  translate: -50% 0;
  display: grid;
  justify-items: center;
  gap: 12px;
  color: var(--graphite);
  font: 400 13px/1.4 var(--mono);
  white-space: nowrap;
  transition: opacity 0.25s;
}

.loader.is-revealing .loader__status {
  opacity: 0;
}

.loader__bar {
  display: block;
  width: 160px;
  height: 1px;
  background: var(--rule);
  overflow: hidden;
}

.loader__bar span {
  display: block;
  height: 100%;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.45s ease;
}

/* Narrow hero ----------------------------------------------------------------
   Phones and portrait tablets: the badge owns the top of the hero and the copy stacks
   just above the name. Keep this query in sync with NARROW_HERO in js/badge.js. */

@media (max-width: 720px), (orientation: portrait) and (max-width: 1100px) {
  .hero__copy {
    top: auto;
    bottom: calc(var(--name-size) * 1.2 + 8px);
    flex-direction: column;
    gap: 10px;
  }

  .hero__intro {
    max-width: 34rem;
    font-size: 16px;
  }

  .hero__intro a {
    margin-top: 8px;
  }

  .hero__school {
    max-width: none;
    text-align: left;
    font-size: 14px;
  }

  .hero__hint {
    display: none;
  }
}

/* Small screens --------------------------------------------------------- */

/* Below this width a side-by-side description squeezes the heading onto two lines. */
@media (max-width: 960px) {
  .section-head {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .section-head p {
    font-size: 16px;
  }

  .project {
    grid-template-columns: 1fr;
  }
}

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

  /* No flicker, no flight: the loader simply fades out over the page. */
  .loader__strip {
    animation: none;
  }

  .loader__row {
    color: var(--ink);
    transition: opacity 0.4s;
  }

  .loader.is-revealing .loader__row {
    translate: 0 calc(-50dvh + var(--name-size) * 0.59 - 20px);
    scale: var(--loader-scale, 0.16);
    opacity: 0;
  }
}
