.tp-visualizer {
  --tp-ink: var(--reader-ink, #20334f);
  --tp-muted: var(--reader-muted, #60718a);
  --tp-accent: var(--reader-accent, #245a9b);
  --tp-accent-soft: var(--reader-accent-soft, #e9f1fc);
  --tp-line: var(--reader-line, #dce4ee);
  --tp-paper: var(--reader-paper, #fff);
  --tp-soft: var(--reader-soft, #f4f7fb);
  width: min(100%, 940px);
  margin: 28px 0 34px;
  overflow: clip;
  border: 1px solid var(--tp-line);
  border-radius: 6px;
  background: var(--tp-paper);
  color: var(--tp-ink);
  box-shadow: 0 8px 24px rgba(28, 51, 79, .055);
  font-family: var(--reader-font, system-ui, sans-serif);
}

.tp-visualizer * { box-sizing: border-box; }
.tp-visualizer button { font: inherit; }
.tp-visualizer button:focus-visible { outline: 3px solid color-mix(in srgb, var(--tp-accent) 35%, transparent); outline-offset: 2px; }
.tp-visualizer-fallback { padding: 22px; }
.tp-visualizer-fallback__label { margin: 0 0 5px !important; color: var(--tp-accent) !important; font: 750 .64rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace !important; letter-spacing: .09em; text-transform: uppercase; }

.tp-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px 15px; border-bottom: 1px solid var(--tp-line); }
.tp-heading-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tp-heading-row h3 { margin: 0 !important; color: var(--tp-ink) !important; font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif !important; font-size: 1.45rem !important; letter-spacing: -.025em; }
.tp-badge { padding: 4px 9px; border-radius: 999px; background: var(--tp-accent-soft); color: var(--tp-accent); font: 750 .56rem/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .07em; text-transform: uppercase; }
.tp-header p { max-width: none !important; margin: 4px 0 0 !important; color: var(--tp-muted) !important; font-size: .76rem !important; line-height: 1.45 !important; }
.tp-reset, .tp-footer button { min-height: 34px; padding: 0 14px; border: 1px solid var(--tp-line); border-radius: 5px; background: var(--tp-paper); color: var(--tp-ink); cursor: pointer; font-size: .68rem; }
.tp-reset:hover, .tp-footer button:hover:not(:disabled) { border-color: var(--tp-accent); color: var(--tp-accent); }

.tp-steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0; padding: 14px 18px 12px; border-bottom: 1px solid var(--tp-line); list-style: none; }
.tp-steps li { position: relative; min-width: 0; text-align: center; }
.tp-steps li:not(:last-child)::after { position: absolute; z-index: 0; top: 12px; left: calc(50% + 15px); width: calc(100% - 30px); height: 1px; background: var(--tp-line); content: ""; }
.tp-steps li.is-complete:not(:last-child)::after { background: color-mix(in srgb, var(--tp-accent) 52%, var(--tp-line)); }
.tp-steps button { position: relative; z-index: 1; width: 100%; padding: 0 4px; border: 0; background: transparent; color: var(--tp-muted); cursor: pointer; font-size: .63rem; line-height: 1.35; }
.tp-steps button span { display: grid; width: 25px; height: 25px; margin: 0 auto 6px; place-items: center; border: 1px solid color-mix(in srgb, var(--tp-muted) 38%, var(--tp-line)); border-radius: 50%; background: var(--tp-paper); color: var(--tp-muted); font: 700 .58rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; }
.tp-steps li.is-complete button span { border-color: var(--tp-accent); background: var(--tp-accent); color: #fff; }
.tp-steps li.is-active button { color: var(--tp-accent); font-weight: 750; }
.tp-steps li.is-active button span { border-color: var(--tp-accent); background: var(--tp-accent-soft); color: var(--tp-accent); box-shadow: 0 0 0 3px var(--tp-paper), 0 0 0 4px color-mix(in srgb, var(--tp-accent) 28%, transparent); }

.tp-stage { padding: 16px 18px 18px; }
.tp-stage-heading { padding: 12px 14px; background: var(--tp-soft); }
.tp-step-count { margin: 0 0 3px !important; color: var(--tp-accent) !important; font: 750 .58rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace !important; letter-spacing: .08em; text-transform: uppercase; }
.tp-stage-heading h4 { margin: 0; color: var(--tp-ink); font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif; font-size: 1.25rem; line-height: 1.2; letter-spacing: -.02em; }
.tp-svg-wrap { margin-top: 12px; overflow-x: auto; }
.tp-svg-wrap svg { display: block; width: 100%; min-width: 690px; height: auto; }

.tp-svg-input rect, .tp-svg-collective-box { fill: var(--tp-soft); stroke: color-mix(in srgb, var(--tp-accent) 32%, var(--tp-line)); }
.tp-svg-label { fill: var(--tp-ink); font-size: 13px; font-weight: 700; }
.tp-svg-shape { fill: var(--tp-muted); font-family: Georgia, Cambria, "Times New Roman", serif; font-size: 12px; font-style: italic; }
.tp-svg-small { fill: var(--tp-muted); font-size: 11px; }
.tp-svg-gpu-title { fill: var(--tp-ink); font-size: 13px; font-weight: 750; }
.tp-svg-gpu-card { fill: color-mix(in srgb, var(--owner) 5%, var(--tp-paper)); stroke: color-mix(in srgb, var(--owner) 42%, var(--tp-line)); }
.tp-svg-cell { fill: color-mix(in srgb, var(--owner) 16%, var(--tp-paper)); stroke: color-mix(in srgb, var(--owner) 76%, var(--tp-line)); }
.tp-svg-input-line, .tp-svg-compute-line, .tp-svg-bus { fill: none; stroke: color-mix(in srgb, var(--tp-muted) 58%, var(--tp-line)); stroke-width: 1.25; }
.tp-svg-operation { fill: var(--tp-accent); font-size: 11px; font-weight: 750; }
.tp-svg-moving-shard { fill: color-mix(in srgb, var(--owner) 23%, var(--tp-paper)); stroke: var(--owner); }

.tp-svg-gpu, .tp-svg-collective, .tp-svg-weight, .tp-svg-output, .tp-svg-operation, .tp-svg-compute-line { transition: opacity 180ms ease; }
.tp-visualizer[data-step="1"] .tp-svg-operation,
.tp-visualizer[data-step="1"] .tp-svg-compute-line,
.tp-visualizer[data-step="1"] .tp-svg-output,
.tp-visualizer[data-step="1"] .tp-svg-collective,
.tp-visualizer[data-step="2"] .tp-svg-output,
.tp-visualizer[data-step="2"] .tp-svg-collective,
.tp-visualizer[data-step="3"] .tp-svg-collective { opacity: .16; }
.tp-visualizer[data-step="2"] .tp-svg-weight { opacity: .62; }
.tp-visualizer[data-step="3"] .tp-svg-weight,
.tp-visualizer[data-step="3"] .tp-svg-operation,
.tp-visualizer[data-step="3"] .tp-svg-compute-line { opacity: .45; }
.tp-visualizer[data-step="4"] .tp-svg-weight,
.tp-visualizer[data-step="4"] .tp-svg-operation,
.tp-visualizer[data-step="4"] .tp-svg-compute-line { opacity: .32; }
.tp-visualizer[data-step="4"] .tp-svg-moving-shard { animation: tp-shard-arrive 700ms cubic-bezier(.2, .8, .2, 1) both; }
.tp-visualizer[data-step="4"] .tp-svg-moving-shard[data-shard="1"] { animation-delay: 80ms; }
.tp-visualizer[data-step="4"] .tp-svg-moving-shard[data-shard="2"] { animation-delay: 160ms; }
.tp-visualizer[data-step="4"] .tp-svg-moving-shard[data-shard="3"] { animation-delay: 240ms; }
@keyframes tp-shard-arrive { from { opacity: 0; transform: translateY(-34px); } to { opacity: 1; transform: translateY(0); } }

.tp-explanation { padding: 0 18px 16px; }
.tp-explanation dl { display: grid; grid-template-columns: 1fr 1fr; margin: 0; border: 1px solid var(--tp-line); border-radius: 5px; }
.tp-explanation dl > div { min-width: 0; padding: 11px 13px; }
.tp-explanation dl > div:nth-child(even) { border-left: 1px solid var(--tp-line); }
.tp-explanation dl > div:nth-child(n + 3) { border-top: 1px solid var(--tp-line); }
.tp-explanation dt { margin-bottom: 4px; color: var(--tp-accent); font: 750 .57rem/1.3 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .07em; text-transform: uppercase; }
.tp-explanation dd { margin: 0; color: var(--tp-muted); font-size: .7rem; line-height: 1.55; }

.tp-footer { display: grid; grid-template-columns: 110px 1fr 110px; gap: 10px; align-items: center; padding: 11px 18px; border-top: 1px solid var(--tp-line); background: color-mix(in srgb, var(--tp-soft) 58%, var(--tp-paper)); }
.tp-footer button:disabled { cursor: default; opacity: .4; }
.tp-status { margin: 0 !important; color: var(--tp-muted) !important; font: .62rem/1.4 ui-monospace, SFMono-Regular, Consolas, monospace !important; text-align: center; }

@media (max-width: 760px) {
  .tp-header { align-items: flex-start; }
  .tp-steps { overflow-x: auto; grid-template-columns: repeat(4, minmax(112px, 1fr)); }
  .tp-explanation dl { grid-template-columns: 1fr; }
  .tp-explanation dl > div:nth-child(even) { border-left: 0; }
  .tp-explanation dl > div + div { border-top: 1px solid var(--tp-line); }
}

@media (max-width: 480px) {
  .tp-header, .tp-stage { padding-inline: 14px; }
  .tp-heading-row { align-items: flex-start; flex-direction: column; gap: 6px; }
  .tp-explanation { padding-inline: 14px; }
  .tp-footer { grid-template-columns: 1fr 1fr; padding-inline: 14px; }
  .tp-status { grid-column: 1 / -1; grid-row: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .tp-svg-gpu, .tp-svg-collective, .tp-svg-weight, .tp-svg-output, .tp-svg-operation, .tp-svg-compute-line { transition: none; }
  .tp-visualizer[data-step="4"] .tp-svg-moving-shard { animation: none; }
}

@media (prefers-color-scheme: dark) {
  .tp-visualizer {
    --tp-ink: #eef2ea;
    --tp-muted: #9aa79a;
    --tp-accent: #63e68c;
    --tp-accent-soft: rgba(99, 230, 140, .12);
    --tp-line: #232922;
    --tp-paper: #12160f;
    --tp-soft: #0e120d;
    box-shadow: none;
  }
}

[data-theme="dark"] .tp-visualizer {
  --tp-ink: #eef2ea;
  --tp-muted: #9aa79a;
  --tp-accent: #63e68c;
  --tp-accent-soft: rgba(99, 230, 140, .12);
  --tp-line: #232922;
  --tp-paper: #12160f;
  --tp-soft: #0e120d;
  box-shadow: none;
}

@media print {
  .tp-reset, .tp-steps, .tp-footer { display: none !important; }
  .tp-visualizer { break-inside: avoid; box-shadow: none; }
}
