/* Balance Builder. Calm dark-navy surface to match the shared game toolbar
   (assets/game-studio.css). Contrast is AA or better on every text/background pair;
   shape and text carry meaning, never colour alone. */
:root {
  --bb-bg: #0f1a2e;
  --bb-card: #14243a;
  --bb-card-2: #1b3150;
  --bb-line: #6f86a8;
  --bb-ink: #f2f6fc;
  --bb-muted: #c3d0e3;
  --bb-teal: #7ddec4;
  --bb-teal-ink: #0a1a2c;
  --bb-amber: #f5c96a;
  --bb-coral: #ffb38a;
  --bb-pink: #f7a8c4;
  --bb-font: "Lexend", "Plus Jakarta Sans", system-ui, sans-serif;
}

html,
body {
  background: var(--bb-bg);
  color: var(--bb-ink);
}
body {
  margin: 0;
  font-family: var(--bb-font);
  font-size: 1.0625rem;
  line-height: 1.5;
}
.bb {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}
.bb:focus {
  outline: none;
}
.bb-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.bb [hidden] {
  display: none !important;
}
.bb-skip {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 200;
  padding: 10px 14px;
  background: var(--bb-teal);
  color: var(--bb-teal-ink);
  border-radius: 8px;
  font-weight: 700;
}
.bb-skip:focus {
  top: 8px;
}

.bb-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.bb-head h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  line-height: 1.15;
}
.bb-tagline {
  margin: 4px 0 0;
  color: var(--bb-muted);
}

/* buttons and fields */
.bb-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 16px;
  border: 2px solid var(--bb-line);
  border-radius: 10px;
  background: var(--bb-card-2);
  color: var(--bb-ink);
  font: 700 1rem/1.3 var(--bb-font);
  cursor: pointer;
}
.bb-btn:hover:not(:disabled):not(.bb-primary):not([aria-pressed="true"]) {
  background: #284670;
}
.bb-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.bb-primary {
  background: var(--bb-teal);
  border-color: var(--bb-teal);
  color: var(--bb-teal-ink);
}
.bb-primary:hover:not(:disabled) {
  background: #a4efdc;
}
.bb-ghost {
  background: transparent;
}
.bb :focus-visible,
.bb-skip:focus-visible {
  outline: 3px solid var(--bb-amber);
  outline-offset: 3px;
}
.bb input[type="text"],
.bb input[type="number"],
.bb select {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  margin-top: 4px;
  padding: 8px 12px;
  border: 2px solid var(--bb-line);
  border-radius: 10px;
  background: #0b1626;
  color: #fff;
  font: 600 1.15rem/1.3 var(--bb-font);
}
.bb label {
  display: block;
  font-weight: 600;
}
.bb fieldset {
  min-width: 0;
  margin: 0 0 8px;
  padding: 8px 12px;
  border: 1px solid var(--bb-line);
  border-radius: 10px;
}
.bb legend {
  padding: 0 6px;
  font-weight: 700;
}
.bb-help {
  margin: 4px 0 8px;
  color: var(--bb-muted);
  font-size: 0.95rem;
}
.bb-card {
  margin: 0 0 12px;
  padding: 14px 16px;
  border: 1px solid var(--bb-line);
  border-radius: 14px;
  background: var(--bb-card);
}
.bb-card h3,
.bb h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}
.bb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.bb-row > * {
  flex: 1 1 140px;
}

/* levels */
.bb-levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.bb-level {
  text-align: left;
  min-height: 64px;
  padding: 10px 14px;
}
.bb-level[aria-pressed="true"] {
  background: var(--bb-teal);
  border-color: var(--bb-teal);
  color: var(--bb-teal-ink);
}
.bb-level small {
  display: block;
  font-weight: 500;
  font-size: 0.85rem;
}
.bb-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 8px;
  border: 1px solid currentColor;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
}

.bb-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}
.bb-status h2 {
  margin: 0;
}
.bb-pill {
  margin: 0;
  padding: 2px 12px;
  border: 1px solid var(--bb-line);
  border-radius: 99px;
  font-size: 0.9rem;
}
.bb-progress {
  margin: 0;
  color: var(--bb-muted);
}

/* stage */
.bb-stage {
  display: grid;
  gap: 8px;
  margin: 8px 0 12px;
}
.bb-scale {
  margin: 0;
  padding: 8px;
  border: 1px solid var(--bb-line);
  border-radius: 14px;
  background: var(--bb-card);
}
.bb-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 340px;
}
.bb-stand {
  fill: #8aa0bd;
}
.bb-beam {
  stroke: var(--bb-teal);
  stroke-width: 9;
  stroke-linecap: round;
}
.bb-pivot {
  fill: var(--bb-amber);
  stroke: #0a1a2c;
  stroke-width: 3;
}
.bb-hangers path {
  stroke: #8aa0bd;
  stroke-width: 2;
  fill: none;
}
.bb-pan {
  fill: #223a5e;
  stroke: #c3d0e3;
  stroke-width: 2.5;
}
.bb-chip-text {
  font-family: var(--bb-font);
  font-weight: 800;
}
.bb-box rect {
  fill: #1f6f66;
  stroke: var(--bb-teal);
  stroke-width: 2;
}
.bb-box text {
  fill: #fff;
}
.bb-weight circle {
  fill: var(--bb-amber);
  stroke: #0a1a2c;
  stroke-width: 2;
}
.bb-weight text {
  fill: #1a1405;
}
.bb-balloon ellipse {
  fill: var(--bb-pink);
  stroke: #0a1a2c;
  stroke-width: 2;
  stroke-dasharray: 5 3;
}
.bb-balloon path {
  stroke: #c3d0e3;
  fill: none;
}
.bb-balloon text {
  fill: #3a0f22;
}
.bb-eq {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 16px;
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 800;
}
.bb-original {
  margin: 0 0 6px;
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  opacity: 0.85;
}
.bb-rel {
  color: var(--bb-amber);
}
.bb-solved .bb-eq {
  color: var(--bb-teal);
}
.bb-history-wrap h3 {
  margin: 8px 0 4px;
  font-size: 1rem;
}
.bb-history {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.bb-history-note {
  margin: 0 0 6px;
  color: var(--bb-muted);
  font-size: 0.9rem;
}
.bb-step,
.bb-step-pending {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 8px 14px;
  border: 1px solid var(--bb-line);
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}
.bb-step {
  cursor: pointer;
}
.bb-step:hover,
.bb-step[aria-pressed="true"] {
  border-color: var(--bb-amber);
}
.bb-step-pending {
  border-style: dashed;
}
.bb-step-label {
  color: var(--bb-muted);
  font-size: 0.85rem;
  font-weight: 700;
}
.bb-step-work {
  font-size: 1.25rem;
  font-weight: 800;
}
.bb-step-result {
  color: var(--bb-teal);
  font-size: 1.1rem;
  font-weight: 800;
}
.bb-history li:empty,
.bb-history .bb-none {
  color: var(--bb-muted);
  border-style: dashed;
  font-weight: 500;
}

/* controls */
.bb-ops {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.bb-op {
  position: relative;
}
.bb-op input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.bb-op > span {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 12px;
  border: 2px solid var(--bb-line);
  border-radius: 10px;
  background: var(--bb-card-2);
  font-weight: 700;
}
.bb-op b {
  font-size: 1.5rem;
  line-height: 1;
}
.bb-op input:checked + span {
  background: var(--bb-teal);
  border-color: var(--bb-teal);
  color: var(--bb-teal-ink);
}
.bb-op input:focus-visible + span {
  outline: 3px solid var(--bb-amber);
  outline-offset: 3px;
}
.bb-working {
  margin: 0 0 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--bb-card-2);
  font-weight: 700;
  overflow-wrap: anywhere;
}
.bb-entry-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 10px;
}
.bb-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.bb-feedback {
  min-height: 3.5em;
}
.bb-chip-tag {
  display: inline-block;
  margin: 0 0 6px;
  padding: 2px 12px;
  border: 2px solid var(--bb-amber);
  border-radius: 99px;
  color: var(--bb-amber);
  font-weight: 700;
  font-size: 0.9rem;
}
.bb-coach,
.bb-hint-text {
  margin: 0 0 6px;
}
.bb-hint-text {
  color: var(--bb-teal);
  font-weight: 600;
}
.bb-coach[data-kind="problem"] {
  color: var(--bb-coral);
}
.bb-ok {
  margin: 0 0 8px;
  color: var(--bb-teal);
  font-weight: 700;
}
.bb-error {
  margin: 4px 0;
  color: var(--bb-coral);
  font-weight: 600;
}
.bb-numline svg,
.bb-line {
  display: block;
  width: 100%;
  max-width: 560px;
  height: auto;
}
.bb-axis,
.bb-line line {
  stroke: #c3d0e3;
  stroke-width: 2;
}
.bb-tick {
  fill: #c3d0e3;
  font-size: 13px;
  font-family: var(--bb-font);
}
.bb-ray {
  stroke: var(--bb-teal);
  stroke-width: 6;
}
.bb-ray-head {
  fill: var(--bb-teal);
}
.bb-dot {
  stroke: var(--bb-teal);
  stroke-width: 4;
}
.bb-open {
  fill: var(--bb-bg);
}
.bb-closed {
  fill: var(--bb-teal);
}

/* editor */
.bb-preview {
  font-size: 1.2rem;
}
.bb-code {
  font: 800 1.8rem/1.2 var(--bb-font);
  letter-spacing: 0.08em;
  color: var(--bb-amber);
}
.bb-lib {
  margin: 0;
  padding: 0;
  list-style: none;
}
.bb-lib li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--bb-line);
}
.bb-lib-eq {
  flex: 1 1 200px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

@media (min-width: 900px) {
  .bb-play-grid,
  #bb-play {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    column-gap: 20px;
  }
  .bb-status {
    grid-column: 1 / -1;
  }
}
@media (max-width: 520px) {
  .bb {
    padding: 12px;
  }
  .bb-ops {
    grid-template-columns: 1fr 1fr;
  }
  .bb-btn {
    flex: 1 1 auto;
  }
}
@media (prefers-reduced-motion: no-preference) {
  .bb-solved .bb-eq {
    animation: bb-settle 0.6s ease-out;
  }
}
@keyframes bb-settle {
  from {
    transform: scale(0.96);
  }
  to {
    transform: scale(1);
  }
}
.studio-reduced-motion .bb-eq {
  animation: none;
}
