.bp-chain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 6px;
  margin: 18px 0;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.3;
}
.bp-link {
  padding: 7px 11px;
  border-radius: 9px;
  background: var(--part-tint);
  color: var(--part-ink);
  font-weight: 600;
}
.bp-link.end { background: #ffedd5; color: #9a3412; }
.bp-rate {
  font: 700 13px/1.2 var(--font-mono);
  color: var(--ink-soft);
  white-space: nowrap;
}
.bp-rate::after { content: " →"; color: var(--part); }

.bp-stages { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 8px; }
.bp-stages .stage-pill { min-height: 40px; padding: 5px 13px; font-size: 13px; }
.bp-stages .stage-pill.active { background: var(--part); color: #fff; }
.bp-stages .stage-pill.done { background: var(--part-tint); color: var(--part-ink); }
.bp-stages .stage-pill[data-stage="blame"].active { background: var(--warn); }
.bp-stages .gloss { border-bottom: 0; cursor: inherit; }

.bp-compact { gap: 6px; margin: 10px 0; }
.bp-compact .toggle { min-height: 40px; padding: 5px 12px; font-size: 13.5px; }
#bp-examples, #wg-examples { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
#bp-examples .toggle, #wg-examples .toggle { justify-content: center; text-align: center; padding: 6px 4px; border-radius: 14px; line-height: 1.3; }
#wg-keys { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
#wg-keys .toggle { justify-content: center; min-height: 40px; padding: 4px 2px; font-size: 12px; white-space: nowrap; }
.bp-compact .gloss { border-bottom: 0; cursor: inherit; }
.bp-row-label { font-size: 13.5px; color: var(--muted); align-self: center; margin-right: 2px; }

.bp-diagram {
  overflow-x: auto;
  margin: 8px 0 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.bp-diagram svg { display: block; min-width: 620px; margin: 0 auto; }
.bp-diagram text { font-family: var(--font-mono); }

.bp-wire { stroke-linecap: round; opacity: 0.62; }
.bp-wire.pos { stroke: #2563eb; }
.bp-wire.neg { stroke: #dc2626; }
.bp-wire.dim { opacity: 0.2; }
.bp-wire.hot { opacity: 1; }
.bp-halo { stroke-linecap: round; opacity: 0.2; }
.bp-halo.fwd { stroke: #0d9488; }
.bp-halo.back { stroke: #ea580c; }
.bp-halo.picked { stroke: #f59e0b; opacity: 0.35; }

.bp-flow {
  stroke-linecap: round;
  stroke-width: 5;
  stroke-dasharray: 0.1 13;
  animation: bp-march 0.55s linear infinite;
}
.bp-flow.under { stroke: #fff; stroke-width: 9; }
.bp-flow.fwd { stroke: #0f766e; }
.bp-flow.back { stroke: #ea580c; }
@keyframes bp-march { to { stroke-dashoffset: -13.1; } }

.bp-node .body { fill: #fff; stroke: #1d2238; stroke-width: 2; }
.bp-node .ring { fill: none; }
.bp-node.hot.fwd .ring { fill: rgba(13, 148, 136, 0.18); }
.bp-node.hot.back .ring { fill: rgba(234, 88, 12, 0.18); }
.bp-node.hot.fwd .body { stroke: #0d9488; stroke-width: 3.5; }
.bp-node.hot.back .body { stroke: #ea580c; stroke-width: 3.5; }
.bp-diagram text.bp-name { font: 700 11.5px var(--font-body); fill: #3b4157; }
.bp-value { font-size: 13.5px; font-weight: 700; fill: #1d2238; }
.bp-value.big { font-size: 17px; }
.bp-value.unknown { fill: #9aa0b2; }
.bp-diagram text.bp-caption { font: 500 12px var(--font-body); fill: #5c6274; }

.bp-pill rect { fill: #fff; stroke: #cfc5ae; stroke-width: 1; }
.bp-pill text { font-size: 12.5px; font-weight: 700; }
.bp-pill.pos text { fill: #1d4ed8; }
.bp-pill.neg text { fill: #b91c1c; }
.bp-pill.hot.fwd rect { stroke: #0d9488; stroke-width: 2; }
.bp-pill.hot.back rect { stroke: #ea580c; stroke-width: 2; }
.bp-pill.changed rect { fill: #fef3c7; stroke: #f59e0b; stroke-width: 2; animation: bp-flash 1.1s ease-out; }
.bp-pill.pickable { cursor: pointer; }
.bp-pill.pickable:hover rect { stroke: #f59e0b; stroke-width: 2; }
.bp-pill.picked rect { fill: #fef3c7; stroke: #d97706; stroke-width: 2.5; }
@keyframes bp-flash {
  0% { fill: #fbbf24; }
  100% { fill: #fef3c7; }
}

.bp-blame rect { fill: #fff7ed; stroke: #ea580c; stroke-width: 1; }
.bp-blame text { font-size: 11px; font-weight: 700; fill: #c2410c; }
.bp-blame.at rect { fill: #ffedd5; }
.bp-blame.fresh rect { stroke-width: 2.5; animation: bp-pop 0.9s ease-out; }
@keyframes bp-pop {
  0% { fill: #fb923c; }
  100% { fill: #fff7ed; }
}

.bp-lossbox line { stroke: #9aa0b2; stroke-width: 2; }
.bp-lossbox rect { fill: #fff; stroke: #9aa0b2; stroke-width: 1.5; }
.bp-lossbox text { font-size: 11.5px; fill: #3b4157; }
.bp-lossbox text.unknown { fill: #9aa0b2; }
.bp-lossbox text.strong { font-weight: 700; fill: #1d2238; }
.bp-lossbox.hot.fwd rect { stroke: #0d9488; stroke-width: 3; }
.bp-lossbox.hot.back rect { stroke: #ea580c; stroke-width: 3; }

.bp-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); margin: 0 0 4px; }
.bp-legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.bp-legend .tag { display: inline-block; padding: 0 6px; border-radius: 6px; border: 1px solid #ea580c; background: #fff7ed; color: #c2410c; font: 700 11px/1.6 var(--font-mono); margin-right: 5px; }

.bp-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: 10px 0 2px; }
.bp-controls .bp-spacer { flex: 1; }
.bp-controls button:last-child { margin-right: 0; }

.bp-panel.stepping { min-height: 250px; }
.interactive .bp-panel p { margin: 6px 0 8px; }
.bp-count { font: 700 12px/1.4 var(--font-body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.bp-panel h4 { margin: 2px 0 6px; }
.interactive p.bp-note { color: var(--ink-soft); margin-bottom: 0; }
.bp-math {
  margin: 8px 0;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.65;
}
.bp-math b { color: var(--fg); }
.bp-o, .bp-math .bp-o { color: var(--warn); }
.chapter-body table.bp-table { margin: 8px 0; font-size: 13px; line-height: 1.35; border-radius: 10px; }
.bp-table th, .bp-table td { padding: 3px 12px; font-family: var(--font-mono); text-align: right; }
.bp-table th:first-child, .bp-table td:first-child { text-align: left; }
.bp-table tr:first-child > :first-child { border-top-left-radius: 9px; }
.bp-table tr:first-child > :last-child { border-top-right-radius: 9px; }
.bp-table tr:last-child > :first-child { border-bottom-left-radius: 9px; }
.bp-table tr:last-child > :last-child { border-bottom-right-radius: 9px; }
.bp-table code { background: none; padding: 0; font-size: inherit; }

.bp-score { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px; align-items: start; margin-top: 12px; }
.bp-score .math-panel { margin-top: 0; }
.bp-score .bp-table { margin: 0; }
.bp-score .bp-table th, .bp-score .bp-table td { text-align: center; }
.bp-score canvas { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; }

@media (max-width: 640px) {
  #bp-examples, #wg-examples { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #wg-keys { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bp-math { padding: 8px 9px; font-size: 11.5px; white-space: pre-wrap; }
  .bp-score { grid-template-columns: 1fr; }
  .bp-panel.stepping { min-height: 0; }
}
