/* ============================================
   Stat figures — numbers inside case-study text
   An ink plate read like an instrument: one
   oversized figure, one scale, nothing else.
   ============================================ */

.stat-figure {
  /* Plate palette — same in light and dark, like the meta-rail ink plates */
  --stat-plate: var(--color-surface-ink);
  --stat-edge: var(--color-surface-ink-edge);
  --stat-ink: var(--color-mocha-1);
  --stat-muted: var(--color-mocha-3);
  --stat-faint: color-mix(in srgb, var(--color-mocha-1) 22%, transparent);
  --stat-ghost: color-mix(in srgb, var(--color-mocha-1) 9%, transparent);
  --stat-pad: var(--space-3);
  --stat-ruler-height: 2.25rem;
  --stat-figure-size: clamp(4rem, 6.4vw, 6rem);

  position: relative;
  margin: var(--space-2) 0;
  padding: var(--stat-pad);
  display: grid;
  gap: var(--space-2);
  min-width: 0;
  background: var(--stat-plate);
  border: 1px solid var(--stat-edge);
  border-radius: 0;
  color: var(--stat-ink);
  font-family: var(--font-body);
  letter-spacing: var(--tracking);
}

/* Sticky side panels share the viewport with copy: a denser plate */
.project-scrolly__panel .stat-figure {
  --stat-figure-size: clamp(3.75rem, 5vw, 4.75rem);
  --stat-ruler-height: 1.75rem;
  gap: 0.6rem;
}

[data-theme="dark"] .stat-figure {
  --stat-plate: color-mix(in srgb, var(--color-surface-ink) 88%, var(--color-mocha-5) 12%);
  --stat-edge: color-mix(in srgb, var(--color-border) 45%, transparent);
}

.project-scrolly__text + .stat-figure,
.stat-figure + .project-scrolly__text,
.project-scrolly__section-title + .stat-figure,
.stat-figure + .project-scrolly__section-title {
  margin-top: var(--space-2);
}

/* ---------- Head: what the scale measures ---------- */

.stat-figure__head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-xxs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--stat-muted);
  font-variant-numeric: tabular-nums;
}

.stat-figure__hint {
  font-weight: var(--weight-regular);
}

/* ---------- Body: the figure and what it means ---------- */

.stat-figure__body {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-3);
  align-items: end;
  min-width: 0;
}

.stat-figure__value-mask {
  overflow: hidden;
  /* room for descender-free numerals; keeps the reveal crisp */
  padding-top: 0.04em;
  margin-bottom: -0.06em;
}

.stat-figure__value {
  margin: 0;
  display: flex;
  align-items: flex-start;
  font-family: var(--font-display);
  font-size: var(--stat-figure-size);
  font-weight: var(--weight-light);
  letter-spacing: var(--tracking-display);
  line-height: 0.8;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--stat-ink);
  transform: translateY(105%);
  transition: transform 0.7s var(--ease-entrance);
}

.stat-figure.is-drawn .stat-figure__value {
  transform: none;
}

.stat-figure__unit {
  margin-left: 0.1em;
  padding-top: 0.06em;
  font-size: 0.3em;
  font-weight: var(--weight-regular);
  letter-spacing: var(--tracking);
  line-height: 1;
  color: var(--stat-muted);
}

.stat-figure__copy {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
  padding-bottom: 0.1rem;
}

.stat-figure__label {
  margin: 0;
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-snug);
  line-height: var(--leading-snug);
  color: var(--stat-ink);
  text-wrap: balance;
}

.stat-figure__detail {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  letter-spacing: var(--tracking-snug);
  line-height: var(--leading-snug);
  color: var(--stat-muted);
  min-height: calc(var(--text-sm) * var(--leading-snug) * 2);
  text-wrap: pretty;
}

.stat-figure__stage:empty,
.stat-figure__controls:empty {
  display: none;
}

.stat-figure__stage {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}

/* ---------- People: a 100-step ruler ---------- */

.stat-figure__ruler {
  position: relative;
  display: grid;
  grid-template-columns: repeat(100, minmax(0, 1fr));
  align-items: end;
  height: var(--stat-ruler-height);
  cursor: crosshair;
  touch-action: pan-y;
}

.stat-figure__mark {
  justify-self: center;
  width: 1px;
  height: 100%;
  background: var(--stat-faint);
  transform-origin: bottom;
  transform: scaleY(0.28);
  transition:
    transform 0.5s var(--ease-entrance),
    background-color 0.25s var(--ease-standard);
}

.stat-figure__mark.is-major {
  transform: scaleY(0.5);
}

.stat-figure.is-drawn .stat-figure__mark.is-on {
  background: var(--stat-ink);
  transform: scaleY(0.6);
  transition-delay: calc(var(--i, 0) * 6ms);
}

.stat-figure.is-drawn .stat-figure__mark.is-on.is-major {
  transform: scaleY(0.9);
}

.stat-figure__mark.is-hot,
.stat-figure.is-drawn .stat-figure__mark.is-hot {
  background: var(--stat-ink);
  transform: scaleY(1);
  transition-delay: 0s;
}

.stat-figure__mark:not(.is-on).is-hot {
  background: var(--stat-muted);
}

/* The cut: where the share ends */
.stat-figure__cut {
  position: absolute;
  left: var(--cut, 0%);
  bottom: 0;
  width: 2px;
  height: calc(100% + 0.4rem);
  margin-left: -1px;
  background: var(--stat-ink);
  transform-origin: bottom;
  transform: scaleY(0);
  transition: transform 0.45s var(--ease-entrance) 0.55s;
  pointer-events: none;
}

.stat-figure.is-drawn .stat-figure__cut {
  transform: scaleY(1);
}

.stat-figure__ends {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xxs);
  letter-spacing: var(--tracking);
  line-height: 1;
  color: var(--stat-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Seconds and count: cells in a row ---------- */

.stat-figure__track,
.stat-figure__bar {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cells, 12), minmax(0, 1fr));
  gap: 2px;
}

.stat-figure__cell,
.stat-figure__part {
  position: relative;
  display: flex;
  align-items: flex-end;
  height: var(--stat-ruler-height);
  padding: 0 0 0.3rem 0.3rem;
  border: 0;
  border-radius: 0;
  background: var(--stat-ghost);
  color: var(--stat-muted);
  font: inherit;
  transition:
    background-color 0.3s var(--ease-standard),
    color 0.3s var(--ease-standard);
}

.stat-figure__cell {
  cursor: pointer;
}

.stat-figure__cell:hover {
  background: var(--stat-faint);
}

.stat-figure__cell.is-on {
  background: var(--stat-ink);
  color: var(--stat-plate);
}

.stat-figure__cell.is-hot {
  box-shadow: inset 0 -3px 0 var(--stat-muted);
}

.stat-figure__cell-num {
  font-size: var(--text-xxs);
  letter-spacing: var(--tracking);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-figure.is-drawn .stat-figure__part {
  background: var(--stat-ink);
  color: var(--stat-plate);
  transition-delay: calc(var(--i, 0) * 40ms);
}

.stat-figure[data-alt].is-drawn .stat-figure__part {
  background: var(--stat-ghost);
  color: var(--stat-muted);
  transition-delay: 0s;
}

/* One day out of the whole year */
.stat-figure__slice {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: max(2px, var(--share, 0%));
  background: var(--stat-ink);
  opacity: 0;
  transition: opacity 0.3s var(--ease-standard);
}

.stat-figure__slice::after {
  content: "";
  position: absolute;
  top: -0.35rem;
  bottom: -0.35rem;
  left: 0;
  width: 1px;
  background: var(--stat-ink);
}

.stat-figure__slice-label {
  position: absolute;
  left: calc(100% + 0.5rem);
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-snug);
  line-height: 1;
  white-space: nowrap;
  color: var(--stat-ink);
}

.stat-figure[data-alt] .stat-figure__part .stat-figure__cell-num {
  opacity: 0;
}

.stat-figure[data-alt] .stat-figure__slice {
  opacity: 1;
  transition-delay: 0.15s;
}

/* ---------- Scale (single value between two ends) ---------- */

.stat-figure__scale {
  position: relative;
  height: var(--stat-ruler-height);
  cursor: crosshair;
  touch-action: pan-y;
  background: linear-gradient(var(--stat-faint), var(--stat-faint)) bottom / 100% 1px no-repeat;
}

.stat-figure__scale-fill {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 100%;
  width: var(--fill, 0%);
  background: var(--stat-ghost);
  border-right: 2px solid var(--stat-ink);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 0.7s var(--ease-entrance);
}

.stat-figure.is-drawn .stat-figure__scale-fill {
  transform: none;
}

/* ---------- Choice: two options side by side ---------- */

.stat-figure__choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
}

.stat-figure__choice {
  display: grid;
  gap: 0.25rem;
  align-content: start;
  padding: var(--space-2);
  border: 0;
  border-radius: 0;
  background: var(--stat-ghost);
  color: var(--stat-muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    background-color 0.25s var(--ease-standard),
    color 0.25s var(--ease-standard);
}

.stat-figure__choice:hover {
  background: var(--stat-faint);
}

.stat-figure__choice[aria-pressed="true"] {
  background: var(--stat-ink);
  color: var(--stat-plate);
}

.stat-figure__choice-value {
  /* the selected value is already the big figure above */
  display: none;
  font-size: var(--text-md);
  font-weight: var(--weight-light);
  letter-spacing: var(--tracking-display);
  line-height: 1;
}

.stat-figure__choice-label {
  font-size: var(--text-sm);
  letter-spacing: var(--tracking-snug);
  line-height: var(--leading-snug);
}

.stat-figure__choice-tag {
  font-size: var(--text-xxs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- Controls and tabs ---------- */

.stat-figure__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.stat-figure__control,
.stat-figure__tab {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  letter-spacing: var(--tracking-snug);
  line-height: 1.2;
  text-align: left;
  border-radius: 0;
  cursor: pointer;
  transition:
    background-color 0.2s var(--ease-standard),
    color 0.2s var(--ease-standard),
    box-shadow 0.2s var(--ease-standard);
}

.stat-figure__control {
  padding: 0.4rem 0.65rem;
  border: 0;
  background: var(--stat-ghost);
  color: var(--stat-muted);
}

.stat-figure__control:hover {
  color: var(--stat-ink);
}

.stat-figure__control[aria-pressed="true"] {
  background: var(--stat-ink);
  color: var(--stat-plate);
}

.stat-figure__tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  margin: 0 calc(var(--stat-pad) * -1) calc(var(--stat-pad) * -1);
  border-top: 1px solid var(--stat-faint);
}

.stat-figure__tab {
  padding: 0.6rem var(--stat-pad);
  border: 0;
  border-left: 1px solid var(--stat-faint);
  background: transparent;
  color: var(--stat-muted);
  font-variant-numeric: tabular-nums;
}

.stat-figure__tab:first-child {
  border-left: 0;
}

.stat-figure__tab:hover {
  color: var(--stat-ink);
}

.stat-figure__tab[aria-selected="true"] {
  background: var(--stat-ink);
  color: var(--stat-plate);
  font-weight: var(--weight-semibold);
}

.stat-figure__tab:focus-visible,
.stat-figure__control:focus-visible,
.stat-figure__cell:focus-visible,
.stat-figure__choice:focus-visible {
  outline: 1px solid var(--stat-ink);
  outline-offset: 2px;
  position: relative;
  z-index: 1;
}

/* ---------- Narrow screens ---------- */

@media (max-width: 768px) {
  .stat-figure {
    --stat-figure-size: clamp(3.75rem, 19vw, 5rem);
  }

  .stat-figure__body {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
  }

  .stat-figure__track .stat-figure__cell-num {
    display: none;
  }

  .stat-figure__track .stat-figure__cell:first-child .stat-figure__cell-num,
  .stat-figure__track .stat-figure__cell:last-child .stat-figure__cell-num {
    display: inline;
  }

  .stat-figure__choices {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stat-figure__value,
  .stat-figure__mark,
  .stat-figure__cut,
  .stat-figure__cell,
  .stat-figure__part,
  .stat-figure__slice,
  .stat-figure__scale-fill,
  .stat-figure__choice {
    transition: none;
  }
}
