/* ============================================================
   TOKENS — every value the site uses lives here.
   ============================================================ */
:root {
  color-scheme: dark;

  /* type: fluid, ratio 1.25, 360px → 1600px */
  --step--1: clamp(0.80rem, 0.77rem + 0.14vw, 0.88rem);
  --step-0:  clamp(1.00rem, 0.94rem + 0.28vw, 1.19rem);
  --step-1:  clamp(1.25rem, 1.14rem + 0.49vw, 1.56rem);
  --step-2:  clamp(1.56rem, 1.37rem + 0.85vw, 2.19rem);
  --step-3:  clamp(1.95rem, 1.63rem + 1.42vw, 3.05rem);
  --display: clamp(3rem, 1.4rem + 6.4vw, 8.5rem);

  /* spacing */
  --space-3xs: 0.25rem; --space-2xs: 0.5rem; --space-xs: 0.75rem;
  --space-s: 1rem; --space-m: 1.5rem; --space-l: 2.5rem;
  --space-xl: 4rem; --space-2xl: 6rem; --space-3xl: clamp(6rem, 10vw, 11rem);

  --gutter: clamp(1rem, 0.6rem + 1.6vw, 2.5rem);
  --radius: 2px;

  /* neutrals: tinted toward blue, never pure black/white */
  --bg:        oklch(17% 0.014 255);
  --bg-elev:   oklch(21% 0.016 255);
  --ink:       oklch(95% 0.008 255);
  --ink-muted: oklch(72% 0.014 255);
  --line:      oklch(32% 0.016 255);

  /* CP AXTRA roles — each colour has exactly one job */
  --blue:   rgb(48 111 199);   /* the request path, interactive */
  --yellow: rgb(246 194 74);   /* cache hit, focus */
  --green:  rgb(67 147 143);   /* 200 OK, success */
  --red:    rgb(218 56 50);    /* errors, Sentry */
  /* text-safe tints of the roles for small type on dark */
  --blue-ink:  color-mix(in oklch, var(--blue) 55%, white);
  --green-ink: color-mix(in oklch, var(--green) 60%, white);
  --red-ink:   color-mix(in oklch, var(--red) 60%, white);

  --focus: var(--yellow);

  /* motion: one easing family */
  --dur-fast: 0.18s; --dur-base: 0.4s; --dur-slow: 0.9s;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  --font-text: "Inter", "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, monospace;

  --header-h: 4.25rem;
}

/* ============================================================
   RESET + BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + var(--space-s)); }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--step-0);
  line-height: 1.6;
  text-wrap: pretty;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
/* grain: removes the flat-CSS look, 3% */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 100; pointer-events: none; opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-weight: 600; text-wrap: balance; letter-spacing: -0.03em; }
p { max-width: 62ch; }
strong { font-weight: 600; color: var(--ink); }

::selection { background: var(--yellow); color: var(--bg); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: var(--radius); }

.skip-link {
  position: fixed; top: var(--space-s); left: var(--space-s); z-index: 200;
  display: inline-flex; align-items: center; min-height: 44px; padding-inline: var(--space-s);
  background: var(--yellow); color: var(--bg); font-weight: 600;
  translate: 0 -200%;
}
.skip-link:focus-visible { translate: 0 0; }

.label {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.4;
  color: var(--blue-ink);
}
.label--err { color: var(--red-ink); }
.label--ok  { color: var(--green-ink); }
.meta { font-family: var(--font-mono); font-size: var(--step--1); color: var(--ink-muted); font-variant-numeric: tabular-nums; }

.link { position: relative; }
.link::after {
  content: ""; position: absolute; left: 0; bottom: -0.1em; width: 100%; height: 1px;
  background: currentColor; transform: scaleX(0); transform-origin: right;
  transition: transform var(--dur-base) var(--ease-out);
}
.link:hover::after, .link:focus-visible::after { transform: scaleX(1); transform-origin: left; }

/* ============================================================
   HEADER
   ============================================================ */
.header {
  position: fixed; inset: 0 0 auto; z-index: 50; height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-m);
  padding-inline: var(--gutter);
  background: color-mix(in oklch, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.header__logo, .header__cta { display: inline-flex; align-items: center; min-height: 44px; }
.header__logo { font-weight: 700; font-size: var(--step-1); letter-spacing: -0.03em; gap: 2px; }
.header__dot { width: 0.3em; height: 0.3em; background: var(--yellow); border-radius: 50%; translate: 0 0.3em; }
.header__cta { font-family: var(--font-mono); font-size: var(--step--1); text-transform: uppercase; letter-spacing: 0.08em; }
.header__status { display: none; align-items: center; gap: var(--space-2xs); color: var(--ink-muted); font-variant-numeric: tabular-nums; }
@media (min-width: 40rem) { .header__status { display: inline-flex; } }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 var(--green); }
@media (prefers-reduced-motion: no-preference) {
  .pulse { animation: pulse 2.4s var(--ease-out) infinite; }
}
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ============================================================
   LAYOUT — sticky trace + scrolling chapters
   ============================================================ */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); padding-top: var(--header-h); }

.trace {
  position: sticky; top: var(--header-h); z-index: 20;
  display: grid; gap: var(--space-2xs);
  padding: var(--space-xs) var(--gutter);
  background: color-mix(in oklch, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.chapters { min-width: 0; padding-inline: var(--gutter); }

@media (min-width: 60rem) {
  .layout { grid-template-columns: minmax(20rem, 5fr) minmax(0, 7fr); }
  .trace {
    height: calc(100svh - var(--header-h));
    grid-template-rows: minmax(0, 1fr) auto;
    padding: var(--space-l) var(--space-l) var(--space-m) var(--gutter);
    background: none; backdrop-filter: none;
    border-bottom: 0; border-right: 1px solid var(--line);
    grid-row: span 2;              /* footer sits in the chapter column, so the map never scrolls off */
  }
  .layout > .footer { grid-column: 2; padding-inline: var(--space-2xl) var(--gutter); }
  .chapters { padding-inline: var(--space-2xl) var(--gutter); }
}

/* ---------- topology map ---------- */
.trace__map { min-height: 0; }
.trace__map svg { width: 100%; height: 100%; overflow: visible; }
.map-path { fill: none; stroke: var(--line); stroke-width: 1.5; }
.map-path--lit { stroke: var(--blue); stroke-width: 2; }
.node a { cursor: pointer; }
.node circle.ring { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; transition: stroke var(--dur-base) var(--ease-out), fill var(--dur-base) var(--ease-out); }
.node text {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  fill: var(--ink-muted); transition: fill var(--dur-base) var(--ease-out);
}
.node .hit { fill: transparent; }
.node.is-passed circle.ring { stroke: var(--blue); }
.node.is-active circle.ring { stroke: var(--c, var(--blue)); fill: color-mix(in oklch, var(--c, var(--blue)) 30%, var(--bg)); }
.node.is-active text, .node a:hover text { fill: var(--ink); }
.node a:focus-visible { outline: none; }
.node a:focus-visible circle.ring { stroke: var(--focus); stroke-width: 2.5; }
.packet { fill: var(--blue); filter: drop-shadow(0 0 6px var(--blue)); }
.packet-halo { fill: none; stroke: var(--blue); stroke-opacity: 0.35; }

/* ---------- trace log ---------- */
.trace__log {
  list-style: none; padding: 0;
  font-family: var(--font-mono); font-size: var(--step--1); line-height: 1.5;
  font-variant-numeric: tabular-nums; color: var(--ink-muted);
  display: grid; align-content: end;
}
.trace__log li { display: grid; grid-template-columns: 6.5ch minmax(0, 1fr) auto; gap: var(--space-xs); white-space: nowrap; }
.trace__log li > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; }
.trace__log .ms { color: var(--ink-muted); }
.trace__log li:last-child { color: var(--ink); }
.trace__log .ok   { color: var(--green-ink); }
.trace__log .hit  { color: var(--yellow); }
.trace__log .err  { color: var(--red-ink); }
@media (prefers-reduced-motion: no-preference) {
  .trace__log li.is-new { animation: logIn var(--dur-base) var(--ease-out); }
}
@keyframes logIn { from { opacity: 0; transform: translateY(6px); } }

/* mobile: horizontal strip, last log line only */
@media (max-width: 59.99rem) {
  .trace__map { height: 3.25rem; }
  .trace__log { min-height: 1.5em; }
  .trace__log li:not(:last-child) { display: none; }
}

/* ============================================================
   CHAPTERS
   ============================================================ */
.hop {
  display: grid; gap: var(--space-m); align-content: center;
  min-height: 85svh;
  padding-block: var(--space-2xl);
  border-bottom: 1px solid var(--line);
}
.hop h2 { font-size: var(--step-3); line-height: 1.08; }
.hop h3 { font-size: var(--step-1); line-height: 1.2; letter-spacing: -0.02em; }
.hop > p:not(.label):not(.meta) { color: var(--ink-muted); }

.hop--hero { min-height: calc(100svh - var(--header-h) - 6rem); align-content: end; padding-bottom: var(--space-xl); }
.hero__title { font-size: var(--display); line-height: 0.92; letter-spacing: -0.045em; font-weight: 700; }
.hero__aka { display: block; color: var(--ink-muted); font-weight: 400; font-size: 0.42em; letter-spacing: -0.03em; margin-top: 0.2em; }
.hero__lede { font-size: var(--step-1); line-height: 1.4; color: var(--ink) !important; max-width: 34ch; }
.hero__hint { color: var(--ink-muted); }

.list { padding: 0; list-style: none; display: grid; gap: var(--space-2xs); }
.list li { display: flex; gap: var(--space-xs); }
.list li::before { content: "→"; font-family: var(--font-mono); color: var(--blue-ink); }

.skills { display: grid; border-top: 1px solid var(--line); }
.skills > div {
  display: grid; gap: var(--space-3xs) var(--space-m); padding-block: var(--space-s);
  border-bottom: 1px solid var(--line);
}
@media (min-width: 40rem) { .skills > div { grid-template-columns: 11rem 1fr; } }
.skills dt { font-family: var(--font-mono); font-size: var(--step--1); text-transform: uppercase; letter-spacing: 0.08em; color: var(--yellow); }
.skills dd { margin: 0; }

.stat { display: flex; align-items: baseline; gap: var(--space-s); }
.stat__num { font-size: var(--display); font-weight: 700; letter-spacing: -0.05em; line-height: 0.9; font-variant-numeric: tabular-nums; }

.facts { display: grid; gap: var(--space-l) var(--space-xl); }
@media (min-width: 48rem) { .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.facts article { display: grid; gap: var(--space-2xs); align-content: start; padding-top: var(--space-s); border-top: 1px solid var(--line); }
.facts article > p:not(.label):not(.meta) { color: var(--ink-muted); }

.hop--response { border-bottom: 0; }
.contact { display: grid; gap: var(--space-s); margin-top: var(--space-xl); }
.contact__mail {
  justify-self: start; font-size: var(--step-3); font-weight: 600; letter-spacing: -0.03em; line-height: 1.1;
  overflow-wrap: anywhere; background-image: linear-gradient(var(--green), var(--green));
  background-size: 100% 2px; background-position: 0 100%; background-repeat: no-repeat;
  padding-bottom: 0.1em; transition: color var(--dur-fast) var(--ease-out);
}
.contact__mail:hover { color: var(--green-ink); }
.contact__links { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-m); }
.contact__links:empty { display: none; }
.contact__links a { display: inline-flex; align-items: center; min-height: 44px; font-family: var(--font-mono); font-size: var(--step--1); text-transform: uppercase; letter-spacing: 0.08em; }

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-s);
  padding: var(--space-l) var(--gutter);
  border-top: 1px solid var(--line);
  font-size: var(--step--1); color: var(--ink-muted);
}
.footer .label { color: var(--ink-muted); font-variant-numeric: tabular-nums; }

/* ============================================================
   404
   ============================================================ */
.notfound { min-height: 100svh; display: grid; align-content: center; gap: var(--space-m); padding: var(--gutter); max-width: 60rem; }
.notfound h1 { font-size: var(--display); line-height: 0.92; letter-spacing: -0.045em; }
.notfound a { justify-self: start; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
