/* The stats page. It shares the game's felt and type, but scrolls and sits on panels:
   the charts need a surface dark enough for the series colours to clear 3:1 against,
   which the felt itself is not, so the panels are an inset step below it. */

:root {
  --felt: #35654d;
  --felt-dark: #284d3b;

  /* The chart surface every mark is measured against. */
  --surface: #1a3227;
  --surface-edge: rgba(255, 255, 255, 0.08);

  /* Diverging pair: which side of the game a result fell on, with a neutral draw.
     Validated against --surface (OKLCH band, chroma, CVD ΔE 19.2 protan / 29.0 normal,
     contrast ≥ 3:1). Changing either of these means running the check again. */
  --ai: #3987e5;
  --you: #e66767;
  --draw: #a7a49b;

  --ink: #fff;
  --secondary: rgba(255, 255, 255, 0.82);
  --muted: rgba(255, 255, 255, 0.6);
  --grid: rgba(255, 255, 255, 0.14);
  --accent: #ffd54a;

  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--felt-dark);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* --- bars, matching the game's --- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 10px;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
  background: rgba(0, 0, 0, 0.2);
}

.bar h1 {
  margin: 0;
  min-width: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.bar h1 span { font-weight: 400; color: var(--muted); }

.bar a { color: var(--secondary); text-decoration: none; }
.bar a:hover, .bar a:focus-visible { color: var(--ink); text-decoration: underline; }

.bar .button {
  padding: 6px 14px;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  color: var(--ink);
}

.bar .button:hover, .bar .button:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  text-decoration: none;
}

footer.bar { font-size: 13px; color: var(--muted); }

/* --- layout --- */

main {
  width: min(1040px, 100%);
  margin-inline: auto;
  padding: 24px max(16px, env(safe-area-inset-left)) 40px;
}

.state {
  margin: 48px 0;
  text-align: center;
  color: var(--muted);
}

.panels {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.panel {
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}

.panel.wide { grid-column: 1 / -1; }

.label {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* --- the hero figure --- */

.hero { grid-column: 1 / -1; }

.figure {
  margin: 10px 0 0;
  font-size: clamp(48px, 11vw, 76px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
  /* Proportional figures: tabular digits read loose at this size. */
  font-variant-numeric: proportional-nums;
}

.interval {
  margin: 10px 0 0;
  font-size: 16px;
  color: var(--secondary);
}

.note {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* --- charts --- */

.chart { margin-top: 14px; }
.chart svg { display: block; max-width: 100%; overflow: visible; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--secondary);
}

.legend span { display: inline-flex; align-items: center; gap: 6px; }

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: currentColor;   /* set per key, so the swatch carries identity, not the text */
}

.axis { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.axis-line { stroke: var(--grid); stroke-width: 1; }
.value-label { fill: var(--secondary); font-size: 12px; font-weight: 600; }
.in-bar { font-size: 12px; font-weight: 600; }

.mark { transition: opacity 0.12s; }
.hit { fill: transparent; cursor: default; }
.hit:hover + .mark, .hit:focus-visible + .mark { opacity: 0.78; }
.hit:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.empty {
  margin: 14px 0 0;
  padding: 16px;
  border: 1px dashed var(--grid);
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
}

/* --- tables --- */

.tables {
  display: grid;
  gap: 20px;
  margin-top: 14px;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
}

.tables h3 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary);
}

.tables > div { overflow-x: auto; }

table { width: 100%; min-width: 360px; border-collapse: collapse; font-size: 13px; }

caption { text-align: left; color: var(--muted); padding-bottom: 6px; }

th, td { padding: 5px 8px 5px 0; text-align: left; }

td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }

thead th {
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--grid);
}

tbody tr + tr td { border-top: 1px solid rgba(255, 255, 255, 0.06); }

td.name { color: var(--secondary); overflow-wrap: anywhere; }

.prose { margin-top: 10px; max-width: 72ch; color: var(--secondary); }
.prose p { margin: 0 0 10px; }
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* --- the tooltip --- */

.tip {
  position: absolute;
  z-index: 10;
  transform: translateX(-50%);
  padding: 6px 10px;
  max-width: 260px;
  border-radius: 8px;
  background: #0f1f18;
  border: 1px solid var(--surface-edge);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
