/* ==========================================================================
   VotingSite · statistics pages (/stats, /server/:slug/stats, owner analytics)
   Companion to style.css: reuses its tokens (--bg, --panel, --border, --text,
   --muted, --accent, --gold, --cyan, --danger, --r) and its dark/light themes.
   No images, no fonts, no JS.
   ========================================================================== */

/* ------------------------------------------------------------- page head -- */
.st-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.st-head-txt { min-width: 0; }
.st-head h1 { margin-bottom: 4px; }
.st-head p { margin: 0; font-size: .9rem; max-width: 70ch; }

.st-section {
  font-size: 1.05rem;
  margin: 22px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-soft, var(--border));
}

/* ------------------------------------------------------------- range pills */
.st-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.st-pills a {
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 600;
  font-size: .82rem;
  line-height: 1;
  white-space: nowrap;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.st-pills a:hover { color: var(--text); border-color: var(--muted); text-decoration: none; }
.st-pills a.active {
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 65%, #000);
  color: var(--accent-ink, #06170a);
}
.st-pills-sm a { padding: 5px 10px; font-size: .76rem; }

/* -------------------------------------------------------------- KPI tiles -- */
.st-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: var(--gap, 16px);
}
.st-kpis-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.st-kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}
/* A tile carrying a sparkline reserves the strip the sparkline occupies. The
   sparkline is absolutely positioned, so without this it painted straight
   through "vs previous period" and "peak 48,398". */
.st-kpi:has(.st-spark) { padding-bottom: 32px; }
.st-kpi .k-label {
  /* line-height:1 clipped the uppercase label's own line box, so its glyphs
     bled into the big number below it. The display font used by .k-value
     overflows its box in the other direction, and 4px of gap was not enough
     for the two to miss each other. */
  font: 600 .68rem/1.4 var(--font, system-ui);
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
}
.st-kpi .k-value {
  font-family: var(--font-display, inherit);
  font-size: 1.45rem;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.st-kpi .k-foot {
  position: relative;   /* stays above the sparkline whatever its height */
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: .76rem;
  line-height: 1.4;
  min-height: 1em;
}
.st-kpi .st-spark {
  position: absolute;
  right: 0; bottom: 0;
  width: 58%;
  height: 26px;
  color: var(--accent);
  opacity: .35;
  pointer-events: none;
}
.st-kpi.t-danger .k-value { color: var(--danger); }
.st-kpi.t-gold .k-value { color: var(--gold); }
.st-kpi.t-cyan .k-value { color: var(--cyan); }

/* ----------------------------------------------------------- delta arrows -- */
.st-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 700;
  font-size: .74rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border: 1px solid transparent;
}
.st-delta.up {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
}
.st-delta.down {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border-color: color-mix(in srgb, var(--danger) 32%, transparent);
}
.st-delta.flat {
  color: var(--muted);
  background: color-mix(in srgb, var(--muted) 12%, transparent);
  border-color: var(--border);
}

/* ------------------------------------------------------------ chart cards -- */
.st-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap, 16px);
  margin-bottom: var(--gap, 16px);
}
.st-grid-side { grid-template-columns: 1.4fr 1fr; }
.st-wide { margin-bottom: var(--gap, 16px); }

.st-card { margin: 0; min-width: 0; }
.st-card > .card-title { margin-bottom: 10px; }
.st-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.st-card-head .card-title { margin: 0; }
.st-foot { font-size: .78rem; margin: 10px 0 0; }

.st-chart { margin: 0; min-width: 0; }
.st-chart-cap {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: .8rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.st-chart-cap .muted { font-weight: 400; font-size: .74rem; }

.st-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.st-empty {
  display: grid;
  place-items: center;
  min-height: 120px;
  border: 1px dashed var(--border);
  border-radius: var(--r);
  color: var(--muted);
  font-size: .85rem;
  text-align: center;
  padding: 12px;
}

/* --------------------------------------------------------- chart internals -- */
.st-gridline { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.st-axis-line { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.st-axis { fill: var(--muted); font: 10px var(--font, system-ui); }
.st-area { fill: currentColor; fill-opacity: .13; stroke: none; }
.st-line-path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
/* The bucket that has not finished yet. Dashed and half-strength, so a period
   that is four hours old does not read as a crash next to whole days. */
.st-line-path.st-partial {
  stroke-dasharray: 4 4;
  opacity: .55;
}
.st-pt.is-partial .st-bar-r { fill-opacity: .3; stroke: currentColor; stroke-dasharray: 3 2; }
.st-pt.is-partial:hover .st-bar-r,
.st-pt.is-partial:focus .st-bar-r { fill-opacity: .55; }

.st-bar-r { fill: currentColor; fill-opacity: .72; transition: fill-opacity .12s ease; }
.st-bar-lbl { fill: var(--text); }
.st-bar-val { fill: var(--muted); font-size: 10px; }

/* one <g> per point: transparent hit area reveals dot, guide and tooltip */
.st-hit { fill: transparent; }
.st-guide { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0; }
.st-dot {
  fill: var(--bg);
  stroke: currentColor;
  stroke-width: 2;
  opacity: 0;
}
.st-tip { opacity: 0; pointer-events: none; }
.st-tip-bg {
  fill: var(--panel-2, var(--panel));
  stroke: var(--border);
  stroke-width: 1;
}
.st-tip-tx { fill: var(--text); font: 600 10px var(--font, system-ui); }

.st-pt { outline: none; }
.st-pt:hover .st-tip,
.st-pt:focus .st-tip,
.st-pt:focus-within .st-tip { opacity: 1; }
.st-pt:hover .st-dot,
.st-pt:focus .st-dot { opacity: 1; }
.st-pt:hover .st-guide,
.st-pt:focus .st-guide { opacity: .5; }
.st-pt:hover .st-bar-r,
.st-pt:focus .st-bar-r { fill-opacity: 1; }
.st-pt:focus .st-tip-bg { stroke: currentColor; }

/* ---------------------------------------------------------------- heatmap -- */
.st-chart.st-heat { overflow-x: auto; }
.st-heat .st-svg { min-width: 430px; }
.st-cell {
  fill: currentColor;
  stroke: transparent;
  stroke-width: 1;
  transition: stroke .12s ease;
  outline: none;
}
.st-cell:hover, .st-cell:focus { stroke: var(--text); }
.st-heat-key {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  font-size: .7rem;
}
.st-heat-key i {
  width: 13px;
  height: 13px;
  border-radius: 2px;
  background: var(--accent);
  display: inline-block;
}

/* -------------------------------------------------------------- sparkline -- */
.st-spark {
  display: inline-block;
  width: 84px;
  height: 22px;
  vertical-align: middle;
  color: var(--accent);
}
.st-spark-empty {
  display: inline-block;
  width: 84px;
  height: 1px;
  border-top: 1px dashed var(--border);
  vertical-align: middle;
}

/* ------------------------------------------------------------------ donut -- */
.st-donut .st-svg { max-width: 190px; margin: 0 auto; }
.st-arc {
  stroke-width: var(--sw, 20);
  transition: stroke-width .12s ease;
  outline: none;
}
.st-arc:hover, .st-arc:focus { stroke-width: var(--swh, 24); }
.st-arc-empty { stroke: var(--border); }
.st-donut-c {
  fill: var(--text);
  font: 700 20px var(--font-display, var(--font, system-ui));
  font-variant-numeric: tabular-nums;
}
.st-donut-s { fill: var(--muted); font: 10px var(--font, system-ui); }

.st-legend { list-style: none; margin: 12px 0 0; padding: 0; }
.st-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: .82rem;
  border-bottom: 1px solid var(--border-soft, var(--border));
}
.st-legend li:last-child { border-bottom: 0; }
.st-legend i { width: 10px; height: 10px; border-radius: 2px; flex: 0 0 auto; }
.st-legend span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-legend b { font-variant-numeric: tabular-nums; }
.st-legend em { color: var(--muted); font-style: normal; font-size: .74rem; min-width: 34px; text-align: right; }

/* ------------------------------------------------------------ leaderboard -- */
/* The metric pills navigate to `?metric=…#leaderboard`, so this section is the
   :target on arrival. Stated explicitly rather than relying on the generic
   `main :target` rule, because the offset has to clear the sticky header
   whether or not this section stays inside <main>. */
.st-board-section { scroll-margin-top: 78px; }

.st-board td, .st-mini td { font-variant-numeric: tabular-nums; }
.st-board .srv-name { display: block; }
.st-board .st-sub { display: block; font-size: .74rem; text-transform: capitalize; }
.st-board .st-trend { width: 100px; color: var(--accent); }
.st-board td.is-metric { color: var(--text); font-weight: 700; }
.st-board tr.is-active { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.st-mini th, .st-mini td { padding: 8px 10px; font-size: .86rem; }

/* Top voters. The medal used to be painted on the <td> itself, so the cell's
   own 8px/10px padding was inside the "circle" · it rendered as a 64x57 ellipse
   and made the first three rows half again as tall as rows 4-10. The medal is
   now an inner <span class="rank-num">, the same element the main ranking table
   uses; here it is scaled down to suit 0.86rem body text. */
/* Same defect on the site-wide leaderboard: rows there are two lines tall
   (server name + game), which stretched the td-painted medal into a very
   obvious oval. Inner span here too, at the board's own scale. */
.st-board td.rank, .st-mini td.rank { width: 1%; white-space: nowrap; }
.st-board .rank-num { min-width: 32px; width: 32px; height: 32px; font-size: 1rem; }

.st-mini td.rank { width: 1%; white-space: nowrap; }
.st-mini .rank-num {
  min-width: 26px;
  width: 26px;
  height: 26px;
  font-size: .85rem;
}
.st-mini .rank-num.rank-1,
.st-mini .rank-num.rank-2,
.st-mini .rank-num.rank-3 {
  font-size: .8rem;
  /* No padding-top nudge here any more: the optical centring for the display
     font is now expressed once, in em, on .rank-num in style.css. A flat 1px
     was never going to hold across the 26px, 32px and 40px medal sizes. */
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .28), 0 0 8px rgba(0, 0, 0, .25);
}

/* ------------------------------------------------------------ facts/funnel -- */
.st-facts { list-style: none; margin: 0; padding: 0; }
.st-facts li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-soft, var(--border));
  font-size: .86rem;
}
.st-facts li:last-child { border-bottom: 0; }
.st-facts span { color: var(--muted); }
.st-facts b { font-variant-numeric: tabular-nums; }

.st-funnel { list-style: none; margin: 0; padding: 0; }
.st-funnel li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 10px;
  padding: 8px 0;
}
.st-funnel .f-label { font-size: .82rem; color: var(--muted); }
.st-funnel b { font-variant-numeric: tabular-nums; grid-row: 1; }
.st-funnel .f-bar {
  grid-column: 1 / -1;
  height: 10px;
  width: var(--pct, 0%);
  min-width: 3px;
  border-radius: 999px;
  background: var(--accent);
}
.st-funnel .f-b { background: var(--cyan); }
.st-funnel .f-c { background: var(--gold); }

/* ------------------------------------------------------------- responsive -- */
@media (max-width: 980px) {
  .st-grid, .st-grid-side { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .st-head { align-items: flex-start; }
  .st-pills { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .st-kpis, .st-kpis-4 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .st-board .st-trend { display: none; }
  .st-legend li { font-size: .78rem; }
}
@media (max-width: 420px) {
  .st-kpis, .st-kpis-4 { grid-template-columns: 1fr 1fr; gap: 8px; }
  .st-kpi { padding: 10px 11px 9px; }
  .st-kpi .k-value { font-size: 1.2rem; }
  .st-kpi .st-spark { display: none; }
  .st-head h1 { font-size: 1.5rem; }
  .st-pills a { padding: 6px 10px; font-size: .78rem; }
  .st-donut .st-svg { max-width: 160px; }
}
@media (max-width: 360px) {
  .st-kpis, .st-kpis-4 { grid-template-columns: 1fr; }
  .st-heat .st-svg { min-width: 380px; }
}

/* ------------------------------------------------------------ light theme -- */
html[data-theme="light"] .st-area { fill-opacity: .16; }
html[data-theme="light"] .st-bar-r { fill-opacity: .82; }
html[data-theme="light"] .st-cell { stroke: #fff; }
html[data-theme="light"] .st-cell:hover,
html[data-theme="light"] .st-cell:focus { stroke: var(--text); }
html[data-theme="light"] .st-tip-bg { fill: var(--bg-elev, #fff); }
html[data-theme="light"] .st-kpi .st-spark { opacity: .5; }
html[data-theme="light"] .st-dot { fill: #fff; }

/* ------------------------------------------------------- motion and print -- */
@media (prefers-reduced-motion: reduce) {
  .st-pills a, .st-bar-r, .st-arc, .st-cell { transition: none; }
}
@media print {
  .st-pills, .st-heat-key { display: none; }
  .st-card, .st-kpi { break-inside: avoid; border-color: #999; }
  .st-tip { display: none; }
}
