/* FOOM STATS tab (src/ui/tabs/stats.js, stats_runs.js, src/ui/charts.js). Fluid: every width is a fraction of the panel
   (auto-fill grids, canvases sized from their box by ResizeObserver) — no fixed-px containers, no sideways scroll.
   Type: 16 titles · 24 big numbers · 12 small caps for labels, axes, legends. */

/* ---------- sticky range bar, hint, jump chips ---------- */
.st-bar { position: sticky; top: 0; z-index: 6; margin: 0 0 var(--sp-2); padding: 6px 8px; background: var(--surface);
  box-shadow: -12px 0 0 0 var(--bg), 12px 0 0 0 var(--bg), 0 -12px 0 0 var(--bg), 0 0 0 var(--px) var(--edge), 0 calc(2 * var(--px)) 0 0 var(--ink); }
.st-bar__row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.st-bar__l { font-family: var(--font-small); font-size: var(--fs-small); color: var(--muted); margin-right: 2px; }
.st-bar__live { margin-left: auto; font-family: var(--font-small); font-size: var(--fs-small); line-height: 12px; color: var(--dim); text-transform: uppercase; white-space: nowrap; }
.st-hint { margin: 0 var(--px) var(--sp-2); font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); color: var(--dim); text-transform: uppercase; text-wrap: balance; }
.st-nav { display: flex; gap: 4px; margin: 0 var(--px) var(--sp-2); overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.st-nav::-webkit-scrollbar { display: none; }
.st-nav .st-chip { flex: none; }
.st-sec { scroll-margin-top: 56px; min-width: 0; }
.st-sec .section { margin-top: var(--sp-4); }
.st-sec:first-of-type .section { margin-top: var(--sp-1); }

/* ---------- chips (range, legend, toggles) ---------- */
.st-chip { display: inline-flex; align-items: center; gap: 4px; min-height: 24px; padding: 4px 8px; max-width: 100%; background: var(--n2); color: var(--sky);
  font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); text-transform: uppercase; white-space: nowrap;
  box-shadow: inset 0 var(--px) 0 0 var(--n3), 0 var(--px) 0 0 var(--ink); }
.st-chip:active { translate: 0 var(--px); }
.st-chip.is-on { color: var(--ink); background: var(--gold); box-shadow: inset 0 var(--px) 0 0 var(--gold-hi), 0 var(--px) 0 0 var(--gold-0); }
.st-chip.is-off { opacity: .4; }
.st-chip__sw { display: inline-block; flex: none; width: 8px; height: 8px; box-shadow: 0 0 0 var(--px) var(--ink); }
.st-chip__l { overflow: hidden; text-overflow: ellipsis; }
.st-chip__v { color: var(--text-hi); font-weight: normal; font-variant-numeric: tabular-nums; }
.st-chip .px-icon { margin: -2px 0; }
.st-chips { display: flex; gap: 4px; margin-left: auto; flex: none; }

/* ---------- big-number tiles ---------- */
.st-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 148px), 1fr)); gap: var(--sp-2); margin: 0 var(--px) var(--sp-3); }
.gt-card.st-tile { margin: 0; padding: 8px 10px 6px; display: flex; flex-direction: column; gap: 2px; min-width: 0; --tc: var(--cyan); --pn-hi: var(--tc); --pn-hi-h: var(--px); }
.st-tile__l { font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); color: var(--muted); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-tile__v { display: flex; align-items: baseline; gap: 4px; min-width: 0; white-space: nowrap; overflow: hidden; }
.st-tile__n { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: var(--fs-big); line-height: calc(28px * var(--text-scale, 1)); color: var(--tc); text-shadow: var(--px) var(--px) 0 var(--ink); font-variant-numeric: tabular-nums; }
.st-tile__u { flex: none; font-family: var(--font-small); font-size: var(--fs-small); color: var(--dim); text-transform: uppercase; }
.st-tile__s { font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); color: var(--text-lo); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-tile__s:empty { display: none; }
.st-tile .st-chart { margin-top: 4px; }

/* ---------- chart cards ---------- */
.st-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: var(--sp-3); margin: 0 var(--px) var(--sp-3); align-items: start; }
.gt-card.st-card { margin: 0; padding: 10px 10px 8px; min-width: 0; }
.st-card--wide { grid-column: 1 / -1; }
.st-chart { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.st-chead { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-width: 0; }
.st-ctitle { flex: 1 1 auto; min-width: 0; color: var(--text-hi); line-height: 20px; white-space: normal; text-transform: uppercase; }
.st-csub { font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); color: var(--muted); text-transform: uppercase; text-wrap: balance; }
.st-chead .st-csub { flex: 1 0 100%; order: 3; margin-top: -2px; }
.st-card > .st-csub { margin-bottom: 6px; }
.st-plot { position: relative; line-height: 0; background: var(--ink); overflow: hidden;
  box-shadow: 0 calc(-1 * var(--px)) 0 0 var(--n3), 0 var(--px) 0 0 var(--n3), calc(-1 * var(--px)) 0 0 0 var(--n3), var(--px) 0 0 0 var(--n3), 0 calc(2 * var(--px)) 0 0 var(--ink); }
.st-plot--mini { box-shadow: none; background: transparent; }
.st-canvas { display: block; image-rendering: pixelated; max-width: 100%; }
.st-lbl { position: absolute; left: 4px; z-index: 1; font-family: var(--font-small); font-size: var(--fs-small); line-height: 12px; color: var(--n7); pointer-events: none; text-transform: uppercase;
  text-shadow: var(--px) var(--px) 0 var(--ink), calc(-1 * var(--px)) 0 0 var(--ink), 0 calc(-1 * var(--px)) 0 var(--ink); font-variant-numeric: tabular-nums; }
.st-lbl--hi { top: 4px; left: 4px; }
.st-lbl--lo { bottom: 4px; }
.st-ref { position: absolute; right: 4px; z-index: 1; font-family: var(--font-small); font-size: var(--fs-small); line-height: 12px; pointer-events: none; text-transform: uppercase;
  text-shadow: var(--px) var(--px) 0 var(--ink), calc(-1 * var(--px)) 0 0 var(--ink); }
.st-empty { display: none; position: absolute; inset: 0; z-index: 2; place-items: center; font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); letter-spacing: 1px; color: var(--dim); text-transform: uppercase; background: color-mix(in srgb, var(--ink) 55%, transparent); }
.st-empty.is-on { display: grid; }
.st-ax { display: flex; justify-content: space-between; gap: 8px; font-family: var(--font-small); font-size: var(--fs-small); line-height: 12px; color: var(--dim); text-transform: uppercase; }
.st-ax__c { color: var(--gold); text-align: center; }
.st-legend { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 2px; }
.st-legend.gt-hide { display: none; }
.st-chart--mini { gap: 0; }

/* ---------- users funnel ---------- */
.st-funnel { display: flex; flex-direction: column; gap: 6px; }
.st-fun { display: grid; grid-template-columns: minmax(64px, 30%) minmax(0, 1fr) auto 44px; align-items: center; gap: 8px; font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); text-transform: uppercase; }
.st-fun.gt-hide { display: none; }
.st-fun__l { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-fun__track { height: 10px; background: var(--ink); box-shadow: inset 0 var(--px) 0 0 #000, 0 0 0 var(--px) var(--n2); }
.st-fun__bar { display: block; height: 100%; width: 0; box-shadow: inset 0 var(--px) 0 0 rgba(255, 255, 255, .25); }
.st-fun__n { color: var(--text-hi); font-weight: normal; text-align: right; font-variant-numeric: tabular-nums; }
.st-fun__p { color: var(--dim); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- arena race board ---------- */
.st-race { display: flex; flex-direction: column; margin-top: 4px; }
.st-race__row { display: grid; grid-template-columns: 28px 18px minmax(0, 1fr) auto; align-items: center; gap: 6px; padding: 4px 0; box-shadow: inset 0 calc(-1 * var(--px)) 0 0 var(--n2);
  font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); text-transform: uppercase; }
.st-race__rk { color: var(--dim); font-variant-numeric: tabular-nums; }
.st-race__ic { display: grid; place-items: center; width: 16px; height: 16px; }
.st-race__mid { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.st-race__nm { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-race__track { height: 5px; background: var(--ink); }
.st-race__bar { display: block; height: 100%; width: 8%; transition: width .4s steps(8); }
.st-race__e { color: var(--text-hi); font-variant-numeric: tabular-nums; text-align: right; min-width: 32px; }
.st-race__row.is-you .st-race__nm, .st-race__row.is-you .st-race__rk, .st-race__row.is-you .st-race__e { color: var(--gold); }

/* ---------- records ---------- */
.st-recs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 148px), 1fr)); gap: var(--sp-2); margin: 0 var(--px) var(--sp-3); }
.gt-card.st-rec { margin: 0; padding: 8px 10px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.st-rec--hi { --pn-edge: var(--gold-1); --pn-hi: var(--gold); --pn-hi-h: 4px; --pn-bg: color-mix(in srgb, var(--gold-0) 14%, var(--surface)); grid-column: 1 / -1; }
.st-rec--fun { --pn-hi: var(--mag); }
.st-rec__l { font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); color: var(--muted); text-transform: uppercase; }
.st-rec__v { display: flex; align-items: baseline; gap: 4px; min-width: 0; font-size: var(--fs-big); line-height: calc(28px * var(--text-scale, 1)); color: var(--gold); text-shadow: var(--px) var(--px) 0 var(--gold-0); overflow: hidden; white-space: nowrap; font-variant-numeric: tabular-nums; }
.st-rec__v > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.st-rec__u { flex: none; font-family: var(--font-small); font-size: var(--fs-small); color: var(--dim); text-shadow: none; text-transform: uppercase; }
.st-rec--hi .st-rec__v { font-size: var(--fs-huge); line-height: calc(36px * var(--text-scale, 1)); }
.st-rec--fun .st-rec__v { color: var(--lav); text-shadow: var(--px) var(--px) 0 var(--space); }
.st-rec__s { font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); color: var(--text-lo); text-transform: uppercase; min-height: calc(14px * var(--text-scale, 1)); overflow: hidden; text-overflow: ellipsis; }
.st-splits { margin: 0 var(--px) var(--sp-3); display: flex; flex-direction: column; gap: 2px; }
.st-split { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 8px; align-items: baseline; padding: 3px 0; box-shadow: inset 0 calc(-1 * var(--px)) 0 0 var(--n2);
  font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); text-transform: uppercase; color: var(--dim); }
.st-split b { color: var(--text-hi); font-weight: normal; }
.st-split__n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.st-split__b.is-pb { color: var(--phos); }

/* ---------- training-run archive ---------- */
.st-runs { display: flex; flex-direction: column; gap: var(--sp-3); }
.st-runs > .gt-card { margin: 0 var(--px); }
.st-runs > .st-grid { margin: 0 var(--px); }
.st-fit { font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); color: var(--cyan); text-transform: none; word-break: break-word; }
.st-ramp { display: flex; align-items: center; gap: 2px; font-family: var(--font-small); font-size: var(--fs-small); line-height: 12px; color: var(--dim); text-transform: uppercase; }
.st-ramp span { margin: 0 4px; }
.st-ramp i { display: block; width: 14px; height: 6px; }
.st-runcard .st-ctitle { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.st-runlist { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.st-run { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto auto auto; gap: 8px; align-items: center; min-height: 28px; padding: 2px 6px; text-align: left;
  font-family: var(--font-small); font-size: var(--fs-small); line-height: calc(14px * var(--text-scale, 1)); text-transform: uppercase; color: var(--text-lo); background: var(--n1);
  box-shadow: inset 0 calc(-1 * var(--px)) 0 0 var(--n2); }
.st-run b { color: var(--text-hi); font-weight: normal; font-variant-numeric: tabular-nums; }
.st-run__n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.st-run.is-on { background: var(--n2); box-shadow: inset var(--px) 0 0 0 var(--gold), inset 0 calc(-1 * var(--px)) 0 0 var(--n3); }
.st-run__p, .st-run__t { color: var(--dim); }
@media (max-width: 380px) { .st-run__t { display: none; } .st-run { grid-template-columns: 8px minmax(0, 1fr) auto auto; } }

/* wide panels: bigger plots get more height */
@container panel (min-width: 700px) {
  .st-tiles { grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); }
}
