/* ==========================================================================
   Stats page: Dexel core look (same base as the homepage, css/pages/home.css)
   Black, white and green base; each number gets its own score colour, like an arcade scoreboard.
   Press Start 2P for headings, labels and numbers; Inter for everything you read.
   Square-ish corners, 2px borders, hard offset shadows, stepped motion. All motion stops under reduced motion.
   The header strip is drawn by js/pages/stats-scene.js; count-ups and reveals by js/pages/stats.js.
   ========================================================================== */

.st-body {
  --st-bg: #FFFFFF;
  --st-ink: #0B0B0B;
  --st-text: #3D3D3D;
  --st-mute: #5C5C5C;
  --st-line: #E4E4E4;
  --st-edge: #0B0B0B;
  --st-card: #F6F6F4;
  --st-red: #ED4245;
  --st-red-text: #C42B2E;
  --st-pixel: var(--font-pixel, 'Press Start 2P', ui-monospace, monospace);
  --st-step: steps(4, end);
  background: var(--st-bg);
  color: var(--st-text);
  font-family: var(--font-sans);
  overflow-x: hidden;
}
[data-theme="dark"] .st-body {
  --st-bg: #0A0A0A;
  --st-ink: #FFFFFF;
  --st-text: #CFCFCF;
  --st-mute: #A8A8A8;
  --st-line: #222222;
  --st-edge: #333333;
  --st-card: #121212;
  --st-red-text: #FF6B6E;
}
.st-body .nav-bar { background-color: var(--st-bg); border-bottom-color: var(--st-line); }

/* Score colours. --acc is the fill (bars, shadows, chips), --acc-text the AA-safe text shade per theme,
   --acc-chart the line and bar colour (the text shade in light so marks stand out on a pale card). */
.st-acc-green  { --acc: #3FAE4F; --acc-text: #1F7A34; }
.st-acc-gold   { --acc: #FFCC33; --acc-text: #8A5F00; }
.st-acc-teal   { --acc: #38D9C0; --acc-text: #0E7A6A; }
.st-acc-violet { --acc: #A78BFA; --acc-text: #6D4BD1; }
.st-acc-pink   { --acc: #FF6FB5; --acc-text: #B4236E; }
[data-theme="dark"] .st-acc-green  { --acc-text: #7ED67A; }
[data-theme="dark"] .st-acc-gold   { --acc-text: #FFCC33; }
[data-theme="dark"] .st-acc-teal   { --acc-text: #38D9C0; }
[data-theme="dark"] .st-acc-violet { --acc-text: #A78BFA; }
[data-theme="dark"] .st-acc-pink   { --acc-text: #FF6FB5; }
[class*="st-acc-"] { --acc-chart: var(--acc-text); }
[data-theme="dark"] [class*="st-acc-"] { --acc-chart: var(--acc); }

/* A small solid square in the card's colour, with a hard ink shadow */
.st-chip {
  flex: 0 0 auto;
  display: inline-block;
  width: 10px;
  height: 10px;
  background: var(--acc, var(--dx-green));
  box-shadow: 2px 2px 0 var(--st-ink);
}

/* --- header strip ---------------------------------------------------------------------------------- */
.st-strip {
  position: relative;
  height: clamp(96px, 13vw, 168px);
  overflow: hidden;
  background: #07070C;
  border-bottom: 2px solid var(--st-edge);
}
[data-theme="light"] .st-strip { background: #7CC8FF; }
.st-strip-scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }

/* --- page header ----------------------------------------------------------------------------------- */
/* .st-body in front so these win over responsive.css, which resets .container padding on small screens */
.st-body .stats-page-container {
  padding-top: 56px;
  padding-bottom: 96px;
  position: relative;
}

.stats-header-section { margin-bottom: 40px; }

.st-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  font-family: var(--st-pixel);
  font-size: 12px;
  line-height: 1;
  text-transform: uppercase;
  color: var(--dx-green-text);
}

.stats-title {
  font-family: var(--st-pixel);
  font-weight: 400;
  font-size: clamp(20px, 3.2vw, 34px);
  line-height: 1.45;
  letter-spacing: 0;
  color: var(--st-ink);
  margin: 0 0 14px;
  text-wrap: balance;
}

.stats-lead {
  font-size: 17px;
  line-height: 1.6;
  color: var(--st-text);
  max-width: 56ch;
  margin: 0;
}

/* Uptime: a neutral pill with a small solid dot (never glowing) */
.stats-uptime {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 0;
  padding: 6px 12px;
  border: 2px solid var(--st-line);
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--st-text);
}
.stats-uptime::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--dx-green);
}
.stats-uptime[hidden] { display: none; }

/* --- score cards ----------------------------------------------------------------------------------- */
.stats-kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 56px;
}

.stats-kpi-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  min-height: 116px;
  padding: 18px;
  background: var(--st-card);
  border: 2px solid var(--st-edge);
  border-radius: 6px;
  box-shadow: 6px 6px 0 var(--acc);
  transition: transform 120ms var(--st-step), box-shadow 120ms var(--st-step);
}
.stats-kpi-card:hover { transform: translate(-2px, -2px); box-shadow: 8px 8px 0 var(--acc); }

.stats-kpi-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-family: var(--st-pixel);
  font-size: 10px;
  line-height: 1.6;
  text-transform: uppercase;
  color: var(--st-mute);
}
.stats-kpi-label .st-chip { margin-top: 2px; }

.stats-kpi-value {
  font-family: var(--st-pixel);
  font-size: clamp(18px, 1.9vw, 24px);
  line-height: 1.2;
  color: var(--st-ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stats-kpi-value.is-counting, .graph-current-num.is-counting { color: var(--acc-text); }

/* --- chart cards ----------------------------------------------------------------------------------- */
.stats-graphs-section {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
}

.graph-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--st-card);
  border: 2px solid var(--st-edge);
  border-radius: 6px;
  box-shadow: 6px 6px 0 var(--acc);
}
.graph-card-span-2 { grid-column: span 2; }

.graph-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 18px 24px;
  padding: 22px 24px;
  border-bottom: 2px solid var(--st-line);
}

.graph-title-group { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.graph-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-family: var(--st-pixel);
  font-weight: 400;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
  color: var(--st-ink);
}

.graph-subtitle { margin: 0; font-size: 14px; line-height: 1.5; color: var(--st-mute); }

.graph-metric-highlight {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-top: 6px;
}

.graph-current-num {
  font-family: var(--st-pixel);
  font-size: clamp(18px, 2vw, 24px);
  line-height: 1.2;
  color: var(--st-ink);
  font-variant-numeric: tabular-nums;
}
.graph-current-num.negative { color: var(--st-red-text); }

/* Neutral pills with a small solid dot: no tints, no glow */
.graph-delta-pill,
.graph-secondary-pill,
.stats-empty-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border: 2px solid var(--st-line);
  border-radius: 4px;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--st-text);
  white-space: nowrap;
}
.graph-delta-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--acc);
}
.graph-delta-pill.negative { color: var(--st-red-text); }
.graph-delta-pill.negative::before { background: var(--st-red); }
/* the pill inside the delta slot while there is no data: let the inner pill draw itself */
.graph-delta-pill:has(> .stats-empty-pill) { padding: 0; border: 0; }
.graph-delta-pill:has(> .stats-empty-pill)::before { display: none; }
.stats-empty-pill::before,
.graph-secondary-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  background: var(--st-mute);
}

/* --- controls -------------------------------------------------------------------------------------- */
.graph-controls-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }

.graph-btn-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 2px solid var(--st-edge);
  border-radius: 4px;
  background: var(--st-bg);
}

.graph-control-btn {
  min-width: 36px;
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  font-family: var(--st-pixel);
  font-size: 10px;
  line-height: 1;
  color: var(--st-text);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms var(--st-step), color 120ms var(--st-step);
}
.graph-control-btn:hover { color: var(--st-ink); background: var(--st-line); }
.graph-control-btn.active { background: var(--dx-green); color: var(--dx-on-green); }

.graph-toggle-btn,
.btn-data-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border: 2px solid var(--st-edge);
  border-radius: 4px;
  background: var(--st-bg);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--st-ink);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--st-edge);
  transition: transform 120ms var(--st-step), box-shadow 120ms var(--st-step);
}
.graph-toggle-btn:hover, .btn-data-action:hover { transform: translateY(-1px); box-shadow: 0 4px 0 var(--st-edge); }
.graph-toggle-btn:active, .btn-data-action:active { transform: translateY(3px); box-shadow: 0 0 0 var(--st-edge); }
.graph-toggle-btn.active { background: var(--st-ink); color: var(--st-bg); }

.drawer-btn-actions { display: inline-flex; gap: 10px; }

.st-body .graph-control-btn:focus-visible,
.st-body .graph-toggle-btn:focus-visible,
.st-body .btn-data-action:focus-visible {
  outline: 3px solid var(--dx-green);
  outline-offset: 2px;
}

/* --- chart surface --------------------------------------------------------------------------------- */
.graph-svg-container {
  position: relative;
  width: 100%;
  height: 280px;
  background: var(--st-card);
  border-radius: 0 0 4px 4px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  cursor: crosshair;
}
.graph-svg-container svg { display: block; width: 100%; height: 100%; }

.chart-path-line {
  fill: none;
  stroke: var(--acc-chart);
  stroke-width: 3px;
  stroke-linecap: square;
  stroke-linejoin: miter;
}
.chart-path-area { fill: var(--acc); fill-opacity: 0.14; }
.chart-dither { fill: var(--acc); fill-opacity: 0.45; }
.chart-point { fill: var(--acc-chart); shape-rendering: crispEdges; }

.chart-bar { fill: var(--acc-chart); shape-rendering: crispEdges; transition: fill 120ms var(--st-step); }
.chart-bar:hover { fill: var(--st-ink); }
.chart-bar.negative { fill: var(--st-red); }
.chart-bar.negative:hover { fill: var(--st-red-text); }

.chart-grid-line { stroke: var(--st-line); stroke-width: 1px; stroke-dasharray: 2 4; shape-rendering: crispEdges; }
.chart-axis-text { font-family: var(--font-mono); font-size: 11px; fill: var(--st-mute); user-select: none; }

.chart-crosshair-line { stroke: var(--st-ink); stroke-width: 1px; stroke-dasharray: 2 3; pointer-events: none; shape-rendering: crispEdges; }
.chart-pin-halo { fill: none; stroke: var(--st-ink); stroke-width: 2px; pointer-events: none; shape-rendering: crispEdges; }
.chart-pin-dot { fill: var(--acc); stroke: var(--st-ink); stroke-width: 2px; pointer-events: none; shape-rendering: crispEdges; }

/* Hover readout */
.graph-hud-tooltip {
  position: absolute;
  top: 14px;
  right: 18px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 150px;
  padding: 10px 12px;
  background: var(--st-bg);
  border: 2px solid var(--st-edge);
  border-radius: 4px;
  box-shadow: 4px 4px 0 var(--acc);
  pointer-events: none;
}
.graph-hud-tooltip.align-left { left: 18px; right: auto; }
.graph-hud-tooltip.align-right { right: 18px; left: auto; }
.graph-hud-date { font-size: 12px; color: var(--st-mute); }
.graph-hud-value { font-family: var(--st-pixel); font-size: 12px; line-height: 1.4; color: var(--st-ink); }
.graph-hud-meta { font-size: 12px; font-weight: 600; color: var(--acc-text); }

/* --- empty state ----------------------------------------------------------------------------------- */
.graph-empty-state {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background: var(--st-card);
  border-radius: 0 0 4px 4px;
}
.graph-empty-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 14px;
  background: var(--st-bg);
  border: 2px solid var(--st-edge);
  border-radius: 4px;
  box-shadow: 3px 3px 0 var(--acc);
  color: var(--acc-chart);
}
.graph-empty-icon svg { shape-rendering: crispEdges; }
.graph-empty-title {
  margin-bottom: 10px;
  font-family: var(--st-pixel);
  font-size: 11px;
  line-height: 1.6;
  color: var(--st-ink);
}
.graph-empty-desc { max-width: 44ch; margin: 0; font-size: 14px; line-height: 1.55; color: var(--st-mute); }

/* --- reveal: a stepped wipe the first time a card scrolls in (only when JS runs) -------------------- */
.st-js .st-reveal { clip-path: inset(0 0 100% 0); }
.st-js .st-reveal.is-in { clip-path: none; animation: st-wipe 420ms steps(6, end); }
@keyframes st-wipe {
  from { clip-path: inset(0 -12px 100% -12px); }
  to { clip-path: inset(0 -12px -12px -12px); }
}

/* --- smaller screens ------------------------------------------------------------------------------- */
@media (max-width: 1100px) {
  .stats-kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 840px) {
  .st-body .stats-page-container { padding-top: 40px; padding-bottom: 72px; }
  .stats-graphs-section { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .graph-card-span-2 { grid-column: span 1; }
  .graph-card-header { padding: 18px; }
  .graph-svg-container { height: 230px; }
  .graph-control-btn { min-height: 40px; min-width: 40px; }
  .graph-toggle-btn, .btn-data-action { min-height: 40px; }
}

@media (max-width: 600px) {
  .st-body .stats-page-container { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .stats-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .stats-kpi-card { padding: 14px; min-height: 104px; box-shadow: 4px 4px 0 var(--acc); }
  .stats-kpi-card:last-child { grid-column: 1 / -1; }
  .stats-kpi-value { font-size: 18px; }
  .stats-lead { font-size: 16px; }
  .graph-card { box-shadow: 4px 4px 0 var(--acc); }
  .stats-kpi-card:hover { transform: none; box-shadow: 4px 4px 0 var(--acc); }
  .graph-current-num { font-size: 18px; }
  .graph-svg-container { height: 200px; }
  .graph-title { font-size: 12px; }
  .graph-btn-group { width: 100%; justify-content: space-between; }
  .graph-control-btn { flex: 1 1 0; }
}

@media (prefers-reduced-motion: reduce) {
  .stats-kpi-card, .graph-toggle-btn, .btn-data-action, .graph-control-btn, .chart-bar { transition: none; }
  .stats-kpi-card:hover, .graph-toggle-btn:hover, .btn-data-action:hover,
  .graph-toggle-btn:active, .btn-data-action:active { transform: none; }
  .st-js .st-reveal, .st-js .st-reveal.is-in { clip-path: none; animation: none; }
}
