/* CSS Variables for Theming */
:root {
  /* Light Mode */
  --bg-primary: #e8ecef;
  --bg-secondary: #ffffff;
  --bg-elevated: #f5f7fa;
  --text-primary: #2d3748;
  --text-secondary: #718096;
  --text-muted: #a0aec0;
  --accent: #48bb78;
  --accent-secondary: #38a169;
  --accent-glow: rgba(72, 187, 120, 0.4);
  --shadow-light: rgba(255, 255, 255, 0.8);
  --shadow-dark: rgba(163, 177, 198, 0.6);
  --shadow-inset-light: rgba(255, 255, 255, 0.5);
  --shadow-inset-dark: rgba(163, 177, 198, 0.4);
  --nav-bg: #e8ecef;
  --border-color: rgba(0, 0, 0, 0.05);
  --orb-color-1: rgba(72, 187, 120, 0.08);
  --orb-color-2: rgba(56, 161, 105, 0.06);
  --orb-color-3: rgba(104, 211, 145, 0.05);
  --gold-color: #ffd700;
  --gold-glow: rgba(255, 215, 0, 0.3);
  --animation-speed: 1;
}

[data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-elevated: #1f2a47;
  --text-primary: #edf2f7;
  --text-secondary: #a0aec0;
  --text-muted: #718096;
  --accent: #68d391;
  --accent-secondary: #48bb78;
  --accent-glow: rgba(104, 211, 145, 0.5);
  --shadow-light: rgba(255, 255, 255, 0.05);
  --shadow-dark: rgba(0, 0, 0, 0.5);
  --shadow-inset-light: rgba(255, 255, 255, 0.03);
  --shadow-inset-dark: rgba(0, 0, 0, 0.4);
  --nav-bg: #16213e;
  --border-color: rgba(255, 255, 255, 0.05);
  --orb-color-1: rgba(104, 211, 145, 0.06);
  --orb-color-2: rgba(72, 187, 120, 0.04);
  --orb-color-3: rgba(56, 161, 105, 0.03);
  --gold-color: #ffed4e;
  --gold-glow: rgba(255, 237, 78, 0.2);
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  max-height: 100dvh;
  width: 100vw;
  transition: background 0.3s ease, color 0.3s ease;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Animated Background */
.animated-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 1;
  will-change: transform;
}

.bg-orb-1 {
  width: 350px;
  height: 350px;
  background: var(--orb-color-1);
  top: -80px;
  right: -100px;
  animation: float1 28s ease-in-out infinite;
  opacity: 0.7;
}

.bg-orb-2 {
  width: 300px;
  height: 300px;
  background: var(--orb-color-2);
  bottom: 15%;
  left: -100px;
  animation: float2 32s ease-in-out infinite;
  opacity: 0.6;
}

.bg-orb-3 {
  width: 250px;
  height: 250px;
  background: var(--orb-color-3);
  bottom: -60px;
  right: 15%;
  animation: float3 30s ease-in-out infinite;
  opacity: 0.5;
}

@keyframes float1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(-30px, 40px) scale(1.1); }
  66% { transform: translate(20px, -20px) scale(0.95); }
}

@keyframes float2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, -30px) scale(1.05); }
}

@keyframes float3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-30px, 30px) scale(1.02); }
}

/* Loading Screen */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s ease;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
}

.loading-logo {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: pulse 1.5s ease-in-out infinite;
}

.loading-title {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.loading-bar-container {
  width: 200px;
  height: 4px;
  background: var(--accent-glow);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.loading-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  animation: loading-fill 1.5s ease-in-out infinite;
}

.loading-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

@keyframes loading-fill {
  0% { width: 0%; }
  50% { width: 70%; }
  100% { width: 100%; }
}

/* App Layout */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  z-index: 1;
}

.app.hidden {
  display: none;
}

/* Header */
.desktop-header {
  display: none;
  padding: 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
}

@media (min-width: 768px) {
  .desktop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}

.desktop-nav-left,
.desktop-nav-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.back-btn,
.desktop-nav-item {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.5rem;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.back-btn:hover,
.desktop-nav-item:hover {
  background: var(--bg-elevated);
  color: var(--accent);
}

/* Main Content */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  padding-bottom: 120px;
  scroll-behavior: smooth;
}

/* Leaderboard Header */
.leaderboard-header {
  text-align: center;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--shadow-dark);
}

.leaderboard-title {
  font-size: 2.5rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.leaderboard-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.leaderboard-info {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Your Rank Section */
.your-rank-section {
  margin-bottom: 2rem;
}

.your-rank-section.hidden {
  display: none;
}

.your-rank-card {
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-elevated));
  border: 2px solid var(--gold-color);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  box-shadow: 0 0 20px var(--gold-glow);
  animation: gold-pulse 2s ease-in-out infinite;
}

@keyframes gold-pulse {
  0%, 100% { box-shadow: 0 0 20px var(--gold-glow); }
  50% { box-shadow: 0 0 30px var(--gold-glow); }
}

.your-rank-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.5rem;
}

.your-rank-badge {
  font-size: 3rem;
  font-weight: 700;
  color: var(--gold-color);
  margin-bottom: 1rem;
  text-shadow: 0 0 10px var(--gold-glow);
}

.your-rank-stats {
  display: flex;
  justify-content: space-around;
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat {
  flex: 1;
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--accent);
}

.top-ten-message {
  background: var(--gold-color);
  color: #000;
  padding: 0.75rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1rem;
  margin-top: 1rem;
}

.top-ten-message.hidden {
  display: none;
}

/* Leaderboard Table */
.leaderboard-table-section {
  background: var(--bg-secondary);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px var(--shadow-dark);
  margin-bottom: 2rem;
}

.table-container {
  overflow-x: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.leaderboard-table thead {
  background: var(--bg-elevated);
  border-bottom: 2px solid var(--border-color);
}

.leaderboard-table th {
  padding: 1rem;
  text-align: left;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 0.8rem;
}

.leaderboard-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.leaderboard-table tbody tr {
  transition: background 0.2s ease;
}

.leaderboard-table tbody tr:hover {
  background: var(--bg-elevated);
}

.leaderboard-table tbody tr:last-child td {
  border-bottom: none;
}

/* Table Columns */
.rank-col {
  width: 5%;
  font-weight: 700;
  color: var(--accent);
}

.wallet-col {
  width: 35%;
}

.earned-col {
  width: 30%;
  text-align: right;
  color: var(--accent);
  font-weight: 600;
}

.taps-col {
  width: 30%;
  text-align: right;
  color: var(--text-secondary);
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
}

.rank-badge.top-three {
  background: var(--gold-glow);
  color: var(--gold-color);
  font-size: 1.2rem;
}

.wallet-address-short {
  font-family: "Courier New", monospace;
  font-size: 0.85rem;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.empty-title {
  font-size: 1.5rem;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.empty-text {
  color: var(--text-secondary);
}

/* Last Updated */
.last-updated-section {
  text-align: center;
  padding: 1rem;
  background: var(--bg-elevated);
  border-radius: 8px;
  margin-top: 2rem;
}

.last-updated {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Theme Toggle */
.theme-toggle {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
}

.theme-toggle input {
  display: none;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-elevated);
  border-radius: 13px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  padding: 0 4px;
}

.toggle-icon {
  font-size: 0.8rem;
  transition: all 0.3s ease;
}

.sun {
  margin-right: auto;
  opacity: 1;
}

.moon {
  margin-left: auto;
  opacity: 0.5;
}

.theme-toggle input:checked ~ .toggle-slider {
  background: var(--accent);
}

.theme-toggle input:checked ~ .toggle-slider .sun {
  opacity: 0.5;
}

.theme-toggle input:checked ~ .toggle-slider .moon {
  opacity: 1;
}

/* Mobile Controls */
.mobile-controls {
  display: flex;
  justify-content: center;
  padding: 1rem;
  gap: 1rem;
}

/* Mobile Theme Toggle */
.mobile-theme {
  width: 50px;
  height: 26px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--nav-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  z-index: 100;
  height: 70px;
}

@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  text-decoration: none;
  color: var(--text-secondary);
  transition: all 0.2s ease;
  border-top: 3px solid transparent;
}

.nav-item:hover,
.nav-item.active {
  color: var(--accent);
  border-top-color: var(--accent);
}

.nav-icon {
  width: 24px;
  height: 24px;
}

.nav-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 80px;
  right: 1rem;
  z-index: 1000;
  pointer-events: none;
}

@media (min-width: 768px) {
  .toast-container {
    bottom: 2rem;
  }
}

/* Responsive Design */
@media (max-width: 600px) {
  .leaderboard-title {
    font-size: 1.8rem;
  }

  .leaderboard-table {
    font-size: 0.85rem;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 0.75rem;
  }

  .rank-col { width: 15%; }
  .wallet-col { width: 35%; }
  .earned-col { width: 25%; }
  .taps-col { width: 25%; }

  .wallet-address-short {
    font-size: 0.75rem;
  }
}

@media (max-width: 400px) {
  .leaderboard-title {
    font-size: 1.5rem;
  }

  .leaderboard-table {
    font-size: 0.75rem;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 0.5rem;
  }

  .your-rank-stats {
    flex-direction: column;
  }
}
