/* Inference Parallelism page: layout and scenario rules. Everything visual (panels, hardware boxes, connector rows, arrows, tooltips, buttons) comes from ../styles.css. */

/* THE SPACE BETWEEN THE THREE BLOCKS: the title, the scenario area (SCENARIO label, buttons, description) and the diagram (from the server
   titles down). One variable sets both gaps (--section-gap, set in styles.css, where it is also the title's gap on every page), so tune it there. Each gap is measured as the eye sees it, between what is drawn: from the bottom
   of the title's letters to the top of the SCENARIO label, and from the bottom of the scenario area to the top of the server titles' letters.
   The empty space the boxes add is taken out, so both gaps are exactly this value: .13em under the title's letters (its line box is as tall as
   the font size), 3px above the label's capitals, 1px above the server titles' capitals (measured for the page's fonts; other fonts differ by
   a pixel or two), and the 22.1px the server titles take above their panels. The spacing inside the blocks is much smaller (12px between the
   buttons, 6px from a server title to its panel, 24px of panel padding). */
main { row-gap: 0; }   /* --section-gap itself is set in styles.css, as the title's gap on every page. row-gap: 0, because the gaps are set per block below (the page's usual 26px would add to them) */
.title { margin-bottom: calc(var(--section-gap) - .13em - 3px); }
.fig { margin-top: calc(var(--section-gap) + 1.15em + 6px - 1px); }
.legend { margin-top: 26px; }   /* what the page's 26px gap gave it, unchanged */

/* The figure's width and its middle column, in one place (the figure is as wide as the Inference Stack's: 1006px, 1134px from a 1190px window).
   The header above it uses the same two columns, so its right column is Server B's column: the scenario description starts where Server B
   starts and is as wide as it. */
main { --fig-w: 1006px; --mid-col: 176px; }
@media (min-width: 1190px) { main { --fig-w: 1134px; } }

/* The header, between the title and the diagram. Left (the first two columns): the SCENARIO label, then the three scenario buttons as a
   staircase. Right (the third column, Server B's): the scenario description, its top level with the label's. The label is 18px tall and 12px
   (the page's usual gap) from the first button; the buttons are one column sized by the widest, so all three are the same width ("Tensor +
   Pipeline"), and each is 41px (a button and that gap) lower and 62px further right than the one before. The first starts 95px in from the
   label's left edge; the shifts use position: relative, which moves a button without changing its width. */
.top { display: grid; width: var(--fig-w); max-width: 100%; grid-template-columns: 1fr var(--mid-col) 1fr; align-items: start; }
.top .traces { grid-column: 1 / 3; grid-row: 1; display: grid; row-gap: 12px; justify-items: start; margin: 0; }
.top .caption { grid-column: 3; grid-row: 1; margin: 0; max-width: none; }
.caption .term { color: var(--bright); font-weight: 500; }   /* the parenthetical terms, "(tensor parallel)" and the like */
.caption .para { display: block; }
.caption .para + .para { margin-top: .75em; }   /* a gap between paragraphs, half a line */
.trace-group { display: grid; grid-template-columns: max-content; row-gap: 12px; margin-left: 95px; }
.trace-group .trace { position: relative; }
.trace-group .trace:nth-child(2) { left: 62px; }
.trace-group .trace:nth-child(3) { left: 124px; }
/* when the servers stack, the description cannot sit beside Server B: it goes below the buttons, as wide as the figure */
@media (max-width: 1080px) {
  .top { grid-template-columns: 1fr; }
  .top .traces { grid-column: 1; }
  .top .caption { grid-column: 1; grid-row: 2; margin-top: 16px; }
}
/* and on a phone the staircase (95 + 124 + 170px across) does not fit: the buttons become a plain column */
@media (max-width: 720px) {
  .trace-group { margin-left: 0; }
  .trace-group .trace:nth-child(2), .trace-group .trace:nth-child(3) { left: 0; }
}

/* Server A | the network | Server B. The middle column holds the RoCE link. */
.gpus { display: grid; width: var(--fig-w); grid-template-columns: 1fr var(--mid-col) 1fr; align-items: start; }

/* one server, top to bottom: an empty strip where the model appears, one row of eight GPUs (each box holds just its number, the row is
   labelled "GPUs" once underneath), the GPU-to-GPU link, the PCIe link, the CPU memory. The block is 371.8px tall and the five rows are
   spread evenly from the top padding to the bottom padding (four equal gaps of about 19.5px). The rows are compact: the links 40px (each holds
   its name and its second line) and the CPU memory about 35px, so there is room for the gaps. */
.server { display: flex; flex-direction: column; justify-content: space-between; min-height: 371.8px; }
.gpu-row { flex-wrap: nowrap; }
.gpu-row .part { flex: 1 1 0; min-width: 0; justify-content: center; padding: 18px 2px; }
.cpu-row .part { flex: 1 1 100%; justify-content: center; padding-top: 8px; padding-bottom: 8px; }
/* the "GPUs" label hangs under its row, inside the gap below it, so the spacing between rows does not count it */
.gpu-block { position: relative; }
.row-label { position: absolute; top: 100%; left: 0; margin-top: 4px; height: 14px; font: 400 .85em/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--dim-text); }

/* links that run sideways (GPU to GPU, server to server) use the same arrow pair, turned 90 degrees */
/* turned anticlockwise so the first arrow of the pair (down when it is vertical) points right when it is turned: A to B in both layouts */
.arr-pair.rot { transform: rotate(-90deg); }

/* the links inside a server: the arrows and the label side by side, the pair centred under the row above. The label has the whole row
   to itself, so its name stays on one line (the carried-text line under it is the second line). */
.server .contract { display: flex; justify-content: center; align-items: center; gap: 14px; height: 40px; min-height: 0; padding: 0; }
.server .contract .label { white-space: nowrap; }

/* the RoCE link sits in the middle column, level with the GPU row: arrows, then the label, centred */
.link-roce { height: auto; min-height: 106px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; margin-top: 94px; padding: 0 2px; text-align: center; }
/* 106px = arrows 30 + label 21 + the carried-text line (2 lines, 39) + two 8px gaps: a fixed height, so the block stays level with the GPU row
   whether or not a scenario is showing its text. 94px = the middle of the GPU row (147px from the panel top: 24 padding + 76 model strip + a
   19.5px gap + half a 55px GPU box) less half of that. */
.link-roce .label { align-items: center; }

/* narrower than 1080px (two server panels plus the 176px middle column) the servers stack and the RoCE link
   becomes the normal vertical connector row between them */
@media (max-width: 1080px) {
  .gpus { grid-template-columns: 1fr; }
  .link-roce { display: grid; height: auto; min-height: 56px; margin-top: 0; padding: 0; text-align: left; }
  .link-roce .label { align-items: stretch; }
  .link-roce .arr-pair.rot { transform: none; }
}

/* ───────────────────────── scenarios (hover) ───────────────────────── */
/* ONE STATE SWITCH. The only thing that changes when a scenario is hovered is the attribute data-trace ("" / s1 / s2 / s3) and the class
   "tracing" on <main> (gpus.js sets no other class). Everything below is chosen from that, and from each element's data-chain (the scenarios
   it is used in), so every change starts at the same moment.
   Idle: the tracing rule in styles.css dims every .part and .contract while a scenario is shown. The GPUs are all in use in every scenario,
   so they stay at full strength; the CPU memory and the links that carry nothing stay dimmed, which is how "idle" shows. */
.tracing .part.gpu { opacity: 1; }
/* Lit: a link is lit when the scenario shown is one of the scenarios in its data-chain. Its second line gets the brighter grey. */
main[data-trace="s1"] .link[data-chain~="s1"], main[data-trace="s2"] .link[data-chain~="s2"], main[data-trace="s3"] .link[data-chain~="s3"] { opacity: 1; color: var(--bright); }
main[data-trace="s1"] .link[data-chain~="s1"] .carry, main[data-trace="s2"] .link[data-chain~="s2"] .carry, main[data-trace="s3"] .link[data-chain~="s3"] .carry { color: var(--mid-text); }
/* A lit link can still have one idle direction (scale-out, B to A, in scenario 3): an arrow with its own data-chain that leaves out the scenario
   shown. The arrows of the other links have no data-chain of their own, so they light with their row. */
main[data-trace="s1"] .link[data-chain~="s1"] .arr-pair svg[data-chain]:not([data-chain~="s1"]),
main[data-trace="s2"] .link[data-chain~="s2"] .arr-pair svg[data-chain]:not([data-chain~="s2"]),
main[data-trace="s3"] .link[data-chain~="s3"] .arr-pair svg[data-chain]:not([data-chain~="s3"]) { opacity: .38; }

/* ONE CLOCK. Every element that changes with the state fades with the same transition: same duration, same easing, no delay, in and out
   (--sync). Elements that did not fade before, the arrows, the second line's colour and the model strip, now do, and the scenario buttons'
   glow and lift use it too. Each element transitions only the properties it sets itself: the name and arrows of a link inherit their colour
   from the link row, so they follow the row's fade; giving them a transition of their own would make them trail behind it. */
main { --sync: .2s ease; }
.gpus .link { transition: opacity var(--sync), color var(--sync); }                 /* the row: its name and arrows follow its colour */
.gpus .link svg { transition: opacity var(--sync); }                                /* an arrow's own opacity (an idle direction) */
.gpus .link .carry { transition: color var(--sync); }                               /* the second line has its own colour */
.gpus .cpu-row .part, .gpus .model-row { transition: opacity var(--sync); }
.gpus .bracket { transition: margin-left var(--sync), margin-right var(--sync); }                  /* scenario 2 stretches the brackets across the gap */
.gpus .bracket::before, .gpus .bracket::after { transition: opacity var(--sync); }                 /* their end ticks */
.gpus .bracket-label { transition: left var(--sync), opacity var(--sync), background-color var(--sync); }
.gpus .io > * { transition: opacity var(--sync); }                                                  /* the PROMPT / OUTPUT labels */
.traces .trace { transition: box-shadow var(--sync), transform var(--sync); }

/* what a link carries: a second line under every link label, a dim "idle" at rest and, when a scenario is shown, the text of that scenario's
   data-s1 / data-s2 / data-s3 attribute (a link that carries nothing there says "idle" again). The line is always there, so nothing moves
   when a scenario appears. In the server rows the NVLink label is held as wide as its longest text (28 characters), so the arrows and the
   label name stay put whichever text is showing. */
.carry { display: block; min-height: 1.5em; }
.carry::after { content: "idle"; }
.link-fabric .carry { min-width: 28ch; }
/* the PCIe row is nailed in place: its second line takes no width of its own, so the longer text of the scenarios ("optional: KV cache
   offload") runs on to the right of the label and the row stays the width it has at rest, centred where it always was */
.link-pcie .carry { width: 0; white-space: nowrap; }
.link-roce .carry { min-height: 3em; }   /* two lines */
main[data-trace="s1"] .carry::after { content: attr(data-s1); }
main[data-trace="s2"] .carry::after { content: attr(data-s2); }
main[data-trace="s3"] .carry::after { content: attr(data-s3); }

/* scenario 1: the servers do not need the network, but it can share a KV cache between them. Between lit and idle: dimmer than the lit links,
   brighter than the idle ones (the tracing rule in styles.css dims it to .38), with that note under its label. */
main[data-trace="s1"] .link-roce { opacity: .65; }
/* the PCIe links, in scenarios 1 and 3: the KV cache can optionally be offloaded to CPU memory over them. The same in-between dimness as the
   optional scale-out link above (scenario 2: idle, dimmed like the rest). */
main[data-trace="s1"] .link-pcie, main[data-trace="s3"] .link-pcie { opacity: .65; }

/* a tooltip is above all the diagram and fully opaque: its row (every link row is its own stacking layer, and a row dimmed by a scenario fades
   everything in it, its tooltip too) goes to the top layer at full strength for as long as its tooltip is open */
.gpus .contract:has(.info:hover), .gpus .contract:has(.info:focus-visible) { z-index: 40; opacity: 1 !important; }

/* tooltips stay inside the page at every width.The ones in the server panels hang under their own link row, as wide as the row (the
   icon is static, so the row is the box they are placed against). The RoCE one, in the narrow middle column, is centred under its
   block. On a phone styles.css already makes every tooltip as wide as its row. */
.gpus .server .info { position: static; }
.gpus .server .tip { left: 0; right: 0; width: auto; max-width: none; }
@media (min-width: 721px) {
  .link-roce .info { position: static; }
  .link-roce .tip { left: 50%; right: auto; transform: translateX(-50%); width: 340px; }
}

/* the model: a strip above each row of GPUs, empty (it only reserves the space) until a scenario is shown. Then it holds eight filled, light
   slices per server (no outline), one directly over each GPU, with a label above them saying what the server's model holds. A slice is
   exactly the width and horizontal place of the GPU under it, and the slices are as far apart as the GPUs: both rows are the same flex row
   (.parts), so the width, the order and the gap come from the same rules and cannot drift apart. */
.model-row { --model-fill: color-mix(in srgb, var(--bright) 85%, var(--bg)); display: flex; flex-direction: column; gap: 6px; height: 76px; opacity: 0; }
.tracing .model-row { opacity: 1; }   /* it fades with everything else (it used to switch visibility, which cannot fade) */
/* Server A's strip is painted above Server B's. In scenario 2 B's half of the bracket line starts at the middle of the gap, exactly where A's
   "one model copy" label sits; B comes later in the page, so without this its line was painted over the label and ran through the text. */
.model-a { position: relative; z-index: 2; }
.model-label { height: 14px; white-space: nowrap; font: 400 .85em/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--bright); }
.model-label::before { content: "Model"; }
.model-cells { flex: 1; flex-wrap: nowrap; }
.model-cells li { flex: 1 1 0; min-width: 0; background: var(--model-fill); }
main[data-trace="s1"] .model-label::before, main[data-trace="s3"] .model-label::before { content: "All layers"; }
main[data-trace="s2"] .model-a .model-label::before { content: "Layers 1–40"; }
main[data-trace="s2"] .model-b .model-label::before { content: "Layers 41–80"; }

/* Copy brackets: above each server's model slices, a thin bracket (a 1px line with a short tick down at each end, no outline, nothing dashed)
   spanning the GPUs that one copy of the model covers, with its label centred on the line. They sit inside the model strip, so they fade in
   and out with it, from the same state switch and on the same clock (the ticks, the stretch and the label have transitions on --sync too).
   Scenario 1: "full model copy A" over Server A's GPUs, "full model copy B" over Server B's. Scenario 3: "prefill model copy" on A, "decode model copy" on B. Scenario 2: one
   bracket across both servers: with the servers side by side each bracket is stretched to the middle of the gap (the panel's 24px padding
   plus half the 176px middle column = 112px) and drops its inner tick, so the two meet as one line, and the single label "one model copy" is
   centred on the join; stacked, each server keeps its own bracket and both say "one model copy". The label has a background the colour of what
   is behind it, to interrupt the line (the panel's grey, or the page's black over the gap). */
.bracket { position: relative; flex: none; height: 14px; color: var(--mid-text); background: linear-gradient(currentColor, currentColor) 0 6px / 100% 1px no-repeat; }
.bracket::before, .bracket::after { content: ""; position: absolute; top: 6px; width: 1px; height: 8px; background: currentColor; }
.bracket::before { left: 0; }
.bracket::after { right: 0; }
.bracket-label { position: absolute; top: 0; left: 50%; transform: translateX(-50%); height: 14px; padding: 0 8px; white-space: nowrap; background: var(--line);
  font: 400 .85em/14px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--mid-text); }
main[data-trace="s1"] .model-a .bracket-label::before { content: "full model copy A"; }
main[data-trace="s1"] .model-b .bracket-label::before { content: "full model copy B"; }
main[data-trace="s2"] .bracket-label::before { content: "one model copy"; }
main[data-trace="s3"] .model-a .bracket-label::before { content: "prefill model copy"; }
main[data-trace="s3"] .model-b .bracket-label::before { content: "decode model copy"; }
@media (min-width: 1081px) {
  main[data-trace="s2"] .model-a .bracket { margin-right: -112px; }
  main[data-trace="s2"] .model-b .bracket { margin-left: -112px; }
  main[data-trace="s2"] .model-a .bracket::after, main[data-trace="s2"] .model-b .bracket::before { opacity: 0; }
  main[data-trace="s2"] .model-a .bracket-label { left: 100%; background: var(--bg); }
  main[data-trace="s2"] .model-b .bracket-label { opacity: 0; }
}

/* PROMPT / OUTPUT: where a request enters and where the answer leaves, on the line of each server's title, right-aligned to the block's right
   edge. The look is that of the Inference Stack's PROMPT / OUTPUT labels (styles.css, .lbl): the same font, size, weight, letter spacing and
   muted grey, and the same 7 x 10px triangle, here pointing down after PROMPT (into the server) and up after OUTPUT (out of it). The text is
   horizontal. They take no room (absolutely positioned) and are hidden at rest; each scenario shows its own from the same state switch and on
   the same clock. Data + Tensor: PROMPT and OUTPUT on both servers, side by side. Tensor + Pipeline and Prefill / Decode: PROMPT on Server A,
   OUTPUT on Server B. Alone, PROMPT sits at the block's edge, which is a second PROMPT (.io-prompt-solo) rather than the first one moving, so
   switching scenario cross-fades the labels instead of sliding them. */
.io { position: absolute; right: 0; bottom: 100%; margin: 0 0 6px; display: flex; align-items: center; gap: 1.5em; white-space: nowrap;
  color: var(--dim-text); font: 500 1.15em/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.io > * { display: inline-flex; align-items: center; gap: 6px; opacity: 0; }
.io-prompt-solo { position: absolute; top: 0; right: 0; bottom: 0; }
.io-tri { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; }
.io-down { border-top: 7px solid currentColor; }
.io-up { border-bottom: 7px solid currentColor; }
main[data-trace="s1"] .io-prompt, main[data-trace="s1"] .io-output,
main[data-trace="s2"] .srv-a .io-prompt-solo, main[data-trace="s2"] .srv-b .io-output,
main[data-trace="s3"] .srv-a .io-prompt-solo, main[data-trace="s3"] .srv-b .io-output { opacity: 1; }
/* Only where they fit. When the servers are stacked, Server B's title line sits right under the scale-out row, whose second line of text runs
   under B's labels once the window is narrower than about 900px (it is 9.5px clear at 901px, more above), and nothing else may move to make
   room. So from 900px down neither server shows them (rather than one server showing them and the other not). */
@media (max-width: 900px) { .io { display: none; } }

/* reserve room for the longest caption, so the figure does not move when the scenario changes (a line is 1.5em). Stacked, from a 901px window,
   the captions take up to 4 lines. Side by side the caption is only as wide as Server A's panel, so it wraps more: up to 7 lines while the
   panel is 415px wide (1081px to 1189px windows), up to 6 lines at 479px (from 1190px). The Data + Tensor caption, in three paragraphs with half
   a line between them, is kept short enough to fit (its gaps count as one of those lines). Narrower windows wrap the captions to more lines
   still and cannot reserve that much. */
@media (min-width: 901px) { .caption { min-height: 6em; } }
@media (min-width: 1081px) { .caption { min-height: 10.5em; } }
@media (min-width: 1190px) { .caption { min-height: 9em; } }

/* legend swatch for the model: a filled light block, no outline */
.swatch.is-model { border: 0; background: color-mix(in srgb, var(--bright) 85%, var(--bg)); }
