/* inference-stack — monospace, monochrome. Dark is the default; [data-theme="light"] flips the palette. */
:root {
  --bg: #000;
  --dim-border: #333;
  --dim-text: #6b6b6b;
  --mid-border: #5e5e5e;
  --mid-text: #a9a9a9;
  --bright: #ffffff;
  --line: #2a2a2a;
  --glow: rgba(255, 255, 255, .35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --dim-border: #d9d9d9;
  --dim-text: #8a8a8a;
  --mid-border: #b3b3b3;
  --mid-text: #555555;
  --bright: #111111;
  --line: #ececec;
  --glow: rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--mid-text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* live theme toggle: fixed top-right, icon only */
.theme-toggle {
  position: fixed; top: 14px; right: 16px; z-index: 50;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; padding: 4px; line-height: 0;
  color: var(--mid-text); cursor: pointer; transition: color .15s;
}
.theme-toggle:hover { color: var(--bright); }

/* ───────────────────────── page sequence ───────────────────────── */
/* The three pages are one sequence (Inference Stack, Inference Parallelism, Agent Architecture), still separate pages: a crossfade between
   them where the browser supports cross-document view transitions (elsewhere navigation is plain), off for reduced motion. The buttons and
   the theme toggle have names of their own, so they are held still while the rest of the page crossfades. */
@media (prefers-reduced-motion: no-preference) { @view-transition { navigation: auto; } }
.pager { view-transition-name: pager; }
.theme-toggle { view-transition-name: theme-toggle; }
::view-transition-group(pager), ::view-transition-group(theme-toggle),
::view-transition-new(pager), ::view-transition-new(theme-toggle) { animation: none; }
::view-transition-old(pager), ::view-transition-old(theme-toggle) { display: none; }

/* back and forward: two squares in the left margin, level with the first two pages' titles (80px tall from 48px: the squares' middle is at 88px), at
   the same place on every page. They hang 16px left of the Agent page's title column, the widest of the three (1320px, 28px padding), so they sit
   left of every title; the margin is only wide enough from 1504px, narrower windows have no buttons (the arrow keys still work, see pager.js). */
.pager { position: absolute; top: 68px; left: calc(50% - 736px); display: none; gap: 8px; }
@media (min-width: 1504px) { .pager { display: flex; } }
.pg {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--mid-border); color: var(--mid-text);
  transition: color .15s, border-color .15s, box-shadow .2s;
}
a.pg:hover, a.pg:focus-visible { outline: none; color: var(--bright); border-color: var(--bright); box-shadow: 0 0 12px 0 var(--glow); }
.pg[aria-disabled="true"] { opacity: .38; }   /* the first page has no back, the last no forward: the idle opacity */

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 48px 28px 90px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  /* THE SPACE FROM THE TITLE TO THE FIRST THING DRAWN under it, the same on all three pages: measured as the eye sees it, from the bottom of the
     title's letters to the top of that first thing (the first tier's title on the Inference Stack page, the SCENARIO label on the Inference
     Parallelism page, the AGENT box on the Agent Architecture page). The Inference Parallelism page also uses it for the space between its blocks. */
  --section-gap: 64px;
}

/* the margin takes out what is already between the title and the first block: .13em is the empty space under the title's letters (its line box is as
   tall as the font size) and 26px is main's gap; each page's first block adds the rest (see the figure, gpus.css and agents.css) */
.title {
  font-family: var(--sans);
  font-size: clamp(40px, 7vw, 80px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--bright);
  margin: 0 0 calc(var(--section-gap) - .13em - 26px);
}
.lead { margin: 0; max-width: 72ch; color: var(--mid-text); }

/* ───────────────────────── figure ───────────────────────── */
/* diagram width: the KV-cache row (the one with the most boxes) needs 957.4px, plus the 24px block padding
   on each side = 1005.4px; 1006px keeps a hair of slack so it never wraps. Every layer shares this width. */
.fig { width: 1006px; max-width: 100%; margin: calc(1.15em + 6px - 1px) 0 0; display: flex; flex-direction: column; }   /* the margin: the first tier's title hangs above the block (1.15em tall and 6px off it, its capitals 1px under its top), so the figure starts that much lower for the title's gap to be --section-gap */

/* parent block: the same look as the frame on the Agent Architecture page.
   A filled panel with a small, spaced, uppercase title at the top left. */
.tier { position: relative; background: var(--line); padding: 24px; }   /* even padding: the title now sits above the block */
.tier-head {
  position: absolute; left: 0; bottom: 100%; margin: 0 0 6px;      /* above the block, on its left edge, 6px off it */
  white-space: nowrap;
  /* line-height 1: a 14px tall box, so the title stays low in the 56px gap */
  font: 400 1.15em/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--bright);   /* titles: the brightest, largest text */
}

/* the Storage title sits on the right edge of its block (the Accelerators title stays left), clear of the bottom connector's label;
   -.12em cancels the letter-spacing after the last letter so the glyphs end exactly on the edge */
.hw .tier:last-child .tier-head { left: auto; right: -.12em; }

/* items sit straight on the grey layer: logo + label, no fill, no border (the transparent border keeps every box the same size).
   Hardware keeps a dashed border; only the four memory-tier boxes (L1 to L4) have a black fill. Labels are dimmer and one size smaller
   (14px to 13px) than the layer titles. */
.parts { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.part {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 18px 24px; line-height: 1.3; white-space: nowrap;   /* ~56px tall: 18px + 18px text + 18px + borders */
  background: transparent; border: 1px solid transparent; color: var(--mid-text); font-size: 13px;
  transition: opacity .2s, border-color .2s, box-shadow .2s, color .2s;
}
.part.hardware { background: transparent; border-style: dashed; border-color: var(--mid-border); }   /* hardware = dashed border, no fill (NVIDIA, AMD) */
.part.hardware.tiered { background: var(--bg); }   /* the memory-tier boxes L1 to L4 (HBM here; DRAM, NVMe, Remote storage below) have a black fill */
/* a memory tier box (HBM L1), laid out like the Storage boxes: name left, tier right */
.part.tiered { justify-content: space-between; min-width: 174px; }   /* (wide screens: fixed sizes below) */
.part.tiered span:last-child { color: var(--dim-text); }

/* Three fixed box widths (wide screens only; narrower screens keep the content-sized boxes and the 1006px diagram).
   Each size is the widest box of its group (natural width incl. the 24px side padding): Small 154.2 (HiCache), Medium 186.3
   (Dynamo Router), Large 260.6 (Offloading Connector), kept at 270 so the KV-cache row and the Accelerators panel
   keep the diagram at 1134px with even padding. The KV-cache row (5 Small + 1 Large + gaps) is the
   widest and sets the diagram width: 1085px + the 24px block padding on each side = 1133px; 1134px keeps a hair of slack.
   The storage tiers are not fixed: three equal columns that fill their panel. */
@media (min-width: 1190px) {
  .fig { width: 1134px; }
  .part, .mem li[class] { flex: 0 0 auto; }
  .part { justify-content: center; }
  .part.tiered { justify-content: space-between; }   /* the HBM tier box keeps name left / tier right */
  .sz-s { width: 155px; }
  .sz-m { width: 187px; }
  .sz-l { width: 270px; }
}
/* vendor mark to the left of the name; flat, takes the box's text colour (theme and trace aware) */
.part .logo { flex: none; display: block; height: 14.4px; width: auto; }
/* Full logos (icon + wordmark) are sized so the wordmark is about the height of the 14px text beside it,
   which balances them with the icon-only marks. Each logo has its own icon-to-wordmark proportion. */
/* Icon-only marks sized for equal visual weight, not equal pixels: the solid NVIDIA eye and AMD arrow
   read heavy at 14.4px, the thin SGLang graphic reads light. */
.part .logo.nvidia   { height: 12.4px; }
.part .logo.amd      { height: 12.4px; }
.part .logo.sgl-icon { height: 17px; }
.part .logo.full.sgl      { height: 11px; }
.part .logo.full.vllm     { height: 10.5px; }
.part .logo.full.llmd     { height: 14px; }
.part .logo.tile { height: 14.4px; }   /* LMCache's app icon: a square tile */

/* PROMPT / OUTPUT labels in the black margin left and right of the Gateway block. Never attached to the block and never widening it:
   absolutely positioned, vertically centred on the block, 10px off its edge. The word is turned 90 degrees anticlockwise (reads bottom
   to top) in the layer titles' mono font, caps and letter spacing at medium weight, in the connector labels' grey. A small
   right-pointing triangle sits in the same column, straight after the last letter (the top, since it reads upward), not rotated, so it
   points right on both sides. No outlines. They need room in the page margin, so they show from a 1340px window up. */
.lbl {
  display: none; position: absolute; top: 50%; transform: translateY(-50%);
  color: var(--dim-text); font: 500 1.15em/1 var(--mono); letter-spacing: .12em; text-transform: uppercase;
}
.lbl-in { right: calc(100% + 10px); }
.lbl-out { left: calc(100% + 10px); }
.lbl-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.lbl-word { writing-mode: vertical-rl; transform: rotate(180deg); }   /* vertical, then turned over so it reads bottom to top */
.lbl-tri { width: 0; height: 0; border-left: 7px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent; }
@media (min-width: 1340px) { .lbl { display: block; } }

/* the interface between two neighbouring layers */
/* three columns: two equal sides and the arrows between them, so the arrows are always in the exact
   horizontal centre; the label sits in the right column, to the right of the arrows */
.contract {
  display: grid; grid-template-columns: 1fr auto 1fr; column-gap: 14px; align-items: center;
  height: 56px; padding: 0;     /* fixed: every gap between layer blocks is the same, whatever the label */
  color: var(--dim-text); transition: opacity .2s, color .2s;   /* connector labels and arrows: dimmer than the items */
}
/* a down arrow and an up arrow side by side (down first: the request; then up: the result), 6px apart */
.contract .arr-pair { grid-column: 2; grid-row: 1; display: flex; gap: 6px; }
.contract .arr-pair svg { display: block; width: 12px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.3; }
.contract .label { grid-column: 3; grid-row: 1; display: flex; flex-direction: column; }
.contract .label small { color: var(--dim-text); font-size: .92em; }
.contract.lit .label small { color: var(--mid-text); }
.contract { position: relative; z-index: 2; }   /* so a tooltip opened in a connector paints over the block below it */
.contract .label .line { display: inline-flex; align-items: center; }

/* (i) info icon + tooltip, reusable: <span class="info" tabindex="0"><svg class="info-ico">…</svg><span class="tip">text</span></span>.
   Icon is the same glyph as the inference router demo (grey disc, the "i" cut out in the page colour). The tooltip is flat:
   page-coloured, dashed border, rounded corners, no shadow. It opens on hover or keyboard focus. */
.info { position: relative; display: inline-flex; align-items: center; margin-left: 6px; cursor: help; outline: none; color: var(--dim-text); }
.info-ico { display: block; }
.info-ico circle { fill: currentColor; }
.info-ico rect { fill: var(--bg); }
.info:hover, .info:focus-visible { color: var(--bright); }
.info .tip {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30;   /* opens leftwards from the icon: the icon sits right of centre, so a rightward tooltip would run off the page */
  width: max-content; max-width: min(510px, calc(100vw - 64px));   /* 340px x 1.5 */
  background: var(--bg); border: 1px dashed var(--mid-border); border-radius: 8px; box-shadow: none;
  padding: 10px 12px; color: var(--mid-text);
  font: 400 12px/1.45 var(--mono); letter-spacing: normal; white-space: normal;
  opacity: 0; visibility: hidden; transition: opacity .12s; pointer-events: none;
}
.info:hover .tip, .info:focus-visible .tip { opacity: 1; visibility: visible; }

.hw { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
/* the three storage tiers sit side by side, so both bottom panels hold a single row */
.mem { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: row; gap: 8px; }
.mem li {
  display: flex; justify-content: space-between; gap: 12px;
  flex: 1 1 0; min-width: 0; white-space: nowrap;       /* three equal columns */
  padding: 18px 24px; line-height: 1.3;   /* same box as .part: ~56px tall */
  background: var(--bg); border: 1px dashed var(--mid-border); color: var(--mid-text); font-size: 13px;   /* hardware: black fill, dashed */
  transition: opacity .2s, border-color .2s, box-shadow .2s;
}
.mem li span:last-child { color: var(--dim-text); }

.legend { display: flex; flex-wrap: wrap; gap: 22px; color: var(--mid-text); }
.legend-item { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.swatch { width: 28px; height: 15px; display: inline-block; }
.swatch.dashed { border: 1px dashed var(--mid-border); }

/* ───────────────────────── traces ───────────────────────── */
.traces { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 4px; }
.traces-label { color: var(--dim-text); letter-spacing: .06em; text-transform: uppercase; font-size: .85em; margin-right: 4px; }
.trace {
  font: inherit; color: var(--bg);
  background: var(--bright); border: 1px solid var(--bright);
  border-radius: 999px; padding: 3px 12px; cursor: pointer;
  transition: box-shadow .2s, transform .15s;
}
.trace:hover, .trace:focus-visible { outline: none; box-shadow: 0 0 12px 0 var(--glow); transform: translateY(-1px); }
.trace[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--bright); }
.caption { margin: -10px 0 0; min-height: 3.2em; max-width: 82ch; color: var(--mid-text); }
/* tracing is behind a flag: nothing of it shows unless <main data-tracing="on"> */
main:not([data-tracing="on"]) :is(.traces, .caption) { display: none; }

/* while a trace is active: dim everything, then light what the trace passes through */
.tracing .part, .tracing .contract, .tracing .mem li { opacity: .38; }
.tracing .lit, .tracing .mem li.lit { opacity: 1; }
.part.lit, .mem li.lit { border-color: var(--bright); color: var(--bright); box-shadow: 0 0 12px 0 var(--glow); }
.contract.lit { color: var(--bright); }

.credit { margin-top: 10px; color: var(--dim-text); }
.credit a { color: var(--mid-text); text-decoration: none; border-bottom: 1px solid var(--dim-border); }
.credit a:hover { color: var(--bright); border-bottom-color: var(--bright); }

@media (max-width: 720px) {
  main { padding: 36px 16px 70px; }
  .tier { padding: 18px 16px; }
  .hw { grid-template-columns: 1fr; }
  .part { white-space: normal; }
  /* on a phone a tooltip as wide as the row it belongs to: it hangs under the connector row (the nearest positioned box once .info is static),
     so it can never run past the screen edge and make the page scroll sideways */
  .info { position: static; }
  .info .tip { left: 0; right: 0; width: auto; max-width: none; }
  .mem { flex-direction: column; }      /* too narrow for three across on a phone */
  /* on a phone the labels wrap to several lines, so the connector rows may grow beyond 56px */
  .contract { height: auto; min-height: 56px; padding: 6px 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
