/* Scoped progressive enhancements for Figures 2, 4 and 5. */
.figure-explorer {
  --viz-blue: #315fe2;
  --viz-purple: #8650b8;
  --viz-green: #008578;
  --viz-gray: #64748b;
  --viz-ink: #17283b;
  --viz-muted: #617084;
  --viz-line: #dce3ed;
  --ink: var(--viz-ink);
  --muted: var(--viz-muted);
  --line: var(--viz-line);
  --accent: var(--viz-blue);
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  overflow: hidden;
  font-size: .98rem;
  line-height: 1.5;
  isolation: isolate;
}
.figure-explorer [hidden] { display: none !important; }
.figure-explorer *, .figure-explorer *::before, .figure-explorer *::after { box-sizing: border-box; }
.figure-explorer button, .figure-explorer input { font: inherit; }
.figure-explorer button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--ink);
  padding: .45rem .8rem;
  cursor: pointer;
}
.figure-explorer button:hover { border-color: var(--viz-blue); }
.figure-explorer button:disabled { opacity: .35; cursor: default; }
.figure-explorer button:focus-visible, .figure-explorer input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.figure-explorer button[aria-pressed="true"] { background: color-mix(in srgb, var(--viz-blue) 9%, var(--bg)); border-color: var(--viz-blue); color: var(--accent); }
.figure-explorer .viz-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.viz-modebar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 18px; background: color-mix(in srgb, var(--ink) 2%, var(--bg)); border-bottom: 1px solid var(--line); }
.viz-view-switch, .viz-segments, .viz-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.viz-modebar button { min-height: 30px; padding: 3px 10px; font-size: .82rem; }
.viz-modebar > a { font-size: .82rem; white-space: nowrap; }
.viz-panel { padding: 22px 24px 18px; }
.viz-kicker { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .09em; font-weight: 600; margin-bottom: 5px; }
.post-content .viz-title { font-size: 1.46rem; letter-spacing: -.025em; line-height: 1.2; margin: 0 0 7px; font-weight: 600; }
.post-content .viz-subtitle { color: var(--muted); font-size: .9rem; margin: 0 0 18px; }
.viz-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 18px 0; }
.viz-segments { border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.viz-segments button { border-color: transparent; background: transparent; min-height: 34px; font-size: .87rem; padding: 4px 11px; }
.viz-small { font-size: .81rem; color: var(--muted); }
.viz-controls button { font-size: .87rem; }
.viz-controls .viz-primary { min-width: 116px; }
.viz-foot { display: flex; flex-wrap: wrap; gap: 5px 16px; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 17px; color: var(--muted); font-size: .81rem; }
.viz-note { border-left: 3px solid var(--viz-blue); padding: 9px 12px; color: var(--muted); background: color-mix(in srgb, var(--viz-blue) 4%, var(--bg)); font-size: .9rem; }
.viz-call-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: .84rem; color: var(--muted); margin: 18px 0 8px; }
.viz-call-title strong { color: var(--ink); }
.replay-flow { display: grid; grid-template-columns: minmax(0,1fr) 28px; column-gap: 6px; }
.replay-flow > :not(.replay-return) { grid-column: 1; }
.replay-cpu { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 5px; min-height: 45px; padding-inline: 12px; }
.replay-cpu span { display: grid; place-items: center; border: 1px solid var(--line); border-radius: 5px; background: color-mix(in srgb, var(--viz-gray) 4%, var(--bg)); font: .82rem ui-monospace, monospace; color: var(--muted); transition: background-color 200ms ease, border-color 200ms ease; }
.replay-cpu span.is-submitted { background: color-mix(in srgb, var(--viz-blue) 8%, var(--bg)); border-color: color-mix(in srgb, var(--viz-blue) 45%, var(--line)); color: var(--accent); }
.replay-cpu span.is-current { border-color: var(--viz-blue); box-shadow: inset 0 -2px var(--viz-blue); }
.replay-cpu .replay-graph-call { grid-column: 1 / -1; }
.replay-handoffs { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 5px; padding-inline: 12px; height: 49px; align-items: center; }
.replay-handoff { text-align: center; color: var(--line); font-size: 1.46rem; line-height: 1; }
.replay-handoff.is-sent { color: var(--viz-blue); }
.replay-graph-handoff { grid-column: 1 / -1; }
.figure-explorer[data-playing="true"] .replay-handoff.is-current { animation: replay-submit 850ms ease-in-out infinite; }
@keyframes replay-submit { 0%, 100% { transform: translateY(-4px); } 60% { transform: translateY(5px); } }
.replay-kernels { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 5px; border: 1px solid var(--line); border-radius: 9px; padding: 12px; }
.replay-kernels button { min-width: 0; min-height: 43px; padding: 5px 0; font: .85rem ui-monospace, monospace; position: relative; color: var(--muted); }
.replay-kernels button.is-queued { color: var(--ink); }
.replay-kernels button:not(:last-child)::after { content: "›"; position: absolute; right: -5px; z-index: 2; color: var(--muted); }
.replay-kernels button.is-past { border-bottom: 3px solid var(--viz-green); }
.replay-gpu-title { margin-top: 8px; }
.replay-return { position: relative; grid-column: 2; grid-row: 2 / 5; align-self: stretch; margin-block: 22.5px 34.5px; border: 2px solid var(--line); border-left: 0; border-radius: 0 9px 9px 0; color: var(--muted); }
.replay-return::before { content: "‹"; position: absolute; top: -15px; left: -5px; font-size: 1.46rem; }
.replay-return span { position: absolute; top: 50%; right: -9px; transform: translateY(-50%); background: var(--bg); padding-block: 3px; font-size: 1.26rem; }
.figure-explorer[data-returned="true"] .replay-return { color: var(--viz-green); border-color: var(--viz-green); }
.replay-legend { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 5px 12px; margin-block: 12px; font-size: .8rem; }
.replay-legend span:first-child { color: var(--viz-blue); }
.replay-legend span:last-child { color: var(--viz-green); }
.replay-status { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.replay-status strong { display: block; font-size: .73rem; letter-spacing: .07em; color: var(--muted); }
.replay-status span { display: block; font-size: .85rem; overflow-wrap: anywhere; }
.replay-detail { margin: 15px 0; min-height: 85px; }
.replay-detail strong { display: block; margin-bottom: 3px; font-size: .94rem; }
.replay-detail span { color: var(--muted); font-size: .89rem; }
.phase-steps { display: grid; grid-template-columns: 1fr .64fr 1fr .64fr 1fr; gap: 5px; margin: 18px 0; }
.viz-panel > .viz-controls { margin: 14px 0; }
.phase-steps button { padding: 9px 3px; font-size: .81rem; line-height: 1.25; }
.phase-steps .phase-barrier { border-style: dashed; color: var(--muted); }
.tile-lanes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tile-lane { border: 1px solid var(--line); border-radius: 11px; padding: 15px; min-width: 0; }
.tile-lane[data-method="local"] { --lane: var(--viz-purple); }
.tile-lane[data-method="mega"] { --lane: var(--viz-green); }
.tile-lane h4 { color: var(--lane); margin: 0 0 2px; font-size: 1.06rem; font-weight: 600; }
.tile-lane .lane-kind { color: var(--muted); font-size: .79rem; }
.lane-action { min-height: 48px; margin: 16px 0 8px; font-size: .87rem; }
.tile-buffer { border: 1.5px solid var(--lane); border-radius: 8px; background: color-mix(in srgb, var(--lane) 7%, var(--bg)); padding: 11px 9px; transition: background-color 250ms ease, border-color 250ms ease; }
.buffer-label { color: var(--lane); font-size: .77rem; margin-bottom: 8px; }
.tile-cells, .output-cells { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 4px; }
.tile-cells span, .output-cells span { text-align: center; border: 1px solid color-mix(in srgb, var(--lane) 30%, var(--line)); border-radius: 4px; padding: 7px 0; font: .81rem ui-monospace, monospace; background: var(--bg); }
.tile-buffer.is-empty { border-style: dashed; border-color: var(--line); background: transparent; }
.tile-buffer.is-empty .tile-cells { opacity: .3; }
.lane-boundary { min-height: 37px; margin: 10px 0 2px; color: var(--muted); font-size: .8rem; text-align: center; }
.lane-boundary.is-barrier { color: var(--lane); border-top: 2px dashed var(--lane); padding-top: 7px; }
.lane-output { min-height: 51px; font-size: .75rem; color: var(--muted); }
.output-cells { margin-top: 5px; }
.output-cells span { padding: 3px 0; }
.tile-counts { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: .76rem; color: var(--muted); }
.tile-counts strong { font-size: 1.21rem; font-weight: 600; color: var(--lane); display: block; }
.phase-detail { margin: 15px 0; min-height: 59px; font-size: .9rem; }
.phase-detail strong { display: block; margin-bottom: 2px; }
.phase-detail span { color: var(--muted); }
.viz-check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .83rem; cursor: pointer; }
.viz-check input { accent-color: var(--viz-blue); width: 16px; height: 16px; }
.latency-headline { display: flex; gap: 18px; justify-content: space-between; flex-wrap: wrap; padding: 14px 0; margin-bottom: 4px; border-block: 1px solid var(--line); }
.latency-gain { font-size: 1.61rem; line-height: 1.15; color: var(--viz-green); font-weight: 600; letter-spacing: -.03em; }
.latency-gain span { font-size: .85rem; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.latency-context { max-width: 300px; color: var(--muted); font-size: .84rem; }
.figure-explorer .latency-bar { display: block; width: 100%; min-height: 67px; text-align: left; padding: 9px 11px; margin: 3px 0; border-color: transparent; background: transparent; color: var(--ink); }
.figure-explorer .latency-bar:hover { background: color-mix(in srgb, var(--ink) 2%, var(--bg)); border-color: var(--line); }
.figure-explorer .latency-bar[aria-pressed="true"] { border-color: var(--method-color); background: color-mix(in srgb, var(--method-color) 5%, var(--bg)); color: var(--ink); }
.latency-bar-label { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; font-size: .91rem; }
.latency-value { font-variant-numeric: tabular-nums; font-size: 1.03rem; font-weight: 600; white-space: nowrap; }
.latency-track { display: block; position: relative; height: 16px; margin: 7px 0 0; background-image: repeating-linear-gradient(to right, var(--line) 0, var(--line) 1px, transparent 1px, transparent 25%); }
.latency-fill { display: block; position: absolute; height: 9px; top: 3px; left: 0; background: var(--method-color); border-radius: 2px; transition: width 350ms cubic-bezier(.2,.65,.3,1); }
.latency-range { position: absolute; top: 1px; height: 13px; min-width: 2px; border-inline: 1.5px solid var(--ink); border-top: 1px solid var(--ink); transform: translateY(1px); }
.latency-axis { display: flex; justify-content: space-between; margin: 3px 11px 10px; font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.latency-options { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.latency-detail { border: 1px solid var(--line); border-radius: 9px; padding: 13px 15px; }
.latency-detail h4 { margin: 0 0 10px; font-size: .94rem; font-weight: 600; }
.latency-detail dl { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; margin: 0; }
.latency-detail dt { color: var(--muted); font-size: .75rem; }
.latency-detail dd { margin: 2px 0 0; font-size: .97rem; font-variant-numeric: tabular-nums; }
.latency-detail .method-description { margin-top: 10px; font-size: .82rem; color: var(--muted); }
.figure-jumps { display: flex; flex-wrap: wrap; gap: 7px 16px; margin: 18px 0 0; font-size: .86rem; }
.figure-jumps span { color: var(--muted); }
@media (max-width: 640px) {
  .viz-panel { padding: 18px 14px 15px; }
  .viz-modebar { padding: 8px 12px; }
  .post-content .viz-title { font-size: 1.31rem; }
  .viz-toolbar { align-items: flex-start; gap: 9px; }
  .tile-lanes { gap: 8px; }
  .tile-lane { padding: 10px 8px; }
  .tile-lane h4 { font-size: .94rem; }
  .lane-kind { display: block; min-height: 40px; }
  .lane-action { min-height: 65px; font-size: .82rem; }
  .tile-buffer { padding: 8px 5px; }
  .buffer-label { min-height: 36px; font-size: .75rem; }
  .tile-cells, .output-cells { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 3px; }
  .lane-boundary { min-height: 58px; font-size: .76rem; }
  .lane-output { min-height: 69px; }
  .tile-counts { gap: 8px; font-size: .75rem; }
  .phase-steps { gap: 3px; }
  .phase-steps button { font-size: .77rem; min-height: 45px; }
  .replay-kernels { padding: 9px 6px; gap: 4px; }
  .replay-kernels button { font-size: .73rem; }
  .replay-flow { grid-template-columns: minmax(0,1fr) 20px; column-gap: 4px; }
  .replay-cpu, .replay-handoffs { gap: 4px; padding-inline: 6px; }
  .replay-cpu span { font-size: .73rem; }
  .replay-cpu .replay-graph-call { font-size: .82rem; }
  .replay-return { margin-bottom: 30.5px; }
  .replay-status { gap: 10px; padding: 10px; }
  .replay-status span { font-size: .79rem; }
  .replay-gpu-title { align-items: flex-start; }
  .replay-gpu-title span { max-width: 135px; text-align: right; }
  .latency-detail { padding: 11px; }
  .latency-detail dd { font-size: .87rem; }
  .latency-context { max-width: 100%; }
  .viz-controls { gap: 4px; }
  .viz-controls button { font-size: .79rem; padding-inline: .6rem; }
}
@media (prefers-color-scheme: dark) {
  .figure-explorer { --viz-blue: #89a7ff; --viz-purple: #c19be4; --viz-green: #65c9b3; --viz-gray: #a0aec0; --viz-ink: #f4f6fb; --viz-muted: #b4bdcb; --viz-line: #354153; }
}
:root[data-theme="dark"] .figure-explorer { --viz-blue: #89a7ff; --viz-purple: #c19be4; --viz-green: #65c9b3; --viz-gray: #a0aec0; --viz-ink: #f4f6fb; --viz-muted: #b4bdcb; --viz-line: #354153; }
@media (prefers-reduced-motion: reduce) {
  .figure-explorer *, .figure-explorer *::before, .figure-explorer *::after { animation: none !important; transition: none !important; }
}
@media print {
  .figure-explorer, .figure-jumps { display: none !important; }
  .post-content .figure-scroll[hidden] { display: block !important; }
}
