/* ---------- Tokens ---------- */

:root {
  --paper: #f3f2ee;
  --ink: #111111;
  --ink-soft: #2a2926;
  --muted: #5f5e59;
  --rule: #d9d7d0;
  --dot: #111111;
  --accent: #b04116;
  --photo-dim: 1;

  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --gutter: clamp(20px, 5vw, 48px);
  --max: 1100px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e0e0d;
    --ink: #ecebe7;
    --ink-soft: #cfcec9;
    --muted: #8e8d88;
    --rule: #2a2a28;
    --dot: #d9d8d3;
  --accent: #e2733d;
  --photo-dim: 0.86;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #0e0e0d;
  --ink: #ecebe7;
  --ink-soft: #cfcec9;
  --muted: #8e8d88;
  --rule: #2a2a28;
  --dot: #d9d8d3;
  --accent: #e2733d;
  --photo-dim: 0.86;
  color-scheme: dark;
}

/* ---------- Base ---------- */

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
p, dd { text-wrap: pretty; }   /* avoids one-word last lines where supported */
ul, ol { padding: 0; list-style: none; }

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  text-decoration-color: var(--rule);
  transition: text-decoration-color 150ms;
}
a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

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

.wrap {
  max-width: calc(var(--max) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------- Header ---------- */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 24px;
  padding: 28px 0;
  font-family: var(--mono);
  font-size: 14px;
}

.wordmark { text-decoration: none; }

.site-header nav {
  display: flex;
  align-items: baseline;
  gap: 22px;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
}
.site-header nav a:hover { color: var(--ink); }

.theme-toggle { color: var(--muted); }
.theme-toggle span[data-mode] { transition: color 150ms; }
.theme-toggle:hover span[data-mode] { color: var(--ink); }

:root:not([data-theme="dark"]) .theme-toggle [data-mode="light"],
:root[data-theme="dark"] .theme-toggle [data-mode="dark"] { color: var(--ink); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle [data-mode="light"] { color: var(--muted); }
  :root:not([data-theme]) .theme-toggle [data-mode="dark"] { color: var(--ink); }
}

/* ---------- Intro ---------- */

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 420px);
  gap: clamp(40px, 7vw, 96px);
  align-items: end;
  padding: clamp(56px, 11vh, 120px) 0 clamp(64px, 12vh, 128px);
}

h1 {
  color: var(--ink);
  font-weight: 500;
  font-size: clamp(52px, 8.4vw, 104px);
  line-height: 0.95;
  letter-spacing: -0.035em;
}

.tagline {
  margin-top: 28px;
  color: var(--ink);
  font-size: clamp(21px, 2.3vw, 26px);
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.lede {
  margin-top: 20px;
  max-width: 34em;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 26px;
  margin-top: 32px;
  font-family: var(--mono);
  font-size: 15px;
}

/* ---------- Portrait ---------- */

.portrait-frame {
  position: relative;
  aspect-ratio: 4 / 5;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

.portrait-frame img,
.portrait-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.portrait-frame img { object-fit: cover; }
.portrait-frame canvas { opacity: 0; }
.portrait.is-ready canvas { opacity: 1; }
.portrait.is-ready .portrait-frame { cursor: pointer; }

/* With JS the photo waits hidden for the dots, so it never flashes on load; from then on
   halftone.js sets its opacity. If the dots can't start, .is-static shows it again, and the
   delayed reveal covers a script that never runs at all. */
.js .portrait:not(.is-ready):not(.is-static) img {
  opacity: 0;
  animation: portrait-fallback 0s 3s forwards;
}
@keyframes portrait-fallback { to { opacity: 1; } }

.portrait figcaption {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

.portrait figcaption {
  align-items: flex-end;
  flex-wrap: wrap;
  row-gap: 4px;
}

/* The margin note: a hand-drawn swirl curling up into the portrait, and a line in italics.
   It draws itself once the dots have formed. */
.photo-toggle {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  margin-top: -34px;
  font-family: var(--sans);
  font-style: italic;
  font-size: 15px;
  color: var(--muted);
  transform: rotate(-3deg);
  transform-origin: right bottom;
  visibility: hidden;
}
.portrait.is-ready .photo-toggle { visibility: visible; }
.photo-toggle:hover { color: var(--ink); }

.hint-arrow {
  width: 62px;
  height: 46px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint-arrow path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}
.portrait.is-ready .hint-line { animation: hint-draw 900ms ease-in-out 1500ms forwards; }
.portrait.is-ready .hint-head { animation: hint-draw 250ms ease-out 2350ms forwards; }
@keyframes hint-draw { to { stroke-dashoffset: 0; } }

.hint-text {
  opacity: 0;
  padding-bottom: 1px;
}
.portrait.is-ready .hint-text { animation: hint-fade 500ms ease 2100ms forwards; }
@keyframes hint-fade { to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .portrait.is-ready .hint-line,
  .portrait.is-ready .hint-head,
  .portrait.is-ready .hint-text { animation-duration: 1ms; animation-delay: 0ms; }
}

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

.section {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 24px;
  padding: 64px 0 72px;
  border-top: 1px solid var(--rule);
}

.label {
  font-family: var(--mono);
  font-weight: 400;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.9;
}

.body { max-width: 40em; }
.body > p + p,
.body > p + ul,
.body > ul + ul { margin-top: 1.1em; }

.title,
.project h3 {
  color: var(--ink);
  font-weight: 500;
  font-size: 20px;
  line-height: 1.4;
}
.title { margin-bottom: 12px; }

/* Work */

.projects { margin-top: -18px; }

.project {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 32px;
  padding: 18px 0 20px;
  border-bottom: 1px solid var(--rule);
}
.project:last-child { border-bottom: 0; }

.project p { margin-top: 4px; }

.status {
  margin-left: 10px;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
}

.stack {
  padding-top: 5px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.client-work {
  margin-top: 4px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.8;
  color: var(--muted);
}
.client-work a { color: var(--muted); }
.client-work a:hover { color: var(--ink); }

.focus {
  font-size: 16px;
  color: var(--muted);
}

.body-wide { max-width: none; }

.section-intro {
  max-width: 40em;
  margin-bottom: 28px;
}

/* Path: square nodes, quiet next to the dotted portrait. Orange marks only the stretch to now. */

.path {
  --node: 7px;
  --line: color-mix(in srgb, var(--muted) 45%, var(--paper));
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0 32px;
}

.stop {
  position: relative;
  padding-top: 30px;
}

.stop::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: var(--node);
  height: var(--node);
  background: var(--ink);
}

.stop::after {
  content: "";
  position: absolute;
  top: 3px;
  left: calc(var(--node) + 6px);
  right: -26px;
  height: 1px;
  background: var(--line);
}
.stop:last-child::after { right: 0; }

.is-turn::after,
.is-now::after { background: var(--accent); }

.is-now::before {
  background: var(--accent);
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

.when {
  display: block;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}
.now { color: var(--accent); }

.stop h3 {
  margin-top: 6px;
  color: var(--ink);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.4;
}

.stop p {
  margin-top: 4px;
  font-size: 16px;
  line-height: 1.5;
}

.role {
  margin-left: 8px;
  font-family: var(--mono);
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
}

/* Teachers: greyscale until you reach for one. */

.teachers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 32px;
}

.teacher {
  display: block;
  color: inherit;
  text-decoration: none;
}
.teacher:focus-visible { outline: none; }

.teacher-photo {
  display: block;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border: 1px solid var(--rule);
  background: var(--rule);
}
.teacher:focus-visible .teacher-photo {
  outline: 1px solid var(--ink);
  outline-offset: 3px;
}

.teacher-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(1) contrast(1.05) brightness(var(--photo-dim));
  transition: filter 500ms ease;
}
.teacher:hover img,
.teacher:focus-visible img,
.teacher:active img { filter: grayscale(0) contrast(1) brightness(var(--photo-dim)); }

.teacher-text {
  display: block;
  margin-top: 14px;
}

.teacher-name {
  display: block;
  color: var(--ink);
  font-weight: 500;
  font-size: 18px;
  line-height: 1.35;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  text-decoration-color: transparent;
  transition: text-decoration-color 150ms;
}
.teacher:hover .teacher-name { text-decoration-color: currentColor; }

.teacher-course {
  display: block;
  margin-top: 2px;
  font-size: 16px;
  line-height: 1.45;
}

.teacher-meta {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
}

.arrow {
  display: inline-block;
  transition: transform 200ms ease;
}
.teacher:hover .arrow,
.teacher:focus-visible .arrow { transform: translate(2px, -2px); }

@media (prefers-reduced-motion: reduce) {
  .teacher-photo img,
  .arrow { transition: none; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Stack */

.stack-list div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}
.stack-list div:first-child { padding-top: 0; }
.stack-list div:last-child { border-bottom: 0; }

.stack-list dt {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--muted);
  line-height: 1.9;
}

/* Contact */

.email {
  font-size: clamp(22px, 3vw, 30px);
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.email a { text-decoration-color: var(--muted); }
.email a:hover { text-decoration-color: currentColor; }

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px 32px;
  flex-wrap: wrap;
  padding: 28px 0 40px;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
}
.site-footer p:first-child { max-width: 60ch; }
.site-footer .credits { flex-basis: 100%; max-width: 92ch; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--ink); }

/* ---------- Section rail (wide screens only) ---------- */

.rail { display: none; }

@media (min-width: 1280px) {
  .rail {
    position: fixed;
    top: 50%;
    right: 22px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    transform: translateY(-50%);
  }

  .rail a {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 6px 0;
    text-decoration: none;
    color: var(--muted);
  }

  .rail-tick {
    display: block;
    width: 12px;
    height: 1px;
    background: currentColor;
    opacity: 0.6;
    transition: width 220ms ease, opacity 220ms ease;
  }

  .rail-label {
    padding: 1px 4px;
    background: var(--paper);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.4;
    opacity: 0;
    transform: translateX(4px);
    transition: opacity 220ms ease, transform 220ms ease;
    pointer-events: none;
  }

  /* The section in view: a longer tick in ink. */
  .rail a[aria-current] { color: var(--ink); }
  .rail a[aria-current] .rail-tick { width: 26px; opacity: 1; }

  /* Reaching for the rail shows every name. */
  .rail:hover .rail-label,
  .rail:focus-within .rail-label {
    opacity: 1;
    transform: none;
  }
  .rail a:hover { color: var(--ink); }
  .rail a:hover .rail-tick { opacity: 1; }
}

/* With room to spare, the current section's name stays visible. */
@media (min-width: 1600px) {
  .rail a[aria-current] .rail-label {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rail-tick,
  .rail-label { transition: none; }
}

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

@media (max-width: 900px) {
  .path { grid-template-columns: 1fr; gap: 0; }
  .stop { padding: 0 0 30px 30px; }
  .stop:last-child { padding-bottom: 0; }
  .stop::before { top: 8px; }
  .stop::after {
    top: calc(8px + var(--node) + 6px);
    bottom: -2px;
    left: 3px;
    right: auto;
    width: 1px;
    height: auto;
  }
  .stop:last-child::after { bottom: auto; right: auto; height: 28px; }
}

@media (max-width: 760px) {
  body { font-size: 17px; }

  .site-header { padding: 20px 0; }
  .site-header nav { gap: 16px; }
  .site-header nav a { display: none; }

  .intro {
    grid-template-columns: 1fr;
    gap: 40px;
    padding: 40px 0 64px;
  }
  .portrait { max-width: 340px; }

  .section {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 44px 0 52px;
  }

  .projects { margin-top: -10px; }
  .project { grid-template-columns: 1fr; }
  .stack { padding-top: 2px; white-space: normal; }

  .teachers { grid-template-columns: 1fr; gap: 0; }
  .teachers li + li { border-top: 1px solid var(--rule); }
  .teacher {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 16px;
    align-items: center;
    padding: 14px 0;
  }
  .teachers li:first-child .teacher { padding-top: 0; }
  .teacher-text { margin-top: 0; }
  .teacher-meta { margin-top: 4px; }
  .stack-list div { grid-template-columns: 96px minmax(0, 1fr); }
}
