/* ---------------------------------------------------------------------
   Division stats dashboard.
   Light and dark palettes, tabular figures, sticky header + name column
   so the stat table stays readable once every column is populated.
--------------------------------------------------------------------- */

/* Palette borrowed from the league site (chesmsbl.com): brick red #bf302c
   with charcoal and cool grays. --accent is for fills, --accent-ink for
   accent-colored text that still has to be readable on a surface. */
:root {
  --bg: #f7f8f9;
  --bg-grad: radial-gradient(1100px 520px at 12% -12%, rgba(191, 48, 44, .07) 0%, transparent 62%);
  --surface: #ffffff;
  --surface-2: #f1f3f4;
  --border: #e5e7e8;
  --border-strong: #d4d9dc;
  --text: #23282b;
  --text-dim: #67767f;
  --accent: #bf302c;
  --accent-hover: #a52925;
  --accent-ink: #a52925;
  --accent-soft: #fbeceb;
  --accent-text: #ffffff;
  --shadow: 0 1px 2px rgba(35, 40, 43, .05), 0 8px 24px rgba(35, 40, 43, .07);
  --radius: 14px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131719;
    --bg-grad: radial-gradient(1100px 520px at 12% -12%, rgba(191, 48, 44, .16) 0%, transparent 62%);
    --surface: #1a1f23;
    --surface-2: #23282b;
    --border: #2b3237;
    --border-strong: #394146;
    --text: #e5e7e8;
    --text-dim: #9ca8af;
    --accent: #bf302c;
    --accent-hover: #d13c37;
    --accent-ink: #f08a84;
    --accent-soft: #2b1a19;
    --accent-text: #ffffff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 10px 30px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  border-top: 3px solid var(--accent);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 72px;
}

/* -- Header ------------------------------------------------------- */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 44px 0 22px;
}

.kicker {
  margin: 0 0 6px;
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.masthead h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3.6vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.masthead .meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: .8rem;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
}

.meta .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.back-link {
  color: var(--text-dim);
  text-decoration: none;
  letter-spacing: .04em;
}
.back-link:hover { color: var(--accent-ink); }

.section-heading {
  margin: 30px 0 14px;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.note {
  margin: 0 0 16px;
  font-size: .82rem;
  color: var(--text-dim);
}

.muted { color: var(--text-dim); }

/* -- Home page ------------------------------------------------------ */

.home-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 6px;
}

.home-link {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.home-link:hover { transform: translateY(-2px); }

.home-link-title { font-weight: 700; font-size: .98rem; }
.home-link-sub { font-size: .78rem; color: var(--text-dim); }

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}

.team-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.team-card:hover { transform: translateY(-2px); border-color: var(--accent); }

.team-logo {
  width: 62px;
  height: 62px;
  object-fit: contain;
  border-radius: 10px;
  background: var(--surface-2);
}

.team-logo-fallback {
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-dim);
}

.team-card-name { font-weight: 600; font-size: .9rem; line-height: 1.25; }
.team-card-sub { font-size: .74rem; color: var(--text-dim); }

.data-note {
  margin-top: 22px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}

.data-note h2 {
  margin: 0 0 8px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.data-note p {
  margin: 0 0 8px;
  font-size: .84rem;
  color: var(--text-dim);
  max-width: 78ch;
}
.data-note p:last-child { margin-bottom: 0; }
.data-note strong { color: var(--text); }
.data-note a { color: var(--accent-ink); }

/* -- Leaders -------------------------------------------------------- */

.leader-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.leader-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 12px;
  box-shadow: var(--shadow);
}

.leader-card h3 {
  margin: 0 0 10px;
  font-size: .82rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.leader-card h3 .abbr {
  font-size: .72rem;
  font-weight: 700;
  color: var(--accent-ink);
  letter-spacing: .04em;
}

.leader-card ol {
  list-style: none;
  margin: 0;
  padding: 0;
  font-variant-numeric: tabular-nums;
}

.leader-card li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: .85rem;
}

.leader-card .rank {
  width: 1.2em;
  color: var(--text-dim);
  font-size: .76rem;
  font-weight: 700;
}

.leader-card .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.leader-card .who-name { font-weight: 600; }
.leader-card .who-team { font-size: .72rem; color: var(--text-dim); }
.leader-card .val { font-weight: 700; }

/* -- League totals share chip --------------------------------------- */

.share {
  display: block;
  font-size: .68rem;
  font-weight: 600;
  color: var(--accent-ink);
  opacity: .9;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: .84rem;
  color: var(--text-dim);
  cursor: pointer;
}
.switch input { accent-color: var(--accent); }

/* -- Controls ------------------------------------------------------ */

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-left: auto;
}

.tab-group {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.tab-group button {
  font: inherit;
  font-size: .86rem;
  font-weight: 600;
  padding: 8px 20px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}

.tab-group button:hover { color: var(--text); }

.tab-group button.active {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 1px 3px rgba(191, 48, 44, .35);
}

select, input[type="search"] {
  font: inherit;
  font-size: .86rem;
  padding: 9px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

select:focus-visible, input[type="search"]:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="search"] { min-width: 190px; }

.refresh-btn {
  font: inherit;
  font-size: .86rem;
  font-weight: 600;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .15s ease;
}
.refresh-btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* -- Table ----------------------------------------------------------*/

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: .85rem;
  font-variant-numeric: tabular-nums;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-align: right;
  white-space: nowrap;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

thead th:hover { color: var(--text); }
thead th.sorted { color: var(--accent-ink); }

thead th .arrow { opacity: .35; font-size: .65rem; margin-left: 5px; }
thead th.sorted .arrow { opacity: 1; }

/* Team + player columns read as labels, everything else as figures. */
thead th:nth-child(1), thead th:nth-child(2),
tbody td:nth-child(1), tbody td:nth-child(2),
tfoot td:nth-child(1), tfoot td:nth-child(2) { text-align: left; }

tbody td, tfoot td {
  padding: 10px 14px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

/* Keep the name visible while scrolling the stat columns sideways. */
thead th:nth-child(2) { position: sticky; left: 0; z-index: 3; }
tbody td.player-cell, tfoot td.player-cell {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  font-weight: 600;
}
tbody tr:hover td.player-cell { background: var(--surface-2); }

td.player-cell .jersey {
  margin-left: 6px;
  font-size: .74rem;
  font-weight: 500;
  color: var(--text-dim);
}

td.team-cell {
  color: var(--text-dim);
  font-size: .8rem;
  font-weight: 500;
}

tfoot .totals-row td {
  background: var(--accent-soft);
  border-top: 2px solid var(--accent);
  border-bottom: none;
  font-weight: 700;
  position: sticky;
  bottom: 0;
}

tfoot .totals-row td.player-cell {
  background: var(--accent-soft);
  color: var(--accent-ink);
  letter-spacing: .04em;
}

.empty-state {
  padding: 64px 24px;
  text-align: center;
  color: var(--text-dim);
}

.empty-state .big {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

/* -- Legend --------------------------------------------------------- */

.legend {
  margin-top: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
}

.legend h2 {
  margin: 0;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.legend dl {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 2px 24px;
  margin: 12px 0 0;
}

.legend dl > div {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 7px 0;
  border-top: 1px solid var(--border);
}

.legend dt {
  min-width: 3.4em;
  font-size: .78rem;
  font-weight: 700;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}

.legend dd {
  margin: 0;
  font-size: .8rem;
  color: var(--text-dim);
}

footer {
  margin-top: 28px;
  font-size: .75rem;
  color: var(--text-dim);
  text-align: center;
}

@media (max-width: 720px) {
  .masthead { align-items: flex-start; }
  .filters { margin-left: 0; width: 100%; }
  input[type="search"] { flex: 1; min-width: 0; }
}

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