/* ============================================================
   Quant etc. — in-article demonstrations
   Loaded after article.css. Same language as everything else:
   black canvas, Satoshi, white text, hairlines and underlines.
   No cards, no colour, no chrome. A demo is a passage of the
   article that happens to move.
   ============================================================ */

.demo {
  margin-top: 3.4em;
  margin-bottom: 3.4em;
  padding-top: 1.6em;
  border-top: 2px solid rgba(255, 255, 255, 0.25);
}

.demo-kicker {
  display: block;
  color: var(--ink-3);
  font-weight: 500;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}

.demo-title {
  margin-top: 0.5em;
  color: var(--ink);
  font-weight: 700;
  font-size: clamp(1.35rem, 2.2vw, 1.7rem);
  letter-spacing: -0.025em;
  line-height: 1.15;
  text-wrap: balance;
}

.demo-dek {
  margin-top: 0.7em;
  color: var(--ink-2);
  font-size: 0.98em;
  line-height: 1.6;
  text-wrap: pretty;
}

.demo-note {
  margin-top: 1.6em;
  color: var(--ink-3);
  font-weight: 500;
  font-size: 0.9rem;
  line-height: 1.55;
  text-wrap: pretty;
}
.demo-note code { font-weight: 700; color: var(--ink-3); }

/* ---- Control rows -------------------------------------------------
   A control is a label and a row of words. The chosen word is white
   and underlined; the others are dim and plain. Nothing is a button.
   ------------------------------------------------------------------- */

.demo-controls { margin-top: 1.8em; display: grid; gap: 1.15em; }

.demo-control {
  display: flex;
  align-items: baseline;
  gap: 10px 20px;
  flex-wrap: wrap;
}

.demo-label {
  flex: 0 0 auto;
  min-width: 8.5em;
  color: var(--ink-3);
  font-weight: 500;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
}

.demo-options {
  display: flex;
  gap: 8px 20px;
  flex-wrap: wrap;
  align-items: baseline;
}

.demo-opt {
  border: 0;
  background: none;
  padding: 0;
  color: var(--ink-3);
  font-family: inherit;
  font-weight: 500;
  font-size: 0.98rem;
  letter-spacing: -0.015em;
  line-height: 1.3;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  transition: color 140ms linear;
}
.demo-opt:hover { color: var(--ink-2); }
.demo-opt[aria-pressed="true"] {
  color: var(--ink);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
}

/* The one real action a demo ever has. */
.demo-run {
  border: 0;
  background: none;
  padding: 0;
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 140ms linear;
}
.demo-run:hover { opacity: 0.6; }
.demo-run[disabled] { opacity: 0.35; cursor: default; }

/* ---- Slider: a line you move a square along ---- */

.demo-slider {
  flex: 1 1 240px;
  min-width: 200px;
  appearance: none;
  -webkit-appearance: none;
  height: 22px;
  background: none;
  cursor: pointer;
}
.demo-slider::-webkit-slider-runnable-track {
  height: 2px;
  background: rgba(255, 255, 255, 0.25);
}
.demo-slider::-moz-range-track {
  height: 2px;
  background: rgba(255, 255, 255, 0.25);
}
.demo-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6px;
  border: 0;
  border-radius: 0;
  background: var(--ink);
}
.demo-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 0;
  background: var(--ink);
}
.demo-slider:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }

.demo-slider-value {
  flex: 0 0 auto;
  min-width: 6.5em;
  color: var(--ink);
  font-weight: 700;
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ---- Bars ---------------------------------------------------------
   A bar is a solid rule that happens to have a length.
   ------------------------------------------------------------------- */

.demo-bars { margin-top: 2.2em; display: grid; gap: 1.35em; }

.demo-bar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px 18px;
}

.demo-bar-name {
  color: var(--ink);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
}
.demo-bar-name .sub {
  color: var(--ink-3);
  font-weight: 500;
  letter-spacing: -0.01em;
}

.demo-bar-value {
  color: var(--ink);
  font-weight: 700;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.demo-bar-value .unit { color: var(--ink-3); font-weight: 500; }

.demo-track {
  position: relative;
  margin-top: 0.55em;
  height: 10px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.demo-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0;
  background: var(--ink);
}
.demo-fill.dim { background: rgba(255, 255, 255, 0.42); }

/* Bars that animate on a timer set their own width from script; bars
   that redraw on a control change may ease. */
.demo-fill.eased { transition: width 260ms var(--ease); }

/* A bar that can go negative grows out from a centre line. */
.demo-track.signed { background: none; }
.demo-track.signed::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.12);
}
.demo-track.signed::after {
  content: "";
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 50%;
  width: 2px;
  background: rgba(255, 255, 255, 0.45);
}
.demo-track.signed .demo-fill { left: 50%; }

/* ---- Readouts: the number the demo exists to show ---- */

.demo-readout {
  margin-top: 2.2em;
  display: grid;
  gap: 1.6em 2.6em;
  grid-template-columns: repeat(auto-fit, minmax(9.5em, 1fr));
}

.demo-stat { min-width: 0; }

.demo-stat-value {
  display: block;
  color: var(--ink);
  font-weight: 700;
  font-size: clamp(1.7rem, 3.4vw, 2.4rem);
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.demo-stat-value.dim { color: var(--ink-3); }
.demo-stat-value .unit {
  font-size: 0.5em;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink-3);
}

.demo-stat-label {
  display: block;
  margin-top: 0.55em;
  color: var(--ink-3);
  font-weight: 500;
  font-size: 0.88rem;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

/* The sentence a demo says about its current state. */
.demo-verdict {
  margin-top: 2em;
  padding-top: 1.4em;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--ink);
  font-weight: 500;
  font-size: 1.02em;
  line-height: 1.55;
  text-wrap: pretty;
  min-height: 3.1em;
}
.demo-verdict strong { font-weight: 700; }
.demo-verdict .quiet { color: var(--ink-3); font-weight: 500; }

/* ---- Interval plot: a point and the range around it ---- */

.demo-interval { margin-top: 2.2em; }

.demo-interval-scale {
  position: relative;
  height: 74px;
}

/* the 50% line */
.demo-interval-scale .chance {
  position: absolute;
  top: 0;
  bottom: 22px;
  width: 2px;
  background: rgba(255, 255, 255, 0.45);
}
.demo-interval-scale .chance-label {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  color: var(--ink-3);
  font-weight: 500;
  font-size: 0.85rem;
  white-space: nowrap;
}

.demo-interval-scale .band {
  position: absolute;
  top: 22px;
  height: 8px;
  background: rgba(255, 255, 255, 0.35);
  transition: left 240ms var(--ease), width 240ms var(--ease);
}
.demo-interval-scale .point {
  position: absolute;
  top: 14px;
  width: 2px;
  height: 24px;
  background: var(--ink);
  transition: left 240ms var(--ease);
}

.demo-axis {
  display: flex;
  justify-content: space-between;
  color: var(--ink-3);
  font-weight: 500;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* ---- Small table inside a demo ---- */

.demo-table {
  width: 100%;
  margin-top: 2em;
  border-collapse: collapse;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.demo-table th {
  text-align: left;
  padding: 0 1.4em 0.6em 0;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.01em;
  border-bottom: 2px solid rgba(255, 255, 255, 0.25);
  white-space: nowrap;
}
.demo-table td {
  padding: 0.7em 1.4em 0.7em 0;
  color: var(--ink-2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.demo-table tr:last-child td { border-bottom: 0; }
.demo-table .num { text-align: right; padding-right: 0; }
.demo-table tr[data-total] td { color: var(--ink); font-weight: 700; }
.demo-table td.name { color: var(--ink); font-weight: 500; }

/* ---- Ledger: a list of signed contributions that must sum ---- */

.demo-ledger { margin-top: 2em; display: grid; gap: 0.9em; }
.demo-ledger-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px 20px;
  padding-bottom: 0.9em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.demo-ledger-row:last-child { border-bottom: 0; }
.demo-ledger-row[data-total] {
  border-top: 2px solid rgba(255, 255, 255, 0.25);
  border-bottom: 0;
  padding-top: 0.9em;
  padding-bottom: 0;
}
.demo-ledger-name { color: var(--ink-2); font-weight: 500; font-size: 0.98rem; }
.demo-ledger-row[data-total] .demo-ledger-name { color: var(--ink); font-weight: 700; }
.demo-ledger-value {
  color: var(--ink);
  font-weight: 700;
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---- A grid of cells you can point at (the cost sensitivity grid) ---- */

.demo-grid-wrap { margin-top: 2em; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.demo-grid {
  border-collapse: collapse;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.demo-grid th {
  padding: 0 0.9em 0.6em;
  color: var(--ink-3);
  font-weight: 500;
  font-size: 0.85rem;
  white-space: nowrap;
}
.demo-grid th[scope="row"] { text-align: right; padding: 0.5em 0.9em 0.5em 0; }
.demo-grid td {
  padding: 0.5em 0.9em;
  text-align: right;
  color: rgba(255, 255, 255, 0.45);
  font-weight: 500;
  transition: color 140ms linear;
}
.demo-grid td[data-live="1"] {
  color: #000000;
  background: var(--ink);
  font-weight: 700;
}

/* ---- Mobile ---- */

@media (max-width: 720px) {
  .demo { margin-top: 2.8em; margin-bottom: 2.8em; }
  .demo-label { min-width: 100%; }
  .demo-control { gap: 6px 16px; }
  .demo-readout { gap: 1.4em 1.6em; grid-template-columns: repeat(auto-fit, minmax(7.5em, 1fr)); }
  .demo-stat-value { font-size: 1.5rem; }
  .demo-slider-value { min-width: 5em; }
}

/* Readers who asked for less motion get the end state, never the show. */
@media (prefers-reduced-motion: reduce) {
  .demo-fill,
  .demo-interval-scale .band,
  .demo-interval-scale .point { transition: none; }
}
