/* ─── Tokens ─────────────────────────────────────────────── */
:root {
  --font-body: "Instrument Sans", system-ui, sans-serif;
  --font-display: "Instrument Serif", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --max: 1060px;
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #faf9f5;
  --panel: #ffffff;
  --ink: #1c1b16;
  --muted: #6e6c60;
  --line: #e8e5da;
  --line-strong: #d8d4c6;
  --accent: #c05b2e;
  --accent-ink: #a84e26;
  --accent-soft: #f6e9e1;
  --ok: #2e7d43;
  --shadow: 0 1px 2px rgba(28, 27, 22, 0.04), 0 12px 40px rgba(28, 27, 22, 0.07);
  --shadow-lift: 0 2px 4px rgba(28, 27, 22, 0.05), 0 20px 60px rgba(28, 27, 22, 0.10);
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161511;
  --panel: #1e1d17;
  --ink: #f0eee6;
  --muted: #a3a094;
  --line: #33312a;
  --line-strong: #45423a;
  --accent: #e07a4a;
  --accent-ink: #e07a4a;
  --accent-soft: #2b241e;
  --ok: #7fd68f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 40px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.35), 0 20px 60px rgba(0, 0, 0, 0.45);
}

/* ─── Base ───────────────────────────────────────────────── */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
}
.mono { font-family: var(--font-mono); font-size: 0.76em; letter-spacing: 0.05em; }
.muted { color: var(--muted); }
a { color: inherit; }
em { font-family: var(--font-display); font-style: italic; }
::selection { background: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 3px; border-radius: 3px; }

.skip {
  position: absolute; left: -999px; top: 8px;
  background: var(--accent); color: #fff;
  padding: 8px 14px; z-index: 30; border-radius: 6px;
}
.skip:focus { left: 8px; }

/* ─── Header ─────────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: 14px max(24px, calc((100% - var(--max)) / 2 + 24px));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { text-decoration: none; font-weight: 600; letter-spacing: -0.01em; }
.top nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.top nav a {
  text-decoration: none; font-size: 0.92rem; color: var(--muted);
  padding: 8px 10px; border-radius: 7px;
}
.top nav a:hover { color: var(--ink); background: color-mix(in srgb, var(--line) 40%, transparent); }
#theme-toggle {
  background: none; border: 1px solid var(--line); color: var(--ink);
  border-radius: 50%; width: 33px; height: 33px; cursor: pointer;
  display: grid; place-items: center; flex: none;
}
#theme-toggle:hover { border-color: var(--line-strong); }
html[data-theme="dark"] .icon-moon { display: none; }
html[data-theme="light"] .icon-sun { display: none; }
.btn.small { padding: 8px 14px; font-size: 0.88rem; }
/* phones: the four section links can't share a row with the brand; scrolling replaces them */
@media (max-width: 720px) { .top nav { display: none; } #theme-toggle { margin-left: auto; } }

/* ─── Buttons ────────────────────────────────────────────── */
.cta-row { display: flex; flex-wrap: wrap; gap: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border: 1px solid var(--line-strong); border-radius: 10px;
  text-decoration: none; font-weight: 500; font-size: 0.95rem;
  background: var(--panel); color: var(--ink);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--accent-ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { box-shadow: var(--shadow-lift); }
button.btn { font: inherit; cursor: pointer; }
.btn .ext { font-size: 0.6rem; border: 1px solid currentColor; padding: 1px 4px; border-radius: 3px; opacity: 0.7; }

/* ─── Hero ───────────────────────────────────────────────── */
.hero {
  max-width: var(--max); margin: 0 auto;
  padding: 96px 24px 72px;
}
.kicker { color: var(--accent-ink); margin: 0 0 22px; }
.hero h1 {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(3rem, 8.5vw, 5.4rem);
  line-height: 1.02; letter-spacing: -0.015em;
  margin: 0 0 26px;
}
.hero h1 em { color: var(--accent-ink); }
.lede { color: var(--muted); font-size: 1.16rem; max-width: 56ch; margin: 0 0 34px; }
.lede strong { color: var(--ink); font-weight: 600; }
.quicklinks { margin: 22px 0 0; display: flex; flex-wrap: wrap; gap: 4px 22px; }
.quicklinks a { color: var(--muted); text-decoration: none; padding: 6px 0; }
.quicklinks a:hover { color: var(--accent-ink); }
/* phones: one row would orphan the last link, so use a deliberate 2x2 */
@media (max-width: 480px) { .quicklinks { display: grid; grid-template-columns: repeat(2, max-content); } }

/* ─── Sections ───────────────────────────────────────────── */
.section { max-width: var(--max); margin: 0 auto; padding: 72px 24px; }
.section-eyebrow { color: var(--accent-ink); margin: 0 0 14px; }
.section-title {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(2.1rem, 5.4vw, 3.3rem);
  line-height: 1.05; letter-spacing: -0.01em;
  margin: 0 0 18px;
}
.section-sub { color: var(--muted); max-width: 58ch; margin: 0 0 26px; }
.section-sub a { text-decoration-color: var(--accent-ink); text-underline-offset: 3px; }

/* ─── Chapters ───────────────────────────────────────────── */
.chapter {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 56px; align-items: center;
  padding: 56px 0;
  border-top: 1px solid var(--line);
}
.chapter:first-of-type { border-top: none; }
.chapter.flip .chapter-text { order: 2; }
.chapter-num {
  color: var(--accent-ink); font-size: 0.8rem;
  border: 1px solid var(--line-strong); border-radius: 50%;
  width: 34px; height: 34px; display: grid; place-items: center;
  margin: 0 0 18px;
}
.chapter h3 {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(1.7rem, 3.6vw, 2.3rem);
  line-height: 1.08; margin: 0 0 16px; letter-spacing: -0.01em;
}
.chapter p { color: var(--muted); max-width: 54ch; margin: 0 0 14px; }
.chapter p strong { color: var(--ink); font-weight: 600; }
.chapter .tech { color: var(--accent-ink); margin-top: 18px; }

/* chapter figures - communicating cards */
.run-card, .chat-card, .eval-card, .stat-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow);
  padding: 26px 28px; margin: 0;
}
.run-card figcaption, .chat-card figcaption, .eval-card figcaption, .eval-card .cap {
  color: var(--muted); font-size: 0.66rem; margin-bottom: 16px;
}
.run-steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.run-steps li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--line);
  font-size: 0.95rem; color: var(--muted);
  transition: color 0.3s;
}
.run-steps li::before {
  content: "○"; color: var(--line-strong); flex: none;
  transition: color 0.3s;
}
.run-steps li.done { color: var(--ink); }
.run-steps li.done::before { content: "●"; color: var(--ok); }
.run-steps li .who { margin-left: auto; color: var(--accent-ink); flex: none; }
.flow { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0; }
.flow li {
  position: relative; padding: 11px 0 11px 26px;
  color: var(--muted); font-size: 0.8rem;
}
.flow li::before {
  content: ""; position: absolute; left: 6px; top: 18px;
  width: 8px; height: 8px; border-radius: 50%;
  border: 2px solid var(--accent); background: var(--panel);
}
.flow li:not(:last-child)::after {
  content: ""; position: absolute; left: 11px; top: 30px; bottom: -8px;
  width: 1px; background: var(--line-strong);
}
.flow li:last-child { color: var(--ok); }
.eval-card .cap { margin: 22px 0 16px; }
.signals { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.signals li {
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.04em;
  border: 1px solid var(--line-strong); border-radius: 100px;
  padding: 6px 13px; color: var(--muted);
}
.stat-card { display: flex; flex-direction: column; gap: 18px; }
.bignum span {
  font-family: var(--font-display); font-size: 2.6rem; line-height: 1;
  color: var(--accent-ink); display: block;
}
.bignum small { color: var(--muted); font-size: 0.85rem; }

/* ─── Architecture details ───────────────────────────────── */
.arch-details {
  margin-top: 40px; border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); box-shadow: var(--shadow);
  padding: 0 28px;
}
.arch-details summary {
  cursor: pointer; padding: 20px 0; font-weight: 500;
  list-style: none; display: flex; align-items: center; gap: 12px;
}
.arch-details summary::-webkit-details-marker { display: none; }
.arch-details summary::after { content: "+"; margin-left: auto; font-size: 1.3rem; color: var(--accent-ink); }
.arch-details[open] summary::after { content: "–"; }
.arch-details summary .mono { color: var(--accent-ink); }
.diagram { margin: 8px 0 24px; }
.diagram svg { width: 100%; height: auto; display: block; }
.node rect { fill: var(--bg); stroke: var(--line-strong); stroke-width: 1.4; transition: stroke 0.15s; }
.node { cursor: pointer; outline: none; }
.node:hover rect, .node:focus-visible rect, .node.active rect { stroke: var(--accent); }
.node.core rect, .node.router rect { stroke: var(--accent); }
.node text { font-family: var(--font-mono); fill: var(--ink); pointer-events: none; }
.node .label { font-size: 12px; font-weight: 500; letter-spacing: 0.06em; }
.node .sub { font-size: 9.5px; fill: var(--muted); }
.node.providers rect { stroke-dasharray: 3 3; }
.wire { fill: none; stroke: var(--accent); stroke-width: 1.3; stroke-dasharray: 4 5; opacity: 0.6; animation: flow 2.4s linear infinite; }
.wire.faint { stroke: var(--muted); opacity: 0.35; }
@keyframes flow { to { stroke-dashoffset: -9; } }
.pulse { fill: var(--accent); }
.diagram figcaption { color: var(--muted); text-align: center; margin-top: 8px; min-height: 1.6em; }
.diagram figcaption.inspecting { color: var(--ink); }

/* ─── Experience ─────────────────────────────────────────── */
.xp { margin-top: 34px; }
.xp-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 20px; margin-bottom: 20px; }
.xp-head h3 { margin: 0; font-size: 1.3rem; font-weight: 600; }
.xp-head .dates { color: var(--muted); margin-left: auto; }
.xp-roles { border-left: 1px solid var(--line-strong); margin-left: 5px; }
.role { position: relative; padding: 4px 0 24px 30px; }
.role::before {
  content: ""; position: absolute; left: -5.5px; top: 12px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 4px var(--bg);
}
.role-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 20px; }
.role-head h4 { margin: 0; font-size: 1.08rem; font-weight: 600; }
.role-head .dates { color: var(--muted); margin-left: auto; }
.role-sum { color: var(--muted); margin: 10px 0 0; max-width: 64ch; }
.role-sum a { text-decoration-color: var(--accent-ink); text-underline-offset: 3px; }
.role ul { margin: 12px 0 0; padding-left: 20px; }
.role li { color: var(--muted); font-size: 0.96rem; margin-bottom: 8px; max-width: 72ch; }
.role li::marker { color: var(--accent-ink); }
.promo { color: var(--accent-ink); margin: 0 0 24px; padding-left: 30px; }

/* ─── Projects ───────────────────────────────────────────── */
.proj-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 34px; }
.proj {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); padding: 26px 28px;
  transition: transform 0.18s, box-shadow 0.18s;
}
.proj:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.proj-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.proj-head h3 { margin: 0; font-size: 1.08rem; font-weight: 600; }
.proj-head a { text-decoration-color: var(--accent-ink); text-underline-offset: 4px; }
.proj-head .dates { color: var(--muted); margin-left: auto; }
.proj p { color: var(--muted); font-size: 0.94rem; margin: 0 0 10px; }
.proj .proof { margin: 12px 0 0; }
.proj .proof a { color: var(--accent-ink); text-decoration: none; }
.proj .proof a:hover { text-decoration: underline; text-underline-offset: 3px; }
.badge {
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: 0.6rem; font-weight: 500; letter-spacing: 0.1em;
  padding: 4px 10px; border-radius: 100px; margin-left: auto;
}

/* ─── About + skills ─────────────────────────────────────── */
.about-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 56px; margin-top: 34px; }
.about-text p { color: var(--muted); margin: 0 0 16px; }
.about-text strong { color: var(--ink); font-weight: 600; }
.skills { margin: 0; }
.skills div {
  display: grid; grid-template-columns: 130px 1fr; gap: 14px;
  border-top: 1px solid var(--line); padding: 12px 0;
}
.skills div:last-child { border-bottom: 1px solid var(--line); }
.skills dt { color: var(--accent-ink); text-transform: uppercase; padding-top: 3px; }
.skills dd { margin: 0; color: var(--muted); font-size: 0.94rem; }

/* ─── Contact band ───────────────────────────────────────── */
.hire-wrap { padding-top: 24px; padding-bottom: 40px; }
.hire {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow-lift);
  padding: 64px 32px; text-align: center;
}
.hire-line {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(1.9rem, 4.6vw, 2.9rem); line-height: 1.1;
  letter-spacing: -0.01em; margin: 0 0 30px;
}
.hire-line em { color: var(--accent-ink); }
.hire .cta-row { justify-content: center; margin-bottom: 24px; }
.hire-meta { margin: 0; font-size: 0.66rem; }

/* ─── Footer ─────────────────────────────────────────────── */
.foot {
  border-top: 1px solid var(--line);
  max-width: var(--max); margin: 0 auto;
  padding: 28px 24px 48px;
  display: flex; flex-wrap: wrap; gap: 10px 24px; justify-content: space-between;
}
.foot p { margin: 0; }
.foot a { text-decoration-color: var(--accent-ink); text-underline-offset: 3px; }

/* ─── Reveal ─────────────────────────────────────────────── */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.in { opacity: 1; transform: none; }
.hero > * { animation: rise 0.65s ease backwards; }
.hero > *:nth-child(2) { animation-delay: 0.07s; }
.hero > *:nth-child(3) { animation-delay: 0.14s; }
.hero > *:nth-child(4) { animation-delay: 0.21s; }
.hero > *:nth-child(5) { animation-delay: 0.28s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .wire { animation: none; }
  .hero > * { animation: none; }
  .reveal { opacity: 1; transform: none; transition: none; }
  .btn:hover, .proj:hover { transform: none; }
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 880px) {
  .hero { padding-top: 64px; }
  .chapter { grid-template-columns: minmax(0, 1fr); gap: 32px; padding: 44px 0; }
  .chapter.flip .chapter-text { order: 0; }
  .proj-grid { grid-template-columns: minmax(0, 1fr); }
  .about-grid { grid-template-columns: minmax(0, 1fr); gap: 36px; }
  .skills div { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .work-head .dates, .role-head .dates, .xp-head .dates { margin-left: 0; }
}
