/* Leaderboard Page */

/* Prevent page-level horizontal overflow - tables scroll within their wrappers */
#leaderboard {
  overflow-x: hidden;
}

#leaderboard .container {
  min-width: 0;
  /* Inherits max-width: 1200px from global .container - no override needed */
}

/* Beat global style.css `.section-title { text-align: center }` on this page */
#leaderboard .competitions-section > .section-title {
  text-align: left;
  margin-bottom: 1rem;
}

#leaderboard .lb-top-heading {
  text-align: left;
  margin: 0;
  width: 100%;
  font-size: clamp(1.35rem, 2.5vw, 2rem);
  line-height: 1.2;
}

/*
 * Always stack: title → (mobile tabs) → toolbar → LHP note.
 * Row layout beside the title was collapsing when LHP hid `.lb-period-game-controls`,
 * making the tab row jump up next to "Top Players".
 */
#leaderboard .lb-top-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
  margin-bottom: 1rem;
  min-width: 0;
}

/* Table scroll wrapper - allows horizontal scroll on mobile without page overflow */
.table-scroll-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -1px; /* slight negative margin so scrollbar doesn't add width */
  border-radius: var(--border-radius);
}

.table-scroll-wrapper .leaderboard-table {
  min-width: 500px; /* ensure table doesn't collapse on narrow screens */
}

/* Minimal stat tiles - metrics, not content cards */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 22px;
}

.stat-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #E8C047;
  line-height: 1.2;
}

.stat-value .jackpot-amount {
  color: #E8C047;
}

.stat-value .jackpot-detail {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.55);
  margin-top: 0.35rem;
}

.stat-value .no-data {
  color: rgba(255, 255, 255, 0.55);
  font-weight: 400;
}

.stat-value .popular-card-name {
  display: block;
  color: #E8C047;
  font-size: 28px;
}

/* Card links: gold, underline only */
.stat-value a.popular-card-name {
  color: #E8C047;
  text-decoration: underline;
}
.stat-value a.popular-card-name:hover {
  color: #E8C047;
  opacity: 0.85;
}

.stat-value .popular-card-count {
  display: block;
  font-size: 13px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.55);
  margin-top: 0.35rem;
}

.stat-note {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
  margin-top: 0.35rem;
}

.leaderboard-table td a {
  color: var(--text-light);
  text-decoration: underline;
}
.leaderboard-table td a:hover {
  color: var(--text-light);
  opacity: 0.85;
}

/*
 * Toolbar: tabs | period controls. Second column only as wide as content (no stretched Apply).
 */
#leaderboard .lb-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 0;
  min-width: 0;
  width: 100%;
}

#leaderboard .lb-toolbar .leaderboard-tabs {
  margin-bottom: 0;
  min-width: 0;
  justify-self: start;
  width: 100%;
  max-width: 100%;
}

#leaderboard .lb-toolbar .period-filter-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  justify-self: end;
  justify-content: flex-end;
  width: max-content;
  max-width: 100%;
}

/* Keep game type + period + Apply on one row — intrinsic width only */
.lb-period-game-controls {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  width: auto;
  max-width: 100%;
}

/* Wide enough for "Scratchers" / "All Time" — avoid clipped select labels */
#leaderboard .lb-toolbar .period-filter-inline .filter-select-sm {
  flex: 0 0 auto;
  min-width: 9.5rem;
  max-width: none;
  width: auto;
}

#leaderboard .lb-toolbar .period-filter-inline .filter-btn-sm,
#leaderboard .lb-toolbar .period-filter-inline button[type="submit"] {
  flex: 0 0 auto;
  width: auto !important;
  min-width: 4.5rem;
  max-width: 8rem;
}

.filter-select-sm {
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--light-color);
  border-radius: var(--border-radius);
  background: var(--bg-card);
  color: var(--text-light);
  font-size: 0.9rem;
  min-width: 120px;
}

.filter-select-sm:focus {
  outline: none;
  border-color: var(--primary);
}

.filter-btn-sm {
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--border-radius);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.filter-btn-sm:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

/* Competitions */
.competitions-section {
  margin-bottom: 2.5rem;
}

.competitions-section .section-title {
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.competition-card {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  border: 1px solid var(--light-color);
  box-shadow: var(--shadow);
}

.competition-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.competition-header h3 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text-light);
  flex: 1 1 auto;
  min-width: 0;
}

.comp-name-with-info {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.25rem;
  white-space: nowrap;
}

.comp-name-with-info .comp-info-btn {
  flex-shrink: 0;
}

.competition-type {
  background: rgba(76, 110, 245, 0.2);
  color: var(--primary);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
}

.competition-scope-badge {
  background: rgba(168, 85, 247, 0.2);
  color: #a855f7;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
}

.competition-dates {
  color: var(--text-gray);
  font-size: 0.9rem;
  white-space: nowrap;
}

.comp-countdown {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.comp-countdown i {
  font-size: 0.85em;
  opacity: 0.9;
}

.comp-countdown-starts {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.upcoming-competition-card .competition-header {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.no-standings, .no-competitions {
  color: var(--text-gray);
  text-align: center;
  padding: 1.5rem;
}

.past-filter {
  margin-bottom: 1rem;
}

.past-filter label {
  margin-right: 0.75rem;
  font-weight: 600;
  color: var(--text-light);
}

.past-standings-container {
  margin-top: 1rem;
}

/* LHP season line: block paragraph; when info exists, text+icon wrapped in shrink-to-fit inline-flex (stays one run) */
.lhp-season-caption-row {
  display: block;
  width: 100%;
  color: var(--text-light);
  line-height: 1.5;
}

.lhp-season-caption-inline {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
  max-width: 100%;
  vertical-align: middle;
}

.lhp-season-caption-row .lhp-season-caption-text {
  color: inherit;
}

.lhp-season-caption-inline .lhp-season-caption-text {
  white-space: nowrap;
}

/* Season info: icon glued to dates; override any global full-width buttons */
.lhp-season-caption-row .lhp-season-info-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: auto !important;
  max-width: none !important;
  margin: 0 !important;
  flex-shrink: 0;
  vertical-align: middle;
  color: rgba(255, 255, 255, 0.72);
  opacity: 1;
}

.lhp-season-caption-row .lhp-season-info-btn:hover {
  color: rgba(255, 255, 255, 0.95);
  opacity: 1;
}

.lhp-season-ended-notice {
  margin: 0 0 0.65rem 0;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border-left: 3px solid rgba(232, 192, 71, 0.55);
  background: rgba(232, 192, 71, 0.08);
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.45;
}

.lhp-leaderboard-meta {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 0.45rem 0;
}

/* Must beat body a:link (underline) — that rule is (0,1,2); class alone loses */
a.lhp-how-link:link,
a.lhp-how-link:visited {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.42);
  text-decoration: none;
  text-underline-offset: unset;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  transition: color 0.15s ease, border-color 0.15s ease;
}

a.lhp-how-link:hover,
a.lhp-how-link:active {
  color: rgba(232, 192, 71, 0.88);
  border-bottom-color: rgba(232, 192, 71, 0.45);
}

.leaderboard-table th.past-lhp-th,
.leaderboard-table td.past-lhp-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Leaderboard tabs */
.leaderboards-section {
  margin-top: 2rem;
}

.leaderboard-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  list-style: none;
  padding: 0;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 0.6rem 1.25rem;
  background: var(--bg-card);
  border: 2px solid var(--light-color);
  border-radius: var(--border-radius);
  color: var(--text-light);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tab-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

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

/* Mobile leaderboard tabs - hidden by default */
.mobile-leaderboard-tabs {
  display: none;
}

/* Tablet and below (992px): use native select for reliable fit */
@media (max-width: 992px) {
  .desktop-leaderboard-tabs {
    display: none !important;
  }
  .mobile-leaderboard-tabs {
    display: block !important;
    margin-bottom: 0;
    width: 100%;
  }

  #leaderboard .lb-toolbar {
    grid-template-columns: 1fr;
    justify-items: end;
  }

  #leaderboard .lb-toolbar .period-filter-inline {
    justify-self: end;
    width: auto;
    max-width: 100%;
    justify-content: flex-end;
  }

  #leaderboard .lb-toolbar .lb-period-game-controls {
    display: flex;
    width: auto;
    max-width: 100%;
  }
  .mobile-tab-select {
    width: 100%;
    max-width: 100%;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    background: var(--bg-card);
    border: 2px solid var(--light-color);
    border-radius: var(--border-radius);
    color: var(--text-light);
    cursor: pointer;
    appearance: auto;
    -webkit-appearance: menulist;
  }
  .mobile-tab-select:focus {
    outline: none;
    border-color: var(--primary);
  }
}

@media (min-width: 993px) {
  .mobile-leaderboard-tabs {
    display: none !important;
  }
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.leaderboard-table thead th {
  background: var(--bg-card);
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-light);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
}

.leaderboard-table tbody td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-color);
}

/* Single rule between header and body (no double line from thick th + first-row td) */
.leaderboard-table tbody tr:first-child td {
  border-top: none;
}

.leaderboard-table tbody tr:hover {
  background: var(--card-hover);
}

.rank-cell {
  font-weight: 600;
  color: var(--text-light);
}

.empty-row {
  text-align: center;
  color: var(--text-gray);
  padding: 2rem !important;
}

.filter-select {
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--light-color);
  border-radius: var(--border-radius);
  background: var(--bg-card);
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Competition info button */
.comp-info-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  margin-left: 0.35rem;
  font-size: 1rem;
  opacity: 0.8;
  vertical-align: middle;
  transition: opacity 0.2s;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.comp-info-btn:hover {
  opacity: 1;
}

.comp-info-btn i {
  font-size: 1rem;
}

.past-comp-header {
  margin-bottom: 1rem;
}

.past-comp-header h3 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text-light);
}

/* Competition info popup */
.comp-info-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.comp-info-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.comp-info-content {
  position: relative;
  background: var(--card-bg);
  border-radius: var(--border-radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--light-color);
}

.comp-info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.comp-info-header h3 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text-light);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  padding-right: 0.5rem;
}

.comp-info-text a {
  color: var(--accent-color, #5b9fff);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.comp-info-text a:hover {
  filter: brightness(1.1);
}

.comp-info-close {
  background: none;
  border: none;
  color: var(--text-gray);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.2s;
}

.comp-info-close:hover {
  color: var(--text-light);
}

.comp-info-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.comp-info-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.6;
  color: var(--text-color);
}

@media (max-width: 768px) {
  .stats-cards {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .stat-card {
    min-width: 0;
  }

  .stat-value {
    font-size: 22px;
  }

  .stat-value .popular-card-name {
    font-size: 22px;
    word-break: break-word;
  }

  #leaderboard .lb-toolbar .period-filter-inline {
    justify-content: flex-end;
  }

  #leaderboard .lb-toolbar .lb-period-game-controls {
    display: flex;
    flex: 0 1 auto;
    width: auto;
    max-width: 100%;
    min-width: 0;
  }

  #leaderboard .lb-toolbar .period-filter-inline .filter-select-sm {
    flex: 1 1 0;
    min-width: 5.5rem;
    max-width: none;
  }

  #leaderboard .lb-toolbar .period-filter-inline .filter-btn-sm {
    flex: 0 0 auto;
    width: auto !important;
    max-width: 7rem;
  }

  .filter-select,
  .filter-select-sm {
    min-width: 0;
  }

  .competition-header {
    gap: 0.5rem;
  }

  .competition-type,
  .competition-dates,
  .comp-countdown {
    font-size: 0.8rem;
  }

  .competition-card {
    overflow: visible;
    min-width: 0;
  }

  .competition-standings {
    min-width: 0;
  }

  .table-scroll-wrapper {
    margin: 0 -0.5rem;
    padding: 0 0.25rem;
  }

  .table-scroll-wrapper .leaderboard-table {
    min-width: 480px;
  }

  .leaderboard-table {
    font-size: 0.8rem;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 0.5rem 0.4rem;
  }

  .past-filter {
    width: 100%;
  }

  .past-filter .filter-select {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .table-scroll-wrapper .leaderboard-table {
    min-width: 400px;
  }

  .stat-value .jackpot-detail {
    font-size: 12px;
  }

  /* One row: if narrow, scroll horizontally instead of stacking Apply under selects */
  #leaderboard .lb-toolbar .period-filter-inline {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
    margin-right: -0.25rem;
    padding-right: 0.25rem;
  }

  #leaderboard .lb-toolbar .lb-period-game-controls {
    width: max-content;
    max-width: 100%;
  }

  #leaderboard .lb-toolbar .period-filter-inline .filter-select-sm {
    flex: 0 0 auto;
    min-width: 7rem;
    max-width: none;
  }
}
