:root {
  color-scheme: dark;
  --bg: #0b1318;
  --bg-soft: rgba(13, 22, 28, 0.82);
  --panel: rgba(14, 22, 30, 0.9);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #ecf2f0;
  --muted: #9ba9aa;
  --accent: #b8e0d8;
  --accent-strong: #d2f1ea;
  --accent-warm: #d1b36a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(120, 165, 156, 0.16), transparent 30%),
    radial-gradient(circle at top right, rgba(209, 179, 106, 0.12), transparent 24%),
    linear-gradient(180deg, #091014 0%, var(--bg) 100%);
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent 85%);
}

.page-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

/* Hero */
.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 28px;
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(10, 16, 22, 0.96), rgba(14, 22, 30, 0.82));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero h1 {
  margin: 0;
  line-height: 1.05;
  font-size: clamp(2.2rem, 4vw, 4.4rem);
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
  color: var(--accent);
}

/* Dashboard layout */
.dashboard-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 20px;
  margin-top: 18px;
}

.sidebar {
  position: sticky;
  top: 20px;
  align-self: start;
  padding: 16px;
  border-radius: 24px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  display: grid;
  gap: 10px;
}

.tab-button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 16px;
  padding: 14px;
  text-align: left;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.tab-button:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(2px);
}

.tab-button.is-active {
  background: linear-gradient(135deg, rgba(184, 224, 216, 0.2), rgba(255, 255, 255, 0.05));
  border-color: rgba(184, 224, 216, 0.28);
}

.tab-panels {
  min-width: 0;
  display: grid;
  gap: 20px;
}

.tab-panel {
  min-width: 0;
}

/* Panel */
.panel {
  padding: 24px;
  border-radius: 24px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  overflow: hidden;
}

.panel h2 {
  margin: 0;
  line-height: 1.05;
  font-size: 1.7rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* Overview cards */
.overview-band {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 8px;
}

.overview-card {
  padding: 16px 14px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: linear-gradient(180deg, rgba(14, 22, 30, 0.92), rgba(11, 17, 23, 0.95));
  box-shadow: var(--shadow);
}

.overview-card .label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
}

.overview-card strong {
  display: block;
  font-size: clamp(1.4rem, 1.8vw, 2.2rem);
  margin-bottom: 8px;
}

.overview-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.home-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.mini-panel {
  padding: 18px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
}

.mini-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.mini-panel-accent {
  background: linear-gradient(135deg, rgba(184, 224, 216, 0.14), rgba(255, 255, 255, 0.03));
}

.mini-label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
}

.mini-panel strong {
  display: block;
  font-size: 1.3rem;
  margin-bottom: 8px;
}

/* Notice */
.notice {
  margin: 18px 0 8px;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid rgba(245, 158, 11, 0.22);
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(255, 255, 255, 0.03));
  color: var(--text);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.notice span {
  color: var(--muted);
}

/* Sortable table */
.table-shell {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sortable-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

.sortable-table th,
.sortable-table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
  vertical-align: middle;
}

.sortable-table thead th {
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, rgba(14, 22, 30, 0.98), rgba(14, 22, 30, 0.92));
  z-index: 1;
}

.sortable-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.sortable-table td {
  color: var(--text);
}

.sortable-table td:first-child {
  font-weight: 700;
}

.table-sort {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 800;
  letter-spacing: 0.01em;
  padding: 0;
  cursor: pointer;
  transition: color 0.18s ease;
}

.table-sort:hover,
.table-sort.is-active {
  color: var(--accent-strong);
}

.table-sort::after {
  content: "";
  display: inline-block;
  margin-left: 8px;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  opacity: 0.35;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.table-sort.is-active::after {
  opacity: 0.95;
}

.table-sort[aria-sort="ascending"]::after {
  transform: rotate(-135deg) translateY(-1px);
}

.table-sort[aria-sort="descending"]::after {
  transform: rotate(45deg) translateY(-2px);
}

.empty-state {
  min-height: 280px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  text-align: center;
  padding: 24px;
}

code {
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent);
}

/* Filter widget */
.filter-widget {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.filter-input-wrap {
  position: relative;
}

.filter-input {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-size: 0.875rem;
  font-family: inherit;
  min-width: 240px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.filter-input::placeholder {
  color: var(--muted);
}

.filter-input:focus {
  border-color: rgba(184, 224, 216, 0.4);
  background: rgba(255, 255, 255, 0.07);
}

.filter-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  max-height: 240px;
  overflow-y: auto;
  background: #0e161e;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  list-style: none;
  margin: 0;
  padding: 0.3rem 0;
  z-index: 100;
}

.filter-dropdown::-webkit-scrollbar {
  width: 4px;
}

.filter-dropdown::-webkit-scrollbar-track {
  background: transparent;
}

.filter-dropdown::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

.filter-option {
  padding: 0.45rem 0.85rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease;
}

.filter-option:hover {
  background: rgba(184, 224, 216, 0.1);
  color: var(--accent-strong);
}

.filter-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.filter-tag {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.7rem;
  background: linear-gradient(135deg, rgba(184, 224, 216, 0.2), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(184, 224, 216, 0.28);
  color: var(--accent-strong);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  font-family: inherit;
}

.filter-tag-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  transition: color 0.15s ease;
}

.filter-tag-remove:hover {
  color: var(--text);
}

/* Pivot table */
.pivot-controls {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.pivot-metric-switch {
  display: flex;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  overflow: hidden;
}

.pivot-metric-btn {
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.pivot-metric-btn + .pivot-metric-btn {
  border-left: 1px solid var(--panel-border);
}

.pivot-metric-btn.is-active {
  background: linear-gradient(135deg, rgba(184, 224, 216, 0.2), rgba(255, 255, 255, 0.05));
  color: var(--accent-strong);
}

.pivot-metric-btn:hover:not(.is-active) {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.pivot-legend {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.pivot-legend-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
}

.pivot-legend-scale {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.pivot-legend-bar {
  width: 80px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(192, 57, 43, 0.8), rgba(127, 140, 141, 0.4), rgba(39, 174, 96, 0.8));
}

.pivot-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.pivot-origin {
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 8px 10px 8px 0;
  text-align: right;
  width: 200px;
  min-width: 200px;
  border-bottom: 1px solid var(--panel-border);
  border-right: 1px solid var(--panel-border);
}

.pivot-col-header {
  padding: 8px 6px;
  text-align: center;
  font-weight: 800;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--panel-border);
  min-width: 0;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  vertical-align: bottom;
  height: 120px;
}

.pivot-row-header {
  padding: 8px 10px 8px 0;
  text-align: right;
  font-weight: 800;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  width: 200px;
  min-width: 200px;
  border-right: 1px solid var(--panel-border);
}

.pivot-cell {
  padding: 6px 4px;
  text-align: center;
  vertical-align: middle;
  border: 1px solid rgba(255, 255, 255, 0.04);
  min-width: 0;
}

.pivot-cell-self,
.pivot-cell-empty {
  color: rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.01);
}

.pivot-primary {
  display: block;
  font-weight: 800;
  font-size: 0.78rem;
  line-height: 1.2;
}

.pivot-games {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 2px;
}

.pivot-col-total {
  border-left: 1px solid rgba(184, 224, 216, 0.2) !important;
  color: var(--accent) !important;
}

.pivot-cell-total {
  border-left: 1px solid rgba(184, 224, 216, 0.2) !important;
  font-weight: 700;
}

/* Responsive */
@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 16px, 1280px);
    padding: 16px 0 32px;
  }

  .hero {
    padding: 20px;
    border-radius: 20px;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    border-radius: 18px;
  }

  .tab-button {
    flex: 1 1 auto;
    min-width: calc(50% - 4px);
    padding: 10px 8px;
    font-size: 0.85rem;
    text-align: center;
    border-radius: 12px;
  }

  .overview-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .home-detail-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 16px;
    border-radius: 18px;
  }

  .panel h2 {
    font-size: 1.3rem;
  }

  .pivot-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .pivot-table {
    table-layout: auto;
    width: auto;
  }

  .pivot-col-header {
    height: 80px;
  }

  .pivot-cell,
  .pivot-cell-self,
  .pivot-cell-empty {
    min-width: 52px;
  }

  .pivot-origin,
  .pivot-row-header {
    min-width: 140px;
    width: 140px;
  }

  .filter-input {
    min-width: 100%;
  }
}

/* Player stats tab */
.player-filter {
  margin-bottom: 1.5rem;
}

.player-filter .filter-input {
  cursor: pointer;
  min-width: 280px;
}

.player-stat-band {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 1.5rem;
}

.player-stat-card {
  padding: 16px 16px 14px;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(14, 22, 30, 0.92), rgba(11, 17, 23, 0.95));
  box-shadow: var(--shadow);
}

.player-stat-card .label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
}

.player-stat-value {
  display: block;
  font-size: clamp(1.4rem, 2vw, 2rem);
  font-weight: 800;
  line-height: 1.1;
}

.player-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.player-chart-card {
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(14, 22, 30, 0.92), rgba(11, 17, 23, 0.95));
  box-shadow: var(--shadow);
}

.player-chart-title {
  margin: 0 0 14px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.player-chart-wrap {
  position: relative;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.player-chart-wrap canvas {
  max-height: 220px;
}

.player-empty {
  margin-top: 0.5rem;
}

@media (max-width: 640px) {
  .player-stat-band {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .player-charts-grid {
    grid-template-columns: 1fr;
  }

  .player-filter .filter-input {
    min-width: 100%;
  }
}

/* Player clear button */
.player-clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  transition: color 0.15s ease;
}

.player-clear-btn:hover {
  color: var(--text);
}

/* ── H2H ─────────────────────────────────────────────────────────── */
.h2h-selectors {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.h2h-selectors .filter-input-wrap {
  flex: 1;
  min-width: 160px;
}

.h2h-vs {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  flex-shrink: 0;
}

/* record banner */
.h2h-record-banner {
  display: flex;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 28px;
}

.h2h-record-player {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 24px;
}

.h2h-record-player:last-child {
  justify-content: flex-end;
}

.h2h-record-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.h2h-record-score {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent-strong);
  line-height: 1;
}

.h2h-record-mid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 20px;
  border-left: 1px solid var(--panel-border);
  border-right: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.h2h-record-games {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

/* flat 3-column grid — every row spans all 3 cells so heights always align */
.h2h-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 32px;
}

.h2h-grid-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  padding: 14px 18px;
  border-bottom: 1px solid var(--panel-border);
}

.h2h-grid-name.h2h-grid-center {
  background: rgba(0,0,0,0.15);
  border-left: 1px solid var(--panel-border);
  border-right: 1px solid var(--panel-border);
}

.h2h-grid-name.h2h-grid-right { text-align: right; }

.h2h-grid-val {
  padding: 5px 18px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.7;
}

.h2h-grid-val.h2h-grid-right { text-align: right; }

.h2h-grid-label {
  padding: 5px 14px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  line-height: 1.7;
  background: rgba(0,0,0,0.15);
  border-left: 1px solid var(--panel-border);
  border-right: 1px solid var(--panel-border);
}

/* section separator row */
.h2h-grid-section {
  border-top: 1px solid var(--panel-border);
  padding-top: 9px;
  margin-top: 0;
}

.h2h-stat-winner { color: var(--accent-strong) !important; }
.h2h-stat-tie    { color: var(--muted) !important; }

/* pie chart section */
.h2h-charts-grid {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.h2h-chart-group {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  overflow: hidden;
  padding: 20px 20px 16px;
}

.h2h-chart-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 14px;
}

.h2h-chart-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.h2h-chart-player-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
  margin-bottom: 8px;
}

.h2h-no-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 0.78rem;
  color: var(--muted);
}