/* Interactive modules: controls, ledgers, grids, and the page patterns that
 * hold them. Everything here uses semantic tokens only, so a module dropped
 * onto the dark field is correct without modification. */

/* Controls ---------------------------------------------------------------- */

.control + .control {
  margin-block-start: 1.15rem;
}

.control__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-block-end: 0.3rem;
}

.control__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}

.control__value {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  flex: 0 0 auto;
}

/* Wide enough for the largest value any control carries with separators
 * ("50,000,000"), because a readout that truncates to "1,000,0" is worse than
 * no readout at all. */
.control__number {
  width: 11ch;
  padding: 0.2rem 0.35rem;
  text-align: end;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums lining-nums;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
}

/* Spinners cost width and offer nothing a slider does not already do. */
.control__number::-webkit-outer-spin-button,
.control__number::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.control__number {
  appearance: textfield;
}

.control__unit {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.control__hint {
  margin-block-start: 0.3rem;
  font-size: var(--text-xs);
  line-height: 1.45;
  color: var(--text-muted);
  max-width: 46ch;
}

.control__group-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  padding-block-end: 0.4rem;
  border-block-end: 1px solid var(--rule);
  margin-block: 1.6rem 0.9rem;
}

/* The track is deliberately tall: this has to be draggable with a thumb. */
.control__range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1.75rem;
  background: transparent;
  cursor: pointer;
  margin: 0;
}

.control__range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--rule);
}

.control__range::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--rule);
}

.control__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-block-start: -9px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}

.control__range::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
}

.control__range:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 4px;
  border-radius: var(--radius);
}

/* Presets ----------------------------------------------------------------- */

.preset {
  border: 0;
  padding: 0;
  margin: 0 0 1.25rem;
}

.preset__legend {
  padding: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  margin-block-end: 0.5rem;
}

.preset__options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.preset__option {
  position: relative;
}

.preset__input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.preset__label {
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0.4rem 0.9rem;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}

/* Selection is carried by fill and weight, not by hue alone. */
.preset__input:checked + .preset__label {
  color: var(--surface);
  background: var(--accent);
  border-color: var(--accent);
}

[data-surface="dark"] .preset__input:checked + .preset__label {
  color: var(--void);
}

.preset__input:focus-visible + .preset__label {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.preset__label:hover {
  background: var(--surface-sunken);
}

.preset__input:checked + .preset__label:hover {
  background: var(--accent-strong);
}

/* Copy link --------------------------------------------------------------- */

/* Spans the control grid rather than taking a cell in the middle of it. */
.copy {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-block-start: 1.75rem;
}

.copy__status {
  font-size: var(--text-xs);
  color: var(--text-muted);
  word-break: break-all;
}

/* Stats ------------------------------------------------------------------- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(9.5rem, 100%), 1fr));
  gap: 1.25rem 1.5rem;
  margin-block: 1.25rem;
}

.stat__note {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Model layout ------------------------------------------------------------ */

.model__controls {
  display: grid;
  min-width: 0;
  gap: 0 2.5rem;
  grid-template-columns: repeat(auto-fit, minmax(min(17rem, 100%), 1fr));
  align-items: start;
}

.model__controls--inline {
  margin-block-end: 1.5rem;
}

.model__panels {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(min(19rem, 100%), 1fr));
  margin-block: 2.5rem 1rem;
}

.model__panel {
  min-width: 0;
  overflow-x: auto;
  padding: 1.25rem 1.35rem 1rem;
  background: var(--surface-sunken);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
}

/* Ledger ------------------------------------------------------------------ */

.ledger {
  font-size: var(--text-sm);
}

.ledger__caption {
  text-align: start;
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--text);
  padding-block-end: 0.6rem;
}

.ledger th {
  font-weight: 400;
  color: var(--text);
}

.ledger__row--top th,
.ledger__row--top td {
  font-weight: 600;
}

.ledger__note {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.ledger__row--total th,
.ledger__row--total td {
  font-weight: 600;
  font-size: var(--text-base);
  border-block-end: 0;
  padding-block-start: 0.7rem;
}

/* The zero goods line is marked as an absence, never as a win. */
.ledger__row--absent th,
.ledger__row--absent td {
  color: var(--text-muted);
}

.ledger__row--absent th::after {
  content: " — absent";
  font-weight: 600;
  color: var(--accent);
}

/* AMM working ------------------------------------------------------------- */

.working,
.translation {
  margin-block-start: 1.75rem;
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  background: var(--surface-sunken);
}

.working__title,
.translation__title {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-block-end: 0.75rem;
}

.working__list,
.translation__list {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1.25rem;
  font-size: var(--text-sm);
}

.working__list dt {
  color: var(--text-muted);
  white-space: nowrap;
}

.working__list dd {
  margin: 0;
  font-variant-numeric: tabular-nums lining-nums;
}

.translation__list dt {
  font-weight: 600;
}

.translation__list dd {
  margin: 0;
  color: var(--text-muted);
  max-width: 56ch;
}

@media (max-width: 34rem) {
  .working__list,
  .translation__list {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .working__list dd,
  .translation__list dd {
    margin-block-end: 0.6rem;
  }
}

/* Funnel ------------------------------------------------------------------ */

.funnel__stage {
  font-size: var(--text-sm);
  font-weight: 600;
  fill: var(--text);
  font-family: var(--font-sans);
}

.funnel__value {
  font-size: var(--text-sm);
  fill: var(--text);
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums lining-nums;
}

.funnel__rate {
  font-size: var(--text-xs);
  fill: var(--text-muted);
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums lining-nums;
}

.funnel__bar--dtc {
  fill: var(--series-dtc);
}

.funnel__bar--token {
  fill: var(--series-token);
}

.funnel__rates {
  grid-column: 1 / -1;
}

/* Cohort grid ------------------------------------------------------------- */

.grid__header {
  font-size: var(--text-xs);
  fill: var(--text-muted);
  font-family: var(--font-sans);
}

.grid__value {
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums lining-nums;
  pointer-events: none;
}

.grid__cell {
  cursor: default;
}

.grid__cell:hover rect,
.grid__cell:focus-visible rect {
  stroke: var(--text);
  stroke-width: 2;
}

.grid__cell:focus {
  outline: none;
}

.grid__readout {
  min-height: 2.5em;
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: var(--measure);
}

/* Concentration ----------------------------------------------------------- */

.series--equality {
  stroke: var(--rule-strong);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
}

.equality-label {
  font-size: var(--text-xs);
  fill: var(--text-muted);
  font-family: var(--font-sans);
  text-anchor: middle;
}

.concentration__reading {
  margin-block-start: 1.5rem;
  max-width: var(--measure);
}

.concentration__line {
  font-size: var(--text-md);
  line-height: 1.55;
}

.concentration__line--quiet {
  margin-block-start: 0.9rem;
  font-size: var(--text-base);
  color: var(--text-muted);
}

.zero-line {
  stroke: var(--rule-strong);
  stroke-width: 1.5;
}

.axis__label {
  font-size: var(--text-xs);
  fill: var(--text-muted);
}

/* Static fallback --------------------------------------------------------- */

/* The markup ships a readable table; the module replaces it. If the module
 * never mounts, this is what remains, and it is not a blank space. */
[data-module][data-mounted="failed"] .fallback__note {
  display: block;
}

.fallback__note {
  display: none;
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* Reading progress -------------------------------------------------------- */

.progress {
  position: sticky;
  inset-block-start: 3.5rem;
  z-index: 40;
  background: var(--surface);
}

.progress__bar {
  height: 3px;
  background: var(--rule);
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  background: var(--accent);
  transform-origin: 0 50%;
  transform: scaleX(0);
}

.contents {
  padding-block: 1.25rem 0.5rem;
}

.contents__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  margin-block-end: 0.5rem;
}

.contents__list {
  margin: 0;
  padding: 0;
  list-style: none;
  columns: 2;
  column-gap: 2rem;
  font-size: var(--text-sm);
}

.contents__link {
  display: block;
  padding-block: 0.28rem;
  color: var(--text-muted);
  text-decoration: none;
  break-inside: avoid;
}

.contents__link:hover {
  color: var(--accent);
}

/* Current section is marked by weight and a rule, not by colour alone. */
.contents__link.is-current {
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
  padding-inline-start: 0.6rem;
}

@media (max-width: 40rem) {
  .contents__list {
    columns: 1;
  }
}

/* Where one order goes ----------------------------------------------------- */

/* The site's claim as one picture. Runs once on entering view; never loops. */
.split__stage {
  margin-block: 1.5rem 0.5rem;
}

.split__svg {
  width: 100%;
  height: auto;
  overflow: visible;
  display: block;
}

/* The three columns beneath the drawing, aligned to where the arcs land. */
.split__legend {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem 1rem;
  margin-block-start: 0.5rem;
  text-align: center;
}

.split__column {
  min-width: 0;
}

.split__apex {
  fill: var(--text-muted);
}

.split__arc {
  fill: none;
  stroke: var(--rule);
  stroke-width: 1;
}

.split__dot {
  opacity: 0;
}

/* Settled is the resting state, and it is also what a reduced-motion reader
 * gets immediately -- the figures are the information and are never withheld
 * behind an animation. */
.split[data-state="settled"] .split__dot {
  opacity: 1;
}

.split[data-state="running"] .split__dot {
  animation: split-dot-in 420ms var(--ease) forwards;
  animation-delay: calc(var(--i, 0) * 34ms);
}

@keyframes split-dot-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.split__dot--goods {
  fill: var(--series-dtc);
}

.split__dot--running {
  fill: var(--text-muted);
}

.split__dot--kept {
  fill: var(--series-token);
}

.split__value {
  font-size: clamp(2rem, 1.2rem + 3.2vw, 3.2rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--text);
}

.split__value--kept {
  color: var(--series-token);
}

.split__caption {
  font-family: var(--font-mono);
  font-size: clamp(0.68rem, 0.55rem + 0.5vw, 0.82rem);
  line-height: 1.35;
  color: var(--text-muted);
  margin-block-start: 0.2rem;
  text-wrap: balance;
}

.split__note {
  max-width: var(--measure);
  font-size: var(--text-md);
  line-height: 1.55;
  color: var(--text);
  margin-block-start: 1rem;
}

@media (prefers-reduced-motion: reduce) {
  .split[data-state="running"] .split__dot {
    animation: none;
    opacity: 1;
  }
}



/* The finding ------------------------------------------------------------- */

/* Each model states what it demonstrates before it offers any controls. A
 * module that shows only mechanism is a dashboard, not an argument. */
.verdict {
  max-width: var(--measure);
  margin-block: 0.5rem 1.75rem;
  padding-inline-start: 1rem;
  border-inline-start: 3px solid var(--accent);
}

.verdict__line {
  font-size: var(--text-md);
  line-height: 1.55;
  color: var(--text);
}

.verdict__line strong {
  font-weight: 600;
}

.verdict__line--quiet {
  margin-block-start: 0.7rem;
  font-size: var(--text-base);
  color: var(--text-muted);
}

/* Assumptions are available, not imposed: the reader sees the answer first. */
.assumptions {
  margin-block-start: 2rem;
  border-block-start: 1px solid var(--rule);
  padding-block-start: 0.5rem;
}

.assumptions > summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--accent);
  padding-block: 0.6rem;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
}

.assumptions > summary:hover {
  color: var(--accent-strong);
}

.assumptions[open] > summary {
  margin-block-end: 1rem;
}
