/*
 * Layout, sheets, rail, typography.
 *
 * The page is written for the stacked reading first: every section is an
 * ordinary block, every picture is finished. That is what phones, reduced
 * motion, and readers without JavaScript get. The held-and-peeled film is a
 * layer on top, switched on by html[data-motion="pinned"] (see the end of
 * this file); nothing below depends on it.
 *
 * Every colour is a role from tokens.css. Nothing here states a raw value.
 */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: auto; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sign);
  font-size: var(--text-md);
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
h1, h2, h3, p, ul, ol, figure, pre { margin: 0; }
ul, ol { padding: 0; list-style: none; }
code, pre { font-family: var(--font-mono); font-variant-ligatures: none; }

/* ───────────────────────── grounds ───────────────────────── */

.hero, .face, .end-section, .foot {
  position: relative;
  color: var(--ink);
  background-color: var(--bg);
  background-image: var(--texture);
  isolation: isolate;
}
/* Grain over every ground, under the content. */
.hero::after, .face::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: var(--grain);
  pointer-events: none;
}

/* ───────────────────────── signage ───────────────────────── */

.ch-kicker {
  display: flex;
  align-items: baseline;
  gap: .6em;
  font-family: var(--font-sign);
  font-size: var(--text-sm);
  font-weight: 600;
  font-stretch: 112%;
  letter-spacing: .1em;
  font-variant-caps: all-small-caps;
  font-size: 1.05rem;
  color: var(--ink-2);
}
.ch-num {
  font-family: var(--font-display);
  font-weight: 400;
  font-variant-caps: normal;
  letter-spacing: 0;
  font-size: 2.4em;
  line-height: .8;
  color: var(--accent);
}
.ch-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-statement);
  line-height: 1.02;
  letter-spacing: -.01em;
  text-wrap: balance;
  color: var(--ink);
}
.ch-body { max-width: var(--measure); font-size: var(--text-md); color: var(--ink); text-wrap: pretty; }
.ch-body + .ch-body { margin-top: var(--space-sm); }
.ch-caption {
  max-width: var(--measure);
  margin-top: var(--space-md);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--line);
  font-size: var(--text-sm);
  font-stretch: 94%;
  color: var(--ink-2);
}
.small-head {
  font-size: var(--text-sm);
  font-weight: 600;
  font-stretch: 112%;
  letter-spacing: .1em;
  font-variant-caps: all-small-caps;
  font-size: 1rem;
  color: var(--ink-2);
}
.todo {
  display: inline-block;
  padding: .05em .45em;
  border: 1px dashed currentColor;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: .8em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.ch-todo { margin-top: var(--space-sm); font-size: var(--text-sm); }

/* ───────────────────────── chrome ───────────────────────── */

.skip {
  position: absolute; left: var(--space-sm); top: -4rem; z-index: 100;
  padding: var(--space-xs) var(--space-sm); border-radius: 6px;
  background: var(--chrome-bg); color: var(--chrome-ink);
}
.skip:focus { top: var(--space-sm); }

.theme-toggle {
  position: fixed; z-index: 60; top: var(--space-sm); right: var(--space-sm);
  display: grid; place-items: center;
  width: 2.75rem; height: 2.75rem; padding: 0;
  border: 1px solid var(--chrome-line); border-radius: 50%;
  background: var(--chrome-bg); color: var(--chrome-ink);
  cursor: pointer;
  transition: transform var(--dur-short) var(--ease-out), border-color var(--dur-short) var(--ease-out);
}
.theme-toggle:hover { border-color: var(--chrome-ink-2); transform: rotate(-12deg); }
.theme-toggle:focus-visible { outline-color: var(--chrome-accent); }
.theme-toggle svg { grid-area: 1 / 1; width: 1.3rem; height: 1.3rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; }
.theme-toggle[data-showing="dark"] .icon-moon,
.theme-toggle[data-showing="light"] .icon-sun,
.theme-toggle:not([data-showing]) .icon-moon { display: none; }

/* ───────────────────────── hero ───────────────────────── */

.hero {
  min-height: 100svh;
  display: grid;
  align-items: end;
  overflow: clip;
  /* The top rows belong to the field (its glowing lines live there); the headline starts below them. */
  padding: max(9.5rem, 30vh) var(--gutter) clamp(3rem, 10vh, 7rem);
  padding-right: calc(var(--gutter) + var(--rail-w));
}
.hero-field {
  position: absolute; inset: 1rem 0 0 0; z-index: -1; overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 0, #000 9rem, rgb(0 0 0 / .5) 14rem, rgb(0 0 0 / .3) 100%);
  mask-image: linear-gradient(180deg, #000 0, #000 9rem, rgb(0 0 0 / .5) 14rem, rgb(0 0 0 / .3) 100%);
}
.hero-inner { position: relative; display: grid; gap: var(--space-md); max-width: 62rem; }
/* A soft scrim of the ground behind the words, so the field never competes with them. */
.hero-inner::before {
  content: ""; position: absolute; z-index: -1; inset: -3rem -6rem -3rem calc(-1 * var(--gutter));
  background: radial-gradient(ellipse 75% 70% at 35% 50%, var(--bg) 45%, color-mix(in oklch, var(--bg) 70%, transparent) 70%, transparent 100%);
  pointer-events: none;
}
.hero-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--text-hero);
  line-height: .98;
  letter-spacing: -.015em;
  text-wrap: balance;
}
.hero-sign {
  font-weight: 600; font-stretch: 116%; letter-spacing: .12em; font-variant-caps: all-small-caps;
  font-size: clamp(1rem, .9rem + .4vw, 1.25rem); color: var(--ink-2);
}
.hero-sign .dot { color: var(--accent); }
.hero-summary { max-width: 40rem; font-size: var(--text-lg); line-height: 1.5; color: var(--ink); text-wrap: pretty; }
.hero-scroll { margin-top: var(--space-lg); font-size: var(--text-xs); font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); }

/* ───────────────────────── rail ───────────────────────── */

/* Without JavaScript the rail is a plain table of contents under the headline. */
.rail { background: var(--bg); padding: var(--space-lg) var(--gutter); border-top: 1px solid var(--line); }
.rail-list { display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-md); }
.rail-item {
  display: inline-flex; align-items: baseline; gap: .4em; text-decoration: none;
  font-weight: 600; font-stretch: 112%; letter-spacing: .08em; font-variant-caps: all-small-caps; font-size: 1.05rem;
  color: var(--ink);
}
.rail-num { font-family: var(--font-display); font-weight: 400; font-variant-caps: normal; letter-spacing: 0; font-size: 1.1em; color: var(--ink-2); }
.rail-num:empty { display: none; }
html[data-rail="side"] .rail-num:empty { display: block; }
.rail-meter, .rail-bar { display: none; }

/* Narrow with JavaScript: a slim progress bar across the top. */
html[data-rail="bar"] .rail { position: static; padding: 0; border: 0; background: none; }
html[data-rail="bar"] .rail-list { display: none; }
html[data-rail="bar"] .rail-bar {
  display: block; position: fixed; z-index: 55; inset: 0 0 auto 0; height: 3px;
  background: var(--chrome-line);
}
html[data-rail="bar"] .rail-bar-fill { display: block; height: 100%; background: var(--chrome-accent); transform-origin: 0 50%; transform: scaleX(var(--progress, 0)); }

/* Wide with JavaScript: a floating rail at the right edge. Its width is reserved by every section. */
html[data-rail="side"] { --rail-w: 11.5rem; }
html[data-rail="side"] .rail {
  position: fixed; z-index: 50; right: var(--space-sm); top: 50%;
  width: calc(var(--rail-w) - 2 * var(--space-sm));
  transform: translateY(-50%);
  padding: var(--space-sm) var(--space-sm) var(--space-sm) var(--space-md);
  border: 1px solid var(--chrome-line); border-radius: 12px;
  background: var(--chrome-bg); color: var(--chrome-ink);
  opacity: 0; visibility: hidden; transition: opacity 240ms var(--ease-out), visibility 0s linear 240ms;
}
html[data-rail="side"] .rail.is-on { opacity: 1; visibility: visible; transition: opacity 240ms var(--ease-out); }
html[data-rail="side"] .rail-list { flex-direction: column; flex-wrap: nowrap; gap: 0; }
html[data-rail="side"] .rail-item {
  display: grid; grid-template-columns: 1.9rem 1fr; grid-template-rows: auto auto; align-items: baseline;
  padding: .28rem 0; font-size: .98rem; color: var(--chrome-ink-2);
}
html[data-rail="side"] .rail-num { grid-column: 1; color: inherit; }
html[data-rail="side"] .rail-name { grid-column: 2; }
html[data-rail="side"] .rail-meter {
  display: block; grid-column: 2; height: 2px; margin-top: .2rem; background: var(--chrome-line);
  transform-origin: 0 50%; transform: scaleY(0); transition: transform var(--dur-short) var(--ease-out);
}
html[data-rail="side"] .rail-fill { display: block; height: 100%; background: var(--chrome-accent); transform-origin: 0 50%; transform: scaleX(var(--progress, 0)); }
html[data-rail="side"] .rail-item.is-past { color: var(--chrome-ink-2); }
html[data-rail="side"] .rail-item.is-here { color: var(--chrome-ink); }
html[data-rail="side"] .rail-item.is-here .rail-num { color: var(--chrome-accent); }
html[data-rail="side"] .rail-item.is-here .rail-meter { transform: scaleY(1); }

/* ───────────────────────── sheets ───────────────────────── */

.sheet { position: relative; }
/* Stacked, each sheet still starts at a physical edge: rounded, lapping the one above. */
.sheet + .sheet, .stack + .end-section { margin-top: calc(-1 * var(--radius-sheet)); }
.plate { position: relative; background: var(--deep); border-radius: var(--radius-sheet) var(--radius-sheet) 0 0; }
.face { border-radius: inherit; overflow: clip; }
.shade { position: absolute; inset: 0; z-index: 5; border-radius: inherit; background: var(--deep); opacity: 0; pointer-events: none; }

.sheet-inner {
  display: grid;
  gap: var(--space-lg);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "head" "notes" "pic";
  padding: clamp(3.5rem, 9vh, 6rem) var(--gutter) clamp(4rem, 10vh, 7rem);
  padding-right: calc(var(--gutter) + var(--rail-w));
  max-width: calc(84rem + var(--rail-w));
}
.ch-head { display: grid; gap: var(--space-md); align-content: start; }
.sheet-inner > .ch-head { grid-area: head; }
.sheet-inner > .ch-notes { grid-area: notes; align-self: start; }
.sheet-inner > .ch-pic { grid-area: pic; min-width: 0; }
.demo { width: 100%; max-width: 44rem; margin-inline: auto; }

@media (min-width: 1024px) {
  .sheet-inner {
    min-height: 100svh;
    align-content: center;
    grid-template-columns: minmax(0, .82fr) minmax(0, 1.18fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "head pic" "notes pic";
    column-gap: clamp(2rem, 4.5vw, 5rem);
  }
  .sheet[data-layout="flip"] .sheet-inner { grid-template-columns: minmax(0, 1.18fr) minmax(0, .82fr); grid-template-areas: "pic head" "pic notes"; }
  .sheet-inner > .ch-pic { align-self: center; }
}

/* ───────────────────────── who ───────────────────────── */

.who-inner { grid-template-areas: "photo" "text"; align-items: center; }
.who-photo { grid-area: photo; width: min(240px, 60vw); }
.who-photo img {
  width: 100%; height: auto; aspect-ratio: 1; object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 1px 0 var(--line), 0 24px 48px -24px oklch(30% 0.03 60 / .45);
}
.who-text { grid-area: text; display: grid; gap: var(--space-md); max-width: 40rem; }
.who-lines { display: grid; gap: var(--space-sm); }
.who-lines li {
  font-family: var(--font-display); font-size: clamp(1.35rem, 1.05rem + 1vw, 1.9rem); line-height: 1.2;
  padding-left: 1.1em; position: relative; text-wrap: pretty;
}
.who-lines li::before { content: "—"; position: absolute; left: 0; color: var(--accent); }
.who-team { padding-top: var(--space-sm); border-top: 1px solid var(--line); color: var(--ink-2); font-size: var(--text-sm); max-width: var(--measure); }
@media (min-width: 1024px) {
  .who-inner { grid-template-columns: auto minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "photo text"; column-gap: clamp(2.5rem, 6vw, 6rem); }
  .who-photo { width: 240px; }
}

/* ───────────────────────── work sheets ───────────────────────── */

.ch-kicker { flex-wrap: wrap; }
.ch-when {
  margin-left: auto; padding-left: var(--space-sm);
  font-weight: 500; font-stretch: 100%; letter-spacing: .06em; font-size: .95rem; color: var(--ink-2);
}
.tech { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: var(--space-md); max-width: var(--measure); }
.tech li {
  padding: .22rem .65rem; border: 1px solid var(--line); border-radius: 999px;
  font-size: var(--text-xs); font-weight: 600; letter-spacing: .02em; color: var(--ink);
  background: color-mix(in oklch, var(--bg), var(--ink) 4%);
}
/* A sheet with steps puts them under its picture: "head pic" / "notes steps". */
.sheet-inner.has-steps { grid-template-areas: "head" "notes" "pic" "steps"; }
.sheet-inner > .ch-side { grid-area: steps; align-self: start; }
.ch-side .ch-caption { margin-top: var(--space-sm); }
.ch-side .tech { margin-top: var(--space-sm); }
@media (min-width: 1024px) {
  .sheet-inner.has-steps { grid-template-areas: "head pic" "notes steps"; grid-template-rows: auto 1fr; row-gap: var(--space-md); }
  .sheet-inner.has-steps > .ch-pic { align-self: end; }
  /* Notes (the Claude Code pinboard) run full width under the picture and the words. */
  #ai .sheet-inner.has-steps { grid-template-areas: "pic head" "pic notes" "side side"; grid-template-rows: auto auto auto; }
  #ai .sheet-inner.has-steps > .ch-pic { align-self: center; }
  #ai .sheet-inner.has-steps > .ch-side { grid-area: side; margin-top: var(--space-md); }
  #ai .pinboard { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem .9rem; }
  #ai .ch-side .tech, #ai .ch-side .ch-caption { max-width: none; }
  .sheet-inner.has-steps { padding-block: clamp(2.5rem, 6vh, 4rem); }
}
.steps { display: grid; gap: .4rem; margin: 0; padding: 0; max-width: 40rem; counter-reset: step; align-self: start; }
.steps li { position: relative; padding-left: 2rem; font-size: var(--text-sm); line-height: 1.45; color: var(--ink); counter-increment: step; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: -.05rem;
  font-family: var(--font-display); font-size: 1.35rem; line-height: 1; color: var(--accent);
}
.steps b { font-weight: 650; }
.ch-links { margin-top: var(--space-sm); font-family: var(--font-mono); font-size: var(--text-sm); }
.ch-links a { color: var(--accent); }

/* GitHub: the repo cards are the picture. */
.repos-inner { grid-template-areas: "head" "repos" "early"; }
.repos-inner > .ch-head { grid-area: head; }
.repos { grid-area: repos; display: grid; gap: var(--space-sm); grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr)); }
.repo {
  display: grid; gap: .3rem; align-content: start;
  padding: 1rem 1.1rem 1.1rem; border: 1px solid var(--line); border-radius: 10px;
  background: color-mix(in oklch, var(--bg), var(--ink) 4%);
  border-top: 3px solid var(--accent);
}
.repo:nth-child(even) { border-top-color: var(--accent-2); }
.repo-top { display: flex; align-items: baseline; gap: .6rem; }
.repo-name { font-family: var(--font-mono); font-size: .92rem; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.repo-stars { margin-left: auto; font-size: var(--text-xs); font-weight: 700; color: var(--accent); white-space: nowrap; }
.repo-lang { font-size: var(--text-xs); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); }
.repo-blurb { font-size: var(--text-sm); color: var(--ink); line-height: 1.5; }
.early { grid-area: early; display: grid; gap: var(--space-xs); }
.early-list { display: flex; flex-wrap: wrap; gap: .35rem 1.2rem; font-family: var(--font-mono); font-size: var(--text-sm); }
.early-list a { color: var(--ink); }
.early-list .repo-stars { margin-left: .4rem; }
@media (min-width: 1024px) {
  .repos-inner { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "head" "repos" "early"; align-content: center; }
  .repos-inner > .ch-head .ch-title { max-width: 22ch; }
  .repos { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

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

/* ───────────────────────── contact ───────────────────────── */

.end-section { padding: clamp(4rem, 12vh, 8rem) var(--gutter) var(--space-2xl); padding-right: calc(var(--gutter) + var(--rail-w)); border-radius: var(--radius-sheet) var(--radius-sheet) 0 0; }
.end-section::after { content: ""; position: absolute; inset: 0; z-index: -1; background-image: var(--grain); pointer-events: none; }
.contact { display: grid; gap: var(--space-md); max-width: 48rem; }
.contact-h { font-family: var(--font-display); font-weight: 400; font-size: var(--text-statement); line-height: 1.02; }
.contact-body { color: var(--ink-2); max-width: var(--measure); font-size: var(--text-lg); }
.contact-links { display: grid; gap: 0; border-top: 1px solid var(--line); margin-top: var(--space-sm); }
.contact-links li {
  display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: var(--space-2xs) var(--space-md); align-items: baseline;
  padding: .75rem 0; border-bottom: 1px solid var(--line);
}
.contact-links li > .todo { grid-column: 2; }
.contact-k { font-weight: 600; font-stretch: 112%; letter-spacing: .08em; font-variant-caps: all-small-caps; font-size: 1.05rem; color: var(--ink-2); }
.contact-links a { font-size: var(--text-lg); overflow-wrap: anywhere; }

.foot {
  display: grid; gap: var(--space-2xs);
  padding: var(--space-lg) var(--gutter) var(--space-xl); padding-right: calc(var(--gutter) + var(--rail-w));
  font-size: var(--text-xs); color: var(--ink-2); border-top: 1px solid var(--line);
}

/* ───────────────────────── small screens ───────────────────────── */

@media (max-width: 640px) {
  .theme-toggle { top: auto; bottom: var(--space-sm); }
  .contact-links li { grid-template-columns: minmax(0, 1fr); }
}

/* ───────────────────────── held and rising sheets (pinned mode) ───────────────────────── */

/*
 * overview.js measures each plate (--plate-h) and the window (--stage-h).
 * The held section is one stage taller than its plate and its plate sticks
 * by its bottom edge (--stick-top); the riser overlaps it by exactly that
 * stage, so it rises over a sheet that is holding still. The riser then holds
 * for --play stages while its picture is scrubbed.
 */
html[data-motion="pinned"] .sheet.is-held { height: calc(var(--plate-h) + var(--stage-h)); }
html[data-motion="pinned"] .sheet.is-held > .plate,
html[data-motion="pinned"] .sheet.is-riser > .plate { position: sticky; top: var(--stick-top, 0px); }
html[data-motion="pinned"] .sheet.is-riser {
  height: calc(var(--plate-h) + var(--play, 1) * var(--stage-h));
  margin-top: calc(-1 * var(--stage-h));
}
html[data-motion="pinned"] .sheet.is-riser > .plate { box-shadow: var(--shadow-rise); will-change: transform; }
html[data-motion="pinned"] .sheet.is-held .face { will-change: transform; }

/* ───────────────────────── pinboard (Claude Code) ───────────────────────── */

/* Hand-kept, but tidy: note cards with a slight, deliberate tilt and a coloured tag. */
.ch-side > .small-head { margin-bottom: var(--space-sm); }
.pinboard { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 13.5rem), 1fr)); gap: .8rem .75rem; }
.pin {
  position: relative; display: grid; gap: .2rem; align-content: start;
  padding: .7rem .8rem .8rem;
  border: 1px solid var(--line); border-radius: 6px;
  background: color-mix(in oklch, var(--bg), var(--ink) 7%);
  box-shadow: 0 10px 22px -16px oklch(0% 0 0 / .7);
  transform: rotate(var(--tilt, 0deg));
  transition: transform var(--dur-short) var(--ease-out);
}
.pin:nth-child(4n + 1) { --tilt: -1.2deg; }
.pin:nth-child(4n + 2) { --tilt: .9deg; }
.pin:nth-child(4n + 3) { --tilt: -.5deg; }
.pin:nth-child(4n) { --tilt: 1.4deg; }
.pin:hover { transform: rotate(0deg) translateY(-2px); }
/* A strip of tape on every other card. */
.pin:nth-child(odd)::before {
  content: ""; position: absolute; top: -.45rem; left: 50%; width: 2.6rem; height: .9rem;
  transform: translateX(-50%) rotate(-3deg);
  background: color-mix(in oklch, var(--accent) 30%, transparent); border-radius: 2px;
}
.pin-tag {
  justify-self: start; padding: .05rem .45rem; border-radius: 999px;
  font-family: var(--font-mono); font-size: .68rem; font-weight: 600; letter-spacing: .04em;
  color: var(--bg); background: var(--accent);
}
.pin-loop .pin-tag { background: var(--accent-2); }
.pin-human .pin-tag { background: var(--ink); }
.pin-mcp .pin-tag { background: var(--ink-2); }
.pin-side-project .pin-tag { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.pin-name { font-size: var(--text-sm); font-weight: 650; color: var(--ink); }
.pin-text { font-size: .8rem; line-height: 1.4; color: var(--ink-2); }
@media (prefers-reduced-motion: reduce) { .pin:hover { transform: rotate(var(--tilt, 0deg)); } }
