/* ─── Global Reset & Variables ────────────────────────────────────── */
:root {
  --font-title: 'Space Grotesk', sans-serif;
  --font-body: 'Outfit', sans-serif;
  --color-bg: #090a0f;
  --color-primary: #8a2be2;
  --color-primary-glow: rgba(138, 43, 226, 0.4);
  --color-accent: #00ffcc;
  --color-accent-glow: rgba(0, 255, 204, 0.4);
  --color-text: #f3f4f6;
  --color-text-muted: #9ca3af;
  --color-panel: rgba(17, 24, 39, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-highlight: rgba(255, 255, 255, 0.03);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--color-bg);
  font-family: var(--font-body);
  color: var(--color-text);
}

/* ─── Game Canvas ─────────────────────────────────────────────────── */
#gameCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
}

/* ─── Start Screen (Main Menu) ────────────────────────────────────── */
#startScreen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at center, #161726 0%, #080811 100%);
  overflow: hidden;
  transition: opacity 0.8s ease-in-out;
}

/* Ambient Animated Orbs */
.start-bg-orbs {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
  animation: float 20s infinite alternate ease-in-out;
}

.orb-1 { width: 400px; height: 400px; background: var(--color-primary); top: -100px; left: 10%; animation-duration: 25s; }
.orb-2 { width: 500px; height: 500px; background: #3b82f6; bottom: -150px; right: 15%; animation-duration: 30s; }
.orb-3 { width: 350px; height: 350px; background: var(--color-accent); top: 30%; right: 5%; animation-duration: 18s; }
.orb-4 { width: 300px; height: 300px; background: #ec4899; bottom: 20%; left: 5%; animation-duration: 22s; }
.orb-5 { width: 250px; height: 250px; background: #eab308; top: 10%; left: 45%; animation-duration: 15s; }

@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(50px, 50px) scale(1.15); }
}

/* Start Container */
.start-container {
  position: relative;
  z-index: 2;
  width: 90%;
  max-width: 480px;
  background: var(--color-panel);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 40px 30px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4),
              inset 0 1px 0 var(--glass-highlight);
  text-align: center;
  animation: containerAppear 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes containerAppear {
  0% { transform: translateY(30px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

/* Logo Design */
.logo-section {
  margin-bottom: 35px;
}

.logo-icon {
  position: relative;
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
}

.logo-cell {
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  border-radius: 43% 57% 50% 50% / 40% 45% 55% 60%;
  animation: blobby 8s linear infinite;
  box-shadow: 0 0 25px var(--color-primary-glow);
}

.logo-cell-inner {
  position: absolute;
  width: 40%;
  height: 40%;
  top: 30%;
  left: 30%;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

@keyframes blobby {
  0% { border-radius: 43% 57% 50% 50% / 40% 45% 55% 60%; }
  33% { border-radius: 55% 45% 58% 42% / 50% 52% 48% 50%; }
  66% { border-radius: 47% 53% 40% 60% / 45% 40% 60% 55%; }
  100% { border-radius: 43% 57% 50% 50% / 40% 45% 55% 60%; }
}

.game-title {
  font-family: var(--font-title);
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 5px;
}

.title-accent {
  background: linear-gradient(135deg, var(--color-accent), #00bbff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title-io {
  font-size: 1.8rem;
  color: var(--color-primary);
  vertical-align: super;
  font-weight: 900;
}

.game-subtitle {
  color: var(--color-text-muted);
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* Nickname Input & Play Button */
.input-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 30px;
}

.input-wrapper {
  position: relative;
  width: 100%;
}

#playerName {
  width: 100%;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 500;
  color: #fff;
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
}

#playerName:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--color-accent);
  box-shadow: 0 0 15px rgba(0, 255, 204, 0.15);
}

.input-glow {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  box-shadow: 0 0 20px var(--color-accent-glow);
}

#playerName:focus + .input-glow {
  opacity: 0.5;
}

#playBtn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--color-primary), #6f1ab6);
  border: none;
  border-radius: 14px;
  font-family: var(--font-title);
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 10px 20px var(--color-primary-glow);
  position: relative;
  overflow: hidden;
}

#playBtn:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 25px rgba(138, 43, 226, 0.6);
  background: linear-gradient(135deg, #9b42fc, var(--color-primary));
}

#playBtn:active {
  transform: translateY(1px);
}

.btn-icon {
  font-size: 0.9rem;
  transition: transform 0.3s;
}

#playBtn:hover .btn-icon {
  transform: translateX(3px);
}

/* Controls Info */
.controls-info {
  display: flex;
  justify-content: space-around;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 16px;
  padding: 15px 10px;
  margin-bottom: 25px;
}

.control-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.control-icon {
  font-size: 1.3rem;
}

/* Online Counter */
.online-count {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 255, 204, 0.05);
  border: 1px solid rgba(0, 255, 204, 0.15);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-accent);
}

.online-dot {
  width: 8px;
  height: 8px;
  background: var(--color-accent);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
  box-shadow: 0 0 8px var(--color-accent);
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.6; }
}

/* ─── HUD / Game UI Overlays ─────────────────────────────────────── */
#gameUI {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: none; /* Let clicks pass through to canvas */
}

#gameUI > * {
  pointer-events: auto; /* Re-enable pointer events for UI items */
}

/* Score Display */
#scoreDisplay {
  position: absolute;
  bottom: 25px;
  left: 25px;
  background: var(--color-panel);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 12px 22px;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 120px;
}

.score-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--color-text-muted);
}

.score-value {
  font-family: var(--font-title);
  font-size: 1.8rem;
  font-weight: 800;
  color: #fff;
}

/* Leaderboard */
#leaderboard {
  position: absolute;
  top: 25px;
  right: 25px;
  width: 250px;
  background: var(--color-panel);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  padding: 18px;
}

.lb-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-title);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 1px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.lb-icon {
  font-size: 1.1rem;
}

#leaderboardList {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 4px 6px;
  border-radius: 8px;
  transition: background 0.2s;
}

.lb-row.me {
  background: rgba(138, 43, 226, 0.15);
  border: 1px solid rgba(138, 43, 226, 0.3);
  font-weight: 600;
}

.lb-player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 70%;
  overflow: hidden;
  white-space: nowrap;
}

.lb-rank {
  font-weight: 700;
  color: var(--color-text-muted);
  width: 18px;
}

.lb-row.me .lb-rank {
  color: var(--color-accent);
}

.lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-score {
  font-weight: 600;
  color: #fff;
}

/* Minimap */
#minimap {
  position: absolute;
  bottom: 25px;
  right: 25px;
  width: 150px;
  height: 150px;
  background: var(--color-panel);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

#minimapCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ─── Death Screen (Game Over) ───────────────────────────────────── */
#deathScreen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9;
  background: rgba(9, 10, 15, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.5s ease-in-out;
}

.death-container {
  width: 90%;
  max-width: 400px;
  background: var(--color-panel);
  border: 1px solid rgba(255, 67, 87, 0.2);
  border-radius: 24px;
  padding: 40px 30px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5),
              0 0 30px rgba(255, 67, 87, 0.1);
  animation: containerAppear 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.death-icon {
  font-size: 3.5rem;
  margin-bottom: 15px;
  animation: wiggle 1s ease-in-out infinite alternate;
}

@keyframes wiggle {
  0% { transform: rotate(-5deg); }
  100% { transform: rotate(5deg); }
}

.death-title {
  font-family: var(--font-title);
  font-size: 2.2rem;
  font-weight: 800;
  color: #ff4757;
  margin-bottom: 8px;
}

.death-eaten-by {
  font-size: 0.95rem;
  color: var(--color-text-muted);
  margin-bottom: 25px;
}

.death-score {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 30px;
}

.death-score-label {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.death-score-value {
  font-family: var(--font-title);
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--color-accent);
}

.respawn-btn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, #ff4757, #ff6b81);
  border: none;
  border-radius: 14px;
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 10px 20px rgba(255, 71, 87, 0.3);
}

.respawn-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 25px rgba(255, 71, 87, 0.5);
  background: linear-gradient(135deg, #ff6b81, #ff4757);
}

.respawn-btn:active {
  transform: translateY(1px);
}

/* Responsive UI Adjustments */
@media (max-width: 600px) {
  .start-container {
    padding: 30px 20px;
  }
  
  .game-title {
    font-size: 2.2rem;
  }
  
  #leaderboard {
    top: 15px;
    right: 15px;
    width: 200px;
    padding: 12px;
  }
  
  #scoreDisplay {
    bottom: 15px;
    left: 15px;
    padding: 8px 15px;
  }
  
  #minimap {
    bottom: 15px;
    right: 15px;
    width: 100px;
    height: 100px;
  }
}
