@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=Share+Tech+Mono&display=swap');

:root {
  --primary-color: #00f2fe;
  --secondary-color: #4facfe;
  --accent-color: #ff0844;
  --bg-gradient: radial-gradient(circle at center, #1b263b 0%, #0d1b2a 100%);
  --glass-bg: rgba(15, 23, 42, 0.65);
  --glass-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --shadow-glow: 0 0 15px rgba(0, 242, 254, 0.4);
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-drag: none;
}

body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh; /* Fallback */
  height: calc(var(--vh, 1vh) * 100); /* Dynamic viewport height to prevent mobile layout clipping */
  overflow: hidden;
  background: var(--bg-gradient);
  font-family: 'Outfit', sans-serif;
  color: var(--text-primary);
  position: relative;
  touch-action: none;
}

/* Custom Cursor */
#cursor {
  position: absolute;
  top: 0;
  left: 0;
  width: 40px;
  height: 40px;
  border: 2px solid var(--primary-color);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 9999;
  transition: width 0.1s ease, height 0.1s ease, border-color 0.15s ease;
  box-shadow: var(--shadow-glow);
  mix-blend-mode: screen;
}

#cursor.boosted {
  width: 80px;
  height: 80px;
  border-color: var(--accent-color);
  box-shadow: 0 0 20px rgba(255, 8, 68, 0.6);
}

@media (hover: none) {
  #cursor {
    display: none !important; /* Hide custom cursor on touch devices to prevent double cursor / latency visual */
  }
  body {
    cursor: auto;
  }
}

/* Canvas styling */
canvas {
  display: block;
  width: 100%;
  height: 100%;
  background-color: transparent;
  z-index: 1;
}

/* Big Scoreboard Overlay (Top-Left Background) */
#scoreboard {
  position: absolute;
  top: 40px;
  left: 40px;
  font-size: clamp(60px, 12vw, 150px);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.05);
  font-family: 'Share Tech Mono', monospace;
  pointer-events: none;
  z-index: 2;
  line-height: 1;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.02);
}

/* Center Stopwatch Overlay (Middle Background) */
#stopwatch {
  position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(50px, 10vw, 120px);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.08);
  font-family: 'Share Tech Mono', monospace;
  pointer-events: none;
  z-index: 2;
  line-height: 1;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.02);
}

/* Active HUD overlay showing smaller real-time values */
.hud-compact {
  position: absolute;
  top: 20px;
  left: 20px;
  display: flex;
  gap: 15px;
  z-index: 10;
  pointer-events: none;
}

.hud-item {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  padding: 8px 16px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

.hud-item span {
  font-family: 'Share Tech Mono', monospace;
  font-size: 18px;
  color: var(--primary-color);
}

/* Control Bar (Top-Right Controls) */
.control-bar {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 10px;
  z-index: 10;
}

.btn-icon {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--primary-color);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.btn-icon:active {
  transform: translateY(0);
}

/* Game Interface Layout */
.game-container {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Right Sidebar Leaderboard */
.leaderboard-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  width: 320px;
  height: 100%;
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border-left: 1px solid var(--glass-border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  z-index: 20; /* High z-index to overlay on top of canvas and HUD */
  transform: translateX(100%); /* Hidden by default, slide in when active */
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.25);
}

.leaderboard-header {
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 15px;
  margin-bottom: 20px;
}

.leaderboard-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, #fff 30%, var(--primary-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}

.leaderboard-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  overflow-y: auto;
  padding-right: 5px;
}

.leaderboard-list::-webkit-scrollbar {
  width: 4px;
}

.leaderboard-list::-webkit-scrollbar-track {
  background: transparent;
}

.leaderboard-list::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 2px;
}

.leaderboard-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  font-size: 14px;
  transition: all 0.15s ease;
}

.leaderboard-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.05);
}

.leaderboard-item.rank-1 {
  background: rgba(255, 215, 0, 0.08);
  border-color: rgba(255, 215, 0, 0.2);
}
.leaderboard-item.rank-1 .rank-badge {
  color: #ffd700;
}

.leaderboard-item.rank-2 {
  background: rgba(192, 192, 192, 0.08);
  border-color: rgba(192, 192, 192, 0.2);
}
.leaderboard-item.rank-2 .rank-badge {
  color: #c0c0c0;
}

.leaderboard-item.rank-3 {
  background: rgba(205, 127, 50, 0.08);
  border-color: rgba(205, 127, 50, 0.2);
}
.leaderboard-item.rank-3 .rank-badge {
  color: #cd7f32;
}

.leaderboard-player {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rank-badge {
  font-family: 'Share Tech Mono', monospace;
  font-weight: bold;
  font-size: 14px;
  color: var(--text-secondary);
}

.player-name {
  font-weight: 600;
}

.player-score {
  font-family: 'Share Tech Mono', monospace;
  font-weight: 700;
  color: var(--primary-color);
}

/* Overlays (Start / Pause / Game Over) */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(13, 27, 42, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.popup-card {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 30px 40px;
  border-radius: 20px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5), var(--shadow-glow);
  animation: scaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scaleIn {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.popup-title {
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 15px 0;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.popup-desc {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 25px;
  line-height: 1.6;
}

.popup-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  margin-bottom: 20px;
  text-align: center;
  transition: all 0.2s ease;
}

.popup-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  border: none;
  color: #0f172a;
  font-size: 16px;
  font-weight: 700;
  padding: 14px 28px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  box-shadow: 0 4px 15px rgba(0, 242, 254, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 242, 254, 0.5);
}

.btn-primary:active {
  transform: translateY(0);
}

/* Bottom Bar - Footer & Shortcut Guide */
.bottom-bar {
  position: absolute;
  bottom: 15px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 10;
  font-size: 12px;
  color: var(--text-secondary);
}

.shortcut-guide {
  display: flex;
  gap: 15px;
}

.shortcut-item {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.03);
  padding: 4px 8px;
  border-radius: 4px;
}

.shortcut-item kbd {
  background: #334155;
  color: #fff;
  border-radius: 3px;
  padding: 1px 4px;
  font-family: inherit;
  font-size: 10px;
  font-weight: bold;
}

.copyright-bar {
  font-weight: 500;
}

/* Mobile virtual actions floating panel */
.mobile-actions {
  display: none;
  position: absolute;
  bottom: 50px;
  left: 50%;
  transform: translateX(-50%);
  gap: 20px;
  z-index: 10;
}

.btn-action {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  transition: all 0.2s ease;
}

.btn-action:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.15);
}

.btn-action.cooldown {
  opacity: 0.5;
  pointer-events: none;
}

/* Toggle Leaderboard Button (Always visible on all screens except during gameplay) */
#btnToggleLeaderboard {
  display: flex;
}

@media (max-width: 480px) {
  .leaderboard-sidebar {
    width: 280px;
  }
}

@media (max-width: 768px) {
  #scoreboard {
    top: 75px;
    left: 20px;
  }
  
  .bottom-bar {
    flex-direction: column;
    gap: 8px;
    align-items: center;
    bottom: 10px;
  }
  
  .shortcut-guide {
    display: none; /* Hide keyboard shortcuts on mobile */
  }
  
  .mobile-actions {
    display: flex; /* Show mobile virtual action buttons */
  }
}
