/**
 * leaderboard.css
 *
 * Purpose: Leaderboard page styles including the rankings table,
 * loading states, error states, and responsive adjustments.
 *
 * Dependencies: base.css
 *
 * Key Styles:
 * - Leaderboard container and title
 * - Flex-based 3-column table layout (Rank, Possible ID, Level)
 * - No internal scrolling - page scrolls instead
 * - Player rank display with medals
 * - Current player highlight
 * - Responsive column widths for all zoom levels
 */

/* ==================== LEADERBOARD PAGE ==================== */

.leaderboard-page {
  display: none;
}

.leaderboard-page.active {
  display: block;
}

.leaderboard-container {
  max-width: 100%;
  width: 100%;
  margin: 0 auto;
  padding: 0 10px;
  box-sizing: border-box;
}

.leaderboard-title {
  font-size: 2.5em;
  color: #667eea;
  padding-top: 24px;
  margin-bottom: 10px;
  text-align: center;
  font-weight: 800;
}

.leaderboard-subtitle {
  font-size: 1em;
  color: #999;
  margin-bottom: 25px;
  text-align: center;
  font-weight: 300;
  letter-spacing: 0.5px;
}

.leaderboard-loading,
.leaderboard-error {
  display: none;
  text-align: center;
  padding: 40px 20px;
  color: #666;
  font-size: 1.1em;
}

.leaderboard-loading.visible,
.leaderboard-error.visible {
  display: block;
}

.leaderboard-error {
  color: #e74c3c;
}

.refresh-leaderboard-btn {
  display: block;
  margin: 20px auto 0;
  background: #667eea;
  color: white;
  border: none;
  padding: 10px 25px;
  font-size: 1em;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 0.3s,
    opacity 0.3s;
}

.refresh-leaderboard-btn:hover {
  transform: scale(1.05);
  opacity: 0.9;
}

.leaderboard-content {
  display: none;
}

.leaderboard-content.visible {
  display: flex;
  flex-direction: column;
}

/*
 * LEADERBOARD TABLE - Flex-based layout for consistent display
 *
 * RESPONSIVE DESIGN: Table fits its content and centers in the container.
 * No percentage-based widths - columns size based on content + padding.
 *
 * NO INTERNAL SCROLLING: Table displays all content naturally without
 * internal scroll mechanisms. Users scroll the entire page instead.
 * This ensures consistent behavior across all zoom levels.
 *
 * Layout: Flex-based structure where:
 * - Table width is auto (fits content), centered with margin: 0 auto
 * - Rows use flex for column alignment
 * - Columns use auto width with padding for spacing
 * - 3-column layout: Rank, Possible ID, Level
 */

.leaderboard-table {
  width: auto; /* Fit content, don't stretch */
  max-width: 100%;
  margin: 0 auto; /* Center the table */
  background: #f8f9fa;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

.leaderboard-table thead {
  background: #667eea;
  color: white;
  flex-shrink: 0;
  display: block;
}

.leaderboard-table tbody {
  display: block;
  overflow: visible;
}

/* No scrollbar styling needed - table displays naturally without internal scrolling */

/* Rows as flex containers for column alignment */
.leaderboard-table tr {
  display: flex;
  box-sizing: border-box;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  font-size: 0.95em;
  white-space: nowrap;
}

/* Column 1: Rank - fixed width, centered */
.leaderboard-table th:nth-child(1),
.leaderboard-table td:nth-child(1) {
  width: 70px;
  min-width: 70px;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  color: #667eea;
  padding: 14px 10px;
}

.leaderboard-table th:nth-child(1) {
  font-weight: 600;
  color: white;
}

/* Column 2: Possible ID - fixed width, left-aligned */
.leaderboard-table th:nth-child(2),
.leaderboard-table td:nth-child(2) {
  width: 180px;
  min-width: 180px;
  font-weight: 600;
  color: #333;
  padding: 14px 24px;
}

.leaderboard-table th:nth-child(2) {
  color: white;
}

/* Column 3: Level - fixed width, centered */
.leaderboard-table th:nth-child(3),
.leaderboard-table td:nth-child(3) {
  width: 80px;
  min-width: 80px;
  justify-content: center;
  text-align: center;
  color: #666;
  font-weight: 600;
  padding: 14px 20px;
}

.leaderboard-table th:nth-child(3) {
  color: white;
}

.leaderboard-table tbody tr {
  border-bottom: 1px solid #e0e0e0;
  transition: background 0.2s;
}

.leaderboard-table tbody tr:last-child {
  border-bottom: none;
}

.leaderboard-table tbody tr:hover {
  background: #f0f0f0;
}

.leaderboard-table tbody tr.current-player {
  background: #e8e8ff;
}

.leaderboard-table tbody tr.current-player:hover {
  background: #dcdcff;
}

.current-player-rank {
  margin-top: 25px;
  padding: 15px 20px;
  background: #f8f9fa;
  border-radius: 10px;
  border: 1px solid #e0e0e0;
  text-align: center;
  font-size: 1em;
  color: #666;
  font-weight: 600;
  display: none;
}

.current-player-rank.visible {
  display: block;
}

.current-player-rank::before {
  content: "━━━━━━";
  display: block;
  color: #d0d0d0;
  margin-bottom: 10px;
  letter-spacing: 3px;
}

/* ==================== LEADERBOARD LAYOUT ==================== */

/*
 * LEADERBOARD DISPLAY IMPLEMENTATION
 * - Table fits its content (top 10 players) without stretching
 * - No internal scrolling - entire page scrolls instead
 * - Back button appears directly below the table with proper spacing
 * - Consistent behavior across all zoom levels (75%, 80%, 90%, 100%)
 *
 * IMPORTANT: .leaderboard-page display is controlled by base rules above.
 * Only .leaderboard-page.active should be visible.
 */

/* When active, make leaderboard page a flex container */
.leaderboard-page.active {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto; /* Allow page scroll if content overflows */
  overflow-x: hidden;
}

/* Leaderboard container - no flex stretching, content fits naturally */
.leaderboard-page.active .leaderboard-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  padding: 0 10px 20px 10px;
  box-sizing: border-box;
  /* No height: 100% - let content determine height */
}

/* Title and subtitle stay fixed (no flex growth) */
.leaderboard-page.active .leaderboard-title,
.leaderboard-page.active .leaderboard-subtitle {
  flex-shrink: 0;
}

/* Content area - fits its content, no stretching */
.leaderboard-page.active .leaderboard-content.visible {
  display: flex;
  flex-direction: column;
  /* No flex: 1 - content fits naturally */
}

/*
 * BACK TO GAME BUTTON - Directly below table with proper spacing
 */
.leaderboard-page.active .leaderboard-container .back-to-game-btn {
  flex-shrink: 0;
  margin-top: 25px;
  padding: 14px 30px;
  font-size: 1.1em;
}

/* ==================== LEADERBOARD RESPONSIVE STYLES ==================== */

/*
 * LEADERBOARD RESPONSIVE DESIGN
 * Ensures the leaderboard table is always visible and centered at all screen sizes
 * and zoom levels. Prevents horizontal overflow and maintains proper button spacing.
 */

/* Medium screens and below */
@media (max-width: 550px) {
  .leaderboard-title {
    font-size: 2em;
    margin-bottom: 8px;
  }

  .leaderboard-subtitle {
    font-size: 0.9em;
    margin-bottom: 20px;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 10px 4px;
    font-size: 0.9em;
  }

  .leaderboard-container .back-to-game-btn {
    margin-top: 20px;
    padding: 12px 25px;
    font-size: 1em;
  }
}

/* Small mobile screens */
@media (max-width: 480px) {
  .leaderboard-container {
    padding: 0 8px 12px 8px;
  }

  .leaderboard-title {
    font-size: 1.8em;
    margin-bottom: 6px;
  }

  .leaderboard-subtitle {
    font-size: 0.85em;
    margin-bottom: 15px;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 12px 16px;
    font-size: 0.85em;
  }

  .leaderboard-table th:nth-child(1),
  .leaderboard-table td:nth-child(1) {
    width: 60px;
    min-width: 60px;
    padding: 12px 8px;
  }

  .leaderboard-table th:nth-child(2),
  .leaderboard-table td:nth-child(2) {
    width: 160px;
    min-width: 160px;
    padding: 12px 18px;
  }

  .leaderboard-table th:nth-child(3),
  .leaderboard-table td:nth-child(3) {
    width: 70px;
    min-width: 70px;
    padding: 12px 16px;
  }

  .leaderboard-container .back-to-game-btn {
    margin-top: 18px;
    padding: 11px 20px;
    font-size: 0.95em;
  }
}

/* Very small mobile screens */
@media (max-width: 375px) {
  .leaderboard-container {
    padding: 0 6px 10px 6px;
  }

  .leaderboard-title {
    font-size: 1.6em;
    margin-bottom: 5px;
  }

  .leaderboard-subtitle {
    font-size: 0.8em;
    margin-bottom: 12px;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 11px 14px;
    font-size: 0.8em;
  }

  .leaderboard-table th:nth-child(1),
  .leaderboard-table td:nth-child(1) {
    width: 55px;
    min-width: 55px;
    padding: 11px 6px;
  }

  .leaderboard-table th:nth-child(2),
  .leaderboard-table td:nth-child(2) {
    width: 145px;
    min-width: 145px;
    padding: 11px 14px;
  }

  .leaderboard-table th:nth-child(3),
  .leaderboard-table td:nth-child(3) {
    width: 65px;
    min-width: 65px;
    padding: 11px 14px;
  }

  .leaderboard-container .back-to-game-btn {
    margin-top: 15px;
    padding: 10px 18px;
    font-size: 0.9em;
  }
}

/* Tiny mobile screens */
@media (max-width: 320px) {
  .leaderboard-container {
    padding: 0 4px 8px 4px;
  }

  .leaderboard-title {
    font-size: 1.4em;
    margin-bottom: 4px;
  }

  .leaderboard-subtitle {
    font-size: 0.75em;
    margin-bottom: 10px;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 10px 12px;
    font-size: 0.75em;
  }

  .leaderboard-table th:nth-child(1),
  .leaderboard-table td:nth-child(1) {
    width: 50px;
    min-width: 50px;
    padding: 10px 5px;
  }

  .leaderboard-table th:nth-child(2),
  .leaderboard-table td:nth-child(2) {
    width: 130px;
    min-width: 130px;
    padding: 10px 12px;
  }

  .leaderboard-table th:nth-child(3),
  .leaderboard-table td:nth-child(3) {
    width: 55px;
    min-width: 55px;
    padding: 10px 12px;
  }

  .leaderboard-container .back-to-game-btn {
    margin-top: 12px;
    padding: 9px 15px;
    font-size: 0.85em;
  }
}
