/* Stats tab. Colours come only from the custom properties in styles.css, so the
   light, dark and forced themes all work. Player colours are set inline. */

.stats-view { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.stats-view .card-head { align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.stats-view .card h3 { margin: 28px 0 10px; }
.st-sub { display: block; font-size: 0.8rem; font-weight: 400; color: var(--muted); line-height: 1.35; }
.st-note { margin: 14px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; max-width: 68ch; }
.st-lead { font-weight: 700; }
.st-scroll { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.st-wide { display: none; }
@media (min-width: 560px) {
  .st-wide { display: table-cell; }
  .st-narrow { display: none; }
}
@media (min-width: 720px) { .stats-view { gap: 20px; } }

/* ---- Filters ---- */
.st-filters { display: grid; gap: 12px; padding-top: 14px; padding-bottom: 14px; }
.st-filter-row { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.st-presets { display: flex; flex: 1 1 100%; }
.st-presets button { flex: 1; padding: 6px 8px; white-space: nowrap; transition: background-color 140ms, color 140ms, box-shadow 140ms; }
.st-presets button:hover { color: var(--text); }
.st-field { flex: 1 1 120px; min-width: 0; }
.st-field-game { flex: 1 1 100%; }
.st-field > span { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.st-field input, .st-field select { width: 100%; }
.st-scope { flex: 1 1 100%; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 0; margin: 0; font-size: 0.875rem; color: var(--muted); }
.st-scope strong { color: var(--text); }
.st-scope > span::before { content: "·"; margin: 0 8px; opacity: 0.6; }
.st-link {
  margin-left: auto; padding: 4px 0 4px 12px; border: 0; background: none; cursor: pointer;
  color: var(--accent); font-size: 0.875rem; font-weight: 600; text-decoration: underline; text-underline-offset: 2px;
}
.st-link:hover { text-decoration-thickness: 2px; }
@media (min-width: 720px) {
  .st-presets { flex: 0 1 auto; }
  .st-presets button { padding: 6px 14px; }
  .st-filter-row { align-items: center; }
  .st-filter-row + .st-filter-row { align-items: end; }
  .st-field { flex: 0 1 180px; }
  .st-field-game { flex: 1 1 200px; }
  .st-scope { flex: 1 1 240px; justify-content: flex-end; }
  .st-link { margin-left: 14px; padding-left: 0; }
}

/* ---- Tiles and highlights ---- */
.st-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .st-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.st-tile { gap: 2px; align-content: start; padding: 14px 16px; }
.st-tile .tile-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.st-tile .tile-value { font-size: 2.1rem; line-height: 1.15; font-variant-numeric: normal; }
.st-tile-sub { font-size: 0.8rem; color: var(--muted); line-height: 1.35; }

.st-highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px 24px; }
.st-hl { display: flex; align-items: center; gap: 12px; min-width: 0; }
.st-hl-text { display: grid; min-width: 0; }
.st-hl-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; color: var(--muted); }
.st-hl-main { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-hl-main .muted { font-family: var(--font-body); font-size: 0.8rem; font-weight: 400; }
.st-hl-sub { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.st-pair { display: inline-flex; flex: none; }
.st-pair .st-avatar { width: 34px; height: 34px; font-size: 0.8rem; }
.st-pair .st-avatar + .st-avatar { margin-left: -10px; box-shadow: 0 0 0 2px var(--surface); }

/* ---- People and games ---- */
.st-avatar { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 14%, transparent); }
.st-avatar.sm { width: 26px; height: 26px; font-size: 0.7rem; }
.st-avatar.lg { width: 56px; height: 56px; font-size: 1.25rem; }
.st-player { display: flex; align-items: center; gap: 10px; min-width: 0; }
.st-player-name { font-weight: 600; }
.st-mono { flex: none; }

/* ---- Tables ---- */
.st-table { white-space: nowrap; }
.st-table th, .st-table td { padding: 10px 8px; vertical-align: middle; }
.st-table th:first-child, .st-table td:first-child { padding-left: 0; }
.st-table th:last-child, .st-table td:last-child { padding-right: 0; }
.st-table tbody tr { transition: background-color 120ms; }
.st-table tbody tr:hover { background: color-mix(in srgb, var(--text) 3.5%, transparent); }
.st-table tbody th { font-weight: 400; }
.st-compact { margin-top: 16px; }
.st-compact th, .st-compact td { padding-top: 7px; padding-bottom: 7px; font-size: 0.92rem; }

.st-board .st-rank-col { width: 34px; padding-right: 4px; }
.st-rank {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  font-size: 0.85rem; font-weight: 700; color: var(--muted);
}
.st-rank.first { color: var(--text); box-shadow: inset 0 0 0 2px var(--gold); }
.st-idle { color: var(--muted); }
.st-idle .st-avatar { opacity: 0.55; }
.st-streak { font-weight: 600; }
.st-streak.hot {
  display: inline-block; min-width: 1.9em; padding: 0 8px; border-radius: 999px; text-align: center;
  background: var(--accent-soft); color: var(--text); font-weight: 700;
}

/* Win-rate meter: a figure, so both ends are round */
.st-rate { display: flex; align-items: center; gap: 10px; min-width: 96px; }
.st-rate-track { flex: 1; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.st-rate-track .st-bar { border-radius: 999px; }
.st-rate-value { width: 2.8em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- Bars: wins per player ---- */
.st-bar { display: block; height: 100%; min-width: 0; border-radius: 0 4px 4px 0; }
.st-bars { display: grid; gap: 2px; }
.st-bar-row {
  display: grid; grid-template-columns: minmax(0, 6.5em) 1fr 4.2em; align-items: center; gap: 12px;
  padding: 7px 8px; margin: 0 -8px; border-radius: 8px; transition: background-color 120ms;
}
.st-bar-row:hover, .st-bar-row:focus-visible { background: color-mix(in srgb, var(--text) 4.5%, transparent); }
.st-bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.st-bar-plot { display: block; height: 14px; border-left: 1px solid var(--border-strong); }
.st-bar-track { display: block; height: 100%; min-width: 3px; border-radius: 0 4px 4px 0; background: var(--surface-2); }
.st-bar-value { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.st-bar-value .muted { font-size: 0.85rem; }

/* ---- Time charts: shared frame ---- */
.st-chart {
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 176px auto;
  column-gap: 8px; padding-top: 22px;
}
.st-yaxis { position: relative; min-width: 1.4em; }
.st-yaxis span {
  position: absolute; right: 0; transform: translateY(50%);
  font-size: 0.72rem; line-height: 1; color: var(--muted); font-variant-numeric: tabular-nums;
}
.st-plot { position: relative; border-radius: 4px; }
.st-plot:focus-visible { outline-offset: 6px; }
.st-grid { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--border); }
.st-grid.base { border-top-color: var(--border-strong); }
.st-xaxis { grid-column: 2; display: flex; padding-top: 6px; }
.st-xaxis span {
  flex: 1 1 0; min-width: 0; text-align: center; white-space: nowrap;
  font-size: 0.72rem; line-height: 1.3; color: var(--muted); min-height: 2.6em;
}
.st-xaxis b { display: block; font-weight: 600; color: var(--text); }

/* Columns: plays per month */
.st-cols { position: absolute; inset: 0; display: flex; }
.st-col {
  flex: 1 1 0; min-width: 0; display: flex; align-items: flex-end; justify-content: center;
  border-radius: 6px 6px 0 0; transition: background-color 120ms;
}
.st-col:hover, .st-col:focus-visible { background: color-mix(in srgb, var(--text) 5%, transparent); }
.st-col-bar {
  position: relative; width: 62%; max-width: 24px; min-height: 3px;
  border-radius: 4px 4px 0 0; background: var(--accent); transition: filter 120ms;
}
.st-col:hover .st-col-bar, .st-col:focus-visible .st-col-bar { filter: brightness(1.12) saturate(1.1); }
.st-col-bar b {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); padding-bottom: 3px;
  font-size: 0.75rem; line-height: 1; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums;
}

/* Lines: running wins */
.st-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.st-lines polyline {
  fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.st-end {
  position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%;
  box-shadow: 0 0 0 2px var(--surface); pointer-events: none;
}
.st-cross { position: absolute; top: -6px; bottom: 0; width: 1px; margin-left: -0.5px; background: var(--border-strong); pointer-events: none; }
[data-race] { cursor: crosshair; touch-action: pan-y; }
.st-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: -4px 0 4px; padding: 0; list-style: none; font-size: 0.875rem; }
.st-legend li { display: inline-flex; align-items: center; gap: 7px; }
.st-legend i { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.st-legend b { font-variant-numeric: tabular-nums; }

/* ---- Tooltip ---- */
.st-tip {
  position: fixed; z-index: 40; left: 0; top: 0; pointer-events: none;
  min-width: 132px; max-width: min(260px, calc(100vw - 16px)); padding: 9px 11px; border-radius: 10px;
  background: var(--text); color: var(--surface);
  font-size: 0.8rem; line-height: 1.45; box-shadow: 0 6px 20px rgb(0 0 0 / 0.22);
}
.st-tip-title { margin-bottom: 3px; font-weight: 600; opacity: 0.75; }
.st-tip-row { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.st-tip-row span { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.st-tip-row i { width: 10px; height: 3px; border-radius: 2px; flex: none; }
.st-tip-row b { font-variant-numeric: tabular-nums; }

/* ---- Head to head ---- */
.st-duel { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; }
.st-duel-side { display: grid; justify-items: center; gap: 8px; min-width: 0; }
.st-duel-side label { width: 100%; max-width: 170px; }
.st-duel-side select { width: 100%; text-align: center; text-align-last: center; font-weight: 600; }
.st-duel-score { font-family: var(--font-display); font-size: 2.6rem; font-weight: 700; line-height: 1; }
.st-duel-mid { display: grid; justify-items: center; gap: 2px; padding: 0 4px; text-align: center; max-width: 9.5em; }
.st-verdict { font-weight: 650; line-height: 1.25; }
.st-split { display: flex; gap: 2px; height: 10px; margin-top: 18px; border-radius: 999px; overflow: hidden; }
.st-split-seg { flex: 1 1 0; min-width: 6px; }
.st-split-seg.tie { background: var(--border-strong); opacity: 0.55; }

.st-matrix { width: auto; min-width: 100%; }
.st-matrix thead th { text-align: center; padding-bottom: 8px; text-transform: none; letter-spacing: 0; }
.st-matrix thead td { border: 0; }
.st-matrix thead .st-avatar { display: grid; margin: 0 auto 4px; }
.st-matrix-name { display: block; max-width: 5.5em; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; font-size: 0.78rem; color: var(--text); }
.st-matrix td, .st-matrix thead th {
  text-align: center; padding-left: 8px; padding-right: 8px;
  font-variant-numeric: tabular-nums; min-width: 3.6em; transition: background-color 120ms;
}
.st-matrix tbody tr:hover { background: none; }
.st-matrix td[data-tip]:hover { background: color-mix(in srgb, var(--text) 7%, transparent); cursor: default; }
.st-matrix .st-h2h-up { background: var(--accent-soft); font-weight: 700; }
.st-matrix .st-h2h-up[data-tip]:hover { background: color-mix(in srgb, var(--accent) 26%, var(--surface)); }
.st-h2h-down, .st-h2h-none { color: var(--muted); }
.st-h2h-self { background: var(--surface-2); }

/* ---- Game records ---- */
.st-game-head { align-items: center; }
.st-inline select { max-width: min(60vw, 260px); }
.st-game { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.st-game-name { display: block; font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; line-height: 1.25; }
.st-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; margin-bottom: 8px; }
.st-facts:empty { display: none; }
.st-fact { display: grid; align-content: start; gap: 1px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.st-fact-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; color: var(--muted); }
.st-fact-value { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-fact-value small { font-family: var(--font-body); font-size: 0.85rem; font-weight: 500; color: var(--muted); }

/* ---- Favourites ---- */
.st-favs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.st-fav { display: grid; gap: 12px; align-content: start; padding: 14px; border: 1px solid var(--border); border-radius: 12px; }
.st-fav dl { display: grid; gap: 10px; margin: 0; }
.st-fav dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; color: var(--muted); }
.st-fav dd { margin: 0; font-weight: 600; }

/* ---- Empty states ---- */
.st-empty-inline { padding: 8px 8px 4px; }
.st-empty-inline p { max-width: 44ch; }
.st-empty-art {
  display: flex; align-items: flex-end; justify-content: center; gap: 5px;
  width: 84px; height: 72px; padding: 14px 14px 16px; margin-bottom: 6px;
  border-radius: 20px; background: var(--accent-soft); transform: rotate(-4deg);
}
.st-empty-art i { flex: 1; border-radius: 3px 3px 0 0; background: var(--accent); opacity: 0.35; }
.st-empty-art i:nth-child(1) { height: 35%; }
.st-empty-art i:nth-child(2) { height: 60%; }
.st-empty-art i:nth-child(3) { height: 45%; }
.st-empty-art i:nth-child(4) { height: 80%; opacity: 0.6; }
.st-empty-art i:nth-child(5) { height: 100%; opacity: 1; }

/* ---- Narrow screens ---- */
@media (max-width: 520px) {
  .st-table th, .st-table td { padding-left: 5px; padding-right: 5px; }
  .st-rate { min-width: 72px; gap: 6px; }
  .st-board .st-rate { min-width: 0; }
  .st-board .st-rate-track { display: none; }
  .st-board .st-rate-value { width: auto; }
  .st-board .st-avatar { width: 36px; height: 36px; }
  .st-matrix tbody th, .st-matrix thead td { position: sticky; left: 0; z-index: 1; background: var(--surface); padding-right: 10px; }
  .st-bar-row { grid-template-columns: minmax(0, 4.6em) 1fr 3.6em; gap: 8px; }
  .st-chart { grid-template-rows: 150px auto; }
  .st-duel-score { font-size: 2.1rem; }
  .st-avatar.lg { width: 48px; height: 48px; font-size: 1.1rem; }
  .st-tile .tile-value { font-size: 1.8rem; }
}

/* ---- Motion: marks ease in when the data changes ---- */
@media (prefers-reduced-motion: no-preference) {
  .st-animate > * { animation: st-in 280ms ease-out both; }
  .st-animate > :nth-child(2) { animation-delay: 30ms; }
  .st-animate > :nth-child(3) { animation-delay: 60ms; }
  .st-animate > :nth-child(4) { animation-delay: 90ms; }
  .st-animate > :nth-child(n+5) { animation-delay: 120ms; }
  .st-animate .st-grow { transform-origin: left center; animation: st-grow-x 560ms cubic-bezier(0.2, 0.8, 0.2, 1) 120ms both; }
  .st-animate .st-rise { transform-origin: center bottom; animation: st-grow-y 560ms cubic-bezier(0.2, 0.8, 0.2, 1) 120ms both; }
  .st-animate .st-lines, .st-animate .st-end { animation: st-fade 500ms ease-out 160ms both; }
  @keyframes st-in { from { opacity: 0; transform: translateY(6px); } }
  @keyframes st-grow-x { from { transform: scaleX(0); } }
  @keyframes st-grow-y { from { transform: scaleY(0); } }
  @keyframes st-fade { from { opacity: 0; } }
}

@media (forced-colors: active) {
  .st-bar, .st-col-bar, .st-split-seg, .st-end, .st-legend i, .st-tip-row i { forced-color-adjust: none; }
}
