/* Daam charts: receipt ink, thin rules, no gridline clutter. Pairs with charts.js.
   Colours come only from the tokens in styles.css, so light, dark and .night all work.
   Motion: bars rest at scale 0 and marks at opacity 0 until the chart root or an
   ancestor has class "in". --ch-delay on any wrapper staggers a whole group. */

.ch {
  font-family: var(--mono);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.ch-empty { margin: 0; padding: 14px 0; text-align: center; font-size: 12px; color: var(--ink-2); }
.ch-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

/* ---------- Shared plot ---------- */
.ch-plot { position: relative; height: var(--ch-h, 64px); border-bottom: 1px solid var(--rule); }
.ch-cols { display: flex; height: 100%; }
.ch-slot { position: relative; flex: 1 1 0; min-width: 0; height: 100%; }
.ch-bar {
  position: absolute; bottom: 0; left: 1px; right: 1px; /* 2px gap between neighbours */
  max-width: 24px; margin: 0 auto;
  height: max(2px, calc(var(--ch-v, 0) * 100%));
  background: var(--ink-2);
  opacity: .6;
  border-radius: 2px 2px 0 0;
  transform: scaleY(0);
  transform-origin: 50% 100%;
  transition: transform .62s var(--ease);
  transition-delay: calc(var(--ch-delay, 0ms) + var(--ch-i, 0) * 18ms);
}
.ch-bar.ch-hi { background: var(--stamp); opacity: 1; }
.ch-bar.ch-mid { background: var(--sahi); opacity: 1; }
.in .ch-bar { transform: none; }

.ch-fx { opacity: 0; transition: opacity .32s var(--ease); transition-delay: calc(var(--ch-delay, 0ms) + 420ms); }
.in .ch-fx { opacity: 1; }

/* "You" caret: the same mark in every chart */
.ch-marks { position: relative; height: 10px; }
.ch-you {
  position: absolute; top: 3px; width: 0; height: 0; margin-left: -4px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-bottom: 6px solid var(--stamp);
}
.ch-tick { position: absolute; top: 0; width: 1px; height: 3px; margin-left: -.5px; background: var(--rule); }

.ch-axis { position: relative; height: 13px; font-size: 9.5px; line-height: 13px; letter-spacing: .04em; color: var(--ink-2); }
.ch-axis span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.ch-axis .ch-l { transform: none; }
.ch-axis .ch-r { transform: translateX(-100%); }
.ch-axis .ch-mid { color: var(--ink); }

/* ---------- Score histogram ---------- */
.ch-hist { --ch-h: 72px; padding-top: 6px; }
.ch-avg { position: absolute; z-index: 1; top: -6px; bottom: 0; width: 1px; margin-left: -.5px; background: var(--ink); }
.ch-key { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.ch-key span { display: inline-flex; align-items: center; gap: 6px; }
.ch-key b { color: var(--ink); font-weight: 600; letter-spacing: 0; }
.ch-key .ch-k-you { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 6px solid var(--stamp); }
.ch-key .ch-k-avg { width: 1px; height: 11px; background: var(--ink); }
.ch-hist .ch-key { transition-delay: calc(var(--ch-delay, 0ms) + 520ms); }

/* Coarse: five wide bars of 100 points */
.ch-coarse .ch-bar { left: 3px; right: 3px; max-width: 64px; }

/* ---------- Dot strip (small crowds) ---------- */
.ch-dots { --ch-step: 9px; padding-top: 4px; }
.ch-dots .ch-plot { height: calc(var(--ch-rows, 1) * var(--ch-step) + 6px); }
.ch-dot {
  position: absolute; z-index: 1;
  bottom: calc(var(--ch-r, 0) * var(--ch-step) + 2px);
  width: 7px; height: 7px; margin-left: -3.5px;
  border-radius: 50%;
  background: var(--ink-2);
  transform: scale(0);
  transition: transform .42s var(--spring);
  transition-delay: calc(var(--ch-delay, 0ms) + var(--ch-i, 0) * 22ms);
}
.ch-dot-you {
  z-index: 2; bottom: -1px;
  width: 11px; height: 11px; margin-left: -5.5px;
  background: var(--stamp);
  box-shadow: 0 0 0 1.5px var(--slip);
  transition-delay: calc(var(--ch-delay, 0ms) + var(--ch-i, 0) * 22ms + 120ms);
}
.in .ch-dot { transform: none; }
.ch-dots .ch-marks { height: 20px; }
.ch-dot-avg { position: absolute; top: -7px; width: 1px; height: 11px; margin-left: -.5px; background: var(--ink); }
.ch-dot-al, .ch-dot-yl {
  position: absolute; top: 6px;
  font-size: 9.5px; line-height: 12px; letter-spacing: .04em; white-space: nowrap;
  transform: translateX(-50%);
}
.ch-dot-al { color: var(--ink); }
.ch-dot-al.ch-low { top: 19px; }
.ch-dots-2 .ch-marks { height: 33px; }
.ch-dot-yl { font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--stamp); }
.ch-dots .ch-l { transform: translateX(-3px); }
.ch-dots .ch-r { transform: translateX(calc(3px - 100%)); }
.ch-dots .ch-to-l { transform: translateX(calc(-100% - 5px)); }
.ch-dots .ch-to-r { transform: translateX(5px); }
.ch-dots .ch-axis .ch-l { transform: none; }
.ch-dots .ch-axis .ch-r { transform: translateX(-100%); }
.ch-dots .ch-fx { transition-delay: calc(var(--ch-delay, 0ms) + 520ms); }

/* ---------- Item line (small crowds) ---------- */
.ch-il {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 7ch 15ch;
  align-items: baseline;
  column-gap: 10px;
  padding: 7px 0;
  font-size: 12px;
  opacity: 0; transform: translateY(4px);
  transition: opacity .28s var(--ease), transform .28s var(--ease);
  transition-delay: calc(var(--ch-delay, 0ms) + var(--ch-i, 0) * 50ms);
}
.in.ch-il { opacity: 1; transform: none; }
.ch-il + .ch-il { border-top: 1px dotted var(--rule); }
.ch-il .ch-item-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-il-avg { text-align: right; font-size: 10.5px; letter-spacing: .04em; color: var(--ink-2); white-space: nowrap; }
.ch-il-avg b { font-size: 13px; font-weight: 600; color: var(--ink); letter-spacing: 0; }
.ch-il-vs { text-align: right; font-size: 10.5px; color: var(--ink-2); white-space: nowrap; }
.ch-il-vs b { font-weight: 600; color: var(--ink); }
.ch-il-vs.ch-up b { color: var(--sahi); }
.ch-il-vs.ch-down b { color: var(--copper-text); }

/* ---------- Item ratio strip ---------- */
.ch-item {
  --ch-h: 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.5ch;
  grid-template-areas: "h h" "p a" "m a" "x .";
  column-gap: 14px;
}
.ch-item-h { grid-area: h; display: flex; gap: 8px; min-width: 0; margin-bottom: 5px; font-size: 12px; }
.ch-item-n { flex: none; color: var(--ink-2); }
.ch-item-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-item .ch-plot { grid-area: p; }
.ch-item .ch-marks { grid-area: m; height: 9px; }
.ch-item .ch-axis { grid-area: x; }
.ch-item .ch-you { top: 2px; }
.ch-item-avg { grid-area: a; align-self: center; display: flex; flex-direction: column; align-items: flex-end; line-height: 1; }
.ch-item-avg b { font-size: 15px; font-weight: 600; }
.ch-item-avg small { margin-top: 3px; font-size: 9px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.ch-item .ch-bar { transition-delay: calc(var(--ch-delay, 0ms) + var(--ch-row, 0) * 70ms + var(--ch-i, 0) * 14ms); }
.ch-item .ch-fx { transition-delay: calc(var(--ch-delay, 0ms) + var(--ch-row, 0) * 70ms + 300ms); }

/* ---------- Leaderboard ---------- */
.ch-lb { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.ch-lb-row {
  display: flex; align-items: baseline; gap: 8px;
  margin: 0 -8px; padding: 7px 8px;
  border-radius: 2px;
  opacity: 0; transform: translateY(4px);
  transition: opacity .28s var(--ease), transform .28s var(--ease);
  transition-delay: calc(var(--ch-delay, 0ms) + var(--ch-i, 0) * 32ms);
}
.in .ch-lb-row { opacity: 1; transform: none; }
.ch-lb-row + .ch-lb-row, .ch-lb-gap + .ch-lb-row { border-top: 1px dotted var(--rule); }
.ch-lb-r { flex: none; min-width: 2ch; color: var(--ink-2); }
.ch-lb-n { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 6px; }
.ch-lb-n > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-lb-n > .ch-anon { color: var(--ink-2); }
.ch-lb-n::after { content: ""; flex: 1; min-width: 8px; border-bottom: 1px dotted var(--ink-2); opacity: .5; transform: translateY(-3px); }
.ch-lb-you { flex: none; font-size: 9.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--stamp); }
.ch-lb-p { flex: none; font-size: 11px; color: var(--ink-2); }
.ch-lb-t { flex: none; min-width: 3ch; text-align: right; font-weight: 600; }
.ch-lb-row.ch-top .ch-lb-r { color: var(--copper-text); font-weight: 600; }
.ch-lb-row.ch-me { background: var(--paper-2); box-shadow: inset 2px 0 0 var(--stamp); }
.ch-lb-row.ch-me, .ch-lb-row.ch-me + .ch-lb-row { border-top-color: transparent; }
.ch-lb-gap { height: 16px; display: flex; align-items: center; justify-content: center; color: var(--ink-2); font-size: 11px; letter-spacing: .3em; }
.ch-lb-gap::before { content: "···"; }

/* ---------- Personal history ---------- */
.ch-history {
  --ch-h: 48px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 8px;
  padding-top: 16px; /* headroom for the latest value */
}
.ch-history .ch-plot { grid-column: 2; border-top: 1px solid var(--rule); }
.ch-history .ch-axis { grid-column: 2; margin-top: 4px; }
.ch-history .ch-bar { transition-delay: calc(var(--ch-delay, 0ms) + var(--ch-i, 0) * 24ms); }
.ch-scale { grid-column: 1; grid-row: 1; position: relative; width: 3ch; height: var(--ch-h); font-size: 9px; line-height: 1; color: var(--ink-2); }
.ch-scale span { position: absolute; right: 0; transform: translateY(-50%); }
.ch-scale-t { top: 0; }
.ch-scale-b { top: 100%; }
.ch-val {
  position: absolute; right: 0; width: calc(100% / 14);
  bottom: calc(var(--ch-v, 0) * 100% + 3px);
  display: flex; justify-content: center;
  font-size: 10.5px; font-weight: 600; line-height: 1; white-space: nowrap;
}
.ch-history .ch-val { transition-delay: calc(var(--ch-delay, 0ms) + 520ms); }

/* ---------- KPI tiles ---------- */
.ch-kpis {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(var(--ch-n, 3), minmax(0, 1fr));
  border-top: 1px dashed var(--rule);
  border-bottom: 1px dashed var(--rule);
}
.ch-kpi {
  min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px 11px;
  opacity: 0; transform: translateY(4px);
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  transition-delay: calc(var(--ch-delay, 0ms) + var(--ch-i, 0) * 70ms);
}
.in .ch-kpi { opacity: 1; transform: none; }
.ch-kpi:first-child { padding-left: 0; }
.ch-kpi:last-child { padding-right: 0; }
.ch-kpi + .ch-kpi { border-left: 1px dashed var(--rule); }
.ch-kpi-l { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-kpi-v {
  font-size: 26px; font-size: clamp(20px, 7.4cqi, 32px);
  font-weight: 600; line-height: 1.05; letter-spacing: 0; white-space: nowrap;
  font-variant-numeric: normal;
}
.ch-kpis-one .ch-kpi { flex-direction: row; align-items: baseline; justify-content: space-between; padding: 12px 0; }
.ch-kpis-one .ch-kpi-l { font-size: 10.5px; }
.ch-kpi-v small { margin-left: 2px; font-size: 12px; font-weight: 500; color: var(--ink-2); letter-spacing: 0; }

/* ---------- Laptop ---------- */
@media (min-width: 900px) {
  .ch-hist { --ch-h: 96px; }
  .ch-history { --ch-h: 56px; }
  .ch-item { --ch-h: 24px; }
  .ch-dot { width: 8px; height: 8px; margin-left: -4px; }
  .ch-dot-you { width: 12px; height: 12px; margin-left: -6px; }
}

/* ---------- Reduced motion: everything shows at once, with or without "in" ---------- */
@media (prefers-reduced-motion: reduce) {
  .ch .ch-bar, .ch .ch-dot { transform: none; transition: none; }
  .ch .ch-fx, .ch-lb-row, .ch-kpi { opacity: 1; transition: none; }
  .ch-lb-row, .ch-kpi, .ch-il { transform: none; }
  .ch-il { opacity: 1; transition: none; }
}
:root[data-motion="fast"] .ch .ch-bar,
:root[data-motion="fast"] .ch .ch-dot { transform: none; transition: none; }
:root[data-motion="fast"] .ch .ch-fx,
:root[data-motion="fast"] .ch-lb-row,
:root[data-motion="fast"] .ch-kpi,
:root[data-motion="fast"] .ch-il { opacity: 1; transition: none; }
:root[data-motion="fast"] .ch-lb-row,
:root[data-motion="fast"] .ch-kpi,
:root[data-motion="fast"] .ch-il { transform: none; }

/* ---------- Forced colours: keep marks visible ---------- */
@media (forced-colors: active) {
  .ch-bar, .ch-avg, .ch-tick, .ch-key .ch-k-avg, .ch-dot, .ch-dot-avg { forced-color-adjust: none; background: CanvasText; opacity: 1; }
  .ch-dot-you { background: Highlight; }
  .ch-bar.ch-hi, .ch-bar.ch-mid { background: Highlight; }
  .ch-you, .ch-key .ch-k-you { forced-color-adjust: none; border-bottom-color: Highlight; }
  .ch-lb-row.ch-me { outline: 1px solid Highlight; }
}
