:root {
  color-scheme: light dark;
  --bg: #f7f7f8;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #5f6672;
  --line: #d9dce2;
  --court: #b98a5a;
  --court-line: #ffffff;
  --accent: #c8102e;
  --up: #b3261e;
  --down: #1a56a8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --panel: #181b21;
    --ink: #eef0f4;
    --muted: #99a1ae;
    --line: #2b303a;
    --court: #3b3128;
    /* Lighter than the light-mode values; each reaches at least 4.5:1 against the #181b21 panel. */
    --accent: #ff6b7a; /* 6.27:1 */
    --up: #ff8f66; /* 7.70:1 */
    --down: #7fb2ff; /* 7.98:1 */
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

h1 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
h1 .season { color: var(--muted); font-weight: 400; }

select {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: inherit;
}

select:disabled { opacity: 0.5; }

main {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
  align-items: start;
}

aside { position: sticky; top: 24px; }
aside .sort { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }

#players { list-style: none; margin: 0; padding: 0; max-height: 72vh; overflow-y: auto; }

#players li button {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

#players li button:hover { background: var(--panel); }
#players li button[aria-current="true"] { background: var(--panel); box-shadow: inset 3px 0 0 var(--accent); }
#players li.empty button { opacity: 0.45; }

#players .who { min-width: 0; }
#players .name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#players .meta { display: block; color: var(--muted); font-size: 12px; }

#players img, #players .badge {
  width: 40px; height: 30px; object-fit: cover; border-radius: 4px; background: var(--line);
}
#players .badge { display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--muted); }

.chart { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
#summary { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.controls { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }

.court-wrap { position: relative; max-width: 560px; }
#court { display: block; width: 100%; height: auto; background: var(--court); border-radius: 8px; }
.court line, .court path, .court circle, .court rect { stroke: var(--court-line); fill: none; stroke-width: 2; }
.hex { stroke: rgba(0, 0, 0, 0.25); stroke-width: 0.5; }

#tooltip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(16, 18, 22, 0.92);
  color: #fff;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-line;
  max-width: 180px;
  transform: translate(-50%, -120%);
}

#legend { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
#empty { margin: 12px 0 0; color: var(--muted); }
#error { margin: 12px 0 0; color: var(--accent); }

#zones { width: 100%; margin-top: 16px; border-collapse: collapse; font-size: 13px; }
#zones th, #zones td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); }
#zones th:first-child, #zones td:first-child { text-align: left; }
#zones tfoot td { font-weight: 700; border-bottom: 0; }
#zones .delta.up { color: var(--up); }
#zones .delta.down { color: var(--down); }

footer { padding: 24px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
footer a { color: inherit; }

@media (max-width: 800px) {
  main { grid-template-columns: minmax(0, 1fr); }
  aside { position: static; }
  #players { display: flex; gap: 8px; max-height: none; overflow-x: auto; padding-bottom: 8px; }
  #players li { flex: 0 0 200px; }
}
