/* Block Bot (#/blocks): the locker, the rule-card editor and the cockpit. Built on styles.css's tokens.
   Every rule here is scoped to a .bb- class: the sheet loads on every page. */

.bb-page, .bb-cockpit {
  --bb-cond: #0b6fa4;
  --bb-cond-bg: #e1eef6;
  --bb-act: #9a4a08;
  --bb-act-bg: #fbeadb;
  --bb-build: #5f4596;
  --bb-build-bg: #ece6f6;
  --bb-switch-bg: #f2c14e;
  --bb-code-bg: #15222a;
  --bb-code-ink: #e2e9e8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) :is(.bb-page, .bb-cockpit) {
    --bb-cond: #7cc7f0;
    --bb-cond-bg: #15303f;
    --bb-act: #f3a865;
    --bb-act-bg: #3a2614;
    --bb-build: #c7b2f0;
    --bb-build-bg: #2b2340;
    --bb-code-bg: #0c1114;
  }
}
:root[data-theme="dark"] :is(.bb-page, .bb-cockpit) {
  --bb-cond: #7cc7f0;
  --bb-cond-bg: #15303f;
  --bb-act: #f3a865;
  --bb-act-bg: #3a2614;
  --bb-build: #c7b2f0;
  --bb-build-bg: #2b2340;
  --bb-code-bg: #0c1114;
}

.bb-page { display: grid; gap: 20px; }
.bb-hero .eyebrow { margin: 0 0 6px; color: var(--signal); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.8rem; }
.bb-hero .lede { margin-top: 12px; }
.bb-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px; }
.bb-card h2 { margin-bottom: 6px; }
.bb-error { color: var(--danger); margin: 0; min-height: 0; }
.bb-error:empty { display: none; }
.bb-inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.bb-inline-form input { min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--bg); flex: 1 1 200px; min-width: 0; }
.bb-inline-form label { flex-basis: 100%; }
.bb-inline-form label.bb-file { flex-basis: auto; }
.bb-spacer { flex: 1; }

/* ---------- locker ---------- */

/* One column, three steps: name your badger, pick a strategy, pick who to play. */
.bb-locker { max-width: 880px; width: 100%; margin: 0 auto; gap: 28px; }
.bb-stage { display: grid; gap: 12px; min-width: 0; }
.bb-stage > p { margin: 0; }
.bb-stage-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.bb-stage-head h2 { margin: 0; font-size: 1.6rem; }
.bb-stage-num { width: 36px; height: 36px; flex: none; display: flex; align-items: center; justify-content: center; border-radius: 999px; background: var(--ink); color: var(--bg); font-weight: 700; font-size: 1.1rem; }
.bb-stage-num.hot { background: var(--signal-bg); color: var(--on-signal); }
.bb-stage-num.done { background: var(--ok); color: var(--bg); }
.bb-stage.locked { opacity: 0.5; }
.bb-lock { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 0.875rem; font-weight: 600; color: var(--muted); }
.bb-signup { border: 3px solid var(--signal-bg); padding: 20px; }
.bb-signup-form { max-width: 560px; margin-top: 0; }
.bb-keep { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; justify-self: start; cursor: pointer; }
.bb-keep input { width: 20px; height: 20px; margin: 0; }
.bb-switching { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--bg); }
.bb-switching p { margin: 0; }
.bb-switching .bb-actions { border-top: 0; padding-top: 0; }
.bb-signup-form input { min-height: 52px; font-size: 1.15rem; border: 2px solid var(--ink); }
.bb-signup-form .btn { min-height: 52px; font-size: 1.1rem; }
.bb-stage-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.bb-stage-foot p { margin: 0; flex: 1 1 280px; }
.bb-file { position: relative; overflow: hidden; }
.bb-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.bb-file:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.bb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.bb-strategy { display: flex; flex-direction: column; gap: 10px; }
.bb-strategy.picked { border: 3px solid var(--signal-bg); padding: 14px; }
.bb-pick { display: flex; flex-direction: column; gap: 4px; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; min-height: 44px; }
.bb-sname { font-size: 1.35rem; font-weight: 700; font-stretch: 87.5%; }
.bb-bringing { font-size: 0.8rem; font-weight: 700; color: var(--signal); }
.bb-actions { display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--line); padding-top: 10px; }
.bb-new { border-style: dashed; display: flex; flex-direction: column; gap: 6px; background: transparent; }
.bb-new h3 { font-size: 1.2rem; }
.bb-legend { font-weight: 700; margin: 0 0 8px; padding: 0; }
.bb-modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.bb-mode, .bb-bot { display: flex; gap: 10px; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 10px 12px; cursor: pointer; min-height: 56px; }
.bb-mode { flex-direction: column; gap: 2px; }
.bb-mode[aria-pressed="true"] { border: 3px solid var(--signal-bg); padding: 8px 10px; }
.bb-bots { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 6px; }
.bb-bot { align-items: center; }
.bb-bot > span:last-child { display: flex; flex-direction: column; }
.bb-bot[aria-pressed="true"] { border: 2px solid var(--ink); padding: 9px 11px; }
.bb-mark { width: 24px; height: 24px; flex: none; display: flex; align-items: center; justify-content: center; border: 2px solid var(--ink); border-radius: 999px; font-weight: 700; }
.bb-bot.multi .bb-mark { border-radius: var(--radius-s); }
.bb-bot[aria-pressed="true"] .bb-mark { background: var(--ink); color: var(--bg); }
/* Free-for-all: a picked house bot's card carries how many copies come, at its right. */
.bb-bots-help { margin: -4px 0 8px; }
.bb-bot-many { position: relative; display: grid; }
.bb-bot-many > .bb-bot { padding-right: 132px; }
.bb-count { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 4px; }
.bb-count .small-btn { min-width: 36px; min-height: 36px; padding: 0; font-size: 1.15rem; line-height: 1; }
.bb-count output { min-width: 1.6em; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.bb-seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.bb-seg button { min-height: 44px; padding: 0 16px; background: var(--bg); border: 0; cursor: pointer; font-weight: 600; }
.bb-seg button + button { border-left: 1px solid var(--line); }
.bb-seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.bb-bring { font-size: 1.1rem; }
.bb-start { min-height: 56px; font-size: 1.15rem; }
.bb-live-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bb-live-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* ---------- top bar of the editor and cockpit ---------- */

.bb-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.bb-back { font-weight: 600; }
.bb-title-in { font: inherit; font-size: clamp(1.4rem, 3vw, 2rem); font-weight: 700; font-stretch: 87.5%; border: 1px solid transparent; border-radius: var(--radius-s); background: transparent; padding: 2px 8px; min-width: 0; flex: 0 1 22ch; }
.bb-title-in:hover, .bb-title-in:focus { border-color: var(--line); background: var(--panel); }
.bb-saved { display: inline-flex; align-items: center; gap: 6px; }
.bb-saved svg { color: var(--ok); }
.bb-bar .btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.bb-banner { margin: 0; padding: 10px 14px; border: 1px solid var(--signal-bg); background: color-mix(in srgb, var(--signal-bg) 18%, var(--panel)); border-radius: var(--radius-m); }

/* ---------- the edit page: Download and Play it by the strategy's name ---------- */

.bb-edit-page { container-type: inline-size; }
.bb-edit-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bb-edit-actions .btn { height: 40px; min-height: 40px; box-sizing: border-box; display: inline-flex; align-items: center; gap: 8px; padding-block: 0; }
.bb-edit-actions svg { flex: none; }
/* Narrow: the top bar sticks, so Download and Play it stay in reach. */
@container (max-width: 879.98px) {
  .bb-edit-page > .bb-bar { position: sticky; top: 0; z-index: 7; background: var(--bg); padding: 8px 0; border-bottom: 1px solid var(--line); }
}

/* Download ▾: the strategy file, or the strategy as a bot in code. */
.bb-menu { position: relative; }
.bb-menu > summary { list-style: none; cursor: pointer; }
.bb-menu > summary::-webkit-details-marker { display: none; }
.bb-menu-caret { display: inline-flex; transition: transform 0.15s; }
.bb-menu[open] .bb-menu-caret { transform: rotate(180deg); }
.bb-menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 260px; display: grid; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}
.bb-menu-list button { display: grid; gap: 1px; text-align: left; padding: 9px 12px; border: 0; border-radius: var(--radius-s); background: none; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.bb-menu-list button:hover, .bb-menu-list button:focus-visible { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.bb-menu-list .muted { font-size: 0.8rem; font-weight: 400; }
@media (prefers-reduced-motion: reduce) { .bb-menu-caret { transition: none; } }

/* ---------- the rules' surface, and the toolbar docked along its top edge (both styles) ---------- */

.bb-surface {
  border: 1px solid var(--line); border-radius: var(--radius-m); padding: 10px 14px 16px;
  background-color: var(--bg); background-image: radial-gradient(color-mix(in srgb, var(--ink) 16%, transparent) 1px, transparent 1px); background-size: 18px 18px;
}
/* Undo and redo on the left, how the rules look on the right: a bar along the surface's top edge, pinned
   there while the rules scroll under it (wide edit page). */
.bb-float-row {
  position: sticky; top: 0; z-index: 6; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px;
  margin: -10px -14px 10px; padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--line);
  border-radius: calc(var(--radius-m) - 1px) calc(var(--radius-m) - 1px) 0 0;
}
.bb-pill { display: inline-flex; align-items: center; gap: 2px; }
.bb-pill + .bb-pill { padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }   /* Cards | Blocks | Python: one segmented control */
.bb-pill-opt {
  height: 38px; min-width: 40px; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 12px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.bb-pill-opt.icon { padding: 0; }
.bb-pill-opt:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.bb-pill-opt[aria-pressed="true"], .bb-pill-opt[aria-pressed="true"]:hover { background: var(--ink); color: var(--bg); }
.bb-pill-opt:disabled { opacity: 0.35; cursor: default; }
.bb-pill-opt:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.bb-pill-sep { width: 1px; height: 24px; margin: 0 4px; background: var(--line); }
/* The cockpit, and a narrow edit page: the palette or the top bar is pinned there already, so the bar
   scrolls with the rules (and anything pinned is drawn over it). */
.compact .bb-float-row { position: static; z-index: auto; }
@container (max-width: 879.98px) { .bb-float-row { position: static; z-index: auto; } }

/* ---------- rule cards ---------- */

.bb-editor { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.bb-rules { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; align-items: stretch; }   /* not a grid: the floating controls' sticky would be stuck in their row */
.bb-empty { margin: 0 0 6px; padding: 16px; border: 1px dashed var(--line); border-radius: var(--radius-m); color: var(--muted); }
.bb-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; }
.bb-rule { flex: 1 1 480px; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 8px 10px; display: grid; gap: 4px; }
.bb-rule.off { opacity: 0.6; }
.bb-rule[data-state="firing"] { border-color: var(--ok); box-shadow: inset 4px 0 0 var(--ok); }
.bb-rule[data-state="waiting"] { box-shadow: inset 4px 0 0 var(--signal-bg); }
.bb-rule-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bb-num { width: 30px; height: 30px; flex: none; display: flex; align-items: center; justify-content: center; border-radius: 999px; background: var(--ink); color: var(--bg); font-weight: 700; }
.bb-sentence { flex: 1 1 300px; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 1.05rem; }
.bb-word { font-weight: 700; }
.bb-word:empty { display: none; }
.bb-chip, .bb-group { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; border-radius: 10px; padding: 4px 6px; border: 2px solid; max-width: 100%; }
.bb-chip.cond { border-color: var(--bb-cond); background: var(--bb-cond-bg); }
.bb-chip.act { border-color: var(--bb-act); background: var(--bb-act-bg); }
.bb-chip.act.build { border-color: var(--bb-build); background: var(--bb-build-bg); }
.bb-chip.switch { border-color: var(--signal); background: var(--bb-switch-bg); color: var(--on-signal); border-radius: var(--radius-m); }
.bb-group { border-style: dashed; border-color: var(--line); border-radius: var(--radius-m); }
/* A step (action) in a rule: a handle to drag it when there are two or more, and a + between steps. */
.bb-step { display: inline-flex; align-items: center; gap: 1px; max-width: 100%; border-radius: 12px; }
/* Dragging: the original fades; a yellow line marks where it will land. */
.bb-rule, .bb-step { position: relative; }
.bb-rule.dragging, .bb-step.dragging { opacity: 0.35; }
.bb-rule.drop-before::before, .bb-rule.drop-after::after,
.bb-step.drop-before::before, .bb-step.drop-after::after {
  content: ""; position: absolute; z-index: 3; pointer-events: none;
  background: var(--signal-bg); border-radius: 3px; box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 55%, transparent);
}
.bb-rule.drop-before::before { left: -4px; right: -4px; top: -13px; height: 5px; }
.bb-rule.drop-after::after { left: -4px; right: -4px; bottom: -13px; height: 5px; }
.bb-step.drop-before::before { top: 0; bottom: 0; left: -6px; width: 5px; }
.bb-step.drop-after::after { top: 0; bottom: 0; right: -6px; width: 5px; }
.bb-step-grip:active { cursor: grabbing; }
.bb-step-grip { width: 18px; min-height: 34px; flex: none; display: flex; align-items: center; justify-content: center; padding: 0; background: none; border: 0; border-radius: 4px; color: var(--muted); cursor: grab; }
.bb-step-grip:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 8%, transparent); }
.bb-step-insert { width: 24px; height: 24px; flex: none; padding: 0; border: 1.5px dashed var(--line); border-radius: 999px; background: none; color: var(--muted); font-weight: 700; line-height: 1; cursor: pointer; opacity: 0.45; }
.bb-rule:hover .bb-step-insert, .bb-step-insert:focus-visible { opacity: 1; }
.bb-step-insert:hover { border-color: var(--ink); color: var(--ink); }
@media (hover: none) { .bb-step-insert { opacity: 0.8; width: 30px; height: 30px; } }
.bb-chip.editing, .bb-group.editing { outline: 3px solid var(--signal-bg); outline-offset: 2px; }
.bb-kind { background: none; border: 0; padding: 4px 6px; min-height: 36px; font-weight: 600; cursor: pointer; border-radius: 6px; color: inherit; text-align: left; }
.bb-kind:hover { background: color-mix(in srgb, var(--ink) 10%, transparent); }
.bb-select { width: auto; field-sizing: content; min-width: 3.5em; min-height: 36px; padding: 4px 6px; border-radius: 6px; background: var(--bg); font-weight: 600; border: 1px solid var(--line); max-width: 100%; }
.bb-chip.switch .bb-select { background: #fff; color: var(--on-signal); }
.bb-num-in { width: 5.5em; field-sizing: content; min-width: 3.5em; min-height: 36px; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); font-weight: 700; }
.bb-plus { min-height: 36px; padding: 0 10px; border: 1px dashed var(--line); border-radius: 999px; background: none; cursor: pointer; color: var(--muted); font-weight: 600; }
.bb-plus:hover { border-color: var(--ink); color: var(--ink); }
.bb-tools { display: flex; gap: 4px; align-items: center; margin-left: auto; }
/* Move Up / Move Down, to the left of each rule card. */
.bb-rule-line { flex: 1 1 560px; min-width: 0; display: flex; gap: 8px; align-items: center; }
.bb-rule-line > .bb-rule { flex: 1 1 0; }
/* On / off: a switch, green and to the right when the rule plays. */
.bb-switch-toggle { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 4px; background: none; border: 0; border-radius: var(--radius-m); color: var(--muted); font: inherit; font-weight: 700; cursor: pointer; }
.bb-switch-track { position: relative; width: 42px; height: 24px; flex: none; border-radius: 999px; background: var(--line); transition: background 0.15s; }
.bb-switch-knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 999px; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.35); transition: left 0.15s; }
.bb-switch-toggle[aria-checked="true"] { color: var(--ok); }
.bb-switch-toggle[aria-checked="true"] .bb-switch-track { background: var(--ok); }
.bb-switch-toggle[aria-checked="true"] .bb-switch-knob { left: 21px; }
.bb-switch-text { min-width: 1.8em; text-align: left; }
.bb-switch-toggle:disabled { opacity: 0.4; cursor: default; }
.bb-icon { min-width: 40px; min-height: 40px; background: none; border: 1px solid transparent; border-radius: var(--radius-s); cursor: pointer; font-size: 1.1rem; color: var(--muted); }
.bb-icon:hover:not(:disabled) { border-color: var(--line); color: var(--ink); }
.bb-icon:disabled { opacity: 0.3; cursor: default; }
.bb-icon.small { min-width: 30px; min-height: 30px; font-size: 0.95rem; padding: 0 4px; }
.bb-live { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.9rem; padding-left: 74px; }
.bb-live[hidden] { display: none; }
.bb-note { margin: 0; padding-left: 74px; font-size: 0.875rem; }
.bb-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--line); flex: none; }
.bb-rule[data-state="firing"] .bb-dot { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 25%, transparent); }
.bb-rule[data-state="waiting"] .bb-dot { background: var(--signal-bg); }
.bb-rule[data-state="firing"] .bb-why { color: var(--ok); font-weight: 600; }
.bb-rule[data-state="waiting"] .bb-why { color: var(--signal); }
.bb-why { color: var(--muted); }
/* How close a waiting rule is (fighters 5 of 8, say). */
.bb-progress { display: block; flex: 0 0 120px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bb-progress span { display: block; height: 100%; background: var(--signal-bg); }
.bb-py { flex: 1 1 340px; min-width: 0; margin: 0; padding: 10px 14px; background: var(--bb-code-bg); color: var(--bb-code-ink); border-radius: var(--radius-m); line-height: 1.55; overflow-x: auto; white-space: pre; display: flex; align-items: center; }
/* The rule being edited (cockpit): a yellow border and its Save / Cancel; the other rules wait. */
.bb-rule.editing-rule { border: 2px solid var(--signal-bg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal-bg) 25%, transparent); }
.bb-save-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 6px; margin-top: 2px; border-top: 1px dashed var(--line); }
.bb-save-row .bb-error { flex-basis: 100%; }
.bb-editor.locked .bb-rule:not(.editing-rule) { opacity: 0.45; pointer-events: none; }
.bb-editor.locked .bb-py { opacity: 0.45; }
.bb-editor.locked .bb-insert, .bb-editor.locked .bb-add-rule { visibility: hidden; pointer-events: none; }

/* Between two rules: a faint line with "+ rule" that lights up on hover or focus. */
.bb-insert { position: relative; display: block; width: 100%; height: 22px; margin: 0; padding: 0; border: 0; background: none; cursor: pointer; color: var(--muted); opacity: 0.6; }
.bb-insert::before { content: ""; position: absolute; left: 8px; right: 8px; top: 50%; border-top: 2px dashed var(--line); }
.bb-insert span { position: relative; display: inline-block; padding: 0 8px; font-size: 0.75rem; font-weight: 700; line-height: 16px; border-radius: 999px; background: var(--bg); }
.bb-insert:hover, .bb-insert:focus-visible { opacity: 1; color: var(--ink); }
.bb-insert:hover::before, .bb-insert:focus-visible::before { border-color: var(--signal-bg); }
.bb-insert:focus-visible { outline: none; }
.bb-insert:focus-visible span { outline: 2px solid var(--focus); }
@media (hover: none) { .bb-insert { opacity: 0.8; height: 28px; } }
.bb-add-rule { margin-top: 10px; min-height: 52px; background: none; border: 2px dashed var(--line); border-radius: var(--radius-m); font-weight: 600; color: var(--muted); cursor: pointer; }
.bb-add-rule:hover { border-color: var(--ink); color: var(--ink); }

.bb-picker { flex: 1 1 300px; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px; display: grid; gap: 12px; position: sticky; top: 12px; }
.bb-picker h2 { font-size: 1.25rem; margin: 0; }
.bb-picker h3 { font-size: 0.85rem; color: var(--muted); margin: 0 0 6px; }
.bb-picker p { margin: 0; }
.bb-picker:has(.bb-picker-head) { border: 2px solid var(--signal-bg); }
.bb-picker-head { display: flex; justify-content: space-between; align-items: center; }
.bb-opt-group > div { display: flex; flex-wrap: wrap; gap: 6px; }
.bb-opt { min-height: 40px; padding: 0 12px; border-radius: 999px; border: 2px solid var(--bb-cond); background: var(--bg); color: inherit; font-weight: 600; cursor: pointer; }
.bb-opt:hover, .bb-opt:focus-visible { background: var(--bb-cond-bg); }
.bb-new-switch { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.bb-new-switch input { min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); min-width: 0; flex: 1 1 160px; }
.bb-switch-list { margin: 0; padding-left: 18px; }

/* ---------- cockpit: rules on the left third, the match on the right two thirds ---------- */

main.bb-full { padding: 8px clamp(8px, 1.5vw, 16px); }
.bb-cockpit {
  --bb-top: 80px;
  display: grid;
  /* The rules (a third, or the width the bar was dragged to), the bar, the match. */
  grid-template-columns: var(--bb-left-w, minmax(0, 1fr)) 16px minmax(0, 2fr);
  gap: 12px 0;
  height: calc(100dvh - var(--bb-top) - 8px);
  min-height: 480px;
}
.bb-left { grid-column: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.bb-right { grid-column: 3; }

/* The bar between them (split.js): drag to resize; its button folds the rules away. */
.bb-split { grid-column: 2; position: relative; display: flex; justify-content: center; min-height: 0; }
.bb-split-bar { width: 100%; cursor: col-resize; touch-action: none; display: flex; justify-content: center; border-radius: 4px; }
.bb-split-bar::before { content: ""; width: 3px; margin: 44px 0 8px; border-radius: 2px; background: var(--line); transition: background 0.15s; }
.bb-split-bar:hover::before, .bb-split-bar:focus-visible::before, .bb-cockpit.resizing .bb-split-bar::before { background: var(--signal-bg); width: 4px; }
.bb-split-bar:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.bb-split-fold {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%); z-index: 2;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--ink); cursor: pointer;
}
.bb-split-fold:hover { border-color: var(--ink); }
.bb-split-fold svg { transform: rotate(90deg); transition: transform 0.15s; }   /* points left: fold away */
.bb-cockpit.folded { grid-template-columns: 0 32px minmax(0, 1fr); }
.bb-cockpit.folded .bb-left { display: none; }
.bb-cockpit.folded .bb-split-fold svg { transform: rotate(-90deg); }
.bb-cockpit.resizing { cursor: col-resize; user-select: none; -webkit-user-select: none; }
@media (prefers-reduced-motion: reduce) { .bb-split-fold svg, .bb-split-bar::before { transition: none; } }
.bb-left-head { display: grid; gap: 4px; }
.bb-left-head .bb-bar { gap: 8px; }
.bb-running { margin: 0; }
.bb-waiting { display: grid; gap: 6px; padding: 10px 12px; border: 2px solid var(--signal-bg); border-radius: var(--radius-m); background: color-mix(in srgb, var(--signal-bg) 14%, var(--panel)); }
.bb-waiting[hidden] { display: none; }
.bb-waiting p { margin: 0; }
.bb-waiting-name { display: inline-block; margin: 2px 4px 0 0; padding: 0 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 0.85rem; }
.bb-waiting .btn { justify-self: start; }
.bb-real-seg { justify-self: start; }
.bb-live-pill { background: var(--signal-bg); color: var(--on-signal); font-weight: 700; font-size: 0.75rem; letter-spacing: 0.08em; padding: 3px 8px; border-radius: var(--radius-s); }
.bb-live-pill[data-state="Completed"] { background: var(--line); }
.bb-match-title { font-size: clamp(1.15rem, 1.8vw, 1.5rem); font-stretch: 87.5%; }
/* Switches and Apply stay in reach while the rules scroll under them. */
.bb-controls { position: sticky; top: 0; z-index: 2; background: var(--bg); display: grid; gap: 6px; padding: 4px 0 6px; border-bottom: 1px solid var(--line); }
.bb-label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 4px; }
.bb-switches { display: flex; flex-wrap: wrap; gap: 6px; }
.bb-switches p { margin: 0; }
.bb-switch { flex: 1 1 110px; min-height: 40px; border-radius: var(--radius-m); border: 2px solid var(--line); background: var(--panel); color: var(--ink); font-size: 1.05rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px; }
.bb-switch span { font-size: 0.75rem; font-weight: 700; padding: 2px 6px; border-radius: var(--radius-s); background: var(--line); color: var(--ink); }
.bb-switch[aria-pressed="true"] { background: var(--signal-bg); border-color: var(--signal-bg); color: var(--on-signal); }
.bb-switch[aria-pressed="true"] span { background: var(--on-signal); color: var(--signal-bg); }
.bb-pending { border: 1px solid var(--signal-bg); background: color-mix(in srgb, var(--signal-bg) 16%, var(--panel)); border-radius: var(--radius-m); padding: 8px 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.bb-pending p { margin: 0; flex: 1 1 140px; }
.bb-pending .bb-error { flex-basis: 100%; }
.bb-good { display: flex; gap: 6px; align-items: flex-start; border: 1px solid var(--ok); border-radius: var(--radius-m); padding: 5px 8px; font-size: 0.85rem; }
.bb-good svg { color: var(--ok); flex: none; margin-top: 3px; }
.bb-row-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.bb-edit-bar .bb-label { margin: 0; }
.bb-hint { margin: -6px 0 0; }
.bb-versions { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.bb-versions li { border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 0.85rem; }
.bb-versions li[aria-current="true"] { border-color: var(--signal-bg); background: color-mix(in srgb, var(--signal-bg) 22%, transparent); }
.bb-ver { padding-bottom: 8px; }

/* The rule cards in a narrow column: dense, one per row, code and picker underneath. */
.bb-editor.compact .bb-rules { flex-basis: 100%; }
.bb-editor.compact .bb-row { gap: 4px; }
.bb-editor.compact .bb-py { flex-basis: 100%; }
.bb-editor.compact .bb-rule { padding: 6px 6px 6px 4px; gap: 2px; }
.bb-editor.compact .bb-rule-main { flex-wrap: nowrap; align-items: flex-start; gap: 4px; }
.bb-editor.compact .bb-num { width: 22px; height: 22px; font-size: 0.8rem; margin-top: 3px; }
.bb-editor.compact .bb-sentence { flex: 1 1 0; min-width: 0; gap: 4px; font-size: 0.92rem; }
.bb-editor.compact .bb-word:not(:empty) { font-size: 0.85rem; }
.bb-editor.compact .bb-chip, .bb-editor.compact .bb-group { padding: 2px 4px; gap: 3px; border-width: 1.5px; border-radius: 8px; }
.bb-editor.compact .bb-kind { min-height: 28px; padding: 2px 4px; }
.bb-editor.compact .bb-select, .bb-editor.compact .bb-num-in { min-height: 28px; padding: 2px 4px; }
.bb-editor.compact .bb-num-in { width: 4em; }
.bb-editor.compact .bb-plus { min-height: 28px; padding: 0 8px; }
.bb-editor.compact .bb-step-grip { width: 14px; min-height: 28px; }
.bb-editor.compact .bb-step-insert { width: 20px; height: 20px; font-size: 0.8rem; }
.bb-editor.compact .bb-icon.small { min-width: 24px; min-height: 24px; }
/* On, delete, up and down as a small 2×2 block instead of a wide column. */
.bb-editor.compact .bb-tools { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; margin-left: 0; flex: none; }
.bb-editor.compact .bb-switch-toggle { min-height: 28px; font-size: 0.75rem; gap: 4px; padding: 0 2px; }
.bb-editor.compact .bb-switch-track { width: 32px; height: 18px; }
.bb-editor.compact .bb-switch-knob { top: 2px; left: 2px; width: 14px; height: 14px; }
.bb-editor.compact .bb-switch-toggle[aria-checked="true"] .bb-switch-knob { left: 16px; }
.bb-editor.compact .bb-tools .bb-icon { min-width: 26px; min-height: 26px; font-size: 0.9rem; padding: 0; }
.bb-editor.compact .bb-rule-line { flex-basis: 100%; gap: 4px; }
.bb-editor.compact .bb-live { padding-left: 0; font-size: 0.82rem; gap: 6px; }
.bb-editor.compact .bb-py { padding: 6px 10px; font-size: 0.78rem; }
.bb-editor.compact .bb-add-rule { min-height: 40px; }
.bb-editor.compact > .bb-rules > p { font-size: 0.8rem; margin: 8px 0 0; }
.bb-picker.inline { position: static; border: 2px solid var(--signal-bg); margin-top: 4px; }
.bb-rules > .bb-picker.inline { margin-bottom: 4px; }

.bb-right { min-height: 0; }
.bb-3d-wrap { position: relative; height: 100%; }
.bb-3d { width: 100%; height: 100%; display: block; }
/* On the view (dark whatever the theme: .hud-dark in styles.css): the camera buttons top left, sound and
   picture quality top right (.map-controls.float), the stats rail, the building card and messages. */
.bb-view-left, .bb-view-right { top: 10px; gap: 4px; }
.bb-view-left { left: 10px; }
.bb-view-right { right: 10px; }
/* The sound button says on or muted with its icon, not with the toolbar's pressed color. */
.bb-view-right button[aria-pressed="true"] { background: var(--panel-2); border-color: var(--line); color: var(--ink); font-weight: 700; }

/* The stats rail down the left of the view: the clock, a trend line per stat, then the scoreboard. */
.bb-hud { position: absolute; top: 54px; left: 10px; display: flex; flex-direction: column; align-items: flex-start; gap: 5px; pointer-events: none; }
.bb-tile { width: 128px; box-sizing: border-box; padding: 6px 8px 4px; border-radius: 8px; background: var(--hud-bg); border: 1px solid var(--hud-edge); display: flex; flex-direction: column; gap: 1px; }
.bb-tile svg { display: block; color: var(--tile, var(--hud-ink)); }
.bb-tile-mark { stroke: var(--hud-accent); }
.bb-tile-label { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--hud-muted); display: flex; justify-content: space-between; gap: 6px; }
.bb-tile-row { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.bb-tile-value { font-size: 1.3rem; font-weight: 700; font-stretch: 87.5%; line-height: 1.05; font-variant-numeric: tabular-nums; color: var(--tile, inherit); }
.bb-tile-rate { font-size: 10px; font-weight: 700; color: var(--hud-muted); white-space: nowrap; }
.bb-tile-rate.up { color: var(--hud-good); }
.bb-tile-rate.down { color: var(--hud-bad); }
.bb-clock { pointer-events: auto; }
.bb-clock .bb-tile-label span { letter-spacing: 0; text-transform: none; font-weight: 600; color: var(--hud-soft); }
.bb-clock .bb-tile-value small { font-size: 0.75rem; font-weight: 600; color: var(--hud-muted); }
.bb-clock-bar { display: block; height: 4px; margin: 3px 0 2px; border-radius: 2px; background: var(--hud-track); overflow: hidden; }
.bb-clock-bar > span { display: block; height: 100%; background: var(--hud-accent); }
/* The building you clicked: a .map3d-card, top right, under the sound and quality buttons. */
.map3d-card.bb-bcard { top: 54px; right: 10px; bottom: auto; left: auto; width: 236px; min-width: 0; max-width: none; box-sizing: border-box; gap: 6px; border-radius: 8px; border-color: var(--hud-edge-mid); background: var(--hud-bg-strong); font-size: 0.85rem; }
.bb-bcard p { margin: 0; }
.bb-bcard-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.bb-bcard-head h2 { margin: 0; font-size: 1.1rem; font-stretch: 87.5%; line-height: 1.15; color: var(--hud-ink-hi); }
.bb-bcard-x, .bb-bcard-zoom { border: 1px solid var(--hud-line); border-radius: 6px; background: transparent; color: var(--hud-ink); font: inherit; font-weight: 600; cursor: pointer; }
.bb-bcard-x:hover, .bb-bcard-zoom:hover { border-color: var(--hud-line-hi); }
.bb-bcard-x { width: 28px; height: 28px; flex: none; padding: 0; background: var(--hud-bg); font-size: 16px; font-weight: 700; line-height: 1; }
.bb-bcard-zoom { justify-self: start; min-height: 32px; padding: 0 10px; }
.bb-bcard-owner { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.bb-bcard-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--pc); flex: none; }
.bb-bcard-hp { display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; }
.bb-bcard-hp span { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; color: var(--hud-muted); }
.bb-hpbar > span { background: var(--hud-good); }
.bb-hpbar.low > span { background: var(--hud-bad); }
.bb-bcard-role { color: var(--hud-soft); }
.bb-bcard-gone { color: var(--hud-bad); font-weight: 700; }
.bb-bcard-stats { margin: 0; display: grid; gap: 2px; }
.bb-bcard-stats div { display: flex; justify-content: space-between; gap: 8px; }
.bb-bcard-stats dt { color: var(--hud-muted); }
.bb-bcard-stats dd { margin: 0; text-align: right; font-weight: 600; }
/* As wide as the longest name needs, up to a limit; past it, names end in … (each has its full name as a tooltip). */
.bb-board { width: max-content; min-width: 176px; max-width: 280px; gap: 3px; pointer-events: auto; }
.bb-board-count { font-weight: 400; letter-spacing: 0; text-transform: none; }
.bb-board ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.bb-board li { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 4px; font-size: 0.8rem; color: var(--hud-soft); }
.bb-board li.me { background: color-mix(in srgb, var(--pc) 28%, transparent); box-shadow: inset 2px 0 0 var(--pc); color: var(--hud-ink-hi); font-weight: 700; }
.bb-board li.out { opacity: 0.5; text-decoration: line-through; }
.bb-board-gap { justify-content: center; line-height: 0.6; color: var(--hud-muted); }
.bb-board-rank { width: 14px; text-align: right; font-weight: 700; color: var(--hud-muted); font-size: 0.75rem; }
.bb-board-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bb-board-score { font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 900px) { .bb-hud { transform: scale(0.85); transform-origin: top left; } }
.bb-result { position: absolute; inset: auto 16px 56px 16px; background: var(--panel); border: 2px solid var(--signal-bg); border-radius: var(--radius-m); padding: 16px; display: grid; gap: 8px; }
.bb-result[hidden] { display: none; }
.bb-result h2 { margin: 0; font-size: 1.8rem; }
.bb-result p { margin: 0; }

/* Narrow screens: the match on top, the rules under it, one scrolling page. */
@media (max-width: 900px) {
  .bb-cockpit, .bb-cockpit.folded { grid-template-columns: minmax(0, 1fr); height: auto; }
  .bb-right { order: -1; height: 56vh; min-height: 300px; }
  .bb-left, .bb-cockpit.folded .bb-left { overflow: visible; display: flex; }
  .bb-left, .bb-right { grid-column: auto; }
  .bb-split { display: none; }   /* one column: nothing to resize or fold */
}

@media (max-width: 640px) {
  .bb-live, .bb-note { padding-left: 0; }
  .bb-modes { grid-template-columns: minmax(0, 1fr); }
  .bb-tools { margin-left: 0; }
}
@media (max-width: 560px) { .map3d-card.bb-bcard { width: 190px; } }
/* While something is being dragged, the "+ rule" labels step aside for the drop line. */
.bb-editor:has(.dragging) .bb-insert { visibility: hidden; }

/* A part of a not-yet-placed block that can be changed once it's placed: {Housing}. */
.bb-slot { white-space: nowrap; }
.bb-slot > [aria-hidden] { opacity: 0.7; font-weight: 400; padding-inline: 1px; }

/* The edit page's way on from blocks: the strategy as a bot in code. */
.bb-code-card { display: grid; gap: 8px; margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--bg); }
.bb-code-card h2 { margin: 0; font-size: 1.05rem; }
.bb-code-card p { margin: 0; }
.bb-code-card .bb-row-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.bb-code-card [hidden] { display: none; }

/* How often a rule may run (every tick, only once, at most every N s), beside its on/off. */
.bb-repeat { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.bb-repeat .bb-num-in { width: 4.5em; }

/* Dragging a rule card by its grip: where it would land, and the insert lines out of the way meanwhile. */
.bb-editor .bb-rule-grip { display: inline-flex; align-items: center; justify-content: center; align-self: stretch; min-width: 28px; padding: 0 4px; border: 0; border-radius: var(--radius-s); background: none; color: var(--muted); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.bb-editor .bb-rule-grip:focus-visible { outline: 2px solid var(--focus); }
.bb-editor .bb-rule-grip:disabled { opacity: 0.35; cursor: default; }
.bb-editor .bb-rule-grip:hover { color: var(--ink); }
.bb-editor .bb-rule-grip svg { width: 10px; height: 18px; }
.bb-editor .bb-row.drop-above { box-shadow: 0 -5px 0 var(--signal-bg); border-radius: 2px; }
.bb-editor .bb-add-rule.drop-above { box-shadow: 0 -5px 0 var(--signal-bg); }
.bb-editor.is-dragging .bb-insert { visibility: hidden; }

/* The first-visit welcome (intro.js): a dialog over the locker, so it sits outside .bb-page. */
.bb-how { margin-top: 10px; }
dialog.bb-intro { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-top: 6px solid var(--signal-bg); border-radius: var(--radius-m); background: var(--panel); color: var(--ink); box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35); }
dialog.bb-intro::backdrop { background: rgba(15, 29, 46, 0.55); }
.bb-intro-body { display: grid; gap: 14px; padding: 28px 32px 24px; }
.bb-intro-body > * { margin: 0; }
.bb-intro-body .eyebrow { color: var(--signal); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.8rem; }
.bb-intro-body h2 { font-size: 2.2rem; line-height: 1.05; }
.bb-intro-body .lede { font-size: 1.1rem; }
.bb-intro-tiles { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.bb-intro-tiles li { display: grid; align-content: start; gap: 4px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--bg); }
.bb-intro-tiles b { font-size: 1.05rem; }
.bb-intro-tiles span { font-size: 0.92rem; color: var(--muted); }
.bb-intro-plan { display: grid; gap: 6px; padding-left: 20px; }
.bb-intro-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.bb-intro-body .bb-inline-form input { flex: 1 1 14em; }
@media (max-width: 560px) {
  .bb-intro-body { padding: 20px 16px; }
  .bb-intro-body h2 { font-size: 1.7rem; }
  .bb-intro-tiles { grid-template-columns: minmax(0, 1fr); }
}

/* The coached first match (coach.js): a card over the match, and a ring on what it's talking about. */
.bb-coach { position: absolute; top: 54px; right: 10px; z-index: 5; width: min(400px, calc(100% - 20px)); max-height: calc(100% - 70px); overflow: auto; box-sizing: border-box; display: grid; gap: 10px; padding: 18px 20px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-top: 5px solid var(--signal-bg); border-radius: var(--radius-m); box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35); }
.bb-coach[hidden] { display: none; }
.bb-coach > *, .bb-coach-next > * { margin: 0; }
.bb-coach h2 { font-size: 1.6rem; line-height: 1.1; }
.bb-coach-kicker { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--signal); }
.bb-coach-keys { list-style: none; padding: 0; display: grid; gap: 4px; }
.bb-coach-keys li { display: flex; align-items: center; gap: 8px; }
.bb-coach-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.bb-coach-dot.firing { background: var(--ok); }
.bb-coach-dot.waiting { background: var(--signal-bg); }
.bb-coach-steps { list-style: none; padding: 0; display: grid; gap: 6px; }
.bb-coach-steps li { display: flex; gap: 8px; align-items: flex-start; }
.bb-coach-steps li.done > span:last-child { color: var(--muted); text-decoration: line-through; }
.bb-coach-mark { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border: 2px solid var(--line); border-radius: 50%; font-size: 0.8rem; font-weight: 700; }
.bb-coach-steps li.done .bb-coach-mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.bb-coach-ideas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.bb-coach-ideas > div { display: grid; align-content: start; gap: 4px; padding: 10px; border-radius: var(--radius-m); background: var(--bg); }
.bb-coach-ideas span { font-size: 0.88rem; }
.bb-coach-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.bb-coach-next { display: grid; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.bb-coach-spot { outline: 3px solid var(--signal-bg) !important; outline-offset: 2px; border-radius: var(--radius-m); animation: bb-coach-pulse 1.6s ease-in-out infinite; }
@keyframes bb-coach-pulse { 50% { outline-color: color-mix(in srgb, var(--signal-bg) 35%, transparent); } }
@media (prefers-reduced-motion: reduce) { .bb-coach-spot { animation: none; } }
@media (max-width: 900px) { .bb-coach { top: auto; bottom: 10px; max-height: 70%; } }
@media (max-width: 560px) { .bb-coach-ideas { grid-template-columns: minmax(0, 1fr); } }
