:root {
  --bg: #f0eee9;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --text: #101010;
  --muted: #6b6b6b;
  --border: #d9d9d9;
  --border-strong: #101010;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 10px;
  --pad: 16px;
  --pad-sm: 12px;
  --gap: 12px;
  --gap-sm: 8px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, white);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  backdrop-filter: blur(6px);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px var(--pad);
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: white;
  text-decoration: none;
  border: 1px solid var(--text);
  background: var(--text);
  padding: 0 14px;
  border-radius: 999px;
}

.home-link:hover {
  background: color-mix(in srgb, var(--text) 92%, white);
  border-color: color-mix(in srgb, var(--text) 92%, white);
}

.home-link:visited {
  color: white;
}

.home-link:focus-visible {
  outline: 2px solid color-mix(in srgb, #2563eb 65%, white);
  outline-offset: 2px;
}

.brand-title {
  font-weight: 800;
  letter-spacing: -0.02em;
}

.badge {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}

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

.tab {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.select,
.input {
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0 10px;
}

.input {
  min-width: 220px;
}

.main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--pad);
  width: 100%;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.card-header {
  padding: 14px var(--pad);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.card-title h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.card-title p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  cursor: pointer;
  background: transparent;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}

.pill[aria-checked="true"] {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.filters-row {
  padding: 12px var(--pad);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}

.chip .x {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1;
}

.combo {
  position: relative;
  display: inline-block;
  width: min(240px, 78vw);
}

.combo .input {
  width: 100%;
  padding-right: 34px;
}

.combo-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}

.combo-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow: auto;
  z-index: 30;
  padding: 6px;
}

.combo-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.combo-item:hover,
.combo-item:focus {
  outline: none;
  background: color-mix(in srgb, var(--bg) 55%, white);
}

.combo-meta {
  font-size: 11px;
  color: var(--muted);
}

.section-row td {
  background: color-mix(in srgb, var(--bg) 65%, white);
  font-weight: 800;
  border-top: 2px solid var(--border-strong);
  border-bottom: 1px solid var(--border);
  padding-top: 10px;
  padding-bottom: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.btn {
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0 12px;
  cursor: pointer;
}

.btn.primary {
  background: var(--text);
  color: white;
  border-color: var(--text);
}

.btn:active {
  transform: translateY(1px);
}

.table-wrap {
  overflow: auto;
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

table.gt {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

table.gt thead th {
  text-align: left;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 10px 10px;
  border-bottom: 2px solid var(--border-strong);
  background: var(--surface);
}

table.gt thead th .th-btn {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

table.gt thead th .th-sort {
  font-size: 11px;
  color: var(--muted);
}

table.gt thead th.cell-right .th-btn,
table.gt thead th.cell-right .th-btn * {
  justify-content: flex-end;
  text-align: right;
}

table.gt tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.gt tbody tr.has-subrow td {
  border-bottom: 0;
}

table.gt tbody tr:hover {
  background: color-mix(in srgb, var(--bg) 60%, white);
}

/* Mobile: horizontal scroll + frozen first column (Player/Team) */
@media (max-width: 768px) {
  table.gt {
    width: max-content;
    min-width: 100%;
  }

  table.gt.freeze-first thead th:first-child {
    position: sticky;
    left: 0;
    z-index: 6;
    background: var(--surface);
    box-shadow: 10px 0 12px -12px rgba(0, 0, 0, 0.35);
  }

  table.gt.freeze-first tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--surface);
    box-shadow: 10px 0 12px -12px rgba(0, 0, 0, 0.35);
  }

  table.gt.freeze-first tbody tr:hover td:first-child {
    background: color-mix(in srgb, var(--bg) 60%, white);
  }

  table.gt.freeze-first tr.subrow td:first-child {
    position: static;
    left: auto;
    z-index: auto;
    background: var(--surface);
    box-shadow: none;
  }

  table.gt.freeze-first tr.section-row td {
    position: static;
    box-shadow: none;
  }
}

.cell-right {
  text-align: right;
}

.player-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.headshot {
  width: 38px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.player-name {
  font-weight: 700;
  line-height: 1.1;
}

.player-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.mini-bar {
  width: 120px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  background: var(--surface-2);
}

.mini-seg {
  height: 100%;
}

.pagination {
  padding: 12px var(--pad);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

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

/* Drawer */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.36);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 50;
}

.overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(520px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 200ms ease;
  z-index: 60;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 12px var(--pad);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}

.drawer-body {
  padding: var(--pad);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawer-player {
  display: flex;
  align-items: center;
  gap: 10px;
}

.drawer-player .headshot {
  width: 56px;
  height: 42px;
}

.drawer-player h3 {
  margin: 0;
  font-size: 16px;
}

.drawer-player p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.bar {
  width: 100%;
  height: 18px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
}

.bar-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bar-headshots {
  position: relative;
  width: 100%;
  height: 18px;
}

.bar-headshot {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  width: 18px;
  height: 14px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface);
  pointer-events: none;
}

.bar-seg {
  height: 100%;
  border-right: 1px solid rgba(255, 255, 255, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  min-width: 0;
  cursor: pointer;
  user-select: none;
}

.bar-label {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-meta {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.25;
}

.tooltip {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 100ms ease, transform 100ms ease;
  /* Fallback for browsers without `color-mix()` */
  background: #d9d3c8;
  color: #1c1c1c;
  /* Darkened version of the base theme color */
  background: color-mix(in srgb, var(--bg) 86%, #111 14%);
  color: color-mix(in srgb, #111 88%, var(--bg) 12%);
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--bg) 65%, #111 35%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  max-width: min(340px, 92vw);
  font-size: 12px;
  line-height: 1.25;
}

.tooltip .muted {
  color: color-mix(in srgb, #111 55%, var(--bg) 45%);
}

.tooltip.open {
  opacity: 1;
  transform: translateY(0);
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .topbar-inner {
    padding: 10px 12px;
  }
  .main {
    padding: 12px;
  }
  .filters-row.desktop-only {
    display: none;
  }
  .drawer {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 92vh;
    border-left: 0;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(105%);
  }
  .drawer.open {
    transform: translateY(0);
  }
}

@media (min-width: 769px) {
  .filters-row.mobile-only {
    display: none;
  }
}
