/* ===== DESIGN TOKENS ===== */
:root {
  /* Color - OKLCH perceptual uniformity */
  --color-bg: oklch(7% 0.03 280);
  --color-surface: oklch(14% 0.04 280);
  --color-surface-hover: oklch(18% 0.05 280);
  --color-border: oklch(25% 0.03 280 / 0.3);
  --color-gold: oklch(80% 0.17 85);
  --color-orange: oklch(65% 0.2 35);
  --color-text: oklch(95% 0.01 280);
  --color-text-dim: oklch(60% 0.03 280);
  --color-text-muted: oklch(45% 0.03 280);
  --color-glass: oklch(100% 0 0 / 0.06);
  --color-glass-border: oklch(100% 0 0 / 0.1);
  --color-glow: oklch(80% 0.17 85 / 0.4);

  /* Typography - Fluid scale */
  --text-xs: clamp(0.625rem, 0.6rem + 0.125vw, 0.75rem);
  --text-sm: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-base: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
  --text-lg: clamp(1.125rem, 1rem + 0.625vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.25rem + 1.25vw, 2rem);
  --text-2xl: clamp(1.75rem, 1.25rem + 2.5vw, 3rem);
  --text-3xl: clamp(2.5rem, 1.5rem + 5vw, 5rem);

  /* Spacing */
  --space-xs: clamp(0.25rem, 0.2rem + 0.25vw, 0.375rem);
  --space-sm: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
  --space-md: clamp(0.75rem, 0.6rem + 0.75vw, 1.125rem);
  --space-lg: clamp(1rem, 0.8rem + 1vw, 1.5rem);
  --space-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2.25rem);
  --space-2xl: clamp(2rem, 1.6rem + 2vw, 3rem);

  /* Depth / Elevation */
  --elevation-1: 0 1px 3px oklch(0% 0 0 / 0.3);
  --elevation-2: 0 4px 12px oklch(0% 0 0 / 0.4);
  --elevation-3: 0 8px 24px oklch(0% 0 0 / 0.5);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
}

/* ===== RESET ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  overflow: hidden;
  height: 100dvh;
  width: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ===== LAYOUT ===== */
#root {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
}

.screen.active {
  display: flex;
}

.panel {
  background: var(--color-bg);
  padding-bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.panel::-webkit-scrollbar { width: 3px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb { background: var(--color-text-muted); border-radius: var(--radius-full); }

/* ===== LOADING ===== */
#loading {
  justify-content: center;
  align-items: center;
  gap: var(--space-lg);
}

.loader {
  width: 48px;
  height: 48px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== HEADER ===== */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-lg) var(--space-xl) var(--space-sm);
}

.balance-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.coin-icon { font-size: var(--text-xl); }

.balance-value {
  font-size: var(--text-2xl);
  font-weight: 800;
  background: linear-gradient(135deg, var(--color-gold), var(--color-orange));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-variant-numeric: tabular-nums;
}

.level-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.level-label {
  font-size: var(--text-sm);
  color: var(--color-gold);
  font-weight: 600;
}

.profit-label {
  font-size: var(--text-xs);
  color: var(--color-text-dim);
}

/* ===== ENERGY ===== */
.energy-section {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 0 var(--space-xl) var(--space-lg);
}

.energy-track {
  flex: 1;
  height: 6px;
  background: var(--color-glass);
  border-radius: var(--radius-full);
  overflow: hidden;
  box-shadow: inset 0 1px 2px oklch(0% 0 0 / 0.2);
}

.energy-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--color-orange), var(--color-gold));
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.energy-value {
  font-size: var(--text-xs);
  color: var(--color-text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 5ch;
  text-align: right;
}

/* ===== COIN ===== */
.coin-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
  position: relative;
}

.coin-btn {
  width: clamp(160px, 40vw, 220px);
  height: clamp(160px, 40vw, 220px);
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 35% 30%, var(--color-gold), oklch(65% 0.2 75) 50%, oklch(45% 0.15 70));
  cursor: pointer;
  position: relative;
  box-shadow:
    0 8px 32px var(--color-glow),
    inset 0 -4px 12px oklch(0% 0 0 / 0.4),
    inset 0 4px 12px oklch(100% 0 0 / 0.2);
  transition: transform 0.1s cubic-bezier(0.34, 1.56, 0.64, 1);
  touch-action: manipulation;
}

.coin-btn:active {
  transform: scale(0.9);
}

.coin-btn:focus-visible {
  outline: 3px solid var(--color-gold);
  outline-offset: 4px;
}

.coin-visual {
  font-size: clamp(3rem, 10vw, 5rem);
  display: block;
  pointer-events: none;
}

.tap-hint {
  font-size: var(--text-sm);
  color: var(--color-text-dim);
  animation: hintPulse 2s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ===== TAP FEEDBACK ===== */
#tapParticles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.tap-fly {
  position: fixed;
  pointer-events: none;
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--color-gold);
  z-index: 100;
  text-shadow: 0 0 12px var(--color-glow);
  animation: flyUp 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes flyUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-100px) scale(1.4); }
}

.coin-particle {
  position: absolute;
  font-size: var(--text-sm);
  animation: particleBurst 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes particleBurst {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--space-xs) 0;
  padding-bottom: max(var(--space-xs), env(safe-area-inset-bottom));
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-sm);
  background: none;
  border: none;
  color: var(--color-text-dim);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: color 0.2s ease;
  min-height: 48px;
  min-width: 48px;
  border-radius: var(--radius-sm);
}

.nav-item:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

.nav-item span:first-child { font-size: var(--text-lg); }

.nav-item.active {
  color: var(--color-gold);
}

.nav-label { font-weight: 500; }

/* ===== PANEL HEADER ===== */
.panel-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.panel-header h2 {
  font-size: var(--text-lg);
  font-weight: 700;
  text-wrap: balance;
}

.panel-back {
  background: var(--color-glass);
  border: 1px solid var(--color-glass-border);
  color: var(--color-text);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background 0.15s ease;
  min-height: 40px;
  min-width: 40px;
}

.panel-back:hover {
  background: var(--color-surface-hover);
}

.panel-back:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
}

/* ===== UPGRADES ===== */
.panel-list {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.upgrade-card {
  background: var(--color-glass);
  border: 1px solid var(--color-glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background 0.15s ease, transform 0.15s ease;
}

.upgrade-card:active {
  transform: scale(0.98);
}

.upgrade-info { flex: 1; }

.upgrade-name {
  font-weight: 600;
  font-size: var(--text-base);
}

.upgrade-desc {
  font-size: var(--text-sm);
  color: var(--color-text-dim);
  margin-top: var(--space-xs);
}

.upgrade-cost {
  color: var(--color-gold);
  font-weight: 700;
  font-size: var(--text-sm);
  margin-top: var(--space-xs);
  font-variant-numeric: tabular-nums;
}

.upgrade-btn {
  background: linear-gradient(135deg, var(--color-gold), var(--color-orange));
  border: none;
  color: oklch(10% 0 0);
  font-weight: 700;
  padding: var(--space-sm) var(--space-xl);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  transition: transform 0.1s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.15s ease;
  min-height: 40px;
  min-width: 40px;
}

.upgrade-btn:active { transform: scale(0.93); }

.upgrade-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.upgrade-btn:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* ===== REFERRAL ===== */
.referral-body {
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  align-items: center;
  text-align: center;
}

.referral-headline {
  font-size: var(--text-base);
  text-wrap: balance;
}

.glass-card {
  background: var(--color-glass);
  border: 1px solid var(--color-glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  box-shadow: var(--elevation-2);
}

.bonus-row {
  font-size: var(--text-sm);
  color: var(--color-text-dim);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  justify-content: center;
}

.bonus-row strong { color: var(--color-gold); }

.btn-glow {
  background: linear-gradient(135deg, var(--color-gold), var(--color-orange));
  border: none;
  color: oklch(10% 0 0);
  font-weight: 700;
  padding: var(--space-md) var(--space-2xl);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-base);
  width: 100%;
  max-width: 320px;
  transition: transform 0.1s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  box-shadow: 0 0 24px var(--color-glow);
  min-height: 48px;
}

.btn-glow:active {
  transform: scale(0.96);
}

.btn-glow:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

.referral-stats {
  display: flex;
  gap: var(--space-2xl);
  justify-content: center;
  width: 100%;
}

.stat-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--color-gold);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-dim);
}

/* ===== LEADERBOARD ===== */
.lb-list {
  gap: var(--space-sm);
}

.lb-item {
  background: var(--color-glass);
  border: 1px solid var(--color-glass-border);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.15s ease;
}

.lb-rank {
  width: 36px;
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: var(--text-base);
}

.lb-rank.top3 { font-size: var(--text-lg); }

.lb-name {
  flex: 1;
  font-weight: 500;
  font-size: var(--text-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-weight: 700;
  color: var(--color-gold);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ===== PREFERS REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .coin-btn { transition: none; }
  .upgrade-card { transition: none; }
  .nav-item { transition: none; }
}
