/* =======================================================
   🏆 CONTEXTO LEADERBOARD STYLES
   ======================================================= */

:root {
  --bg-primary: #15202b;
  --bg-secondary: #1e2433;
  --bg-card: #252d3d;
  --bg-hover: rgba(255, 255, 255, 0.15);
  --orange-accent: #ff8c42;
  --pink-accent: #ff4081;
  --blue-accent: #4a90e2;
  --text-primary: #1a1a2e;
  --text-dim: #5a5a7a;
  --border-color: rgba(255, 255, 255, 0.2);
  --success-color: #10b981;
  --warning-color: #fbbf24;
  --background-image: none;
  --leaderboard-bg: transparent;
  --row-bg: transparent;
}

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

body {
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(135deg, #a8d8ea 0%, #d4e8f0 50%, #c9e4f5 100%);
  background-image: url('https://i.pinimg.com/originals/f1/a7/07/f1a707c5bad8b99796c8c4591d8fc6a2.gif');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: var(--text-primary);
  min-height: 100vh;
  margin: 0;
  padding: 0;
}

/* Background overlay for readability when image is set */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(168, 216, 234, 0.7) 0%, rgba(212, 232, 240, 0.75) 50%, rgba(201, 228, 245, 0.7) 100%);
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

body[data-has-bg-image="true"]::before {
  opacity: 1;
}

.leaderboard-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* =======================================================
   HEADER
   ======================================================= */

.leaderboard-header {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.leaderboard-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--orange-accent);
  text-align: center;
  flex: 1;
  margin: 0;
}

.settings-button {
  background: var(--orange-accent);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 28px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 300;
  line-height: 1;
  padding: 0;
}

.settings-button:hover {
  background: var(--pink-accent);
  transform: rotate(90deg) scale(1.1);
}

/* =======================================================
   FILTER BAR
   ======================================================= */

.filter-bar {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 15px;
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.filter-section {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.filter-section:has(.streamer-mode-toggle) {
  flex: 1;
}

.time-range-buttons {
  display: flex;
  gap: 8px;
}

.filter-btn, .mode-btn {
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14px;
  transition: all 0.3s ease;
}

.filter-btn:hover, .mode-btn:hover {
  background: var(--bg-hover);
  border-color: var(--orange-accent);
}

.filter-btn.active, .mode-btn.active {
  background: var(--orange-accent);
  border-color: var(--orange-accent);
  color: white;
}

.live-hosts-btn {
  background: #ef4444 !important;
  border-color: #ef4444 !important;
  animation: livePulse 2s ease-in-out infinite;
  margin-left: auto;
}

.live-hosts-btn:hover {
  background: #dc2626 !important;
  border-color: #dc2626 !important;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.streamer-mode-toggle {
  display: flex;
  gap: 8px;
  flex: 1;
}

.streamer-input-container {
  display: flex;
  gap: 8px;
  align-items: center;
}

.streamer-input {
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  font-size: 14px;
  min-width: 200px;
}

.streamer-input:focus {
  outline: none;
  border-color: var(--orange-accent);
}

.streamer-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.apply-btn {
  background: var(--success-color);
  border: none;
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14px;
  transition: all 0.3s ease;
}

.apply-btn:hover {
  background: #059669;
  transform: scale(1.05);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: white;
  margin: 0;
  height: 100%;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.search-section {
  flex: 1;
  min-width: 250px;
}

.search-container {
  position: relative;
  width: 100%;
}

.search-input {
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  color: white;
  padding: 8px 40px 8px 12px;
  border-radius: 8px;
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  font-size: 14px;
  width: 100%;
}

.search-input:focus {
  outline: none;
  border-color: var(--orange-accent);
}

.search-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.clear-search-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--text-dim);
  border: none;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.clear-search-btn:hover {
  background: var(--pink-accent);
}

/* =======================================================
   FILTER INFO
   ======================================================= */

.filter-info {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  padding: 12px 20px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  color: #000000;
  backdrop-filter: blur(10px);
}

/* =======================================================
   LEADERBOARD LIST
   ======================================================= */

.leaderboard-container {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 12px;
  padding: 20px;
  margin: 0 auto 20px;
  min-height: 400px;
  box-shadow: none;
  width: 80%;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.leaderboard-row {
  background: transparent;
  border: none;
  border-radius: 10px;
  padding: 3px 10px;
  display: flex;
  align-items: center;
  gap: 15px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.leaderboard-row:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateX(5px);
}

.leaderboard-row.highlighted {
  background: rgba(255, 193, 7, 0.4);
  box-shadow: 0 0 20px rgba(255, 193, 7, 0.3);
}

.rank-number {
  font-size: 24px;
  font-weight: 800;
  color: #000000;
  min-width: 50px;
  text-align: center;
}

.rank-number.top1 {
  color: #000000;
}

.rank-number.top2 {
  color: #000000;
}

.rank-number.top3 {
  color: #000000;
}

.player-avatar {
  width: 50px;
  height: 50px;
  border-radius: 0;
  border: none;
  object-fit: cover;
  background: transparent;
}

.player-info {
  flex: 1;
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.player-text {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.player-nickname {
  font-size: 18px;
  font-weight: 700;
  color: #000000;
}

.player-id {
  font-size: 12px;
  color: #333333;
  font-weight: 600;
}

.win-count {
  font-size: 20px;
  font-weight: 800;
  color: #000000;
  display: flex;
  align-items: center;
  gap: 5px;
}

.found-badge {
  background: var(--warning-color);
  color: #1e2433;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 800;
  margin-left: 10px;
}

/* =======================================================
   PAGINATION
   ======================================================= */

.pagination-container {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
}

.pagination-info {
  font-size: 14px;
  font-weight: 700;
  color: white;
}

.pagination-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.page-btn {
  background: rgba(255, 255, 255, 0.6);
  border: 2px solid var(--border-color);
  color: #000000;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14px;
  min-width: 40px;
  transition: all 0.3s ease;
  backdrop-filter: blur(5px);
}

.page-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.9);
  border-color: var(--orange-accent);
  transform: translateY(-1px);
}

.page-btn.active {
  background: var(--orange-accent);
  border-color: var(--orange-accent);
  color: white;
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =======================================================
   LOADING & EMPTY STATES
   ======================================================= */

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 20px;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid var(--border-color);
  border-top: 4px solid var(--orange-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: white;
}

.empty-state p {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
}

.empty-state-hint {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 600;
}

.error-message {
  background: rgba(239, 68, 68, 0.2);
  border: 2px solid #ef4444;
  color: #fca5a5;
  padding: 15px 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  text-align: center;
  font-weight: 600;
}

/* =======================================================
   SETTINGS PANEL
   ======================================================= */

.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.settings-panel {
  background: var(--bg-card);
  border-radius: 16px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.settings-header {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 16px 16px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--border-color);
}

.settings-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  color: var(--orange-accent);
}

.close-settings-btn {
  background: var(--text-dim);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 24px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.close-settings-btn:hover {
  background: var(--pink-accent);
  transform: rotate(90deg);
}

.settings-content {
  padding: 20px;
}

.settings-section {
  margin-bottom: 30px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section h3 {
  font-size: 18px;
  font-weight: 700;
  color: white;
  margin-bottom: 15px;
}

.background-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.background-option {
  position: relative;
  height: 100px;
  border-radius: 10px;
  border: 3px solid var(--border-color);
  cursor: pointer;
  overflow: hidden;
  transition: all 0.3s ease;
  background-size: cover;
  background-position: center;
}

.background-option:hover {
  border-color: var(--orange-accent);
  transform: scale(1.05);
}

.background-option.selected {
  border-color: var(--orange-accent);
  box-shadow: 0 0 20px rgba(255, 140, 66, 0.5);
}

.background-option.selected::after {
  content: '✓';
  position: absolute;
  top: 5px;
  right: 5px;
  background: var(--orange-accent);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
}

.export-info {
  font-size: 14px;
  color: white;
  margin-bottom: 15px;
}

.export-btn {
  background: var(--success-color);
  border: none;
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 16px;
  width: 100%;
  transition: all 0.3s ease;
}

.export-btn:hover:not(:disabled) {
  background: #059669;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.export-btn:disabled {
  background: var(--text-dim);
  cursor: not-allowed;
  opacity: 0.5;
}

.export-hint {
  font-size: 12px;
  color: var(--warning-color);
  margin-top: 10px;
  text-align: center;
}

/* =======================================================
   RESPONSIVE DESIGN
   ======================================================= */

@media (max-width: 768px) {
  .leaderboard-page {
    padding: 10px;
  }

  .leaderboard-title {
    font-size: 20px;
  }

  .settings-button {
    width: 36px;
    height: 36px;
    font-size: 24px;
  }

  .filter-bar {
    padding: 15px;
    gap: 10px;
  }

  .filter-section {
    width: 100%;
  }

  .filter-section:has(.streamer-mode-toggle) {
    width: auto;
    display: flex;
    justify-content: flex-start;
    flex: 1;
  }

  .time-range-buttons {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .streamer-mode-toggle {
    width: 100%;
    flex: 1;
  }

  .live-hosts-btn {
    margin-left: auto;
  }

  .streamer-input {
    min-width: 100%;
  }

  .leaderboard-row {
    padding: 12px 15px;
    gap: 10px;
  }

  .rank-number {
    font-size: 20px;
    min-width: 40px;
  }

  .player-avatar {
    width: 40px;
    height: 40px;
  }

  .player-nickname {
    font-size: 16px;
  }

  .win-count {
    font-size: 16px;
  }

  .background-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}

@media (max-width: 500px) {
  .header-content {
    flex-direction: column;
    gap: 15px;
  }

  .settings-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    width: 50px;
    height: 50px;
    font-size: 32px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }

  .leaderboard-container {
    width: 95%;
    padding: 10px 5px;
  }

  .leaderboard-row {
    flex-wrap: nowrap;
    padding: 5px 5px;
    gap: 5px;
  }

  .rank-number {
    font-size: 16px;
    min-width: 30px;
  }

  .player-avatar {
    width: 32px;
    height: 32px;
  }

  .player-info {
    flex: 1;
    min-width: 0;
    gap: 5px;
  }

  .player-text {
    min-width: 0;
    overflow: hidden;
  }

  .player-nickname {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .player-id {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .win-count {
    font-size: 14px;
    min-width: 50px;
    text-align: right;
    flex-shrink: 0;
  }

  .filter-bar {
    padding: 10px;
    gap: 8px;
  }

  .filter-btn, .mode-btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  .leaderboard-title {
    font-size: 18px;
  }

  .pagination-controls button {
    padding: 6px 10px;
    font-size: 12px;
  }
}
