/* Fonts: self-hosted Latin subsets (see fonts/). The fallback face is
   metric-matched to Inter so the swap to the web font barely moves text. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/inter-5.3.0.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geist Mono";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/geist-mono-5.3.0.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter Fallback";
  src: local("Arial"), local("Helvetica");
  ascent-override: 90.44%;
  descent-override: 22.52%;
  line-gap-override: 0%;
  size-adjust: 107.12%;
}

:root {
  --bg: #F8F8F8;
  --ink: #222;
  --grey: #5F5F5F;
  --line: #DADADA;
  --underline: #C4C4C4;
  --side: 310px;         /* wide enough for the longest path on one line */
  --row: 26px;
  --col: 720px;          /* text column */
  --edge: 20px;          /* smallest gap between content and the window edge */
  --gutter: 56px;        /* gap between the sidebar and the content */
  --gap-section: 14vh;
  --gap-entry: 11vh;
  --gap-head: 7vh;       /* section heading to its first entry */
  --reveal: 40px;        /* how far content rises as it is revealed */
  --snap: 40px;          /* where a section title lands when the page snaps to it */
  --sans: "Inter", "Inter Fallback", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 17px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
[hidden] { display: none !important; }
img { display: block; max-width: 100%; height: auto; }
a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  transition: color .2s, text-decoration-color .2s;
}
a:hover { text-decoration-color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 2px; }
[tabindex="-1"]:focus { outline: none; }
::selection { background: var(--ink); color: var(--bg); }

.skip {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--ink);
  color: var(--bg);
  text-decoration: none;
  transform: translateY(-200%);
}
.skip:focus { transform: none; }

/* Sidebar: the live path and the file tree */
.side {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
  width: var(--side);
  padding: 40px 4px 40px 24px;
  overflow-y: auto;
  scrollbar-width: none;
  font: 400 13px/var(--row) var(--mono);
  color: var(--grey);
}
.side::-webkit-scrollbar { display: none; }
.menu, .progress { display: none; }

.path { margin-bottom: 10px; color: var(--ink); white-space: nowrap; }
/* The caret is an inline box around a word joiner, so it never wraps away
   from the last character of the path. */
.caret {
  margin-left: 1px;
  padding-right: .5ch;
  background: var(--ink);
  animation: blink 1s steps(1) 5;
}
@keyframes blink { 50% { opacity: 0; } }

.tree { position: relative; }
.tree ul { list-style: none; }
.row {
  display: block;
  position: relative;
  padding-left: 24px;
  color: var(--grey);
  white-space: nowrap;
  text-decoration: none;
  transition: color .2s;
}
.row:hover, .row[aria-current] { color: var(--ink); }
.t-root > .row { padding-left: 20px; }
.tree ul ul .row { padding-left: 48px; }

/* Connector lines. A row's centre sits half a row plus half a pixel down,
   level with the 1px lines at top: var(--mid) and with the 9px blob's centre. */
.tree { --mid: calc(var(--row) / 2); }
.trunk { position: absolute; left: 4px; top: var(--mid); bottom: calc(var(--mid) - 1px); width: 1px; background: var(--line); }
.trunk-fill {
  position: absolute;
  inset: 0;
  background: var(--ink);
  transform: scaleY(0);
  transform-origin: 50% 0;
  will-change: transform;
}
.blob {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--ink);
  transform: translateY(calc(var(--mid) - 4px));
  will-change: transform;
}
.tree > ul > li:not(.t-root) > .row::before,
.tree ul ul .row::before,
.tree ul ul > li::before,
.tree ul ul > li:not(:last-child)::after {
  content: "";
  position: absolute;
  background: var(--line);
  transition: background-color .2s;
}
.tree > ul > li:not(.t-root) > .row::before { left: 5px; top: var(--mid); width: 13px; height: 1px; }
.tree ul ul > li { position: relative; }
.tree ul ul > li::before { left: 27px; top: 0; width: 1px; height: calc(var(--mid) + 1px); }
.tree ul ul > li:not(:last-child)::after { left: 27px; top: calc(var(--mid) + 1px); bottom: 0; width: 1px; }
.tree ul ul .row::before { left: 28px; top: var(--mid); width: 14px; height: 1px; }

/* The active row's connector, plus the way down to it from its parent. */
.tree li.is-active > .row::before,
.tree li.on-path > .row::before,
.tree ul ul > li.is-active::before,
.tree ul ul > li.trail::before,
.tree ul ul > li.trail:not(:last-child)::after { background: var(--ink); }

/* Hero. Centred on the whole page; on narrow windows it moves right only as
   far as it must to clear the sidebar. */
.hero {
  position: relative;
  display: flex;
  align-items: center;
  height: 100vh;
  height: 100svh;
}
.hero-inner {
  --name: min(8.5vw, 200px);         /* size of the name */
  --name-w: calc(var(--name) * 6.7); /* RUFUS SMITH is about 6.7em wide */
  --left: max(calc(var(--side) + var(--edge)), calc((100% - var(--name-w)) / 2));
  width: var(--name-w);
  margin-left: var(--left);
  text-align: center;
}
.hero-name {
  font-size: var(--name);
  font-weight: 700;
  line-height: .9;
  letter-spacing: -.02em;
  text-transform: uppercase;
  font-kerning: none;
  white-space: nowrap;
}
.hero-meta { margin-top: .8em; font-size: calc(var(--name) / 4); line-height: 1.2; }
.handle {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: .35em .8em;
  font-weight: 700;
  letter-spacing: -.02em;
}
.handle a { padding-bottom: 2px; border-bottom: 2px solid var(--underline); text-decoration: none; transition: border-color .25s; }
.handle a:hover, .handle a:focus-visible { border-color: var(--ink); }
.avatar { flex: none; width: 1.15em; height: 1.15em; margin-right: -.45em; border-radius: 50%; filter: grayscale(1); transition: filter .4s; }
.handle:hover .avatar, .handle:focus-within .avatar { filter: none; }

/* Until the intro runs, keep the hero name and handle hidden. If the script
   never runs, they appear after 3s anyway. This uses visibility, not
   opacity, because the scroll exit animates opacity. */
.intro .hero-name, .intro .handle { visibility: hidden; animation: intro-failsafe 0s 3s forwards; }
@keyframes intro-failsafe { to { visibility: visible; } }

/* Content column: left-aligned a fixed gap from the sidebar, so every title
   starts on the same line. */
.section {
  --left: calc(var(--side) + var(--gutter));
  width: min(var(--col), calc(100% - var(--left) - var(--edge)));
  margin-left: var(--left);
}
.section { padding-top: var(--gap-section); }
#projects { padding-top: 0; }
.section > .head { scroll-margin-top: var(--snap); } /* js/main.js snaps titles to this */
/* Tall enough that the last title can still snap to the top. */
main > .section:last-child { min-height: calc(100vh - var(--snap) + var(--gap-section)); }

.eyebrow { font: 400 13px/1.5 var(--mono); color: var(--grey); }
.head > .eyebrow + h2 { margin-top: 14px; }
h2 { font-size: clamp(32px, 3.4vw, 48px); font-weight: 700; line-height: 1; letter-spacing: -.035em; }
/* SplitText's line masks (js/main.js) clip at the line box, which cuts off descenders at line-height 1: pad the line so the mask reaches them, and pull the layout back. */
.section > .head > h2 > div { margin-bottom: -.2em; }
.section > .head > h2 > div > div { padding-bottom: .2em; }
h3, h2.title { font-size: clamp(21px, 1.7vw, 25px); font-weight: 650; line-height: 1.2; letter-spacing: -.02em; }
.when { font-size: 14px; color: var(--grey); font-variant-numeric: tabular-nums; white-space: nowrap; }

.section > .head + .entry, .section > .head + .schools { margin-top: var(--gap-head); }
#achievements > .head + .entry { margin-top: 48px; }
.section > .head + .plain { margin-top: 48px; }
.entry + .entry { margin-top: var(--gap-entry); }

.meta { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 10px; }
.url { display: flex; gap: 28px; margin-top: 8px; font-weight: 500; }
.url a::after { content: " ↗" / ""; } /* empty alt so screen readers skip the arrow */
.tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; list-style: none; }
.tags li {
  padding: 6px 10px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font: 400 12px/1 var(--mono);
  color: var(--grey);
}

.media { margin-top: 40px; }
.media a { display: block; }
.media img { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #EFEFEF; }
.media.portrait { max-width: 400px; }
.media figcaption { margin-top: 12px; font-size: 14px; line-height: 1.4; color: var(--grey); }

.body { margin-top: 36px; }
.media + .body { margin-top: 40px; }
.body > * + * { margin-top: 16px; }
.body ul { list-style: none; }
.body li { position: relative; padding-left: 24px; }
.body li + li { margin-top: 10px; }
.body li::before { content: ""; position: absolute; left: 0; top: .8em; width: 12px; height: 1px; background: var(--grey); }
.head + .body { margin-top: 28px; }

.org { display: flex; gap: 18px; align-items: flex-start; }
.org img { flex: none; width: 48px; height: 48px; margin-top: 2px; border-radius: 8px; }
.org h3 + p { margin-top: 4px; }
.context, .grades { color: var(--grey); }
.schools { list-style: none; }

.plain { list-style: none; }
.entry .plain { margin-top: 28px; }
.plain li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 24px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}
.plain li:last-child { border-bottom: 1px solid var(--line); }
.plain .when { font-size: 15px; text-align: right; }

/* Projects graph (js/graph.js): each project joined to its topics and tools.
   It lines up with the column on the left and takes the free width to the
   right. Nodes are moved with transforms; links are drawn on the canvas. */
.graph-intro, .project-list { margin-top: var(--gap-head); }
.graph-key { display: flex; flex-wrap: wrap; gap: 6px 20px; list-style: none; font: 400 13px/1.5 var(--mono); color: var(--grey); }
.graph-key li { display: flex; align-items: center; gap: 8px; }
.graph-hint { margin-top: 8px; font-size: 15px; color: var(--grey); }
.graph {
  position: relative;
  width: calc(100vw - var(--side) - var(--gutter) - var(--edge)); /* the column's left edge to the window edge */
  height: clamp(560px, calc(100vh - 140px), 1000px);
  margin-top: 16px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}
.graph canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.node {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: center;
  translate: -50% calc(-1 * var(--r));
  cursor: grab;
  touch-action: none;
  transition: opacity .3s;
}
.node:active { cursor: grabbing; }
[data-kind="project"] { --r: 6px; }
[data-kind="topic"] { --r: 4px; }
[data-kind="tool"] { --r: 3px; }
.pip { flex: none; width: calc(2 * var(--r)); height: calc(2 * var(--r)); border-radius: 50%; transition: transform .3s, box-shadow .3s; }
.pip[data-kind="project"] { background: var(--ink); }
.pip[data-kind="topic"] { background: var(--bg); box-shadow: inset 0 0 0 1.5px var(--ink); }
.pip[data-kind="tool"] { background: var(--grey); }
.node .label { padding: 0 4px; border-radius: 4px; background: var(--bg); line-height: 1.3; white-space: nowrap; transition: color .3s; }
.node[data-kind="project"] { cursor: pointer; }
.node[data-kind="project"] .label { max-width: 15em; white-space: normal; text-wrap: balance; font-size: 13px; font-weight: 600; letter-spacing: -.01em; }
.node[data-kind="project"] small { display: block; margin-top: 2px; font: 400 11px/1.4 var(--mono); letter-spacing: 0; color: var(--grey); }
.node[data-kind="topic"] .label { font: 400 11px/1.4 var(--mono); }
.node[data-kind="tool"] .label { font: 400 11px/1.4 var(--mono); color: var(--grey); }
.node.hot .pip { transform: scale(1.35); }
.node.hot .pip[data-kind="project"], .node:focus-visible .pip[data-kind="project"] { transform: none; box-shadow: 0 0 0 3px var(--bg), 0 0 0 4px var(--ink); }
.node:focus-visible { outline: none; }
.node:focus-visible .label { outline: 1px solid var(--ink); outline-offset: 1px; }
.graph.lit .node:not(.on) { opacity: .15; }
.graph.lit .node.on .label { color: var(--ink); }

/* A project's own page. Opening one slides the whole page left as the
   project comes in from the right; --back (0 to 1) follows a swipe back. */
.view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: var(--bg);
  color: var(--ink);
  box-shadow: -1px 0 0 var(--line), -32px 0 64px -32px rgb(0 0 0 / .18);
  transform: translateX(100%);
  transition: transform .45s cubic-bezier(.32, .72, 0, 1);
}
.view.shown { transform: none; }
.view::backdrop { background: transparent; }
.side, main { transition: transform .45s cubic-bezier(.32, .72, 0, 1), opacity .45s; }
.viewing .side, .viewing main { transform: translateX(calc(-20% * (1 - var(--back, 0)))); opacity: calc(.35 + .65 * var(--back, 0)); }
.dragging .side, .dragging main, .dragging .view { transition: none; }
html:has(.view[open]) { overflow: hidden; }
.view-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 64px;
  padding: 0 var(--edge);
  border-bottom: 1px solid var(--line);
  background: rgb(248 248 248 / .92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.back { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; background: none; color: var(--ink); cursor: pointer; transition: border-color .2s, transform .2s; }
.back:hover { border-color: var(--ink); transform: translateX(-2px); }
.view-path { overflow: hidden; font: 400 13px/1.5 var(--mono); color: var(--grey); white-space: nowrap; text-overflow: ellipsis; }
.view-leaf { color: var(--ink); }
.view-body { width: min(var(--col), 100% - 2 * var(--edge)); margin: 0 auto; padding: 9vh 0 16vh; }
.view h3 { font-size: clamp(36px, 4.4vw, 56px); font-weight: 700; line-height: 1.05; letter-spacing: -.035em; }

/* Scroll reveals. The script marks targets with data-reveal and then adds
   .reveals to <html>, so without it (or with reduced motion) nothing hides. */
.reveals [data-reveal] { opacity: 0; transform: translateY(var(--reveal)); }

/* 404 */
.notfound { display: flex; flex-direction: column; justify-content: center; min-height: 100vh; padding: 48px max(24px, 8vw); }
.notfound h1 { font-size: clamp(48px, 9vw, 128px); font-weight: 700; line-height: .95; letter-spacing: -.035em; }
.notfound .lead { margin-top: 24px; font-size: clamp(18px, 1.8vw, 22px); }
.links { display: flex; flex-wrap: wrap; gap: 12px 32px; margin-top: 32px; list-style: none; }
.links a { font-weight: 500; }

/* Digit recognition demo (scoresheet-demo.html) */
.demo { width: min(var(--col), 100% - 2 * var(--edge)); margin: 0 auto; padding: 9vh 0 16vh; }
.demo h1 { margin-top: 32px; font-size: clamp(36px, 4.4vw, 56px); font-weight: 700; line-height: 1.05; letter-spacing: -.035em; }
.demo .lead { margin-top: 20px; font-size: clamp(18px, 1.8vw, 22px); }
.demo > h2 { margin-top: 64px; font-size: 24px; letter-spacing: -.02em; }
.demo > p:not(.lead, .mnist-status), .demo > ol { margin-top: 16px; }
.demo > ol { padding-left: 1.4em; }
.demo > ol li + li { margin-top: 8px; }
.mnist { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 40px; }
.mnist-pane { display: flex; flex-direction: column; gap: 8px; }
.mnist-chart { position: relative; flex: 1 1 280px; }
.mnist-label, .mnist-mono, .mnist-digits { font: 400 11px/1.4 var(--mono); color: var(--grey); }
.mnist-label { display: flex; justify-content: space-between; gap: 12px; text-transform: uppercase; letter-spacing: .14em; }
.mnist canvas { display: block; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
[data-mnist="draw"] { width: 280px; height: 280px; max-width: 100%; aspect-ratio: 1; cursor: crosshair; touch-action: none; }
[data-mnist="draw"]:hover { border-color: var(--underline); }
[data-mnist="chart"] { width: 100%; height: 280px; }
[data-mnist="clear"] { align-self: flex-start; padding: 6px 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font: 500 14px/1.4 var(--sans); cursor: pointer; }
[data-mnist="clear"]:hover { border-color: var(--ink); }
.mnist-digits { display: grid; grid-template-columns: repeat(10, 1fr); text-align: center; list-style: none; font-size: 12px; }
.mnist-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; pointer-events: none; }
.mnist-overlay > * { max-width: 420px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font: 400 12px/1.5 var(--mono); }
.mnist-overlay h2 { font: 600 15px/1.4 var(--sans); }
.mnist-overlay p + p, .mnist-overlay h2 + p { margin-top: 6px; font-family: var(--sans); font-size: 14px; color: var(--grey); }
.mnist-status { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
[data-mnist="dot"] { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
[data-mnist="dot"][data-phase="ready"] { background: var(--grey); }
[data-mnist="dot"][data-phase="classifying"] { background: var(--ink); }

/* Phones and small tablets: the sidebar becomes a top bar showing the path,
   with a progress line, and the tree opens from it as a sheet. */
@media (max-width: 899px) {
  :root { --side: 0px; --gutter: var(--edge); --row: 36px; --reveal: 24px; --snap: 72px; --gap-section: 12vh; --gap-entry: 9vh; --gap-head: 6vh; }
  .side {
    inset: 0 0 auto 0;
    z-index: 20;
    width: auto;
    height: 48px;
    padding: 0 52px 0 20px;
    overflow: visible;
    background: var(--bg);
  }
  .path { margin: 0; overflow: hidden; line-height: 48px; }
  .menu {
    display: block;
    position: absolute;
    inset: 0;
    width: 100%;
    border: 0;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .menu::after {
    content: "";
    position: absolute;
    top: 19px;
    right: 24px;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--ink);
    border-bottom: 1.5px solid var(--ink);
    transform: rotate(45deg);
    transition: transform .25s;
  }
  .menu[aria-expanded="true"]::after { transform: translateY(4px) rotate(-135deg); }
  .menu:focus-visible { outline-offset: -4px; }
  .progress { display: block; position: absolute; right: 0; bottom: 0; left: 0; height: 1px; background: var(--line); }
  .progress-fill {
    position: absolute;
    inset: 0;
    background: var(--ink);
    transform: scaleX(0);
    transform-origin: 0 50%;
    will-change: transform;
  }
  .sheet {
    position: fixed;
    top: 48px;
    right: 0;
    left: 0;
    max-height: calc(100svh - 48px);
    padding: 12px 20px 24px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    visibility: hidden;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity .25s, transform .25s, visibility 0s .25s;
  }
  .menu-open .sheet { visibility: visible; opacity: 1; transform: none; transition: opacity .25s, transform .25s; }
  html.menu-open { overflow: hidden; }
  .hero-inner { --name: min(26vw, 200px); width: auto; margin-inline: var(--edge); }
  .hero-name { white-space: normal; }
  .plain li { flex-direction: column; gap: 2px; }
  .plain .when { text-align: left; }
  .graph { height: 640px; }
  .view-bar { height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .caret { animation: none; }
  .sheet, .menu-open .sheet, .menu::after, .view, .side, main { transition: none; }
}
