* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: transparent !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: transparent !important;
  min-height: 100vh;
  padding: 0;
  color: #e0e0e0;
}

.container {
  max-width: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: transparent;
}

h1 {
  text-align: center;
  margin: 0;
  color: #1a1a2e;
  font-size: clamp(1.5em, 4vw, 2.2em);
  font-weight: 700;
  letter-spacing: -0.01em;
}

h2 {
  color: #ffffff;
  margin-bottom: 15px;
  font-size: clamp(1.2em, 2.5vw, 1.5em);
}

/* ============================================================
   BANNER HEADER — full width, sharp edges
   ============================================================ */
.header-banner {
  background: transparent;
  border-radius: 0;
  padding: 24px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

/* ============================================================
   SUMMARY STATS ROW
   ============================================================ */
.stats-row {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 8px;
}

.stat-card {
  background: rgba(30, 30, 60, 0.05);
  border-radius: 8px;
  padding: 10px 6px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0;
  min-width: 0;
}

.stat-label {
  font-size: 0.6em;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: 1.3;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-value {
  font-size: 1.15em;
  font-weight: 700;
  color: #1a1a2e;
  white-space: nowrap;
  margin-top: 3px;
}

.stat-positive {
  color: #16a34a !important;
}

.stat-negative {
  color: #dc2626 !important;
}

/* ============================================================
   PERFORMANCE CHART
   ============================================================ */
.chart-container {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  padding: 20px;
  margin: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.chart-wrapper {
  position: relative;
  height: 320px;
  width: 100%;
}

@media (max-width: 768px) {
  .chart-wrapper {
    height: 240px;
  }
}

/* ============================================================
   TABLE CONTAINERS
   ============================================================ */
.table-container {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  padding: 20px;
  margin: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: visible;
  position: relative;
}

.table-header-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  gap: 15px;
}

.clear-all-filters-btn {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #ffffff;
  font-size: 0.9em;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.clear-all-filters-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.table-wrapper {
  overflow: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

/* Loading overlay */
.table-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: #b0b0b0;
}

.table-loading.hidden {
  display: none;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   TABLE BASE STYLES
   ============================================================ */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  overflow: hidden;
  font-size: clamp(0.75em, 1.2vw, 0.9em);
  table-layout: fixed;
}

th {
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  color: #ffffff;
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
  background: rgba(45, 45, 68, 0.95) !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th.sorted-asc,
th.sorted-desc {
  color: #667eea;
}

#tournamentTable th {
  cursor: pointer;
  transition: color 0.2s ease;
}

#tournamentTable th:hover {
  color: #667eea;
}

td {
  padding: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: #e0e0e0;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

tbody tr {
  transition: background 0.15s ease;
}

/* Zebra stripe (applied via JS per-group) */
tbody tr.row-stripe {
  background: rgba(255, 255, 255, 0.04);
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.07);
}

/* Scrollbar styling (horizontal only) */
.table-wrapper::-webkit-scrollbar {
  height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
}

.table-wrapper::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ============================================================
   ROW COLOR CODING
   ============================================================ */

/* Win: subtle green */
tr.row-win,
tr.row-win.row-stripe {
  background: rgba(74, 222, 128, 0.07);
}
tr.row-win td {
  color: #c8f0d4;
}
tr.row-win:hover {
  background: rgba(74, 222, 128, 0.12);
}

/* Loss: subtle red (tournament table) */
tr.row-loss,
tr.row-loss.row-stripe {
  background: rgba(248, 113, 113, 0.07);
}
tr.row-loss td {
  color: #f5c6c6;
}
tr.row-loss:hover {
  background: rgba(248, 113, 113, 0.12);
}

/* Gold: big win / 1st place — slow shimmer on tr background */
tr.row-gold,
tr.row-gold.row-stripe {
  border-left: 3px solid rgba(255, 200, 0, 0.7);
  background-image:
    linear-gradient(
      105deg,
      rgba(255, 200, 0, 0.14) 0%,
      rgba(255, 200, 0, 0.06) 35%,
      rgba(255, 225, 100, 0.18) 45%,
      rgba(255, 225, 100, 0.22) 50%,
      rgba(255, 225, 100, 0.18) 55%,
      rgba(255, 200, 0, 0.06) 65%,
      rgba(255, 210, 50, 0.10) 100%
    );
  background-size: 200% 100%;
  animation: goldShimmer 8s linear infinite;
}
tr.row-gold td {
  color: #fde68a;
}
tr.row-gold td:first-child {
  position: relative;
  padding-left: 20px;
}
tr.row-gold td:first-child::before {
  content: "★";
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.6em;
  color: rgba(255, 215, 0, 0.8);
  animation: sparkle 3s ease-in-out infinite;
}
tr.row-gold:hover {
  background-image:
    linear-gradient(
      105deg,
      rgba(255, 200, 0, 0.20) 0%,
      rgba(255, 200, 0, 0.10) 35%,
      rgba(255, 225, 100, 0.26) 45%,
      rgba(255, 225, 100, 0.30) 50%,
      rgba(255, 225, 100, 0.26) 55%,
      rgba(255, 200, 0, 0.10) 65%,
      rgba(255, 210, 50, 0.16) 100%
    );
}

@keyframes goldShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes sparkle {
  0%, 100% { opacity: 0.5; transform: translateY(-50%) scale(1); }
  50%      { opacity: 1; transform: translateY(-50%) scale(1.3); }
}

/* Pending: same as normal rows (no special styling) */

/* ============================================================
   TOURNAMENT GROUP DIVIDER
   ============================================================ */
tr.group-first td {
  border-top: 2px solid rgba(150, 160, 200, 0.45);
}

/* group-alt kept only for JS compatibility — no alternate tinting */
tr.group-alt {
  background-color: transparent;
}

tr.group-alt.row-stripe {
  background-color: rgba(255, 255, 255, 0.04);
}

tr.group-alt.row-win,
tr.group-alt.row-win.row-stripe {
  background: rgba(74, 222, 128, 0.07);
}

tr.group-alt.row-loss,
tr.group-alt.row-loss.row-stripe {
  background: rgba(248, 113, 113, 0.07);
}

tr.group-alt.row-gold,
tr.group-alt.row-gold.row-stripe {
  border-left: 3px solid rgba(255, 200, 0, 0.7);
  background-image:
    linear-gradient(
      105deg,
      rgba(255, 200, 0, 0.14) 0%,
      rgba(255, 200, 0, 0.06) 35%,
      rgba(255, 225, 100, 0.18) 45%,
      rgba(255, 225, 100, 0.22) 50%,
      rgba(255, 225, 100, 0.18) 55%,
      rgba(255, 200, 0, 0.06) 65%,
      rgba(255, 210, 50, 0.10) 100%
    );
  background-size: 200% 100%;
  animation: goldShimmer 8s linear infinite;
}

/* ============================================================
   FILTER DROPDOWN
   ============================================================ */
.th-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.th-content span {
  flex: 1;
  min-width: 0;
}

.filter-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
  opacity: 0.7;
}

.filter-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  opacity: 1;
}

.filter-btn.sorted-asc,
.filter-btn.sorted-desc {
  color: #667eea;
  opacity: 1;
}

.filter-btn svg {
  width: 12px;
  height: 12px;
}

.filter-dropdown {
  position: fixed !important;
  background: rgba(30, 30, 46, 0.98);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 10000;
  display: none;
  min-width: 200px;
  max-width: 300px;
  max-height: 400px;
  overflow: visible;
  flex-direction: column;
  transform: none;
  margin: 0;
}

.filter-dropdown.active {
  display: flex;
  animation: fadeInDown 0.2s ease;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.filter-search {
  margin-bottom: 12px;
}

.filter-input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #ffffff;
  font-size: 0.9em;
  outline: none;
  transition: all 0.2s ease;
}

.filter-input:focus {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(102, 126, 234, 0.5);
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.filter-input::placeholder {
  color: #888;
}

.filter-options {
  max-height: 200px;
  min-height: 50px;
  overflow-y: auto;
  overflow-x: hidden;
  margin-bottom: 12px;
}

.filter-option {
  display: flex;
  align-items: center;
  padding: 8px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s ease;
  user-select: none;
}

.filter-option:hover {
  background: rgba(255, 255, 255, 0.08);
}

.filter-checkbox {
  margin-right: 8px;
  cursor: pointer;
  width: 16px;
  height: 16px;
  accent-color: #667eea;
}

.filter-option span {
  color: #e0e0e0;
  font-size: 0.9em;
  flex: 1;
}

.filter-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sort-btn,
.clear-filter-btn {
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 0.85em;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.sort-btn:hover {
  background: rgba(102, 126, 234, 0.2);
  border-color: rgba(102, 126, 234, 0.4);
  color: #ffffff;
}

.clear-filter-btn {
  background: rgba(255, 100, 100, 0.1);
  border-color: rgba(255, 100, 100, 0.2);
  color: #ffaaaa;
}

.clear-filter-btn:hover {
  background: rgba(255, 100, 100, 0.2);
  border-color: rgba(255, 100, 100, 0.4);
  color: #ffffff;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 968px) {
  .stats-row {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }

  .stat-card { padding: 8px 4px; }
  .stat-label { font-size: 0.55em; }
  .stat-value { font-size: 1em; }

  .table-container { margin: 0 10px; }
}

@media (max-width: 768px) {
  .header-banner { padding: 16px 14px; }

  .stats-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .stat-card { padding: 8px 6px; border-radius: 6px; }
  .stat-label { font-size: 0.55em; }
  .stat-value { font-size: 0.95em; }

  .table-container {
    padding: 12px;
    margin: 0 8px;
    border-radius: 12px;
  }

  th, td {
    padding: 6px;
    font-size: 0.8em;
  }

  .table-header-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .clear-all-filters-btn { width: 100%; }

  .filter-dropdown {
    max-width: calc(100vw - 24px);
    min-width: min(280px, calc(100vw - 24px));
  }
}

@media (max-width: 480px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  th, td {
    padding: 4px 6px;
    font-size: 0.75em;
  }

  h2 {
    font-size: 1.1em;
    margin-bottom: 10px;
  }
}