/* ==========================================================================
   Tanmay Khanna — portfolio
   Visual language: drafting film + instrument panels.
   Sections
     0  Tokens
     1  Base + utilities
     2  Navigation + rail
     3  Hero
     4  Sheet layout + shared components
     5  About / Experience / Data
     6  Systems (flows, agent engine)
     7  Research (SAGA, notebook)
     8  Open source / Projects / Skills / Proof / Log / Principles / Contact
     9  Footer
    10  Responsive
    11  Reduced motion
   ========================================================================== */

/* ---------- 0. Tokens ---------- */
:root {
  /* paper */
  --film: #E6EAEE;
  --film-2: #F2F4F7;
  --film-3: #D9DFE5;
  /* ink */
  --ink: #131922;
  --ink-2: #47525F;
  --ink-3: #6B7684;
  --rule: #B4BDC8;
  --rule-soft: #CDD4DC;
  /* accents: cobalt primary, amber secondary */
  --cobalt: #2B44E6;
  --cobalt-strong: #1E33C4;
  --cobalt-soft: rgba(43, 68, 230, 0.09);
  --amber: #E0930B;
  --amber-ink: #8A5300;
  --amber-soft: rgba(224, 147, 11, 0.13);
  /* semantic */
  --green-ink: #0B6B4B;
  --green-soft: rgba(11, 107, 75, 0.11);
  /* instrument panels */
  --panel: #0F1720;
  --panel-2: #17212D;
  --panel-ink: #D6DDE6;
  --panel-dim: #93A0B0;
  --panel-rule: #2A3644;
  --panel-cobalt: #8DA0FF;
  --panel-amber: #F5B551;
  --panel-green: #63D6A5;

  --font-display: "Bricolage Grotesque", "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --gutter: clamp(1.25rem, 4vw, 2.5rem);
  --nav-h: 3.75rem;
  --radius: 2px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ---------- 1. Base + utilities ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + 1rem);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.62;
  color: var(--ink);
  background-color: var(--film);
  /* drafting-film dot grid */
  background-image: radial-gradient(circle at 1px 1px, rgba(19, 25, 34, 0.12) 1px, transparent 1.3px);
  background-size: 24px 24px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }

img, svg, canvas { max-width: 100%; }
h1, h2, h3, h4, p, ul, ol, dl, dd, figure, blockquote { margin: 0; }
ul, ol { padding: 0; }
button { font: inherit; color: inherit; }

a { color: var(--cobalt); text-underline-offset: 0.22em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 3px; }
.instrument :focus-visible { outline-color: var(--panel-cobalt); }

.mono { font-family: var(--font-mono); }

.wrap { width: min(1200px, 100% - 2 * var(--gutter)); margin-inline: auto; }

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

.skip {
  position: fixed; top: 0.5rem; left: 0.5rem; z-index: 100;
  padding: 0.6rem 0.9rem; background: var(--ink); color: var(--film);
  transform: translateY(-200%); transition: transform 0.15s;
}
.skip:focus { transform: none; }

/* Panels: light drawing sheet with registration marks */
.panel {
  position: relative;
  background: var(--film-2);
  border: 1px solid var(--ink);
}
.panel::before, .panel::after {
  content: ""; position: absolute; width: 10px; height: 10px;
  border: 2px solid var(--cobalt); pointer-events: none;
}
.panel::before { top: -6px; left: -6px; border-right: 0; border-bottom: 0; }
.panel::after { bottom: -6px; right: -6px; border-left: 0; border-top: 0; }

/* Instrument: dark terminal / trace surfaces */
.instrument {
  background: var(--panel);
  color: var(--panel-ink);
  border: 1px solid var(--panel);
}

/* Chips: status markers */
.chip {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.32rem 0.55rem;
  font: 500 0.75rem/1 var(--font-mono);
  border: 1px solid currentColor; border-radius: var(--radius);
  white-space: nowrap;
}
.chip::before { content: ""; width: 0.45rem; height: 0.45rem; background: currentColor; }
.chip--done { color: var(--green-ink); background: var(--green-soft); }
.chip--wip { color: var(--amber-ink); background: var(--amber-soft); }
.chip--wip::before { background: var(--amber); }
.chip--research { color: var(--cobalt); background: var(--cobalt-soft); }
.chip--soon { color: var(--ink-2); }
.chip--soon::before { background: transparent; border: 1px solid currentColor; }
.chip--note { color: var(--ink-2); }
.chip--note::before { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.72rem 1.05rem;
  font: 500 0.95rem/1 var(--font-body);
  color: var(--ink); background: transparent;
  border: 1px solid var(--ink); border-radius: var(--radius);
  text-decoration: none; cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--ink); color: var(--film); text-decoration: none; }
.btn--primary { color: #fff; background: var(--cobalt); border-color: var(--cobalt); }
.btn--primary:hover { background: var(--cobalt-strong); border-color: var(--cobalt-strong); color: #fff; }
.btn--small { padding: 0.55rem 0.8rem; font-size: 0.88rem; }

/* Tags: technology markers, also drive cross-highlighting */
.techs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1.25rem 0; }
.tag {
  padding: 0.3rem 0.55rem;
  font: 400 0.8rem/1.2 var(--font-mono);
  color: var(--ink); background: transparent;
  border: 1px solid var(--rule); border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.tag:hover, .tag:focus-visible, .tag.is-on { border-color: var(--cobalt); background: var(--cobalt-soft); }
.tag--static { display: inline-block; cursor: default; margin: 0 0.3rem 0.3rem 0; }

/* ---------- 2. Navigation + rail ---------- */
.nav {
  position: fixed; inset: 0 0 auto 0; z-index: 50;
  height: var(--nav-h);
  background: rgba(230, 234, 238, 0.9);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.nav__bar { height: 100%; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.nav__brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font: 600 1.05rem/1 var(--font-display); letter-spacing: -0.01em;
  color: var(--ink); text-decoration: none;
}
.nav__menu ul { display: flex; gap: clamp(1rem, 2.2vw, 2rem); list-style: none; margin: 0; }
.nav__menu a {
  position: relative; display: block; padding: 0.5rem 0;
  font-size: 0.92rem; color: var(--ink-2); text-decoration: none;
}
.nav__menu a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0.15rem; height: 2px;
  background: var(--cobalt); transform: scaleX(0); transform-origin: left;
  transition: transform 0.25s var(--ease);
}
.nav__menu a:hover { color: var(--ink); }
.nav__menu a[aria-current="location"] { color: var(--ink); }
.nav__menu a[aria-current="location"]::after, .nav__menu a:hover::after { transform: scaleX(1); }

.nav__toggle {
  display: none; width: 2.75rem; height: 2.75rem; padding: 0;
  background: transparent; border: 1px solid var(--ink); border-radius: var(--radius); cursor: pointer;
  align-items: center; justify-content: center;
}
.nav__bars { display: grid; gap: 6px; width: 18px; }
.nav__bars i { display: block; height: 2px; background: var(--ink); transition: transform 0.2s var(--ease); }
.nav__toggle[aria-expanded="true"] .nav__bars i:first-child { transform: translateY(4px) rotate(45deg); }
.nav__toggle[aria-expanded="true"] .nav__bars i:last-child { transform: translateY(-4px) rotate(-45deg); }

.nav__progress {
  position: absolute; left: 0; bottom: -1px; height: 2px; width: 100%;
  background: var(--cobalt); transform-origin: left; transform: scaleX(var(--scroll, 0));
}

.rail {
  position: fixed; right: 1.1rem; top: 50%; z-index: 40; transform: translateY(-50%);
  display: none; flex-direction: column; align-items: flex-end; gap: 2px;
}
.rail a {
  position: relative; display: flex; align-items: center; justify-content: flex-end;
  height: 14px; width: 90px; text-decoration: none;
}
.rail a::after {
  content: ""; display: block; height: 2px; width: 12px; background: var(--rule);
  transition: width 0.25s var(--ease), background-color 0.25s;
}
.rail a span {
  position: absolute; right: 42px; font: 400 0.7rem/1 var(--font-mono);
  color: var(--cobalt); opacity: 0; transition: opacity 0.2s; white-space: nowrap;
}
.rail a:hover span, .rail a.is-active span { opacity: 1; }
.rail a.is-active::after { width: 30px; background: var(--cobalt); }
.rail a:hover::after { background: var(--ink); }

/* ---------- 3. Hero ---------- */
.hero { padding: calc(var(--nav-h) + clamp(2.5rem, 6vw, 4.5rem)) 0 clamp(3rem, 7vw, 6rem); }
.hero__grid {
  display: grid; gap: clamp(2rem, 4vw, 3.5rem); align-items: center;
  grid-template-columns: minmax(0, 1.02fr) minmax(0, 1fr);
}
.hero__where { font-size: 0.85rem; color: var(--ink-2); margin-bottom: 1.25rem; }
.hero__title {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(3.1rem, 7.4vw, 6.3rem); line-height: 0.94; letter-spacing: -0.035em;
  font-variation-settings: "opsz" 96; text-wrap: balance;
}
.hero__lede {
  margin-top: 1.5rem; max-width: 30ch;
  font: 500 clamp(1.25rem, 2.2vw, 1.6rem)/1.3 var(--font-display); letter-spacing: -0.01em;
}
.hero__intro { margin-top: 1rem; max-width: 50ch; color: var(--ink-2); }

.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0; margin: 1.25rem 0 2rem; list-style: none; }
.chain li { display: flex; align-items: center; }
.chain li + li::before {
  content: "→"; content: "→" / "";
  margin-inline: 0.35rem; color: var(--ink-3); font-family: var(--font-mono);
}
.chain__btn {
  padding: 0.4rem 0.6rem; font: 500 0.88rem/1.2 var(--font-mono);
  color: var(--ink); background: transparent;
  border: 1px solid var(--rule); border-radius: var(--radius); cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}
.chain__btn:hover, .chain__btn.is-active { border-color: var(--cobalt); background: var(--cobalt-soft); color: var(--cobalt-strong); }

.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.hero__viz { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: clamp(30rem, 68vh, 40rem); background: var(--film-2); }
.hero__viz canvas { display: block; width: 100%; height: 100%; min-height: 20rem; touch-action: pan-y; }
.viz__cap { display: grid; gap: 0.35rem; padding: 0.9rem 1.1rem 1rem; border-top: 1px solid var(--rule); min-height: 6.4rem; }
.viz__name { font-size: 0.85rem; font-weight: 500; color: var(--cobalt); }
.viz__text { font-size: 0.95rem; line-height: 1.5; color: var(--ink-2); max-width: 46ch; }

/* one orchestrated entrance: the page load */
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes settle { from { opacity: 0; } to { opacity: 1; } }
.hero__copy > * { animation: rise 0.8s var(--ease) both; }
.hero__copy > :nth-child(2) { animation-delay: 0.06s; }
.hero__copy > :nth-child(3) { animation-delay: 0.14s; }
.hero__copy > :nth-child(4) { animation-delay: 0.22s; }
.hero__copy > :nth-child(5) { animation-delay: 0.3s; }
.hero__copy > :nth-child(6) { animation-delay: 0.38s; }
.hero__viz { animation: settle 1.2s 0.25s both; }

/* ---------- 4. Sheet layout + shared components ---------- */
.sheet { padding: clamp(4rem, 8vw, 7rem) 0; border-top: 1px solid var(--rule); }
.sheet__grid { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: 0 clamp(1.5rem, 4vw, 4rem); }
.sheet__tab {
  position: sticky; top: calc(var(--nav-h) + 1.5rem); align-self: start;
  display: flex; flex-direction: column; gap: 0.15rem;
  font-size: 0.82rem; color: var(--ink-2);
}
.sheet__idx { color: var(--cobalt); font-weight: 500; }
.sheet__tab::after {
  content: ""; display: block; width: 1px; margin-top: 0.75rem;
  height: calc(var(--p, 0) * 7rem); background: var(--cobalt);
}
.sheet__body { min-width: 0; }

.h2 {
  font: 600 clamp(2rem, 4vw, 3rem)/1.05 var(--font-display);
  letter-spacing: -0.025em; text-wrap: balance; max-width: 22ch;
  margin-bottom: 1.5rem;
}
.statement {
  font: 600 clamp(1.9rem, 4.4vw, 3.4rem)/1.08 var(--font-display);
  letter-spacing: -0.028em; max-width: 24ch; text-wrap: balance;
}
.statement--contact { font-size: clamp(2.4rem, 6.4vw, 5rem); line-height: 1; max-width: 16ch; }
.lede { font: 500 clamp(1.3rem, 2.4vw, 1.75rem)/1.28 var(--font-display); letter-spacing: -0.012em; max-width: 34ch; margin: 2rem 0 1rem; }

.prose { max-width: 62ch; }
.prose--wide { max-width: 68ch; }
.prose p + p { margin-top: 1em; }
.prose h4 { font: 600 1rem/1.3 var(--font-display); margin: 1.5rem 0 0.4rem; }
.prose h4:first-child { margin-top: 0; }
.note { margin-top: 1rem; font-size: 0.92rem; color: var(--ink-2); max-width: 62ch; }
.links { display: flex; flex-wrap: wrap; gap: 0.4rem 1.5rem; margin-top: 1.25rem; }

.ticks { list-style: none; margin: 1rem 0; display: grid; gap: 0.45rem; }
.ticks li { position: relative; padding-left: 1.4rem; }
.ticks li::before {
  content: ""; position: absolute; left: 0; top: 0.5em; width: 0.5rem; height: 0.5rem;
  border: 1.5px solid var(--cobalt);
}
.ticks--tall { gap: 0.8rem; }

.case { margin-top: clamp(3rem, 6vw, 5rem); padding-top: 1.75rem; border-top: 1px solid var(--ink); }
.case:first-of-type { margin-top: 2rem; }
.case__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem 1.5rem; margin-bottom: 1.25rem; }
.case__title { font: 600 clamp(1.6rem, 3vw, 2.3rem)/1.1 var(--font-display); letter-spacing: -0.02em; }

.term { margin: 0; }
.term__bar { display: flex; align-items: center; gap: 0.35rem; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--panel-rule); }
.term__bar i { width: 8px; height: 8px; border: 1px solid var(--panel-dim); }
.term__bar span { margin-left: 0.5rem; font-size: 0.72rem; color: var(--panel-dim); }
.term__screen { padding: 1rem 1.1rem 1.2rem; font-size: 0.85rem; line-height: 1.7; min-height: 11rem; }
.term__screen p + p { margin-top: 0.1rem; }
.term__p { color: var(--panel-green); }
.term__o { color: var(--panel-ink); margin-bottom: 0.5rem; }
.term__caret { display: inline-block; width: 0.55em; height: 1em; margin-left: 0.15em; vertical-align: -0.15em; background: var(--panel-cobalt); animation: blink 1.1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

/* ---------- 5. About / Experience / Data ---------- */
.about__grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: clamp(1.5rem, 4vw, 3rem); margin-top: 2.5rem; align-items: start; }

.threads { margin-top: 3rem; border-bottom: 1px solid var(--rule); }
.threads > div { display: grid; grid-template-columns: minmax(11rem, 18rem) minmax(0, 1fr); gap: 0.4rem 1.5rem; padding: 1rem 0; border-top: 1px solid var(--rule); }
.threads dt { font: 600 1.1rem/1.3 var(--font-display); letter-spacing: -0.01em; }
.threads dd { color: var(--ink-2); max-width: 58ch; }

.role { margin-bottom: 0.5rem; }
.role__title { font: 700 clamp(2.4rem, 5.6vw, 4.4rem)/0.98 var(--font-display); letter-spacing: -0.032em; font-variation-settings: "opsz" 96; }
.role__org { margin-top: 0.4rem; font: 600 clamp(1.4rem, 2.6vw, 2rem)/1.2 var(--font-display); color: var(--cobalt); }
.role__meta { margin-top: 0.5rem; font-size: 0.85rem; color: var(--ink-2); }

.tabs { margin-top: 2.5rem; }
.tabs__list { display: flex; gap: 0.25rem; overflow-x: auto; border-bottom: 1px solid var(--ink); scrollbar-width: thin; }
.tabs__list [role="tab"] {
  flex: none; padding: 0.7rem 0.95rem; font-size: 0.92rem; color: var(--ink-2);
  background: transparent; border: 0; border-bottom: 3px solid transparent; margin-bottom: -1px; cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tabs__list [role="tab"]:hover { color: var(--ink); }
.tabs__list [role="tab"][aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--cobalt); }
.tabs__panel { padding: 1.5rem 1.5rem 1.75rem; margin-top: 1.25rem; }
.tabs__panel h3 { font: 600 1.35rem/1.2 var(--font-display); margin-bottom: 0.75rem; }
.tabs__panel .ticks { columns: 2; column-gap: 2rem; display: block; }
.tabs__panel .ticks li { break-inside: avoid; margin-bottom: 0.45rem; }
.tabs__panel .note { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.tabs__panel > p:not(.note) { margin-bottom: 0.5rem; }

.pipe { margin: 2rem 0 1.25rem; }
.pipe canvas { display: block; width: 100%; height: var(--pipe-h, 330px); }
.pipe__cap { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem 0.9rem; padding: 0.8rem 1.1rem; border-top: 1px solid var(--rule); font-size: 0.88rem; color: var(--ink-2); }
.stages { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.stages button {
  padding: 0.4rem 0.65rem; font: 500 0.85rem/1.2 var(--font-mono); color: var(--ink);
  background: transparent; border: 1px solid var(--rule); border-radius: var(--radius); cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}
.stages button:hover, .stages button.is-active { border-color: var(--cobalt); background: var(--cobalt-soft); color: var(--cobalt-strong); }
.readout { margin-top: 1.25rem; min-height: 4.6em; padding-left: 0.9rem; border-left: 2px solid var(--cobalt); color: var(--ink-2); max-width: 62ch; }

/* ---------- 6. Systems: flow diagrams + agent engine ---------- */
.flow { padding: 1.5rem; margin-top: 1rem; }
.flow__track { list-style: none; margin: 0; display: grid; gap: 1.9rem; }
.flow__stage { position: relative; display: flex; flex-direction: column; gap: 0.6rem; min-width: 0; }
.flow__label { font-size: 0.72rem; color: var(--ink-2); }

.node {
  display: flex; flex-direction: column; gap: 0.2rem; width: 100%;
  padding: 0.75rem 0.85rem; text-align: left;
  color: var(--ink); background: var(--film-2);
  border: 1px solid var(--ink-2); border-radius: var(--radius); cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
}
.node__name { font: 500 0.92rem/1.2 var(--font-mono); }
.node__sub { font-size: 0.82rem; line-height: 1.35; color: var(--ink-2); }
.node:hover, .node:focus-visible { border-color: var(--cobalt); }
.node.is-related { border-color: var(--cobalt); background: var(--cobalt-soft); box-shadow: inset 0 0 0 1px var(--cobalt); }
.node--side { border-style: dashed; max-width: 22rem; }
.node--open { border-style: dashed; border-color: var(--amber-ink); }
.node--open .node__sub { color: var(--amber-ink); }

.flow__stage.is-done .node { border-color: var(--ink); }
.flow__stage.is-active .node { border-color: var(--cobalt); background: var(--cobalt-soft); box-shadow: inset 0 0 0 1px var(--cobalt); }

/* connectors: horizontal on wide screens, vertical on narrow */
.flow__stage + .flow__stage::before { content: ""; position: absolute; background: var(--rule); }
.flow__stage + .flow__stage::after { content: ""; position: absolute; border: 5px solid transparent; }
.flow__stage.is-done::before { background: var(--cobalt); }
.flow__stage.is-active::before {
  background: linear-gradient(var(--sweep-dir, 90deg), var(--cobalt) 50%, var(--rule) 50%);
  background-size: var(--sweep-size, 200% 100%); animation: sweep 0.6s var(--ease) forwards;
}
.flow__stage.is-done::after, .flow__stage.is-active::after { border-left-color: var(--cobalt); border-top-color: var(--cobalt); }
@keyframes sweep { from { background-position: 100% 100%; } to { background-position: 0 0; } }

.flow__side { margin-top: 1.25rem; }
.flow__readout {
  margin-top: 1.25rem; min-height: 3.3em; padding-left: 0.9rem;
  border-left: 2px solid var(--cobalt); font-size: 0.95rem; color: var(--ink-2); max-width: 62ch;
}
.flow__ctl { margin-top: 0.9rem; }

.frames { display: flex; gap: 3px; margin-top: 0.25rem; }
.frames i { display: block; width: 1rem; height: 0.65rem; border: 1px solid var(--ink-2); transition: background-color 0.2s, border-color 0.2s; }
.flow__stage.is-active .frames i { border-color: var(--cobalt); animation: frame 1s ease-in-out infinite; }
.flow__stage.is-active .frames i:nth-child(2) { animation-delay: 0.1s; }
.flow__stage.is-active .frames i:nth-child(3) { animation-delay: 0.2s; }
.flow__stage.is-active .frames i:nth-child(4) { animation-delay: 0.3s; }
.flow__stage.is-active .frames i:nth-child(5) { animation-delay: 0.4s; }
@keyframes frame { 0%, 100% { background: transparent; } 40% { background: var(--cobalt); } }

.trace { margin-top: 1rem; padding: 1rem 1.25rem 1.1rem; }
.trace__head { font-size: 0.74rem; color: var(--panel-amber); margin-bottom: 0.6rem; }
.trace__log { list-style: none; margin: 0; font-size: 0.82rem; line-height: 1.6; max-height: 17rem; overflow-y: auto; }
.trace__log li { padding: 0.15rem 0; animation: settle 0.3s both; }
.trace__log li.trace__idle { color: var(--panel-dim); animation: none; }
.trace__who { color: var(--panel-cobalt); margin-right: 0.5rem; }

.principle {
  margin: 1.75rem 0; padding: 0.5rem 0 0.5rem 1.4rem; max-width: 40ch;
  border-left: 3px solid var(--cobalt);
  font: 600 clamp(1.2rem, 2.4vw, 1.65rem)/1.3 var(--font-display); letter-spacing: -0.012em;
}

/* Agent engine */
.engine { margin-top: 1rem; }
.engine__ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem; margin-bottom: 1rem; }
.seg { display: inline-flex; border: 1px solid var(--ink); border-radius: var(--radius); overflow: hidden; }
.seg__btn { padding: 0.55rem 0.85rem; font-size: 0.88rem; background: transparent; border: 0; cursor: pointer; transition: background-color 0.15s, color 0.15s; }
.seg__btn + .seg__btn { border-left: 1px solid var(--ink); }
.seg__btn[aria-pressed="true"] { background: var(--ink); color: var(--film); }
.seg__btn:focus-visible { outline-offset: -3px; }

.engine__grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.engine__flow { list-style: none; margin: 0; padding: 1.4rem 1.25rem 0.5rem 1.6rem; }
.an {
  position: relative; display: block; margin: 0 0 1.1rem; padding: 0.55rem 0.85rem;
  border-left: 2px solid var(--panel-rule);
  transition: background-color 0.25s, border-color 0.25s, opacity 0.25s;
}
.an::before {
  content: ""; position: absolute; left: -7px; top: 0.85rem; width: 12px; height: 12px;
  background: var(--panel); border: 2px solid var(--panel-dim); transition: background-color 0.25s, border-color 0.25s;
}
.an__name { display: block; font-size: 0.83rem; font-weight: 500; color: var(--panel-ink); }
.an__desc { display: block; font-size: 0.86rem; color: var(--panel-dim); }
.an.is-done { border-left-color: var(--panel-cobalt); }
.an.is-done::before { border-color: var(--panel-cobalt); }
.an.is-active { border-left-color: var(--panel-cobalt); background: rgba(141, 160, 255, 0.13); }
.an.is-active::before { background: var(--panel-cobalt); border-color: var(--panel-cobalt); }
.an.is-related { background: rgba(141, 160, 255, 0.16); box-shadow: inset 0 0 0 1px var(--panel-cobalt); }

.an__badge { display: none; margin-top: 0.35rem; padding: 0.15rem 0.4rem; font-size: 0.7rem; border: 1px solid currentColor; }
.engine[data-scenario="known"] .an__badge--hit { display: inline-block; color: var(--panel-green); }
.engine[data-scenario="unknown"] .an__badge--miss { display: inline-block; color: var(--panel-amber); }

.an-branch { margin: 0 0 1.1rem 1.1rem; padding-left: 0.85rem; border-left: 2px dashed var(--panel-amber); transition: opacity 0.25s; }
.an-branch__label { margin-bottom: 0.7rem; font-size: 0.72rem; color: var(--panel-amber); }
.an-branch ol { list-style: none; margin: 0; padding: 0; }
.engine[data-scenario="known"] .an-branch { opacity: 0.38; }

.engine__side { display: grid; gap: 1rem; }
.actors { padding: 1rem 1.15rem 1.15rem; }
.actors__head { font-size: 0.74rem; color: var(--panel-dim); margin-bottom: 0.6rem; }
.actors ul { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; margin: 0; }
.actor { padding: 0.35rem 0.6rem; font: 400 0.8rem/1.2 var(--font-mono); color: var(--panel-dim); border: 1px solid var(--panel-rule); transition: background-color 0.2s, color 0.2s, border-color 0.2s; }
.actor.is-active { background: var(--panel-cobalt); border-color: var(--panel-cobalt); color: var(--panel); }
.engine__side .trace { margin-top: 0; }

.engine__meta { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: clamp(1.5rem, 4vw, 3rem); margin-top: 2.5rem; align-items: start; }
.sandbox { display: grid; grid-template-columns: 1fr 1.5fr 1fr; gap: 0.6rem; align-items: stretch; }
.sandbox__io { display: flex; flex-direction: column; justify-content: center; gap: 0.2rem; padding: 0.8rem; font-size: 0.78rem; border: 1px dashed var(--ink-2); }
.sandbox__io span { color: var(--ink-2); }
.sandbox__box { padding: 0.8rem 0.9rem; background: var(--film-2); border: 2px solid var(--ink); font-size: 0.78rem; }
.sandbox__box ul { list-style: none; margin: 0.4rem 0 0; color: var(--ink-2); }
.sandbox__box li::before { content: "+ "; color: var(--cobalt); }

.metrics { margin-top: 3rem; }
.metrics h4 { font: 600 1.15rem/1.3 var(--font-display); margin-bottom: 0.75rem; }
.metrics table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
.metrics th, .metrics td { padding: 0.75rem 0.75rem 0.75rem 0; text-align: left; vertical-align: top; border-top: 1px solid var(--rule); }
.metrics thead th { font: 500 0.75rem/1.2 var(--font-mono); color: var(--ink-2); border-top: 1px solid var(--ink); }
.metrics tbody th { font-weight: 500; width: 26%; }
.metrics td { color: var(--ink-2); }
.metrics td:last-child { white-space: nowrap; }
.metrics tbody tr:last-child > * { border-bottom: 1px solid var(--rule); }

/* ---------- 7. Research: SAGA + notebook ---------- */
.challenges { margin-top: 2.5rem; max-width: 46rem; }
.challenges h4 { font: 600 1.15rem/1.3 var(--font-display); margin-bottom: 0.6rem; }
.challenges details { border-top: 1px solid var(--rule); }
.challenges details:last-of-type { border-bottom: 1px solid var(--rule); }
.challenges summary {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: 0.85rem 0; cursor: pointer; list-style: none; font-weight: 500;
}
.challenges summary::-webkit-details-marker { display: none; }
.challenges summary::after { content: "+"; font: 400 1.1rem/1 var(--font-mono); color: var(--cobalt); }
.challenges details[open] summary::after { content: "–"; }
.challenges details p { padding: 0 2rem 1rem 0; color: var(--ink-2); animation: settle 0.3s both; }
.challenges summary:focus-visible { outline-offset: -2px; }

.topics { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; margin: 1.25rem 0 0; }
.topics li { padding: 0.3rem 0.6rem; font: 400 0.82rem/1.2 var(--font-mono); color: var(--ink-2); border: 1px solid var(--rule); }

.notebook { display: grid; grid-template-columns: 13rem minmax(0, 1fr); gap: 1.5rem; margin-top: 2rem; align-items: start; }
.notebook__steps { list-style: none; margin: 0; border-left: 1px solid var(--ink-2); }
.notebook__steps li { position: relative; }
.notebook__steps button {
  display: block; width: 100%; padding: 0.5rem 0.75rem; text-align: left;
  font: 400 0.88rem/1.2 var(--font-mono); color: var(--ink-2);
  background: transparent; border: 0; border-left: 3px solid transparent; margin-left: -2px; cursor: pointer;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.notebook__steps button:hover { color: var(--ink); background: var(--cobalt-soft); }
.notebook__steps button[aria-pressed="true"] { color: var(--cobalt-strong); font-weight: 500; border-left-color: var(--cobalt); background: var(--cobalt-soft); }
.notebook__steps li:last-child::after { content: "repeat from model"; display: block; padding: 0.4rem 0.75rem 0; font: 400 0.72rem/1.2 var(--font-mono); color: var(--amber-ink); }
.notebook__page {
  position: relative; min-height: 17rem; padding: 1.2rem 1.5rem 1.2rem 4.2rem;
  border: 1px solid var(--ink);
  background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(1.8rem - 1px), rgba(43, 68, 230, 0.17) calc(1.8rem - 1px), rgba(43, 68, 230, 0.17) 1.8rem), var(--film-2);
  background-position: 0 1.2rem;
  line-height: 1.8rem;
}
.notebook__page::before { content: ""; position: absolute; top: 0; bottom: 0; left: 3.2rem; width: 1px; background: var(--amber); }
.notebook__page p { margin: 0; }
.notebook__step { color: var(--cobalt); font-size: 0.85rem; font-weight: 500; }
.notebook__text { font-size: 1.02rem; margin-bottom: 1.8rem !important; max-width: 52ch; }
.notebook__eg { font-size: 0.83rem; color: var(--ink); max-width: 54ch; margin-bottom: 1.8rem !important; }
.notebook__foot { font-size: 0.72rem; color: var(--ink-2); }
.notebook__ctl { grid-column: 1 / -1; }
.notebook__page.is-turning { animation: settle 0.35s both; }

/* ---------- 8. Open source / Projects / Skills / Proof / Log / Principles / Contact ---------- */
.oss__grid, .proj__grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(1.5rem, 4vw, 3rem); align-items: start; }
.proj__grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }

.cmap { padding: 1.25rem; }
.cmap__hint { font-size: 0.75rem; color: var(--ink-2); margin-bottom: 0.9rem; }
.cmap__root {
  display: block; width: 100%; padding: 0.8rem 1rem; text-align: left; font-size: 0.9rem; font-weight: 500;
  color: var(--ink); background: var(--film); border: 1px solid var(--ink); cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}
.cmap__root::before { content: "+ "; color: var(--cobalt); }
.cmap__root[aria-expanded="true"] { background: var(--ink); color: var(--film); }
.cmap__root[aria-expanded="true"]::before { content: "– "; color: var(--panel-cobalt); }
.cmap__list { list-style: none; margin: 0.9rem 0 0 1.1rem; padding: 0 0 0 1.2rem; border-left: 1px solid var(--ink-2); }
.cmap__list li { position: relative; margin-bottom: 0.6rem; animation: rise 0.4s var(--ease) both; }
.cmap__list li:nth-child(2) { animation-delay: 0.06s; }
.cmap__list li:nth-child(3) { animation-delay: 0.12s; }
.cmap__list li:nth-child(4) { animation-delay: 0.18s; }
.cmap__list li::before { content: ""; position: absolute; left: -1.2rem; top: 1.1rem; width: 1rem; height: 1px; background: var(--ink-2); }
.cmap__mod { display: block; width: 100%; padding: 0.6rem 0.8rem; text-align: left; font-size: 0.84rem; background: var(--film); border: 1px solid var(--rule); cursor: pointer; transition: border-color 0.15s, background-color 0.15s; }
.cmap__mod:hover, .cmap__mod[aria-expanded="true"] { border-color: var(--cobalt); background: var(--cobalt-soft); }
.cmap__list p { padding: 0.55rem 0.8rem 0.2rem; font-size: 0.88rem; color: var(--ink-2); animation: settle 0.3s both; }

.case--explore { padding: 1.75rem; border: 1px dashed var(--amber-ink); background: var(--amber-soft); }
.case--explore .prose { margin-bottom: 0.5rem; }

.tags-inline { margin-top: 1rem; font-size: 0.82rem; color: var(--ink-2); }

.scaffold { padding: 1.1rem 1.25rem 1.25rem; }
.scaffold__cmd { font-size: 0.88rem; }
.scaffold__opts { display: flex; flex-wrap: wrap; gap: 0.9rem 1.75rem; margin: 1rem 0; }
.scaffold fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.scaffold legend { padding: 0; margin-bottom: 0.3rem; font-size: 0.72rem; color: var(--panel-dim); }
.scaffold label { display: block; font-size: 0.85rem; line-height: 1.9; cursor: pointer; }
.scaffold input { accent-color: var(--panel-cobalt); margin-right: 0.35rem; }
.scaffold__tree { margin: 0; padding: 0.9rem 0; overflow-x: auto; font-size: 0.8rem; line-height: 1.55; border-top: 1px solid var(--panel-rule); border-bottom: 1px solid var(--panel-rule); }
.scaffold__tree .hl { color: var(--panel-cobalt); }
.scaffold__tree .dim { color: var(--panel-dim); }
.scaffold__note { margin-top: 0.8rem; font-size: 0.78rem; color: var(--panel-ink); min-height: 2.6em; }
.scaffold__src { font-size: 0.7rem; color: var(--panel-dim); }

.layers { padding: 0.25rem 1.25rem; }
.layer { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: 0.5rem 1rem; align-items: baseline; padding: 0.95rem 0; border-bottom: 1px solid var(--rule); transition: background-color 0.2s; }
.layer:last-child { border-bottom: 0; }
.layer__name { font-size: 0.8rem; color: var(--ink-2); }
.layer.is-related { background: var(--cobalt-soft); }
.tag--static.is-related { border-color: var(--cobalt); background: var(--cobalt-soft); }

.more { margin-top: clamp(3rem, 6vw, 5rem); }
.more__title { font: 600 clamp(1.6rem, 3vw, 2.3rem)/1.1 var(--font-display); letter-spacing: -0.02em; padding-top: 1.75rem; border-top: 1px solid var(--ink); margin-bottom: 1rem; }
.more__list { list-style: none; margin: 0; }
.more__list > li { display: grid; grid-template-columns: minmax(12rem, 17rem) minmax(0, 1fr); gap: 0.4rem 2rem; padding: 1.1rem 0; border-top: 1px solid var(--rule); }
.more__list > li:last-child { border-bottom: 1px solid var(--rule); }
.more__list h4 { font: 600 1.25rem/1.2 var(--font-display); letter-spacing: -0.01em; }
.more__list h4 a { color: var(--ink); }
.more__list h4 a:hover { color: var(--cobalt); }
.more__stack { margin-top: 0.3rem; font-size: 0.78rem; color: var(--ink-2); }
.more__list p { color: var(--ink-2); max-width: 62ch; }

.skills { margin-top: 2rem; border-bottom: 1px solid var(--rule); }
.skills > div { display: grid; grid-template-columns: 10rem minmax(0, 1fr); gap: 0.5rem 1.5rem; padding: 1rem 0; border-top: 1px solid var(--rule); }
.skills dt { font: 600 1.05rem/1.4 var(--font-display); }
.skills ul { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; margin: 0; }
.skills li { padding: 0.25rem 0.6rem; font-size: 0.92rem; border: 1px solid var(--rule); transition: border-color 0.15s, background-color 0.15s; }
.skills li[data-tag]:hover, .skills li.is-related { border-color: var(--cobalt); background: var(--cobalt-soft); }

.repos { margin-top: 2rem; padding: 1.25rem 1.4rem 1.4rem; max-width: 52rem; }
.repos__cmd { font-size: 0.85rem; margin-bottom: 0.8rem; }
.repos ul { list-style: none; margin: 0; font-size: 0.86rem; }
.repos li { display: grid; grid-template-columns: minmax(11rem, 16rem) minmax(0, 1fr); gap: 0.2rem 1rem; padding: 0.55rem 0; border-top: 1px solid var(--panel-rule); }
.repos a { color: var(--panel-cobalt); }
.repos a:hover { color: #fff; }
.repos span { color: var(--panel-dim); }
.proof__cta { margin-top: 1.75rem; }

.log { list-style: none; margin: 2rem 0 0; border-bottom: 1px solid var(--rule); }
.log li { display: grid; grid-template-columns: 8.5rem minmax(0, 1fr) auto; gap: 0.4rem 1.25rem; align-items: baseline; padding: 1.1rem 0; border-top: 1px solid var(--rule); }
.log__tag { font-size: 0.82rem; color: var(--cobalt); }
.log h3 { font: 600 1.25rem/1.25 var(--font-display); letter-spacing: -0.01em; }

.principles { margin-top: 1.5rem; border-bottom: 1px solid var(--ink); }
.principles > div { display: grid; grid-template-columns: minmax(0, 21rem) minmax(0, 1fr); gap: 0.5rem 2rem; padding: 1.4rem 0; border-top: 1px solid var(--ink); }
.principles dt { font: 600 clamp(1.3rem, 2.4vw, 1.75rem)/1.15 var(--font-display); letter-spacing: -0.018em; }
.principles dd { color: var(--ink-2); max-width: 52ch; align-self: center; }

.contact { list-style: none; margin: 2.5rem 0 0; border-top: 1px solid var(--ink); max-width: 46rem; }
.contact a {
  position: relative; display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 0.25rem 1rem; align-items: baseline;
  padding: 1.1rem 0; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule);
}
.contact a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--cobalt); transform: scaleX(0); transform-origin: left; transition: transform 0.3s var(--ease);
}
.contact a:hover::after, .contact a:focus-visible::after { transform: scaleX(1); }
.contact__k { font: 600 1.6rem/1.1 var(--font-display); letter-spacing: -0.015em; transition: color 0.2s; }
.contact a:hover .contact__k { color: var(--cobalt); }
.contact__v { font-size: 0.9rem; color: var(--ink-2); overflow-wrap: anywhere; }

/* ---------- 9. Footer ---------- */
.footer { padding: 2.5rem 0 3rem; border-top: 1px solid var(--ink); }
.footer__grid { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 1rem 2rem; align-items: end; color: var(--ink-2); font-size: 0.95rem; }
.footer__name { font: 600 1.25rem/1.2 var(--font-display); color: var(--ink); }
.footer__copy { font-size: 0.78rem; }

/* ---------- 10. Responsive ---------- */
@media (min-width: 1400px) { .rail { display: flex; } }

@media (max-width: 899.98px) {
  .nav__toggle { display: inline-flex; }
  .nav__menu {
    position: absolute; top: 100%; left: 0; right: 0; padding: 0.5rem var(--gutter) 1.25rem;
    background: var(--film); border-bottom: 1px solid var(--ink); animation: rise 0.25s var(--ease) both;
  }
  .nav__menu ul { flex-direction: column; gap: 0; }
  .nav__menu a { padding: 0.85rem 0; font-size: 1.1rem; border-bottom: 1px solid var(--rule); }
  .nav__menu a::after { display: none; }
  .nav__menu a[aria-current="location"] { color: var(--cobalt); }

  .hero__grid { grid-template-columns: 1fr; }
  .hero__viz { min-height: 35rem; }

  .sheet__grid { grid-template-columns: 1fr; }
  .sheet__tab { position: static; flex-direction: row; align-items: center; gap: 0.6rem; margin-bottom: 1.75rem; }
  .sheet__tab::after { width: calc(var(--p, 0) * 4rem); height: 1px; margin: 0; }

  .about__grid, .oss__grid, .proj__grid, .engine__grid, .engine__meta { grid-template-columns: 1fr; }
  .notebook { grid-template-columns: 1fr; }
  .notebook__steps { display: flex; flex-wrap: wrap; border-left: 0; gap: 0.3rem; }
  .notebook__steps button { border: 1px solid var(--rule); margin: 0; }
  .notebook__steps button[aria-pressed="true"] { border-color: var(--cobalt); }
  .notebook__steps li:last-child::after { display: none; }

  /* flows go vertical */
  .flow__stage + .flow__stage::before { left: 1.5rem; top: -1.9rem; width: 2px; height: 1.9rem; --sweep-dir: 180deg; --sweep-size: 100% 200%; }
  .flow__stage + .flow__stage::after { left: calc(1.5rem - 4px); top: -0.5rem; border-width: 5px 4px 0; border-color: var(--rule) transparent transparent; }
  .flow__stage.is-done::after, .flow__stage.is-active::after { border-top-color: var(--cobalt); border-left-color: transparent; }
  .flow__side { margin-top: 1.5rem; }
}

@media (min-width: 900px) {
  .flow__track { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 2.4rem; align-items: center; }
  .flow--saga .flow__track { align-items: center; }
  .flow__stage + .flow__stage::before { left: -2.4rem; top: 50%; width: 2.4rem; height: 2px; margin-top: -1px; }
  .flow__stage + .flow__stage::after { left: -0.55rem; top: calc(50% - 5px); border-width: 5px 0 5px 6px; border-color: transparent transparent transparent var(--rule); }
  .flow__stage.is-done::after, .flow__stage.is-active::after { border-left-color: var(--cobalt); border-top-color: transparent; }
}

@media (max-width: 720px) {
  .threads > div, .skills > div, .principles > div, .more__list > li, .repos li { grid-template-columns: 1fr; }
  .log li { grid-template-columns: 1fr; }
  .log li .chip { justify-self: start; }
  .contact a { grid-template-columns: 1fr; }
  .contact__k { font-size: 1.5rem; }
  .footer__grid { grid-template-columns: 1fr; align-items: start; }
  .tabs__panel .ticks { columns: 1; }
  .tabs__panel { padding: 1.25rem; }
  .flow { padding: 1.1rem; }
  .sandbox { grid-template-columns: 1fr; }
  .layer { grid-template-columns: 1fr; }

  .metrics thead { display: none; }
  .metrics table, .metrics tbody, .metrics tr, .metrics th, .metrics td { display: block; width: 100%; }
  .metrics tr { padding: 0.8rem 0; border-top: 1px solid var(--rule); }
  .metrics th, .metrics td { padding: 0.1rem 0; border: 0 !important; }
  .metrics tbody th { width: 100%; }
  .metrics td:last-child { margin-top: 0.4rem; }
}

/* ---------- 11. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
  }
  .term__caret { animation: none; }
  .hero__copy > *, .hero__viz { animation: none; }
}
