:root {
  /* Colors */
  --primary: #0052FF;
  --primary-light: #4D7CFF;
  --primary-gradient: linear-gradient(135deg, #0052FF 0%, #4D7CFF 100%);
  
  --bg-color: #F8FAFC;
  --surface-color: #FFFFFF;
  --surface-hover: #F1F5F9;
  
  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-light: #F8FAFC; /* For inverted sections */
  
  --border-color: #E2E8F0;
  --border-focus: #94A3B8;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-primary: 0 4px 14px 0 rgba(0, 82, 255, 0.39);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  
  /* Radius */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Animation */
  --transition-base: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding-bottom: 80px; /* Mobile Nav Space */
}

@media (min-width: 768px) {
  body {
    padding-bottom: 40px;
    padding-top: 72px;
  }
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  margin-bottom: var(--space-sm);
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

.subtitle {
  font-size: 1.125rem;
  color: var(--text-muted);
  margin-bottom: var(--space-xl);
  font-weight: 400;
  max-width: 600px;
}

/* Layout */
.container {
  width: 100%;
  max-width: 1000px;
  padding: var(--space-lg);
  margin: 0 auto;
}

/* Navigation */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border-color);
  z-index: 1000;
  padding: var(--space-sm) var(--space-lg);
}

@media (min-width: 768px) {
  .nav {
    top: 0;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--border-color);
  }
}

.nav-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: none;
  align-items: center;
  gap: var(--space-sm);
}

@media (min-width: 768px) {
  .brand { display: flex; }
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-main);
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav nav {
  display: flex;
  justify-content: space-around;
  width: 100%;
  gap: var(--space-md);
}

@media (min-width: 768px) {
  .nav nav { width: auto; }
}

.nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  gap: 4px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  transition: var(--transition-base);
}

.nav-icon {
  font-size: 1.5rem;
  filter: grayscale(1);
  transition: var(--transition-base);
}

.nav a:hover {
  color: var(--text-main);
  background: var(--surface-hover);
}

.nav a.active {
  color: var(--primary);
}

.nav a.active .nav-icon {
  filter: grayscale(0);
  transform: scale(1.1);
}

/* Components: Card */
.card {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-light);
}

/* Components: Tabs */
.tabs {
  display: flex;
  background: var(--surface-color);
  padding: var(--space-xs);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  margin-bottom: var(--space-xl);
  box-shadow: var(--shadow-sm);
  width: fit-content;
}

.tab {
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: var(--transition-base);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 1px solid transparent;
}

.tab:hover {
  color: var(--text-main);
  background: var(--surface-hover);
}

.tab.active {
  background: var(--primary-gradient);
  color: white;
  box-shadow: var(--shadow-primary);
}

.tab-label {
  font-size: 0.9rem;
}

.tab-count {
  font-size: 0.75rem;
  opacity: 0.8;
  font-weight: 400;
}

/* Components: Section Title */
.section-title {
  font-size: 1.5rem;
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  position: relative;
  padding-left: var(--space-md);
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 24px;
  background: var(--primary-gradient);
  border-radius: var(--radius-full);
}

.section-title .icon {
  font-size: 1.2em;
}

/* Components: List/Table */
.rank-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.rank-item {
  display: flex;
  align-items: center;
  background: var(--surface-color);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  transition: var(--transition-base);
}

.rank-item:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-md);
  transform: translateX(4px);
}

.rank-num {
  font-size: 1.25rem;
  font-weight: 800;
  width: 40px;
  color: var(--text-muted);
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

.rank-item:nth-child(1) .rank-num { color: #F59E0B; }
.rank-item:nth-child(2) .rank-num { color: #64748B; }
.rank-item:nth-child(3) .rank-num { color: #B45309; }

.rank-info {
  flex: 1;
  margin-left: var(--space-md);
  min-width: 0; /* Text truncation fix */
}

.rank-name {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.badge-grade {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: #EEF2FF;
  color: var(--primary);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge.warning {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: #FFFBEB;
  color: #D97706;
  border: 1px solid #FEF3C7;
  font-weight: 600;
}

.rank-meta {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rank-score {
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--primary);
  text-align: right;
  min-width: 80px;
  flex-shrink: 0;
}

.rank-score span {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

.medal {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.medal.gold { background: #FEF3C7; color: #B45309; }
.medal.silver { background: #F1F5F9; color: #475569; }
.medal.bronze { background: #FFEDD5; color: #9A3412; }

/* Forms */
input, select, textarea {
  display: block;
  width: 100%;
  padding: var(--space-md);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-main);
  background-color: var(--surface-color);
  background-clip: padding-box;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: var(--transition-base);
  margin-bottom: var(--space-md);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(0, 82, 255, 0.1);
}

label {
  display: block;
  margin-bottom: var(--space-sm);
  font-weight: 600;
  color: var(--text-main);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-md) var(--space-xl);
  font-weight: 600;
  font-size: 1rem;
  border-radius: var(--radius-full);
  color: white;
  background: var(--primary-gradient);
  border: none;
  cursor: pointer;
  transition: var(--transition-base);
  text-decoration: none;
  box-shadow: var(--shadow-primary);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text-main);
  box-shadow: none;
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--border-color);
  transform: translateY(-1px);
}

.form-group {
  margin-bottom: var(--space-lg);
}

.form-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: -8px;
  margin-bottom: var(--space-md);
}

/* Animations */
@keyframes pulse-glow {
  0% { box-shadow: 0 0 0 0 rgba(0, 82, 255, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(0, 82, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 82, 255, 0); }
}

.pulse {
  animation: pulse-glow 2s infinite;
}

@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-6px); }
  100% { transform: translateY(0px); }
}

.floating {
  animation: float 4s ease-in-out infinite;
}

/* Inverted Section (for contrast) */
.inverted-section {
  background: var(--text-main);
  color: var(--text-light);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  margin-top: var(--space-xl);
}

.inverted-section h2 {
  color: var(--text-light);
}

.inverted-section .text-muted {
  color: #94A3B8;
}

/* Empty State */
.empty {
  padding: var(--space-xl);
  text-align: center;
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border-color);
  color: var(--text-muted);
}

/* Player Selector */
.player-selector {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--surface-color);
  margin-top: var(--space-sm);
}

.player-option {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  transition: var(--transition-base);
}

.player-option:last-child {
  border-bottom: none;
}

.player-option:hover {
  background: var(--surface-hover);
}

.player-option.selected {
  background: #EEF2FF; /* Light primary */
  border-color: var(--primary-light);
}

.player-option input[type="radio"] {
  display: none;
}

.player-check {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-base);
  flex-shrink: 0;
}

.player-option.selected .player-check {
  border-color: var(--primary);
  background: var(--primary);
}

.player-check::after {
  content: "✓";
  color: white;
  font-size: 12px;
  opacity: 0;
  transform: scale(0.5);
  transition: var(--transition-base);
}

.player-option.selected .player-check::after {
  opacity: 1;
  transform: scale(1);
}

.player-info-text {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.player-name-text {
  font-weight: 600;
  color: var(--text-main);
}

.player-meta-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* VS Badge for Form */
.vs-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg) 0;
  position: relative;
}

.vs-divider::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  height: 1px;
  background: var(--border-color);
  z-index: 0;
}

.vs-badge {
  background: var(--surface-color);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  z-index: 1;
  position: relative;
}

/* Selection Preview */
.selection-preview {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.selection-side {
  flex: 1;
  text-align: center;
  font-weight: 600;
  color: var(--text-muted);
}

.selection-side.active {
  color: var(--primary);
}

/* Responsive */
@media (max-width: 640px) {
  h1 { font-size: 2rem; }
  .container { padding: var(--space-md); }
  .rank-item { padding: var(--space-md); }
  .rank-score { font-size: 1.25rem; }
  
  .rank-name { font-size: 1rem; }
  .rank-num { font-size: 1.1rem; width: 30px; }
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.stat-box {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
  transition: var(--transition-base);
}

.stat-box:hover {
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Challenge Item */
.challenge-item {
  background: var(--surface-color);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-md);
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
}

.challenge-item:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-md);
}

.challenge-item.pending { border-left: 4px solid #F59E0B; }
.challenge-item.success { border-left: 4px solid #10B981; }
.challenge-item.fail { border-left: 4px solid #EF4444; }
.challenge-item.muted { border-left: 4px solid #94A3B8; }

.challenge-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.challenge-vs {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.vs-tag {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 400;
  margin: 0 4px;
}

.challenge-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: center;
}

.challenge-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Inverted List Items */
.inverted-section .rank-item {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  color: white;
}
.inverted-section .rank-num {
  color: rgba(255, 255, 255, 0.5);
}
.inverted-section .rank-name {
  color: white;
}
.inverted-section .rank-meta {
  color: rgba(255, 255, 255, 0.6);
}
.inverted-section .rank-score {
  color: var(--primary-light);
}
.inverted-section .rank-score span {
  color: rgba(255, 255, 255, 0.4);
}
.inverted-section .badge-grade {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}
