/* Two-block toy simulator figure (twoblocks.js). Everything is scoped to .tb. */

.tb {
  /* Series colours: floor <-> bottom block, bottom <-> top block. The teal is a
     more saturated step of --accent-cool so the pair passes colour-blind checks. */
  --tb-floor: #008c80;
  --tb-pair: #b34f27;
  --tb-grid: #ece8e3;
  --tb-axis: #cfc8c0;
  /* Status (readout only, never a series) */
  --tb-ok: #617347;
  --tb-warn: #9a6400;
  --tb-bad: #b3261e;
}

.tb .tb-app {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text);
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

/* Presets */
.tb .tb-presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.tb .tb-presets-label {
  margin-right: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.tb .tb-chip,
.tb .tb-btn {
  appearance: none;
  margin: 0;
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  line-height: 1.3;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.tb .tb-chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
}

.tb .tb-chip:hover { border-color: var(--muted); }

.tb .tb-chip[aria-pressed="true"] {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}

.tb .tb-hint {
  min-height: 2.9em;
  margin: 10px 0 12px;
  color: var(--muted);
  font-size: 0.84rem;
}

/* Scene and plot */
.tb .tb-stage {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 14px;
  height: 300px;
}

.tb .tb-scene,
.tb .tb-plot {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.tb .tb-scene canvas {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  border-radius: 6px;
  background: var(--bg);
}

.tb .tb-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  margin-bottom: 4px;
  font-size: 0.78rem;
}

.tb .tb-legend-item { white-space: nowrap; }
.tb .tb-legend-name { margin-right: 6px; }

.tb .tb-legend-val,
.tb .tb-clock {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tb .tb-key {
  display: inline-block;
  width: 14px;
  height: 2px;
  margin-right: 6px;
  border-radius: 1px;
  vertical-align: middle;
}

.tb .tb-key-floor { background: var(--tb-floor); }
.tb .tb-key-pair { background: var(--tb-pair); }

.tb .tb-plot-box {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.tb .tb-plot-box canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 4px;
  cursor: crosshair;
}

.tb canvas:focus-visible,
.tb .tb-chip:focus-visible,
.tb .tb-btn:focus-visible,
.tb input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tb .tb-tip {
  position: absolute;
  z-index: 2;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  box-shadow: 0 4px 14px rgba(54, 46, 38, 0.1);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: nowrap;
  pointer-events: none;
}

.tb .tb-tip[hidden] { display: none; }
.tb .tb-tip-t { color: var(--muted); font-variant-numeric: tabular-nums; }
.tb .tb-tip-row strong { font-weight: 600; font-variant-numeric: tabular-nums; }
.tb .tb-tip-name { margin-left: 6px; color: var(--muted); }

/* Readout */
.tb .tb-readout {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  min-height: 2.9em;
  margin-top: 14px;
  padding: 8px 12px;
  border-left: 3px solid var(--tb-ok);
  border-radius: 0 6px 6px 0;
  background: var(--surface);
  font-weight: 500;
}

.tb .tb-readout-icon {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--tb-ok);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.tb .tb-readout.tb-warn { border-left-color: var(--tb-warn); }
.tb .tb-readout.tb-warn .tb-readout-icon { background: var(--tb-warn); }
.tb .tb-readout.tb-bad { border-left-color: var(--tb-bad); }
.tb .tb-readout.tb-bad .tb-readout-icon { background: var(--tb-bad); }

/* Buttons */
.tb .tb-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 12px 0 14px;
}

.tb .tb-btn {
  padding: 6px 14px;
  border-radius: 6px;
  background: var(--bg);
  font-weight: 500;
}

.tb .tb-btn:hover { border-color: var(--muted); }
.tb .tb-btn:disabled { color: var(--muted); cursor: default; opacity: 0.6; }

.tb .tb-btn-primary {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}

.tb .tb-btn-primary:hover { border-color: var(--accent); background: var(--accent); }
.tb .tb-clock { margin-left: auto; font-size: 0.8rem; }

/* Sliders */
.tb .tb-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.tb .tb-control-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
}

.tb .tb-control-head label { font-weight: 600; }
.tb .tb-control-val { font-variant-numeric: tabular-nums; white-space: nowrap; }

.tb input[type="range"] {
  display: block;
  width: 100%;
  margin: 6px 0 2px;
  accent-color: var(--text);
  cursor: pointer;
}

.tb .tb-control-ends {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.72rem;
}

.tb .tb-stability {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.8rem;
}

.tb .tb-app .tb-stability.tb-stability-bad { color: var(--tb-bad); }

.tb .tb-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* No-JS fallback and caption */
.tb .tb-fallback-note {
  margin: 0 0 8px;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.84rem;
}

.tb figcaption {
  margin-top: 10px;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.84rem;
  line-height: 1.55;
}

@media (max-width: 560px) {
  .tb .tb-app { padding: 12px; }
  .tb .tb-stage {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
  }
  .tb .tb-scene canvas { flex: none; height: 230px; }
  .tb .tb-plot-box { flex: none; height: 210px; }
  .tb .tb-controls { grid-template-columns: minmax(0, 1fr); }
  .tb .tb-hint { min-height: 4.4em; }
  .tb .tb-readout { min-height: 4.2em; }
}

@media (prefers-reduced-motion: reduce) {
  .tb .tb-chip,
  .tb .tb-btn { transition: none; }
}
