/*
 * The mini-block site's own layer, on top of shared-ui.
 *
 * One thing is loud here and everything else is quiet: the wall, a full-bleed
 * grid where every square is one mini-block and every column is one EVM block,
 * drawn by app.js on a canvas as the sequencer stamps them. A cursor sweeps it
 * left to right and wraps, like an oscilloscope, so a square never moves once
 * it has landed and can always be picked.
 *
 * The rest is type: the headline, the height the wall has reached, five
 * figures measured by this page, the selected mini-block and the raw stream.
 * Continuous motion is the wall's alone, and it stops under
 * prefers-reduced-motion (app.js redraws it once a second instead).
 */

.mb {
  --mb-edge: max(var(--pickle-gutter), calc((100vw - var(--pickle-content)) / 2));
  padding: var(--pickle-space-6) 0 var(--pickle-section-sm);
}

/* ===================================================================== head */

.mb-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--pickle-space-5) var(--pickle-space-6);
  align-items: end;
  padding-inline: var(--mb-edge);
}

.mb-intro { min-width: 0; }

.mb-h {
  max-width: 13ch;
  margin: 0 0 var(--pickle-space-4);
  font-family: var(--pickle-font-display);
  font-size: clamp(2.1rem, 4.6vw, 3.9rem);
  font-weight: 600;
  line-height: var(--pickle-leading-display);
  letter-spacing: var(--pickle-tracking-display);
  text-wrap: balance;
}

.mb-lede {
  max-width: 44ch;
  margin: 0;
  color: var(--pickle-muted);
  font-size: clamp(1rem, 1.3vw, 1.1rem);
  line-height: 1.6;
}

.mb-height { text-align: right; }

/* The height counts at up to a hundred a second. Tabular digits keep the
 * number the same width while its last two places blur. */
.mb-n {
  display: block;
  color: var(--pickle-text);
  font-family: var(--pickle-font-display);
  font-size: clamp(3rem, 9.4vw, 8.5rem);
  font-weight: 600;
  line-height: .86;
  letter-spacing: -.05em;
  white-space: nowrap;
}

.mb-n.wait { color: var(--pickle-faint); }

.mb-n-label {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pickle-space-1) var(--pickle-space-5);
  justify-content: flex-end;
  margin: var(--pickle-space-3) 0 0;
  color: var(--pickle-subtle);
  font-family: var(--pickle-font-mono);
  font-size: var(--pickle-text-xs);
}

.mb-n-label b {
  color: var(--pickle-muted);
  font-weight: 400;
}

/* ==================================================================== stage */

.mb-stage { margin-top: var(--pickle-space-6); }

.mb-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pickle-space-3) var(--pickle-space-5);
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--mb-edge) var(--pickle-space-3);
}

.mb-state {
  display: inline-flex;
  gap: var(--pickle-space-2);
  align-items: center;
  margin: 0;
  color: var(--pickle-muted);
  font-family: var(--pickle-font-mono);
  font-size: var(--pickle-text-xs);
}

.mb-beat {
  width: 7px;
  height: 7px;
  background: var(--pickle-subtle);
  border-radius: 50%;
}

.mb-state[data-state="live"] { color: var(--pickle-text); }
.mb-state[data-state="live"] .mb-beat { background: var(--pickle-mint); animation: pickle-pulse 1s infinite; }
.mb-state[data-state="polling"] .mb-beat,
.mb-state[data-state="reconnecting"] .mb-beat { background: var(--pickle-amber); }
.mb-state[data-state="reconnecting"],
.mb-state[data-state="polling"] { color: var(--pickle-amber); }
.mb-state[data-state="offline"] { color: var(--pickle-rose); }
.mb-state[data-state="offline"] .mb-beat { background: var(--pickle-rose); }
.mb-state[data-state="paused"] .mb-beat { background: var(--pickle-text); border-radius: 0; }

.mb-tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pickle-space-3) var(--pickle-space-5);
  align-items: center;
}

.mb-key {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pickle-space-1) var(--pickle-space-4);
  margin: 0;
  color: var(--pickle-subtle);
  font-family: var(--pickle-font-mono);
  font-size: var(--pickle-text-2xs);
}

.mb-key span {
  display: inline-flex;
  gap: var(--pickle-space-2);
  align-items: center;
}

/* The same three marks the canvas draws, at the same proportions. */
.mb-sw {
  display: inline-block;
  width: 10px;
  height: 10px;
}

.mb-sw.plain {
  background: rgb(0 231 136 / 50%);
  box-shadow: inset 0 0 0 2px var(--pickle-bg-deep);
}

.mb-sw.tx { background: var(--pickle-mint-hi); }
.mb-sw.fail { background: var(--pickle-rose); }

#pause[aria-pressed="true"] {
  color: var(--pickle-accent-text);
  border-color: var(--pickle-mint-line);
  background: var(--pickle-mint-soft);
}

/* The wall. Its height is set by app.js from the cell pitch it picks for the
 * viewport (--mb-wall-h); before that, and with no JavaScript, the ground is
 * the schedule itself: a faint dot for every 10 ms slot. */
.mb-wall {
  position: relative;
  background-color: var(--pickle-bg-deep);
  background-image: radial-gradient(circle, rgb(0 231 136 / 14%) 1px, transparent 1.5px);
  background-position: var(--mb-edge) 22px;
  background-size: 12px 12px;
  border-block: 1px solid var(--pickle-line);
}

.mb-canvas {
  display: block;
  width: 100%;
  height: var(--mb-wall-h, 21rem);
  cursor: crosshair;
  touch-action: manipulation;
}

.mb-canvas:focus-visible {
  outline: 2px solid var(--pickle-focus);
  outline-offset: -2px;
  border-radius: 0;
}

.mb-tip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  min-width: 11rem;
  padding: var(--pickle-space-2) var(--pickle-space-3);
  color: var(--pickle-muted);
  font-family: var(--pickle-font-mono);
  font-size: var(--pickle-text-2xs);
  line-height: 1.6;
  white-space: nowrap;
  pointer-events: none;
  background: var(--pickle-surface-2);
  border: 1px solid var(--pickle-line);
  border-radius: var(--pickle-radius);
  transform: translate(var(--mb-tx, 0), var(--mb-ty, 0));
  display: none;
}

.mb-tip.on { display: block; }
.mb-tip b { color: var(--pickle-text); font-weight: 500; }

.mb-stall {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  max-width: calc(100% - 2 * var(--pickle-gutter));
  margin: 0;
  padding: var(--pickle-space-2) var(--pickle-space-4);
  color: var(--pickle-text);
  font-family: var(--pickle-font-mono);
  font-size: var(--pickle-text-xs);
  text-align: center;
  background: var(--pickle-surface-2);
  border: 1px solid var(--pickle-line);
  border-radius: var(--pickle-radius);
  transform: translate(-50%, -50%);
}

.mb-stall[hidden] { display: none; }

/* ===================================================================== body */

.mb-body {
  display: grid;
  grid-template-columns: minmax(0, 22rem) minmax(0, 1fr);
  gap: var(--pickle-space-7) var(--pickle-space-6);
  align-items: start;
  padding: var(--pickle-space-6) var(--mb-edge) 0;
}

.mb-figs {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--pickle-space-5);
  margin: 0;
}

.mb-fig {
  min-width: 0;
  padding-top: var(--pickle-space-3);
  border-top: 1px solid var(--pickle-line);
}

.mb-fig dt {
  color: var(--pickle-muted);
  font-size: var(--pickle-text-sm);
}

.mb-fig dd {
  display: flex;
  flex-direction: column;
  gap: var(--pickle-space-1);
  margin: var(--pickle-space-2) 0 0;
}

.mb-fig dd b {
  color: var(--pickle-text);
  font-family: var(--pickle-font-display);
  font-size: clamp(1.45rem, 2.2vw, 1.9rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -.03em;
  white-space: nowrap;
}

.mb-fig dd small {
  color: var(--pickle-subtle);
  font-family: var(--pickle-font-mono);
  font-size: var(--pickle-text-2xs);
  line-height: 1.5;
}

/* ------------------------------------------------------------------- detail */

.mb-detail {
  min-width: 0;
  padding: var(--pickle-space-5);
  background: var(--pickle-surface-1);
  border: 1px solid var(--pickle-line);
  border-top: 2px solid var(--pickle-mint);
  border-radius: var(--pickle-radius);
}

.mb-detail-empty {
  margin: 0;
  color: var(--pickle-muted);
  font-size: var(--pickle-text-sm);
  line-height: 1.6;
}

.mb-detail-h {
  margin: 0 0 var(--pickle-space-4);
  font-family: var(--pickle-font-display);
  font-size: var(--pickle-text-xl);
  font-weight: 600;
  letter-spacing: -.02em;
}

.mb-detail-h .num { font-variant-numeric: tabular-nums; }

.mb-kv {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--pickle-space-2) var(--pickle-space-4);
  margin: 0 0 var(--pickle-space-4);
  font-size: var(--pickle-text-sm);
}

.mb-kv dt { color: var(--pickle-subtle); }

.mb-kv dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--pickle-text);
  font-family: var(--pickle-font-mono);
  font-size: var(--pickle-text-xs);
}

.mb-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pickle-space-2);
  margin: 0 0 var(--pickle-space-4);
}

.mb-txs {
  display: grid;
  gap: 1px;
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--pickle-line);
  border: 1px solid var(--pickle-line);
}

.mb-tx {
  display: grid;
  gap: var(--pickle-space-1);
  padding: var(--pickle-space-3);
  background: var(--pickle-surface-1);
  font-size: var(--pickle-text-xs);
}

.mb-tx a {
  color: var(--pickle-accent-text);
  font-family: var(--pickle-font-mono);
  overflow-wrap: anywhere;
}

.mb-tx span {
  color: var(--pickle-muted);
  font-family: var(--pickle-font-mono);
  overflow-wrap: anywhere;
}

.mb-tx .bad { color: var(--pickle-rose); }

.mb-note {
  margin: 0;
  color: var(--pickle-subtle);
  font-size: var(--pickle-text-xs);
  line-height: 1.6;
}

/* ---------------------------------------------------------------------- raw */

.mb-raw { min-width: 0; }

.mb-raw-h {
  margin: 0 0 var(--pickle-space-4);
  font-family: var(--pickle-font-display);
  font-size: var(--pickle-text-xl);
  font-weight: 600;
  letter-spacing: -.02em;
}

.mb-raw .ex-stats { margin-bottom: var(--pickle-space-4); }
.mb-stream { height: min(46vh, 26rem); }

/* =============================================================== responsive */

@media (max-width: 1080px) {
  .mb-figs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .mb-head { grid-template-columns: minmax(0, 1fr); }
  .mb-height { text-align: left; }
  .mb-n-label { justify-content: flex-start; }
  .mb-body { grid-template-columns: minmax(0, 1fr); gap: var(--pickle-space-6); }
}

@media (max-width: 560px) {
  .mb { padding-top: var(--pickle-space-5); }
  .mb-stage { margin-top: var(--pickle-space-5); }
  .mb-figs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--pickle-space-4); }
  .mb-fig:last-child { grid-column: 1 / -1; }
  /* The state and the one control share a row; the key takes the next. */
  .mb-tools { display: contents; }
  .mb-key { order: 3; flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .mb-state[data-state="live"] .mb-beat { animation: none; }
}
