:root {
  --fg: #1a1a1a;
  --muted: #666;
  --accent: #1f4a80;
  --border: #d8d8d8;
  --row-alt: #f5f7fa;
  --bg: #ffffff;
  --chip-active-fg: #fff;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --fg: #e8e8e8;
  --muted: #9aa3ad;
  --accent: #6aa8ff;
  --border: #2c3138;
  --row-alt: #1b1f24;
  --bg: #14171c;
  --chip-active-fg: #0b0d10;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fg: #e8e8e8;
    --muted: #9aa3ad;
    --accent: #6aa8ff;
    --border: #2c3138;
    --row-alt: #1b1f24;
    --bg: #14171c;
    --chip-active-fg: #0b0d10;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  margin: 0;
  padding: 0 1.25rem 3rem;
  line-height: 1.45;
  max-width: 1180px;
  margin-left: auto;
  margin-right: auto;
}

header {
  padding: 1.5rem 0 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.6rem;
}

header .sub {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

header a {
  color: var(--accent);
}

nav#view-bar {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin: 1rem 0;
}

nav#view-bar #generated {
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: auto;
}

#theme-toggle {
  font: inherit;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  width: 2rem;
  height: 1.85rem;
  cursor: pointer;
  line-height: 1;
}

#theme-toggle:hover {
  border-color: var(--accent);
}

#leaderboard tbody tr {
  cursor: pointer;
}

#leaderboard tbody tr:hover td {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

#player-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

#player-modal[hidden] { display: none; }

#player-modal .modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}

#player-modal .modal-body {
  position: relative;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: min(900px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 1.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

#player-modal h2 { margin: 0 0 0.25rem; }

#player-modal .modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.7rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  width: 2rem;
  height: 2rem;
}

#player-modal .modal-close:hover { color: var(--accent); }

#player-chart {
  height: 280px;
  width: 100%;
  margin: 0.75rem 0 1rem;
}

#player-seasons th, #player-seasons td { padding: 0.3rem 0.6rem; }

#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

#controls label,
nav#view-bar label {
  font-size: 0.9rem;
  color: var(--muted);
}

#controls input,
#controls select,
nav#view-bar select {
  font: inherit;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--fg);
  margin-left: 0.25rem;
}

#controls input[type="search"] {
  min-width: 220px;
}

.chip-group {
  border: 0;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.chip-group legend {
  font-size: 0.9rem;
  color: var(--muted);
  padding: 0 0.5rem 0 0;
}

.chip-group .hint {
  font-size: 0.8rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  background: var(--bg);
  color: var(--fg);
}

.chip input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chip:has(input:checked) {
  background: var(--accent);
  color: var(--chip-active-fg);
  border-color: var(--accent);
}

#chart-section {
  margin: 1.5rem 0;
}

#chart-section h2,
#table-section h2 {
  font-size: 1.05rem;
  margin: 0 0 0.5rem;
}

#table-section { margin-top: 1.5rem; }

#chart {
  height: 380px;
  width: 100%;
  margin-top: 0.5rem;
}

.note {
  color: var(--muted);
  font-size: 0.85rem;
}

label.inline { color: var(--muted); font-size: 0.9rem; }
label.inline input { width: 4.5rem; }

.table-wrap {
  max-height: 720px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 3px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--bg);
  font-weight: 600;
  color: var(--fg);
  z-index: 1;
}

th[data-sort] {
  cursor: pointer;
  user-select: none;
  /* No position override here -- the base `th { position: sticky }` already
   * establishes a positioning context for the absolute ::after below. */
}

th[data-sort]:hover {
  color: var(--accent);
}

/* Absolute-position the sort glyph so it doesn't sit in the inline flow and
 * shift the header text away from the right edge -- otherwise numeric
 * headers don't right-align with their right-aligned data cells. */
th[data-sort]::after {
  content: "";
  position: absolute;
  right: 0.35em;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.75em;
  pointer-events: none;
}

th.sort-asc::after { content: "▲"; color: var(--accent); }
th.sort-desc::after { content: "▼"; color: var(--accent); }

body[data-view="season"] .years-col,
body[data-view="season"] .career-only {
  display: none;
}

/* The rank-col tint must be OPAQUE for the sticky <th>: a translucent
 * background lets row data show through when the body scrolls under it. */
th.rank-col, td.rank-col {
  font-weight: 700;
  background: color-mix(in srgb, var(--accent) 8%, var(--bg));
}
th.rank-col { color: var(--accent); }
tr:nth-child(even) td.rank-col {
  background: color-mix(in srgb, var(--accent) 14%, var(--row-alt));
}

tr:nth-child(even) td {
  background: var(--row-alt);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  /* Extra right padding on numeric columns leaves room for the absolute-
   * positioned sort arrow on the header while preserving alignment with
   * the data cells (which use the same padding). */
  padding-right: 1.4em;
}

#load-more {
  display: block;
  margin: 0.75rem auto 0;
  padding: 0.4rem 1rem;
  font: inherit;
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}

#load-more:hover {
  background: var(--row-alt);
  border-color: var(--accent);
}

footer {
  margin-top: 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.error {
  color: #a30000;
  background: #fff0f0;
  padding: 0.75rem 1rem;
  border: 1px solid #f3c2c2;
  border-radius: 3px;
  white-space: pre-wrap;
}

.banner {
  margin: 0.75rem 0;
  padding: 0.55rem 0.9rem;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--fg);
  font-size: 0.88rem;
  border-radius: 2px;
}

.banner strong { color: var(--accent); }
