/* agent widget styles: #tb-agent-loop (.tbag-*) and #tb-edit-sites (.tbes-*) */

/* =====================================================================
   #tb-agent-loop
   ===================================================================== */
#tb-agent-loop { min-height: 640px; }
#tb-agent-loop .figure__head { align-items: center; }
.tbag-play { flex: none; gap: 6px; }
.tbag-play svg { width: 13px; height: 13px; }

/* candidates */
.tbag-cands { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-bottom: 18px; }
.tbag-cands__label { font: 600 0.74rem/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-right: 4px; }
.tbag-cand { display: inline-flex; align-items: center; gap: 9px; padding: 7px 12px 7px 7px; border-radius: 999px; border: 1px solid var(--rule-2); background: var(--surface); color: var(--ink-2); font: 550 0.86rem/1.2 var(--sans); cursor: pointer; transition: border-color .2s, background .2s, color .2s, box-shadow .2s; text-align: left; }
.tbag-cand:hover { border-color: var(--agent); color: var(--ink); }
.tbag-cand[aria-pressed="true"] { border-color: var(--agent); background: var(--agent-soft); color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--agent) 14%, transparent); }
.tbag-cand__n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--rule-2); font-size: 0.78rem; color: var(--muted); flex: none; }
.tbag-cand[aria-pressed="true"] .tbag-cand__n { background: var(--agent); border-color: var(--agent); color: var(--surface); }
.tbag-cand__st { width: 18px; height: 18px; border-radius: 50%; flex: none; display: grid; place-items: center; border: 1.5px dashed var(--rule-2); transition: background .3s, border-color .3s; }
.tbag-cand__st svg { width: 12px; height: 12px; }
.tbag-cand[data-st="kept"] .tbag-cand__st { border: 0; background: var(--good); color: var(--surface); }
.tbag-cand[data-st="rej"] .tbag-cand__st { border: 0; background: var(--bad); color: var(--surface); }

/* main grid */
.tbag-grid { display: grid; grid-template-columns: 320px minmax(0, 1fr) 232px; gap: 24px; align-items: start; }
.tbag-colhead { display: flex; align-items: baseline; gap: 10px; font: 600 0.74rem/1.2 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; min-height: 18px; }
.tbag-colhead--agent > span:first-child { color: var(--agent); }
.tbag-ctitle { min-height: 2.6em; font: 600 0.86rem/1.3 var(--sans); letter-spacing: 0; text-transform: none; color: var(--ink); min-width: 0; }

/* model svg */
.tbag-model { min-width: 0; }
.tbag-svg { width: 100%; height: auto; overflow: visible; }
.tbag-t { font: 500 12.5px var(--sans); fill: var(--ink-2); }
.tbag-t--muted { fill: var(--muted); }
.tbag-t--small { font-size: 12px; fill: var(--ink-2); }
.tbag-t--strong { font-weight: 650; font-size: 12.5px; fill: var(--ink); }
.tbag-t--tower { font-weight: 650; font-size: 13px; }
.tbag-t--img { fill: var(--img); } .tbag-t--txt { fill: var(--txt); }
.tbag-t--d { font: italic 700 16px var(--serif); fill: var(--ours-ink); }
.tbag-t--ours { fill: var(--ours-ink); font-weight: 600; font-size: 12px; }
.tbag-t--bad { fill: var(--bad); font-weight: 600; font-size: 12px; }
.tbag-spacebox { fill: var(--surface-2); stroke: var(--rule-2); stroke-width: 1; }
.tbag-pt--img { fill: var(--img); } .tbag-pt--txt { fill: var(--txt); }
.tbag-pt { opacity: .85; }
.tbag-cl, .tbag-cl__in { transition: transform .7s cubic-bezier(.3,.7,.2,1); transform-box: fill-box; transform-origin: center; }
.tbag-svg.fx-collapse .tbag-cl--img { transform: translateX(56px); }
.tbag-svg.fx-collapse .tbag-cl--txt { transform: translateX(-56px); }
.tbag-svg.fx-collapse .tbag-gap { opacity: 0; }
.tbag-svg.fx-shrink .tbag-cl__in { transform: scaleY(.84); }
.tbag-hurt { opacity: 0; transition: opacity .4s; }
.tbag-svg.fx-collapse .tbag-hurt { opacity: 1; }
.tbag-gapline { stroke: var(--muted); stroke-width: 1.4; }
.tbag-ahead { fill: var(--muted); }
.tbag-ahead2 { fill: var(--ours); }
.tbag-gap { transition: opacity .4s; }
.tbag-gap.is-read .tbag-gapline { stroke: var(--agent); stroke-width: 2.2; }
.tbag-gap.is-read text { fill: var(--agent); font-weight: 650; }
.tbag-dirs { opacity: 0; transition: opacity .5s; }
.tbag-dir { stroke: var(--ours); stroke-width: 2.2; stroke-linecap: round; }
.tbag-svg.show-dirs .tbag-dirs { opacity: 1; }
.tbag-svg.fx-collapse .tbag-dirs { opacity: 0; }

.tbag-blk .tbag-frame { stroke-width: 1.2; transition: fill .3s, stroke .3s, stroke-width .3s; }
.tbag-blk--img > .tbag-frame { fill: var(--img-soft); stroke: color-mix(in srgb, var(--img) 45%, var(--rule)); }
.tbag-blk--txt > .tbag-frame { fill: var(--txt-soft); stroke: color-mix(in srgb, var(--txt) 45%, var(--rule)); }
.tbag-blk--proj.tbag-blk--img > .tbag-frame { fill: color-mix(in srgb, var(--img) 22%, var(--surface)); stroke: var(--img); }
.tbag-blk--proj.tbag-blk--txt > .tbag-frame { fill: color-mix(in srgb, var(--txt) 22%, var(--surface)); stroke: var(--txt); }
.tbag-head { stroke: none; transition: fill .3s, opacity .3s; }
.tbag-head--img { fill: color-mix(in srgb, var(--img) 55%, var(--surface)); }
.tbag-head--txt { fill: color-mix(in srgb, var(--txt) 55%, var(--surface)); }
.tbag-spine { stroke-width: 1.4; stroke-dasharray: 2 4; stroke-linecap: round; }
.tbag-spine--img { stroke: color-mix(in srgb, var(--img) 60%, transparent); }
.tbag-spine--txt { stroke: color-mix(in srgb, var(--txt) 60%, transparent); }
.tbag-flow { stroke-width: 1.6; fill: none; }
.tbag-flow--img { stroke: var(--img); } .tbag-flow--txt { stroke: var(--txt); }
.tbag-input rect { fill: var(--surface); stroke: var(--rule-2); }
.tbag-dcell { fill: var(--ours); transition: fill .3s; }
.tbag-dframe { fill: none; stroke: var(--rule-2); stroke-width: 1.2; transition: stroke .3s, stroke-width .3s; }
.tbag-link { fill: none; stroke: var(--rule-2); stroke-width: 1.2; stroke-dasharray: 3 4; transition: stroke .3s; }
.tbag-badge { fill: var(--agent); stroke: var(--surface); stroke-width: 2; opacity: 0; transform-box: fill-box; transform-origin: center; transform: scale(.3); transition: opacity .35s, transform .45s cubic-bezier(.3,1.6,.5,1); }

/* highlight states */
.tbag-part.is-read > .tbag-frame, .tbag-part.is-edit > .tbag-frame { stroke: var(--agent); stroke-width: 2.4; }
.tbag-part.is-read > .tbag-frame { stroke-dasharray: 5 3; animation: tbag-march 1.2s linear infinite; }
.tbag-head.is-read { fill: var(--agent); animation: tbag-pulse 1.1s ease-in-out infinite; }
.tbag-head.is-edit { fill: var(--agent); }
.tbag-head.is-patched { fill: var(--agent); }
.tbag-badge.is-patched, .tbag-part.is-patched > .tbag-badge { opacity: 1; transform: none; }
.tbag-D.is-read .tbag-dframe, .tbag-D.is-edit .tbag-dframe { stroke: var(--agent); stroke-width: 2.4; stroke-dasharray: 5 3; animation: tbag-march 1.2s linear infinite; }
.tbag-links.is-read .tbag-link { stroke: var(--agent); animation: tbag-march 1.2s linear infinite; }
.tbag-svg.fx-collapse .tbag-spacebox { stroke: var(--bad); }
@keyframes tbag-march { to { stroke-dashoffset: -16; } }
@keyframes tbag-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* Astra column */
.tbag-astra { min-width: 0; }
.tbag-rail { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.tbag-step { position: relative; display: flex; align-items: flex-start; gap: 8px; padding: 9px 10px 12px; border-radius: 10px; border: 1px solid var(--rule); background: var(--surface); text-align: left; cursor: pointer; overflow: hidden; transition: border-color .2s, background .2s; --p: 0; min-width: 0; }
.tbag-step:hover { border-color: var(--agent); }
.tbag-step__n { width: 22px; height: 22px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 0.74rem; background: var(--surface-2); border: 1px solid var(--rule-2); color: var(--muted); transition: background .2s, color .2s, border-color .2s; }
.tbag-step__txt { display: flex; flex-direction: column; min-width: 0; }
.tbag-step__name { font: 650 0.86rem/1.25 var(--sans); color: var(--ink); }
.tbag-step__cap { font: 400 0.75rem/1.3 var(--sans); color: var(--muted); }
.tbag-step__bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--agent); transform-origin: 0 50%; transform: scaleX(var(--p)); }
.tbag-step[data-state="active"] { border-color: var(--agent); background: var(--agent-soft); }
.tbag-step[data-state="active"] .tbag-step__n { background: var(--agent); border-color: var(--agent); color: var(--surface); }
.tbag-step[data-state="done"] .tbag-step__n { border-color: var(--agent); color: var(--agent); }
.tbag-step[data-state="done"] .tbag-step__bar { opacity: .35; }

.tbag-say { display: flex; align-items: flex-start; gap: 10px; min-height: 48px; margin-bottom: 12px; }
.tbag-avatar { width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--agent); color: var(--surface); font: 700 0.8rem/1 var(--sans); box-shadow: 0 0 0 4px var(--agent-soft); }
.tbag-say__txt { margin: 0; font-size: 0.9rem; line-height: 1.45; color: var(--ink-2); padding-top: 3px; }
.tbag-say.is-kept .tbag-say__txt { color: var(--ink); }
.tbag-say.is-rej .tbag-say__txt { color: var(--ink); }

.tbag-code { border-radius: var(--radius-sm); overflow: hidden; border: 1px solid #252c38; background: #12161d; }
.tbag-code__bar { display: flex; align-items: center; gap: 10px; padding: 7px 12px; background: #1a1f28; border-bottom: 1px solid #252c38; }
.tbag-code__dots { display: inline-flex; gap: 5px; }
.tbag-code__dots i { width: 8px; height: 8px; border-radius: 50%; background: #3a4352; display: block; }
.tbag-code__file { color: #aab3c2; font-size: 0.76rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbag-code__tag { font: 600 0.7rem/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: #8b95a6; border: 1px solid #343c4b; border-radius: 999px; padding: 3px 7px; }
#tb-agent-loop pre.tbag-code__pre { border: 0; border-radius: 0; padding: 10px 12px 12px 4px; min-height: 168px; font-size: 0.8rem; line-height: 1.7; overflow-x: auto; white-space: pre; }
.tbag-line { display: flex; align-items: center; }
.tbag-tick { width: 18px; flex: none; display: inline-grid; place-items: center; color: #46c990; }
.tbag-tick svg { width: 12px; height: 12px; animation: tbag-pop .3s ease-out; }
.tbag-ln { width: 20px; flex: none; color: #4b5566; text-align: right; margin-right: 12px; font-size: 0.72rem; user-select: none; }
.tbag-cursor { display: inline-block; width: 7px; height: 1.1em; vertical-align: -0.2em; background: #3fc9c2; margin-left: 1px; animation: tbag-blink 1s steps(1) infinite; }
@keyframes tbag-blink { 50% { opacity: 0; } }
@keyframes tbag-pop { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }

.tbag-detail { margin-top: 12px; height: 178px; overflow: hidden; padding: 12px 14px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--surface-2); }
.tbag-dlabel { font: 600 0.72rem/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.tbag-chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; align-items: stretch; }
.tbag-tool { display: flex; align-items: center; padding: 5px 10px; border-radius: 9px; font: 550 0.78rem/1.25 var(--sans); color: var(--faint); background: var(--surface); border: 1px solid var(--rule); transition: color .3s, background .3s, border-color .3s; }
.tbag-tool.is-lit.is-on { color: var(--agent); background: var(--agent-soft); border-color: color-mix(in srgb, var(--agent) 45%, transparent); }
.tbag-checks, .tbag-rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.tbag-checks li, .tbag-rules li { display: flex; align-items: center; gap: 9px; font-size: 0.86rem; color: var(--ink-2); opacity: 0; transform: translateX(-6px); transition: opacity .35s, transform .35s; }
.tbag-checks li.is-on, .tbag-rules li.is-on { opacity: 1; transform: none; }
.tbag-ic { width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; }
.tbag-ic svg { width: 13px; height: 13px; }
.tbag-ic--good { background: var(--good-soft); color: var(--good); }
.tbag-ic--bad { background: var(--bad-soft); color: var(--bad); }
.tbag-ic--muted { background: var(--neutral-soft); color: var(--muted); }
.tbag-ic--agent { background: var(--agent-soft); color: var(--agent); }
.tbag-rules__t { flex: 1; min-width: 0; line-height: 1.35; }
.tbag-rules__v { font: 650 0.78rem/1 var(--sans); white-space: nowrap; }
.tbag-v--good { color: var(--good); } .tbag-v--bad { color: var(--bad); } .tbag-v--muted { color: var(--muted); }
.tbag-verdict { display: inline-flex; align-items: center; gap: 7px; margin-top: 10px; padding: 5px 12px 5px 6px; border-radius: 999px; font: 650 0.86rem/1 var(--sans); opacity: 0; transform: scale(.9); transition: opacity .35s, transform .45s cubic-bezier(.3,1.5,.5,1); }
.tbag-verdict.is-on { opacity: 1; transform: none; }
.tbag-verdict--kept { background: var(--good-soft); color: var(--good); }
.tbag-verdict--kept .tbag-ic { background: var(--good); color: var(--surface); }
.tbag-verdict--rej { background: var(--bad-soft); color: var(--bad); }
.tbag-verdict--rej .tbag-ic { background: var(--bad); color: var(--surface); }
.tbag-endrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: 0.88rem; color: var(--ink-2); }
.tbag-endrow__k { font-weight: 600; color: var(--ink); }
.tbag-arrow { color: var(--muted); }

/* side column */
.tbag-side { min-width: 0; display: grid; gap: 12px; align-content: start; }
.tbag-side > .tbag-colhead { margin-bottom: -2px; }
.tbag-card { border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--surface); padding: 12px 14px; }
.tbag-card__head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tbag-card h4 { margin: 0; font: 650 0.9rem/1.2 var(--sans); flex: 1; }
.tbag-patch { min-height: 228px; }
.tbag-pempty { margin: 0 0 6px; font-size: 0.84rem; color: var(--muted); }
.tbag-plist, .tbag-rlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tbag-plist li, .tbag-rlist li { display: flex; align-items: flex-start; gap: 8px; font-size: 0.84rem; line-height: 1.3; color: var(--ink); }
.tbag-plist li.is-new { animation: tbag-in .5s cubic-bezier(.2,.8,.2,1); }
.tbag-plist__t { display: flex; flex-direction: column; min-width: 0; }
.tbag-plist__t small { font-size: 0.75rem; color: var(--muted); margin-top: 1px; }
.tbag-rlist li { color: var(--muted); }
.tbag-rlist .tbag-plist__t { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--bad) 60%, transparent); }
.tbag-rlist .tbag-plist__t small { text-decoration: none; display: inline-block; }
.tbag-rej { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--rule-2); }
.tbag-rej.is-empty { visibility: hidden; }
.tbag-sublabel { font: 600 0.7rem/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
@keyframes tbag-in { from { opacity: 0; transform: translateY(-6px); background: var(--agent-soft); } to { opacity: 1; transform: none; } }

.tbag-seal { background: var(--surface-2); }
.tbag-lock { width: 22px; height: 22px; color: var(--ink-2); flex: none; }
.tbag-lock svg { width: 100%; height: 100%; overflow: visible; }
.tbag-lock .tbag-keyhole, .tbag-seal__lk .tbag-keyhole { fill: var(--surface-2); }
.tbag-shackle { transition: transform .6s cubic-bezier(.3,1.4,.5,1); transform-origin: 16.5px 11px; }
.tbag-seal.is-open .tbag-lock .tbag-shackle, .tbag-seal.is-open .tbag-seal__lk .tbag-shackle { transform: translateY(-3px) rotate(28deg); }
.tbag-seal__list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.tbag-seal__list li { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; font-weight: 600; color: var(--ink); background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 6px 8px; }
.tbag-seal__lk { width: 15px; height: 15px; color: var(--muted); flex: none; }
.tbag-seal__lk svg { width: 100%; height: 100%; overflow: visible; }
.tbag-seal__n { flex: 1; }
.tbag-seal__chip { font: 600 0.72rem/1 var(--sans); color: var(--muted); padding: 3px 7px; border-radius: 999px; background: var(--neutral-soft); white-space: nowrap; }
.tbag-seal.is-open .tbag-seal__chip { background: var(--agent-soft); color: var(--agent); }
.tbag-seal__note { margin: 0; font-size: 0.8rem; line-height: 1.4; color: var(--muted); }

/* responsive */
.tbag-loop.is-mid .tbag-grid { grid-template-columns: 320px minmax(0, 1fr); }
.tbag-loop.is-mid .tbag-side { grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tbag-loop.is-mid .tbag-side > .tbag-colhead { grid-column: 1 / -1; }
.tbag-loop.is-mid .tbag-detail { height: 192px; }
.tbag-loop.is-narrow .tbag-detail { height: 224px; }
.tbag-loop.is-narrow .tbag-grid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
.tbag-loop.is-narrow .tbag-model { order: 2; }
.tbag-loop.is-narrow .tbag-astra { order: 1; }
.tbag-loop.is-narrow .tbag-side { order: 3; grid-template-columns: minmax(0, 1fr); }
.tbag-loop.is-narrow .tbag-svg { max-width: 360px; margin-inline: auto; }
.tbag-loop.is-narrow .tbag-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tbag-loop.is-narrow .tbag-cands { flex-direction: column; align-items: stretch; }
.tbag-loop.is-narrow .tbag-cand { border-radius: 12px; }
.tbag-loop.is-narrow .tbag-cand__name { flex: 1; }
.tbag-loop.is-narrow .tbag-colhead--agent { flex-direction: column; gap: 4px; }
.tbag-loop.is-narrow .tbag-patch { min-height: 230px; }
.tbag-loop.is-narrow .tbag-say { min-height: 70px; }
.tbag-loop.is-narrow .tbag-ctitle { min-height: 3.9em; }
#tb-agent-loop .tbag-loop.is-narrow pre.tbag-code__pre { white-space: pre-wrap; overflow-x: hidden; }
.tbag-loop.is-narrow .tbag-line > span:last-child { min-width: 0; padding-left: 2ch; text-indent: -2ch; }
#tb-agent-loop .tbag-loop.is-narrow pre.tbag-code__pre { font-size: 0.75rem; padding-right: 8px; }
.tbag-loop.is-narrow .tbag-ln { display: none; }
.tbag-loop.is-narrow .tbag-tick { width: 16px; margin-right: 2px; }
.tbag-loop.is-narrow .tbag-line { align-items: flex-start; }
.tbag-loop.is-narrow .tbag-tick { margin-top: 0.3em; }

@media (prefers-reduced-motion: reduce) {
  .tbag-part.is-read > .tbag-frame, .tbag-head.is-read, .tbag-D.is-read .tbag-dframe, .tbag-links.is-read .tbag-link, .tbag-cursor { animation: none; }
}
.tbag-loop.is-still .tbag-part.is-read > .tbag-frame, .tbag-loop.is-still .tbag-head.is-read, .tbag-loop.is-still .tbag-D.is-read .tbag-dframe, .tbag-loop.is-still .tbag-links.is-read .tbag-link, .tbag-loop.is-still .tbag-cursor, .tbag-loop.is-still .tbag-tick svg, .tbag-loop.is-still .tbag-plist li { animation: none; }
.tbag-loop.is-still * { transition-duration: 0s !important; }
.tbag-mlegend { margin-top: 12px; justify-content: center; gap: 6px 14px; font-size: 0.78rem; }
.tbag-mlegend .tbag-lg { width: 14px; height: 10px; border-radius: 3px; background: var(--agent-soft); border: 1.5px solid var(--agent); }
.tbag-mlegend .tbag-lg--read { border-style: dashed; }
.tbag-mlegend .tbag-lg--patch { width: 10px; height: 10px; border-radius: 50%; background: var(--agent); border: 0; }

/* =====================================================================
   #tb-edit-sites
   ===================================================================== */
.tbes .figure__body { display: grid; gap: 18px; }
.tbes-heads { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tbes-big { display: flex; flex-direction: column; gap: 4px; }
.tbes-big__v { font: 500 1.05rem/1 var(--serif); color: var(--muted); }
.tbes-big__v b { font: 600 2rem/1 var(--serif); color: var(--ink); letter-spacing: -0.02em; margin-right: 2px; }
.tbes-big__l { font-size: 0.84rem; color: var(--muted); line-height: 1.35; }
.tbes-kinds { display: grid; gap: 8px; }
.tbes-strip { display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 3px; }
.tbes-strip__c { height: 12px; border-radius: 3px; display: block; }
.tbes-c--ours { background: var(--ours); color: var(--ours); }
.tbes-c--neutral { background: var(--neutral); color: var(--neutral); }
.tbes-c--faint { background: color-mix(in srgb, var(--neutral) 40%, var(--surface)); color: color-mix(in srgb, var(--neutral) 40%, var(--surface)); }
.tbes-kinds__lg { gap: 4px 14px; }
.tbes-kinds__lg b { color: var(--ink); font-weight: 600; }
.tbes .legend i { background: currentColor; }
.tbes .legend i.tbes-c--ours { color: var(--ours); } .tbes .legend i.tbes-c--neutral { color: var(--neutral); } 

/* matrix */
.tbes-matrix { --cw: 40px; --gw: 62px; display: grid; gap: 0; border-top: 1px solid var(--rule); padding-top: 8px; }
.tbes-row { display: grid; grid-template-columns: minmax(0, 1fr) var(--gw) repeat(7, var(--cw)); align-items: center; }
.tbes-row--head { align-items: end; padding-bottom: 8px; border-bottom: 1px solid var(--rule); }
.tbes-row--head .tbes-lab { font: 600 0.72rem/1.2 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); align-self: end; padding-left: 8px; }
.tbes-gain--head { white-space: nowrap; font: 600 0.72rem/1.2 var(--sans) !important; letter-spacing: .02em; color: var(--muted) !important; text-align: right; align-self: end; padding-right: 8px; }
.tbes-col { display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: default; border-radius: 6px; padding: 2px 0; }
.tbes-col__n { font-size: 0.75rem; color: var(--ink-2); }
.tbes-col__bar { width: 14px; height: 46px; display: flex; align-items: flex-end; position: relative; }
.tbes-col__bar::before { content: ""; width: 100%; height: calc(var(--h) * 100%); border-radius: 3px 3px 1px 1px; background: currentColor; transform-origin: 50% 100%; transform: scaleY(0); transition: transform .6s cubic-bezier(.2,.8,.2,1); transition-delay: calc(var(--i) * 50ms); }
.tbes.is-in .tbes-col__bar::before { transform: none; }
.tbes-col__name { display: flex; flex-direction: column; align-items: center; font-size: 0.75rem; line-height: 1.15; color: var(--ink-2); white-space: nowrap; }
.tbes-col__name b { font-weight: 650; color: currentColor; }
.tbes-col__name span { color: var(--muted); }
.tbes-col.tbes-t--img { color: var(--img); } .tbes-col.tbes-t--txt { color: var(--txt); } .tbes-col.tbes-t--both { color: var(--neutral); }
.tbes-col .tbes-col__n { color: var(--ink-2); }

.tbes-row--data { min-height: 30px; border-radius: 7px; cursor: default; opacity: 0; transform: translateY(6px); transition: opacity .45s, transform .45s, background .15s; transition-delay: calc(var(--i) * 45ms + 150ms), calc(var(--i) * 45ms + 150ms), 0s; }
.tbes.is-in .tbes-row--data { opacity: 1; transform: none; }
.tbes-row--data:nth-child(odd) { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.tbes-row--data.is-hot { background: var(--agent-soft); }
.tbes-row--data:focus-visible { outline: 2px solid var(--agent); outline-offset: -1px; border-radius: 7px; }
.tbes-lab { min-width: 0; padding-left: 8px; display: flex; flex-direction: column; }
.tbes-lab__name { font-size: 0.86rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tbes-lab__gain { display: none; font-size: 0.75rem; color: var(--agent); }
.tbes-gain { text-align: right; padding-right: 8px; font-size: 0.84rem; color: var(--agent); font-weight: 600; }
.tbes-cell { display: grid; place-items: center; height: 30px; }
.tbes-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--rule-2); opacity: .7; transition: transform .2s, opacity .2s; }
.tbes-dot.is-on { width: 15px; height: 15px; opacity: 1; box-shadow: 0 0 0 2px var(--surface); }
.tbes-dot.tbes-t--img { background: var(--img); } .tbes-dot.tbes-t--txt { background: var(--txt); } .tbes-dot.tbes-t--both { background: var(--neutral); }
.tbes-matrix.has-hot .tbes-row--data:not(.is-hot) .tbes-dot.is-on { opacity: .35; }
.tbes-matrix.has-hot .tbes-row--data:not(.is-hot) .tbes-lab__name, .tbes-matrix.has-hot .tbes-row--data:not(.is-hot) .tbes-gain { opacity: .55; }
.tbes-row--data.is-hot .tbes-dot.is-on { transform: scale(1.12); box-shadow: 0 0 0 2px var(--agent-soft); }

/* readout under the matrix */
.tbes-readout { min-height: 124px; padding: 10px 12px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--surface-2); display: grid; gap: 6px; align-content: start; }
.tbes-readout.is-row { border-color: color-mix(in srgb, var(--agent) 45%, var(--rule)); background: var(--agent-soft); }
.tbes-ro__title { font: 650 0.88rem/1.3 var(--sans); color: var(--ink); display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; }
.tbes-ro__sites { font-weight: 450; font-size: 0.8rem; color: var(--muted); }
.tbes-ro__vals { display: flex; flex-wrap: wrap; gap: 4px 20px; align-items: baseline; }
.tbes-ro__it { display: inline-flex; align-items: baseline; gap: 6px; }
.tbes-ro__k { font-size: 0.8rem; color: var(--muted); }
.tbes-ro__v { font-size: 0.98rem; font-weight: 650; color: var(--agent); }
.tbes-ro__sub { font-size: 0.75rem; color: var(--muted); }
.tbes-ro__hint { font-size: 0.8rem; color: var(--muted); }

/* results + controls */
.tbes-bottom { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.tbes-sub { font: 600 0.72rem/1.3 var(--sans); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.tbes-res__items { display: grid; gap: 10px; }
.tbes-stat { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--agent-soft); }
.tbes-stat__v { font: 600 1.45rem/1.1 var(--mono); color: var(--agent); letter-spacing: -0.03em; }
.tbes-stat__l { font-size: 0.8rem; color: var(--ink-2); line-height: 1.35; }
.tbes-ctl__lg { font-size: 0.75rem; gap: 4px 12px; margin-bottom: 8px; }
.tbes-ctl__groups { display: grid; gap: 10px; }
.tbes-ctl__name { font-size: 0.8rem; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.tbes-ctl__row { margin-bottom: 4px; }
.tbes-ctl__track { display: flex; align-items: center; justify-content: flex-end; gap: 6px; height: 16px; border-right: 1.5px solid var(--ink-2); padding-right: 0; }
.tbes-ctl__val { font-size: 0.75rem; color: var(--ink-2); }
.tbes-ctl__bar { height: 12px; width: calc(var(--w) * (100% - 44px)); border-radius: 3px 0 0 3px; transform-origin: 100% 50%; transform: scaleX(0); transition: transform .6s cubic-bezier(.2,.8,.2,1); transition-delay: calc(var(--i) * 80ms + 300ms); }
.tbes.is-in .tbes-ctl__bar { transform: none; }
.tbes-search { margin: 0; font-size: 0.86rem; line-height: 1.5; color: var(--ink-2); padding: 10px 14px; border-left: 3px solid var(--rule-2); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* narrow */
.tbes.is-narrow .tbes-matrix { --cw: 29px; --gw: 0px; }
.tbes.is-narrow .tbes-gain { visibility: hidden; overflow: hidden; padding: 0; width: 0; }
.tbes.is-narrow .tbes-lab__gain { display: block; }
.tbes.is-narrow .tbes-lab__name { white-space: normal; font-size: 0.8rem; line-height: 1.25; }
.tbes.is-narrow .tbes-row--data { min-height: 40px; padding: 3px 0; }
.tbes.is-narrow .tbes-col__name { writing-mode: vertical-rl; transform: rotate(180deg); flex-direction: row; gap: 3px; align-items: center; }
.tbes.is-narrow .tbes-col__name b, .tbes.is-narrow .tbes-col__name span { display: inline; }
.tbes.is-narrow .tbes-readout { min-height: 170px; }
.tbes.is-narrow .tbes-bottom { grid-template-columns: minmax(0, 1fr); }
.tbes.is-narrow .tbes-heads { gap: 10px; }
.tbes.is-narrow .tbes-big__v b { font-size: 1.7rem; }
.tbes-src { display: inline-block; margin-left: 7px; padding: 1px 6px; border-radius: 999px; background: var(--ours-soft); color: var(--ours-ink); font: 650 0.7rem/1.4 var(--sans); vertical-align: 1px; }
.tbes-ro__hint .tbes-src { margin: 0 4px 0 0; }
.tbes-ro__hint { line-height: 1.45; }
