/* The /stats dashboard. Colours: a validated categorical order (blue, orange,
   aqua, yellow), a one-hue blue ramp for the retention grid, and separate steps
   for dark mode. Text never wears a series colour. */
:root {
  color-scheme: light;
  --page: #f9f9f9; --card: #ffffff; --ink: #191919; --soft: #666666; --line: #e7e7e7; --base: #c2c2c2;
  --track: #efefef; --ring: rgba(11, 11, 11, 0.1);
  --s1: #257de0; --s2: #f47230; --s3: #00b894; --s4: #f2a600; --muted: #c2c2c2;
  --good: #006c10; --bad: #b42b2c;
  --h1: #cce3fd; --h2: #9dc8f7; --h3: #6aabf1; --h4: #338ced; --h5: #1b64be; --h-ink: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b; --card: #191919; --ink: #efefef; --soft: #9c9c9c; --line: #303030; --base: #474747;
    --track: #262626; --ring: rgba(255, 255, 255, 0.1);
    --s1: #338ced; --s2: #e76624; --s3: #00a888; --s4: #d28e05; --muted: #5a5a5a;
    --good: #53c556; --bad: #eb6263;
    --h1: #0f2f5c; --h2: #0f4a96; --h3: #1b64be; --h4: #338ced; --h5: #84b9f3; --h-ink: #0b0b0b;
  }
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--page); color: var(--ink); }
main { max-width: 76rem; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
a { color: inherit; }
h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { margin: 0 0 0.15rem; font-size: 1.05rem; }
h3 { margin: 1.25rem 0 0.5rem; font-size: 0.95rem; }
.sub { margin: 0 0 0.9rem; color: var(--soft); font-size: 0.85rem; }
.note { color: var(--soft); font-size: 0.82rem; }
h2.group { margin: 2.2rem 0 0.7rem; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--soft); }

.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 0.75rem; }
.top .sub { margin: 0.2rem 0 0; }
nav { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--card); }
nav a { padding: 0.35rem 0.85rem; border-radius: 999px; color: var(--soft); text-decoration: none; font-size: 0.88rem; white-space: nowrap; }
nav a:hover { background: var(--track); }
nav a[aria-current] { background: var(--ink); color: var(--card); }

/* Tiles: one hero, five more. */
.tiles { display: grid; grid-template-columns: 1.6fr repeat(5, 1fr); gap: 0.6rem; margin: 1.25rem 0 0; }
.tile { margin: 0; background: var(--card); border: 1px solid var(--ring); border-radius: 12px; padding: 0.85rem 0.95rem 0.7rem; display: flex; flex-direction: column; min-width: 0; }
.tile dt { color: var(--soft); font-size: 0.82rem; }
.tile dd { margin: 0; }
.tile .value { font-size: 1.75rem; font-weight: 600; line-height: 1.2; margin-top: 0.15rem; }
.tile.hero .value { font-size: 3.2rem; line-height: 1.05; }
.tile .note { margin-top: 0.3rem; font-size: 0.76rem; line-height: 1.35; }
.tile .spark-wrap { margin-top: auto; padding-top: 0.5rem; }
.spark { display: block; width: 100%; height: 28px; }
.spark .line { stroke-width: 1.5; }
.delta { display: inline-block; margin-top: 0.2rem; font-size: 0.78rem; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.delta.flat { color: var(--soft); }

/* Cards. */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.card { background: var(--card); border: 1px solid var(--ring); border-radius: 14px; padding: 1rem 1.1rem 1.1rem; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.story { margin-top: 0.75rem; }
.story ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }
.story li { margin: 0.3rem 0; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 1.5rem; align-items: start; }

/* Time charts: marks stretch, text doesn't. */
.chart { margin: 0; }
.plot { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 170px; gap: 0.5rem; }
.yaxis { display: flex; flex-direction: column; justify-content: space-between; font-size: 0.72rem; color: var(--soft); text-align: right; font-variant-numeric: tabular-nums; line-height: 1; margin: -0.3em 0; min-width: 1.6rem; }
.marks { width: 100%; height: 170px; overflow: visible; display: block; }
.xaxis { display: flex; justify-content: space-between; margin: 0.35rem 0 0 2.1rem; font-size: 0.72rem; color: var(--soft); }
.grid { stroke: var(--line); stroke-width: 1; }
.base { stroke: var(--base); stroke-width: 1; }
.slot { fill: transparent; }
.hit { outline: none; }
.hit.on .slot, .hit:focus-visible .slot { fill: var(--ring); }
.cross { stroke: var(--soft); stroke-width: 1; opacity: 0; }
.hit.on .cross, .hit:focus-visible .cross { opacity: 1; }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area { stroke: none; opacity: 0.1; }

/* Series colours, for fills and strokes alike. */
rect.s1, polygon.s1 { fill: var(--s1); }
rect.s2, polygon.s2 { fill: var(--s2); }
rect.s3, polygon.s3 { fill: var(--s3); }
rect.s4, polygon.s4 { fill: var(--s4); }
rect.muted { fill: var(--muted); }
.key.box.s1 { background: var(--s1); }
.key.box.s2 { background: var(--s2); }
.key.box.s3 { background: var(--s3); }
.key.box.s4 { background: var(--s4); }
.key.box.muted { background: var(--muted); }
.line.s1 { stroke: var(--s1); }
.line.s2 { stroke: var(--s2); }
.line.s3 { stroke: var(--s3); }
.key.line.s1 { border-color: var(--s1); }
.key.line.s2 { border-color: var(--s2); }
.key.line.s3 { border-color: var(--s3); }
.track { fill: var(--track); }

.legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; list-style: none; margin: 0.7rem 0 0; padding: 0; font-size: 0.8rem; color: var(--soft); }
.legend li { display: flex; align-items: center; gap: 0.4rem; }
.key { display: inline-block; flex: none; }
.key.box { width: 10px; height: 10px; border-radius: 3px; }
.key.line { width: 14px; height: 0; border-top: 2px solid; border-radius: 2px; }

/* Ranked bars and funnels. */
.bars, .funnel, .facts { list-style: none; margin: 0; padding: 0; }
.bars li, .funnel li { display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 1rem; padding: 0.35rem 0.25rem; margin: 0 -0.25rem; border-radius: 6px; outline: none; }
.bars li.on, .funnel li.on, .bars li:focus-visible, .funnel li:focus-visible { background: var(--track); }
.bars svg, .funnel svg { grid-column: 1 / -1; display: block; }
.bars strong, .funnel strong { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-label { font-size: 0.9rem; }
.bar-note { grid-column: 1 / -1; font-size: 0.76rem; color: var(--soft); order: 3; }
.funnel li { margin-bottom: 0.25rem; }
.funnel em { font-style: normal; font-size: 0.72rem; color: var(--bad); border: 1px solid currentColor; border-radius: 999px; padding: 0 0.4rem; margin-left: 0.35rem; white-space: nowrap; }
.facts { margin-top: 1rem; }
.facts li { padding: 0.35rem 0; border-top: 1px solid var(--line); font-size: 0.86rem; color: var(--soft); }
.facts strong { color: var(--ink); font-weight: 600; margin-right: 0.2rem; }

.segmented { display: block; margin-top: 0.2rem; }
.segmented g { outline: none; }
.segmented g.on rect, .segmented g:focus-visible rect { opacity: 0.8; }

.mini { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin: 0; }
.mini > div { border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.75rem; }
.mini dt { font-size: 0.8rem; color: var(--soft); }
.mini dd { margin: 0.1rem 0 0; font-size: 1.35rem; font-weight: 600; }
.mini dd.note { font-size: 0.74rem; font-weight: 400; line-height: 1.35; }

/* Retention grid. */
.cohort td.heat { text-align: center; font-size: 0.8rem; border-bottom: 2px solid var(--card); border-right: 2px solid var(--card); outline: none; padding: 0.38rem 0.5rem; }
.cohort td.none { border-bottom-color: transparent; }
.h0 { background: var(--track); color: var(--soft); }
.h1 { background: var(--h1); }
.h2 { background: var(--h2); }
.h3 { background: var(--h3); }
.h4 { background: var(--h4); color: var(--h-ink); }
.h5 { background: var(--h5); color: var(--h-ink); }
.cohort td.partial { outline: 1.5px dashed var(--base); outline-offset: -3px; }
.cohort td.on, .cohort td:focus-visible { box-shadow: inset 0 0 0 2px var(--ink); }

/* Tables. */
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 0.86rem; }
th, td { padding: 0.38rem 0.6rem 0.38rem 0; border-bottom: 1px solid var(--line); text-align: right; font-weight: 400; white-space: nowrap; }
thead th { font-weight: 600; color: var(--soft); font-size: 0.78rem; }
th:first-child { text-align: left; }
details.data { margin-top: 0.6rem; }
details.data summary { font-size: 0.78rem; color: var(--soft); cursor: pointer; }
details.data table { margin-top: 0.4rem; }
details.all { margin-top: 2rem; border-top: 1px solid var(--line); padding-top: 1rem; }
details.all summary { cursor: pointer; font-weight: 600; }
.foot { margin-top: 2rem; max-width: 52rem; }

/* Tooltip. */
.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--card); color: var(--ink); border: 1px solid var(--ring); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14); border-radius: 8px; padding: 0.45rem 0.6rem; font-size: 0.8rem; line-height: 1.45; max-width: 18rem; }
.tip[hidden] { display: none; }
.tip-head { color: var(--soft); font-size: 0.75rem; margin-bottom: 0.1rem; }
.tip strong { font-variant-numeric: tabular-nums; font-weight: 600; }

@media (max-width: 64rem) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .tile.hero { grid-column: 1 / -1; }
}
@media (max-width: 46rem) {
  .cards, .split { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .mini { grid-template-columns: 1fr; }
  nav a { padding: 0.35rem 0.6rem; }
  .plot { grid-template-rows: 150px; }
  .marks { height: 150px; }
}
@media (forced-colors: active) {
  rect.s1, rect.s2, rect.s3, rect.s4, rect.muted { fill: CanvasText; }
  .line { stroke: CanvasText; }
}
.first { margin-top: 0; }
.bars + .chart { margin-top: 1.25rem; }
.cohort td.unknown { background: transparent; color: var(--soft); }
line.deploy { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 4 3; opacity: 0.7; pointer-events: none; }
