:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --ink: #17201b;
  --muted: #5d6a62;
  --line: #d7ded8;
  --green: #126b4e;
  --green-soft: #e6f2ec;
  --teal: #0d7c80;
  --red: #a6403a;
  --red-soft: #f8e9e7;
  --amber: #9a6512;
  --amber-soft: #f7efd9;
  --focus: #0d7c80;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
}

button, a { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent); outline-offset: 2px; }

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 20px clamp(16px, 4vw, 56px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  background: var(--green);
  color: #fff;
  border-radius: 6px;
  font-size: 20px;
  font-weight: 800;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(20px, 3vw, 30px); line-height: 1.25; letter-spacing: 0; }
h2 { margin-bottom: 5px; font-size: 18px; letter-spacing: 0; }
.title-block p, .section-heading p { margin-bottom: 0; color: var(--muted); line-height: 1.55; }

.download-link {
  color: #fff;
  background: var(--green);
  border-radius: 5px;
  padding: 10px 14px;
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

main { width: min(1500px, 100%); margin: 0 auto; }

.scope-band {
  display: flex;
  gap: 12px 24px;
  flex-wrap: wrap;
  padding: 14px clamp(16px, 4vw, 56px);
  background: #ecf4f0;
  border-bottom: 1px solid #cadbd2;
  color: #244a39;
}

.controls {
  display: grid;
  grid-template-columns: minmax(240px, 0.7fr) minmax(420px, 1.3fr);
  gap: 22px;
  padding: 22px clamp(16px, 4vw, 56px) 12px;
}

.control-group { min-width: 0; }
.control-label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; font-weight: 700; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button {
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
}
.segmented button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 10px clamp(16px, 4vw, 56px) 20px;
}
.stat {
  min-height: 100px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.stat-label { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat-value { margin-top: 8px; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-note { margin-top: 4px; color: var(--muted); font-size: 13px; }

.chart-section, .table-section, .daily-overview, .downloads { padding: 20px clamp(16px, 4vw, 56px); }
.chart-section, .table-section, .daily-overview { border-top: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 14px; }
.legend { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--teal); }
.chart-wrap { min-height: 330px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#retention-chart { width: 100%; height: 330px; display: block; }
.grid-line { stroke: var(--line); stroke-width: 1; }
.axis-label { fill: var(--muted); font-size: 11px; }
.chart-line { fill: none; stroke: var(--teal); stroke-width: 2.5; }
.chart-point { fill: var(--surface); stroke: var(--teal); stroke-width: 2; }
.chart-point.small { stroke: var(--amber); }
.chart-point.tiny { stroke: var(--red); }
.chart-hit { fill: transparent; }

.reading-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 56px);
  background: #fff9ea;
  border-top: 1px solid #e6d6aa;
  border-bottom: 1px solid #e6d6aa;
}
.reading-item strong { display: block; margin-bottom: 5px; color: #5d4210; }
.reading-item span { color: #6d5a35; line-height: 1.55; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; background: #edf1ed; color: #344139; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7faf7; }
tr.no-game { background: #f1f3f0; }
tr.anomaly { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.type-cell { font-weight: 700; white-space: nowrap; }
.rate-cell { min-width: 190px; }
.rate-value { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.bar-track { flex: 0 0 86px; height: 7px; background: #e4e9e5; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--teal); }
.sample { display: inline-block; padding: 3px 7px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.sample.stable { background: var(--green-soft); color: var(--green); }
.sample.caution { background: var(--amber-soft); color: var(--amber); }
.sample.tiny { background: var(--red-soft); color: var(--red); }
.table-total { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.audit-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px;
  padding: 24px clamp(16px, 4vw, 56px);
  background: #eaf3f3;
  border-top: 1px solid #c6dada;
  border-bottom: 1px solid #c6dada;
}
.audit-band p { margin-bottom: 0; color: #36585a; line-height: 1.65; }

.downloads { background: var(--surface); }
.download-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.download-grid a { padding: 9px 11px; border: 1px solid var(--line); border-radius: 5px; color: var(--green); text-decoration: none; font-weight: 700; }

footer { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding: 18px clamp(16px, 4vw, 56px); color: var(--muted); border-top: 1px solid var(--line); font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
  .controls { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reading-band, .audit-band { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr); gap: 12px; }
  .download-link { grid-column: 1 / -1; text-align: center; }
  .stat-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: start; flex-direction: column; }
  .legend { white-space: normal; }
  #retention-chart { height: 300px; }
  .chart-wrap { min-height: 300px; }
}
