/* Refract documentation — figures.
   A small component library for schematic illustrations of the app, sharing the
   visual language of the homepage prototype (css/prototype.css). Everything is
   markup + SVG: crisp at any zoom, no binary assets, no dark-mode mismatch. */

:root {
  --fig-surface: #1c1c1e;
  --fig-sidebar: #1a1a1a;
  --fig-plot: #1e1e20;
  --fig-bar: #2a2a2c;
  --fig-border: rgba(255, 255, 255, 0.07);
  --fig-border-strong: rgba(255, 255, 255, 0.11);
  --fig-text: #f5f5f7;
  --fig-muted: #a1a1a6;
  --fig-dim: #6e6e73;
  --fig-accent: #5b7a9a;
  --fig-mono: ui-monospace, "SF Mono", "Cascadia Code", monospace;

  /* Numbered-badge palette. Desaturated tints in the steel/slate family the
     rest of the site uses, rather than saturated pastels — they read as one
     set, and each carries dark text at 8:1 or better. */
  --badge-1: #9fbdd6;
  --badge-2: #cfc4a8;
  --badge-3: #a4c8b0;
  --badge-4: #b9b2d0;
  --badge-5: #d2b5b5;
  --badge-6: #9ec6c8;
  --badge-ink: #16212b;

  --trace-red: rgba(235, 97, 92, 0.85);
  --trace-amber: rgba(242, 191, 82, 0.85);
  --trace-green: rgba(77, 209, 115, 0.85);
  --trace-teal: rgba(56, 199, 173, 0.85);
  --trace-cyan: rgba(71, 199, 235, 0.85);
  --trace-azure: rgba(77, 166, 242, 0.85);
  --trace-blue: rgba(82, 133, 242, 0.85);
  --trace-violet: rgba(158, 115, 230, 0.85);
  --trace-magenta: rgba(230, 97, 184, 0.85);
}

/* ═══════════════════════════════════════════════════
   FIGURE WRAPPER
   ═══════════════════════════════════════════════════ */

.fig {
  margin: 1.6rem 0 1.9rem;
}

.fig-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.fig-cap {
  display: block;
  margin-top: 0.65rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--color-text-tertiary);
}

.fig-cap b {
  font-weight: 500;
  color: var(--color-text-muted);
}

/* ═══════════════════════════════════════════════════
   APP FRAME
   ═══════════════════════════════════════════════════ */

.fig-app {
  border: 1px solid var(--fig-border-strong);
  border-radius: 10px;
  background: var(--fig-surface);
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  min-width: 460px;
}

.fig-bar {
  height: 26px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  background: var(--fig-bar);
  border-bottom: 1px solid var(--fig-border);
}

.fig-bar i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #3a3a3c;
  flex-shrink: 0;
}

.fig-bar i:nth-child(1) { background: #ff5f57; }
.fig-bar i:nth-child(2) { background: #febc2e; }
.fig-bar i:nth-child(3) { background: #28c840; }

.fig-bar .fig-bar-title {
  margin-left: auto;
  margin-right: auto;
  font-size: 0.6875rem;
  color: var(--fig-dim);
  transform: translateX(-16px);
}

.fig-bar .fig-tb {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.fig-tb span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 18px;
  border-radius: 5px;
  font-size: 0.625rem;
  color: var(--fig-dim);
  border: 1px solid transparent;
}

.fig-tb span.on {
  background: rgba(91, 122, 154, 0.18);
  border-color: rgba(91, 122, 154, 0.4);
  color: #9fbcd8;
}

.fig-body {
  display: flex;
  align-items: stretch;
}

/* ═══════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════ */

.fig-side {
  width: 196px;
  min-width: 196px;
  background: var(--fig-sidebar);
  border-right: 1px solid var(--fig-border);
  display: flex;
  flex-direction: column;
}

.fig-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 6px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--fig-text);
}

.fig-side-head span {
  color: var(--fig-muted);
  font-weight: 400;
}

.fig-side-foot {
  margin-top: auto;
  padding: 6px 11px;
  font-size: 0.6875rem;
  color: var(--fig-dim);
  border-top: 1px solid var(--fig-border);
}

/* ── Rows ───────────────────────────────────────── */

.fig-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3.5px 11px;
  font-family: var(--fig-mono);
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--fig-text);
  white-space: nowrap;
}

.fig-row.trace {
  font-size: 0.6875rem;
  color: var(--fig-muted);
  padding-left: 26px;
}

.fig-row.trace.dep {
  padding-left: 38px;
}

.fig-row.sel {
  background: rgba(91, 122, 154, 0.2);
  box-shadow: inset 0 0 0 1px rgba(91, 122, 154, 0.4);
  border-radius: 4px;
}

.fig-row.dim {
  opacity: 0.55;
}

.fig-row .grow {
  margin-left: auto;
  color: var(--fig-dim);
  font-size: 0.5625rem;
}

.fig-chev {
  width: 9px;
  color: var(--fig-dim);
  font-size: 0.5rem;
  flex-shrink: 0;
}

/* Monotone source icons — drawn rather than set in emoji, so they take the
   surrounding text colour and a size we control. */
.fig-ico {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.1;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--fig-dim);
  vertical-align: -1px;
}

/* Trace markers — mirror the app's source-browser glyphs. */
.fig-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c, var(--trace-azure));
  flex-shrink: 0;
}

.fig-dot.hollow {
  background: none;
  border: 1px solid var(--fig-muted);
}

.fig-dot.fn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 5px;
  font-weight: 700;
  font-style: italic;
  color: #fff;
  line-height: 1;
}

.fig-glyph {
  width: 8px;
  flex-shrink: 0;
  font-size: 0.5625rem;
  color: var(--fig-dim);
  text-align: center;
}

.fig-badge {
  font-family: var(--fig-mono);
  font-size: 0.5625rem;
  color: var(--fig-dim);
  padding: 0 3px;
}

.fig-tag {
  font-size: 0.5625rem;
  color: var(--fig-accent);
  border: 1px solid rgba(91, 122, 154, 0.35);
  border-radius: 3px;
  padding: 0 3px;
}

.fig-status {
  padding: 0 11px 5px 28px;
  font-size: 0.625rem;
  color: #4fb96a;
  font-family: var(--fig-mono);
}

.fig-status.wait { color: var(--trace-amber); }

/* ═══════════════════════════════════════════════════
   MAIN / TRACKS
   ═══════════════════════════════════════════════════ */

.fig-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.fig-ruler {
  display: flex;
  height: 26px;
  background: var(--fig-surface);
  border-bottom: 1px solid var(--fig-border);
}

.fig-ruler-pad {
  width: 200px;
  min-width: 200px;
  border-right: 1px solid var(--fig-border);
}

.fig-ruler svg {
  flex: 1;
  width: 100%;
  height: 100%;
  display: block;
}

.fig-track {
  display: flex;
  height: 132px;
  border-bottom: 1px solid var(--fig-border);
  min-height: 0;
}

.fig-track:last-child {
  border-bottom: none;
}

.fig-thead {
  width: 150px;
  min-width: 150px;
  padding: 9px 8px;
  background: var(--fig-surface);
  border-right: 1px solid var(--fig-border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.fig-tname {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--fig-mono);
  font-size: 0.75rem;
  color: var(--fig-text);
}

.fig-tname .bar {
  width: 4px;
  height: 13px;
  border-radius: 2px;
  background: var(--c, var(--trace-azure));
  flex-shrink: 0;
}

.fig-titem {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 9px;
  font-family: var(--fig-mono);
  font-size: 0.6875rem;
  color: var(--fig-muted);
}

.fig-yaxis {
  width: 50px;
  min-width: 50px;
  background: var(--fig-surface);
  border-right: 1px solid var(--fig-border);
}

.fig-yaxis svg {
  width: 100%;
  height: 100%;
  display: block;
}

.fig-ytick {
  position: absolute;
  right: 7px;
  transform: translateY(-50%);
  font-family: var(--fig-mono);
  font-size: 9.5px;
  line-height: 1;
  color: var(--fig-muted);
  white-space: nowrap;
}

.fig-plot {
  flex: 1;
  min-width: 0;
  position: relative;
  background: var(--fig-plot);
}

.fig-plot svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ═══════════════════════════════════════════════════
   PANELS / POPOVERS
   ═══════════════════════════════════════════════════ */

.fig-panel {
  border: 1px solid var(--fig-border-strong);
  border-radius: 8px;
  background: var(--fig-surface);
  padding: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  min-width: 0;
}

.fig-panel-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.32);
  margin-bottom: 8px;
}

.fig-tile {
  border: 1px solid var(--fig-border);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.025);
  padding: 5px 8px;
}

.fig-tile-label {
  font-size: 0.5625rem;
  color: var(--fig-dim);
  margin-bottom: 2px;
}

.fig-tile-value {
  font-family: var(--fig-mono);
  font-size: 0.6875rem;
  color: var(--fig-text);
}

.fig-segs {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.fig-seg {
  flex: 1 1 auto;
  text-align: center;
  padding: 4px 8px;
  border: 1px solid var(--fig-border);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.025);
  font-size: 0.625rem;
  color: var(--fig-muted);
  white-space: nowrap;
}

.fig-seg.on {
  background: rgba(91, 122, 154, 0.2);
  border-color: rgba(91, 122, 154, 0.45);
  color: #cddcea;
}

.fig-cols {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.fig-cols > * {
  flex: 1 1 190px;
  min-width: 0;
}

/* ═══════════════════════════════════════════════════
   BYTE / PACKET STRIPS
   ═══════════════════════════════════════════════════ */

.fig-bytes {
  display: flex;
  align-items: stretch;
  gap: 2px;
  font-family: var(--fig-mono);
  min-width: 420px;
}

.fig-byte {
  flex: 1 1 auto;
  padding: 7px 4px;
  border-radius: 4px;
  text-align: center;
  font-size: 0.625rem;
  line-height: 1.3;
  border: 1px solid var(--fig-border-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--fig-muted);
  white-space: nowrap;
}

.fig-byte b {
  display: block;
  font-weight: 500;
  font-size: 0.5625rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fig-dim);
  margin-bottom: 2px;
}

.fig-byte.sync { background: rgba(158, 115, 230, 0.16); border-color: rgba(158, 115, 230, 0.42); color: #d7c4f2; }
.fig-byte.len { background: rgba(242, 191, 82, 0.15); border-color: rgba(242, 191, 82, 0.42); color: #f0dca6; }
.fig-byte.delim { background: rgba(77, 209, 115, 0.15); border-color: rgba(77, 209, 115, 0.42); color: #b7ecc7; }
.fig-byte.data { background: rgba(77, 166, 242, 0.15); border-color: rgba(77, 166, 242, 0.42); color: #b9d8f7; }
.fig-byte.pad { background: rgba(255, 255, 255, 0.02); border-style: dashed; color: var(--fig-dim); }
.fig-byte.f32 { background: rgba(82, 133, 242, 0.15); border-color: rgba(82, 133, 242, 0.42); color: #bcccf8; }
.fig-byte.u16 { background: rgba(56, 199, 173, 0.15); border-color: rgba(56, 199, 173, 0.42); color: #b0e8dd; }
.fig-byte.i32 { background: rgba(245, 140, 77, 0.15); border-color: rgba(245, 140, 77, 0.42); color: #f6cdaf; }

.fig-bytes-note {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-family: var(--fig-mono);
  font-size: 0.5625rem;
  color: var(--fig-dim);
  min-width: 420px;
}

/* ═══════════════════════════════════════════════════
   DIAGRAMS
   ═══════════════════════════════════════════════════ */

.fig-diagram {
  border: 1px solid var(--fig-border);
  border-radius: 10px;
  background: var(--fig-surface);
  padding: 16px;
}

.fig-diagram svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.d-label { font-family: var(--font-sans); font-size: 11px; fill: #f5f5f7; }
.d-sub { font-family: var(--font-sans); font-size: 9.5px; fill: #a1a1a6; }
.d-mono { font-family: var(--fig-mono); font-size: 9.5px; fill: #cdd6e0; }
.d-tiny { font-family: var(--font-sans); font-size: 8.5px; fill: #6e6e73; }
.d-box { fill: rgba(255, 255, 255, 0.035); stroke: rgba(255, 255, 255, 0.12); }
.d-box-accent { fill: rgba(91, 122, 154, 0.16); stroke: rgba(91, 122, 154, 0.45); }
.d-line { stroke: rgba(255, 255, 255, 0.22); fill: none; }
.d-line-accent { stroke: rgba(91, 122, 154, 0.8); fill: none; }
.d-dash { stroke: rgba(255, 255, 255, 0.16); stroke-dasharray: 3 3; fill: none; }
.d-grid { stroke: rgba(255, 255, 255, 0.07); }

/* ═══════════════════════════════════════════════════
   NUMBERED ANNOTATIONS
   ═══════════════════════════════════════════════════ */

.fig-keys {
  list-style: none;
  counter-reset: figkey;
  margin: 0.85rem 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.95rem 1.6rem;
}

.fig-keys li {
  counter-increment: figkey;
  position: relative;
  padding: 0.2rem 0.45rem 0.2rem 2.05rem;
  margin: -0.2rem 0 0 -0.45rem;
  border-radius: 7px;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--color-text-muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.fig-keys li:is(:hover, :focus-visible) {
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text);
  outline: none;
}

.fig-keys li:focus-visible {
  box-shadow: 0 0 0 2px var(--key);
}

.fig-keys li::before {
  content: counter(figkey);
  position: absolute;
  left: 0.45rem;
  top: 0.35rem;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--key, var(--badge-1));
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: var(--badge-ink);
}

@media (prefers-reduced-motion: reduce) {
  .fig-keys li {
    transition: none;
  }
}

.fig-keys li b {
  color: var(--color-text);
  font-weight: 500;
}

/* Numbered badge tying a spot in a figure to its entry in .fig-keys.
   Each number has its own hue so a badge and its key entry pair up by colour as
   well as by digit; the hues come from --badge-1..6 above. */
/* ═══════════════════════════════════════════════════
   KEYED FIGURES
   ═══════════════════════════════════════════════════ */

/* A mock explained by the numbered list beneath it. Pointing at a key dims the
   mock and lights only the part that key names; pointing at a part of the mock
   lights its key. Numbers live in the list rather than as badges over the
   drawing, so the figure reads as the interface it depicts.

   Built on :has(), so it needs no script. Where :has() is unsupported the
   figure simply stays in its resting state and the list still reads. */

/* Each key's colour, set once and read by both the list marker and the region
   it names, so the two can never drift apart. */
[data-fig-key="1"], .fig-keys > li:nth-child(1) { --key: var(--badge-1); --key-soft: rgba(159, 189, 214, 0.16); }
[data-fig-key="2"], .fig-keys > li:nth-child(2) { --key: var(--badge-2); --key-soft: rgba(207, 196, 168, 0.16); }
[data-fig-key="3"], .fig-keys > li:nth-child(3) { --key: var(--badge-3); --key-soft: rgba(164, 200, 176, 0.16); }
[data-fig-key="4"], .fig-keys > li:nth-child(4) { --key: var(--badge-4); --key-soft: rgba(185, 178, 208, 0.16); }
[data-fig-key="5"], .fig-keys > li:nth-child(5) { --key: var(--badge-5); --key-soft: rgba(210, 181, 181, 0.16); }
[data-fig-key="6"], .fig-keys > li:nth-child(6) { --key: var(--badge-6); --key-soft: rgba(158, 198, 200, 0.16); }

.fig-stage {
  position: relative;
}

/* The scrim that covers everything the active key does not name. It sits above
   the mock; the named region is lifted through it. */
.fig-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: inherit;
  background: var(--fig-surface);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.fig-keyed:has(.fig-keys > li:is(:hover, :focus-visible)) .fig-stage::after,
.fig-keyed:has([data-fig-key]:hover) .fig-stage::after {
  opacity: 0.76;
}

/* The highlight is painted with inset shadows rather than a border or an
   outline: these mocks are laid out at fixed widths, so anything occupying
   layout would nudge them, and an inset never reaches outside its own box —
   two highlights cannot overlap, because the boxes themselves do not.

   Where one key names a run of adjacent elements — a column of table cells,
   the signal rows of a track — script replaces the per-element boxes with a
   single box around the run (see .fig-keybox). These per-element rules are
   what a reader without script sees, and they are correct on their own.

   Once script adds .fig-boxed the per-element rules stop matching outright,
   rather than being overridden — an override would have to out-specify the
   lit selectors below, and it would lose. */
[data-fig-key] {
  --ring: transparent;
  border-radius: 4px;
  box-shadow:
    inset 1.5px 0 0 0 var(--ring),
    inset -1.5px 0 0 0 var(--ring),
    inset 0 1.5px 0 0 var(--ring),
    inset 0 -1.5px 0 0 var(--ring);
  transition: box-shadow 0.18s ease, background-color 0.18s ease;
}

/* Everything a key names is lifted through the scrim, marks included. */
.fig-keyed [data-fig-key]:hover,
.fig-keyed:has(.fig-keys > li:nth-child(1):is(:hover, :focus-visible)) [data-fig-key="1"],
.fig-keyed:has(.fig-keys > li:nth-child(1):is(:hover, :focus-visible)) [data-fig-lift="1"],
.fig-keyed:has(.fig-keys > li:nth-child(2):is(:hover, :focus-visible)) [data-fig-key="2"],
.fig-keyed:has(.fig-keys > li:nth-child(2):is(:hover, :focus-visible)) [data-fig-lift="2"],
.fig-keyed:has(.fig-keys > li:nth-child(3):is(:hover, :focus-visible)) [data-fig-key="3"],
.fig-keyed:has(.fig-keys > li:nth-child(3):is(:hover, :focus-visible)) [data-fig-lift="3"],
.fig-keyed:has(.fig-keys > li:nth-child(4):is(:hover, :focus-visible)) [data-fig-key="4"],
.fig-keyed:has(.fig-keys > li:nth-child(4):is(:hover, :focus-visible)) [data-fig-lift="4"],
.fig-keyed:has(.fig-keys > li:nth-child(5):is(:hover, :focus-visible)) [data-fig-key="5"],
.fig-keyed:has(.fig-keys > li:nth-child(5):is(:hover, :focus-visible)) [data-fig-lift="5"],
.fig-keyed:has(.fig-keys > li:nth-child(6):is(:hover, :focus-visible)) [data-fig-key="6"],
.fig-keyed:has(.fig-keys > li:nth-child(6):is(:hover, :focus-visible)) [data-fig-lift="6"] {
  z-index: 5;
}

/* Regions with a box worth drawing take the ring and the tint. The marks are
   left alone: a snap dot is 7px across and a cursor is a 1px hairline, so a
   box around either would be larger than the thing it points at. They simply
   stay at full strength while the scrim takes everything else down. */
.fig-keyed:not(.fig-boxed) [data-fig-key]:hover:not([data-fig-lift]),
.fig-keyed:not(.fig-boxed):has(.fig-keys > li:nth-child(1):is(:hover, :focus-visible)) [data-fig-key="1"]:not([data-fig-lift]),
.fig-keyed:not(.fig-boxed):has(.fig-keys > li:nth-child(2):is(:hover, :focus-visible)) [data-fig-key="2"]:not([data-fig-lift]),
.fig-keyed:not(.fig-boxed):has(.fig-keys > li:nth-child(3):is(:hover, :focus-visible)) [data-fig-key="3"]:not([data-fig-lift]),
.fig-keyed:not(.fig-boxed):has(.fig-keys > li:nth-child(4):is(:hover, :focus-visible)) [data-fig-key="4"]:not([data-fig-lift]),
.fig-keyed:not(.fig-boxed):has(.fig-keys > li:nth-child(5):is(:hover, :focus-visible)) [data-fig-key="5"]:not([data-fig-lift]),
.fig-keyed:not(.fig-boxed):has(.fig-keys > li:nth-child(6):is(:hover, :focus-visible)) [data-fig-key="6"]:not([data-fig-lift]) {
  position: relative;
  --ring: var(--key);
  background-color: var(--key-soft);
}

/* One box around a run of adjacent elements sharing a key, positioned over the
   mock by script. */
.fig-keybox {
  position: absolute;
  z-index: 5;
  border-radius: 5px;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 0 1.5px var(--key);
  background-color: var(--key-soft);
  transition: opacity 0.18s ease;
}

.fig-keyed:has([data-fig-key="1"]:hover) .fig-keybox[data-fig-key="1"],
.fig-keyed:has([data-fig-key="2"]:hover) .fig-keybox[data-fig-key="2"],
.fig-keyed:has([data-fig-key="3"]:hover) .fig-keybox[data-fig-key="3"],
.fig-keyed:has([data-fig-key="4"]:hover) .fig-keybox[data-fig-key="4"],
.fig-keyed:has([data-fig-key="5"]:hover) .fig-keybox[data-fig-key="5"],
.fig-keyed:has([data-fig-key="6"]:hover) .fig-keybox[data-fig-key="6"],
.fig-keyed:has(.fig-keys > li:nth-child(1):is(:hover, :focus-visible)) [data-fig-key="1"].fig-keybox,
.fig-keyed:has(.fig-keys > li:nth-child(2):is(:hover, :focus-visible)) [data-fig-key="2"].fig-keybox,
.fig-keyed:has(.fig-keys > li:nth-child(3):is(:hover, :focus-visible)) [data-fig-key="3"].fig-keybox,
.fig-keyed:has(.fig-keys > li:nth-child(4):is(:hover, :focus-visible)) [data-fig-key="4"].fig-keybox,
.fig-keyed:has(.fig-keys > li:nth-child(5):is(:hover, :focus-visible)) [data-fig-key="5"].fig-keybox,
.fig-keyed:has(.fig-keys > li:nth-child(6):is(:hover, :focus-visible)) [data-fig-key="6"].fig-keybox {
  opacity: 1;
}

/* Pointing at the mock lights the key that explains it. */
.fig-keyed:has([data-fig-key="1"]:hover) .fig-keys > li:nth-child(1),
.fig-keyed:has([data-fig-key="2"]:hover) .fig-keys > li:nth-child(2),
.fig-keyed:has([data-fig-key="3"]:hover) .fig-keys > li:nth-child(3),
.fig-keyed:has([data-fig-key="4"]:hover) .fig-keys > li:nth-child(4),
.fig-keyed:has([data-fig-key="5"]:hover) .fig-keys > li:nth-child(5),
.fig-keyed:has([data-fig-key="6"]:hover) .fig-keys > li:nth-child(6) {
  background: rgba(255, 255, 255, 0.05);
  color: var(--color-text);
}

@media (prefers-reduced-motion: reduce) {
  .fig-stage::after,
  [data-fig-key] {
    transition: none;
  }
}

@media print {
  .fig-stage::after {
    display: none;
  }
}

.fig-side,
.fig-thead,
.fig-yaxis,
.fig-plot,
.fig-ruler,
.fig-handle {
  position: relative;
}

.fig-handle {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding-left: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-top: 1px solid var(--fig-border);
}

.fig-handle::after {
  content: "";
  flex: 1;
  height: 3px;
  margin-right: 6px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.09);
}


/* ═══════════════════════════════════════════════════
   MEASUREMENT TABLE / CALCULATION PAD
   ═══════════════════════════════════════════════════ */

/* The docked measurement readout: a spreadsheet of samples on the left, a
   calculation pad on the right. Built from divs rather than a <table> so the
   fixed column widths match the app, where every cell is one of a handful of
   fixed widths and rows line up without measuring. */

.fig-measure {
  border: 1px solid var(--fig-border-strong);
  border-radius: 8px;
  background: var(--fig-surface);
  overflow: hidden;
  min-width: 480px;
}

.fig-measure-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 10px;
  border-bottom: 1px solid var(--fig-border);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.32);
}

.fig-measure-head .fig-segs {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.fig-measure-head .fig-seg {
  padding: 2px 9px;
}

.fig-measure-head .close {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.625rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--fig-muted);
}

/* Rows / From / To / Span strip above the table. */
.fig-measure-sum {
  display: flex;
  gap: 16px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--fig-border);
}

.fig-measure-sum span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-size: 0.625rem;
  color: rgba(255, 255, 255, 0.32);
}

.fig-measure-sum b {
  font-family: var(--fig-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--fig-text);
}

.fig-measure-body {
  display: flex;
  align-items: stretch;
}

/* The table is a run of fixed-width columns, so it must not stretch: a grown
   table would leave its zebra rows and rules short of its own right edge. The
   pad takes whatever is left. */
.fig-measure-body .fig-mtable {
  flex: 0 0 auto;
  border: 0;
  border-radius: 0;
}

.fig-measure-body .fig-mpad {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  border-radius: 0;
  border-left: 1px solid var(--fig-border-strong);
}

/* ── Overlaid measurement marks ────────────────── */

/* Cursors and snap dots sit on top of the plot as positioned HTML, not inside
   its SVG: that SVG is drawn with preserveAspectRatio="none" so the curves fill
   the width, and the same stretch would squash a circle into an oval, a chip
   into a wide plate, and a 1px rule into a thick band. Percentages of the plot
   box keep them attached to their x while they stay the shape they are. */

.fig-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  margin-left: -0.5px;
  background: rgba(91, 122, 154, 0.85);
  pointer-events: none;
}

/* The numbered chip, drawn on the topmost track only. */
.fig-cursor b {
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  background: rgba(91, 122, 154, 0.95);
  font-family: var(--fig-mono);
  font-size: 8.5px;
  font-weight: 700;
  line-height: 1;
  color: #f5f5f7;
}

.fig-snap {
  position: absolute;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.92);
  pointer-events: none;
}

/* ── The table ─────────────────────────────────── */

.fig-mtable {
  border: 1px solid var(--fig-border-strong);
  border-radius: 8px;
  background: var(--fig-surface);
  overflow: hidden;
  position: relative;
}

/* Track group band: one tinted plate per track, spanning its own columns. */
.fig-mt-band {
  display: flex;
  align-items: center;
  height: 19px;
  padding-top: 2px;
}

.fig-mt-band b {
  margin: 0 2px;
  height: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-family: var(--font-sans);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}

.fig-mt-row {
  display: flex;
  align-items: center;
  height: 20px;
}

.fig-mt-row.head {
  height: 19px;
  border-bottom: 1px solid var(--fig-border-strong);
  font-family: var(--font-sans);
  font-size: 8.5px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.35);
}

.fig-mt-row.zebra {
  background: rgba(255, 255, 255, 0.025);
}

.fig-mt-row > * {
  flex: 0 0 auto;
  padding-right: 8px;
  text-align: right;
  font-family: var(--fig-mono);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
  overflow: hidden;
}

/* The three column widths, scaled down from the app's 54 / 128 / 108 pt. */
.fig-mt-row > .n { width: 30px; color: rgba(255, 255, 255, 0.3); }
.fig-mt-row > .x { width: 84px; color: rgba(255, 255, 255, 0.6); }
.fig-mt-row > .c { width: 76px; }

/* A header cell carries its signal's marker beside the name, so both sit
   right-aligned over the numbers below. */
.fig-mt-row.head > * {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.fig-mt-row.head .c { color: rgba(255, 255, 255, 0.75); }

.fig-mt-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c);
  flex-shrink: 0;
}

/* Hollow triangle: the marker a column wears while it reads as offsets. */
.fig-mt-tri {
  width: 0;
  height: 0;
  flex-shrink: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 7px solid var(--c);
  position: relative;
}

.fig-mt-tri::after {
  content: "";
  position: absolute;
  left: -2.5px;
  top: 1.5px;
  border-left: 2.5px solid transparent;
  border-right: 2.5px solid transparent;
  border-bottom: 4.5px solid var(--fig-surface);
}

/* Delta cells carry a trace of direction, damped so a column of them still
   reads as text. The sign says the same thing, so the hue is only ever
   reinforcement. */
.fig-mt-row > .up { color: #86c79a; }
.fig-mt-row > .down { color: #d99a95; }

/* The row a column's offsets are measured from keeps its absolute value. */
.fig-mt-row > .base {
  font-style: italic;
  color: rgba(255, 255, 255, 0.42);
}

.fig-mt-row > .gap { color: rgba(255, 255, 255, 0.25); }

.fig-mt-row > .sel {
  background: rgba(91, 122, 154, 0.24);
  border-radius: 2px;
}

/* Rule between the row-number/x gutter and the signal columns, and between
   one track's block of columns and the next. */
.fig-mt-rule {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.14);
  pointer-events: none;
}

.fig-mt-rule.soft { background: rgba(255, 255, 255, 0.07); }

/* ── The pad ───────────────────────────────────── */

.fig-mpad {
  border: 1px solid var(--fig-border-strong);
  border-radius: 8px;
  background: var(--fig-surface);
  padding: 5px 0;
  position: relative;
  overflow: hidden;
}

.fig-mp-row {
  display: flex;
  align-items: center;
  height: 24px;
}

.fig-mp-row.on {
  background: rgba(91, 122, 154, 0.09);
}

.fig-mp-n {
  width: 22px;
  flex: 0 0 auto;
  padding-right: 4px;
  text-align: right;
  font-family: var(--fig-mono);
  font-size: 8.5px;
  color: rgba(255, 255, 255, 0.25);
}

.fig-mp-expr {
  flex: 1 1 auto;
  min-width: 0;
  padding-left: 6px;
  font-family: var(--fig-mono);
  font-size: 10.5px;
  color: var(--fig-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fig-mp-expr .ph {
  color: var(--fig-dim);
}

/* Reference pill, mirroring the editor's own: the token's colour at low alpha
   with a thin border of the same hue. */
.fig-mp-pill {
  display: inline-block;
  padding: 1px 4px;
  margin: 0 -1px;
  border-radius: 4px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 60%, transparent);
}

.fig-mp-ans {
  width: 76px;
  flex: 0 0 auto;
  padding-right: 10px;
  text-align: right;
  font-family: var(--fig-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--fig-accent);
  white-space: nowrap;
}

/* A per-row result is a column, not an answer: the pad says how big it is. */
.fig-mp-ans.pts {
  font-weight: 400;
  font-style: italic;
  color: var(--fig-muted);
}

.fig-mp-ans.err {
  color: var(--trace-amber);
}

/* One rule down the whole pane, so the answer column reads as a property of
   the pad rather than of any one line. */
.fig-mpad-rule {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 76px;
  width: 1px;
  background: rgba(255, 255, 255, 0.13);
  pointer-events: none;
}

/* Vertical splitter between the table and the pad. */
.fig-vhandle {
  flex: 0 0 auto;
  width: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-left: 1px solid var(--fig-border);
  border-right: 1px solid var(--fig-border);
  position: relative;
}

.fig-vhandle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 26px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.09);
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════ */

@media (max-width: 700px) {
  .fig-keys {
    grid-template-columns: 1fr;
  }
}
