/* --- DESIGN SYSTEM & BRIGHT LIGHT THEMES --- */
:root {
  /* Squirtle Theme - Bright Sky Blue */
  --bg-color: #f0f9ff;          /* Light sky blue background */
  --panel-bg: rgba(224, 242, 254, 0.95); /* Bright translucent blue panel */
  --border-color: #7dd3fc;
  --accent-color: #0284c7;      /* Vivid Sky Blue */
  --accent-secondary: #0d9488;  /* Teal */
  --glow-shadow: 0 8px 32px rgba(2, 132, 199, 0.15);
  --text-primary: #0f172a;      /* Dark slate text for readability */
  --text-muted: #475569;
  --font-retro: 'Press Start 2P', monospace;
  --font-sans: 'Outfit', sans-serif;
  --border-radius: 20px;
}

body.theme-pikachu {
  /* Pikachu Theme - Bright Pastel Yellow */
  --bg-color: #fefce8;
  --panel-bg: rgba(254, 249, 195, 0.95);
  --border-color: #fde047;
  --accent-color: #ca8a04;      /* Gold */
  --accent-secondary: #dc2626;  /* Red */
  --glow-shadow: 0 8px 32px rgba(202, 138, 4, 0.15);
}

body.theme-creeper {
  /* Creeper Theme - Bright Pastel Green */
  --bg-color: #f0fdf4;
  --panel-bg: rgba(220, 252, 231, 0.95);
  --border-color: #86efac;
  --accent-color: #16a34a;      /* Grass Green */
  --accent-secondary: #15803d;  /* Dark Green */
  --glow-shadow: 0 8px 32px rgba(22, 163, 74, 0.15);
}

/* --- RESET & BASE --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  position: relative;
  transition: background-color 0.5s ease;
  padding: 1.5rem 1rem;
}

/* Bright animated grid background */
.bg-effects {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.bg-effects::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background-image: 
    linear-gradient(rgba(0, 0, 0, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.02) 1px, transparent 1px);
  background-size: 50px 50px;
  transform: perspective(500px) rotateX(55deg);
  animation: gridScroll 25s infinite linear;
}

@keyframes gridScroll {
  0% { transform: perspective(500px) rotateX(55deg) translateY(0); }
  100% { transform: perspective(500px) rotateX(55deg) translateY(50px); }
}

/* --- MAIN CONTAINER (EXPANDED SIZE) --- */
.clash-container {
  width: 100%;
  max-width: 920px; /* Increased width */
  height: 92vh;     /* Increased height */
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 2;
}

/* --- HUD DASHBOARD (LIGHT THEME) --- */
.hud-dashboard {
  background: var(--panel-bg);
  border: 4px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 0.65rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--glow-shadow);
  transition: all 0.4s ease;
  gap: 0.5rem;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-grow: 1;
  max-width: 50%;
}

.level-badge {
  background: var(--accent-color);
  color: #fff;
  font-family: var(--font-retro);
  font-size: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  white-space: nowrap;
}

.xp-bar-container {
  background: rgba(0, 0, 0, 0.06);
  border: 2px solid var(--border-color);
  height: 24px;
  border-radius: 10px;
  flex-grow: 1;
  position: relative;
  overflow: hidden;
}

.xp-bar-fill {
  background: linear-gradient(90deg, var(--accent-color), var(--accent-secondary));
  height: 100%;
  transition: width 0.3s ease;
}

.xp-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-retro);
  font-size: 0.45rem;
  color: var(--text-primary);
  width: 100%;
  text-align: center;
  white-space: nowrap;
}

.timer-display {
  font-family: var(--font-retro);
  font-size: 1.1rem;
  color: var(--accent-color);
  background: rgba(255,255,255,0.7);
  padding: 0.35rem 0.75rem;
  border-radius: 10px;
  border: 2px solid var(--border-color);
}

.rank-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.7);
  padding: 0.25rem 0.75rem;
  border-radius: 10px;
  border: 2px solid var(--border-color);
}

.rank-label {
  font-family: var(--font-retro);
  font-size: 0.45rem;
  color: var(--text-muted);
}

.rank-value {
  font-family: var(--font-retro);
  font-size: 0.8rem;
  color: var(--accent-color);
}

/* --- THE GAME VIEWPORT (MAXIMIZED AREA) --- */
.game-frame {
  position: relative;
  width: 100%;
  flex-grow: 1; /* Automatically stretches vertically to fill container */
  background: #f8fafc; /* Bright canvas background fallback */
  border: 6px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--glow-shadow);
  transition: all 0.4s ease;
}

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

/* Subtle CRT scanline overlay (lighter opacity) */
.game-frame::after {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  background: linear-gradient(rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.04) 50%);
  background-size: 100% 4px;
  z-index: 8;
  pointer-events: none;
}

/* --- FLOATING LEADERBOARD PANEL (LIGHT THEME) --- */
.leaderboard-panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 170px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
  z-index: 5;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

.leaderboard-panel h3 {
  font-family: var(--font-retro);
  font-size: 0.5rem;
  color: var(--accent-color);
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.2rem;
  text-align: center;
}

.leaderboard-panel ol {
  list-style: none;
}

.leaderboard-panel li {
  font-family: var(--font-retro);
  font-size: 0.45rem;
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  color: var(--text-primary);
}

.leaderboard-panel li.highlight {
  color: #ca8a04; /* Gold highlight for player */
  font-weight: bold;
}

/* Active powerup timers */
.powerup-indicators {
  position: absolute;
  top: 1rem;
  left: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 5;
}

.powerup-badge {
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--accent-color);
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  font-family: var(--font-retro);
  font-size: 0.45rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* --- OVERLAYS --- */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(240, 249, 255, 0.96); /* Bright light background overlay */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 2rem;
  text-align: center;
}

body.theme-pikachu .overlay { background: rgba(254, 252, 232, 0.96); }
body.theme-creeper .overlay { background: rgba(240, 253, 244, 0.96); }

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-title {
  font-family: var(--font-retro);
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
  color: var(--accent-color);
  text-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.overlay-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  max-width: 80%;
  line-height: 1.4;
}

/* --- CHARACTER GRID --- */
.character-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  width: 100%;
  margin-bottom: 2rem;
}

.char-card {
  background: rgba(255, 255, 255, 0.6);
  border: 3px solid var(--border-color);
  border-radius: 16px;
  padding: 1.25rem 0.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.02);
}

.char-card:hover {
  transform: translateY(-5px);
  border-color: var(--accent-color);
  background: rgba(255, 255, 255, 0.9);
}

.char-card.selected {
  background: #fff;
  border-color: var(--accent-color);
  box-shadow: 0 8px 20px rgba(0,0,0,0.06);
}

.char-avatar {
  width: 64px;
  height: 64px;
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid var(--border-color);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.char-card.selected .char-avatar {
  transform: scale(1.1) rotate(5deg);
  border-color: var(--accent-color);
}

.char-card h3 {
  font-family: var(--font-retro);
  font-size: 0.65rem;
  letter-spacing: 0.5px;
}

.char-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* --- BUTTONS --- */
.action-btn {
  font-family: var(--font-retro);
  font-size: 0.8rem;
  background: var(--accent-color);
  color: #fff;
  border: none;
  padding: 1rem 2.25rem;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
  transition: all 0.1s ease;
}

.action-btn:active {
  transform: translateY(4px);
  box-shadow: 0 0px 0 transparent;
}

.btn-secondary {
  background: #64748b;
}

.button-row {
  display: flex;
  gap: 1rem;
}

/* --- STATS SUMMARY --- */
.stats-summary {
  background: rgba(255, 255, 255, 0.8);
  border: 3px solid #ef4444;
  border-radius: 16px;
  padding: 1.25rem;
  width: 260px;
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.05);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-retro);
  font-size: 0.7rem;
  color: var(--text-primary);
}

.stat-val {
  font-weight: bold;
}

.text-danger {
  color: #ef4444 !important;
}

/* --- CONTROLS LAYER (JOYSTICK & BOOST) --- */
.controls-layer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  padding: 0 0.5rem;
}

/* Joystick */
.joystick-zone {
  display: none;
  width: 100px;
  height: 100px;
}

.joystick-base {
  width: 90px;
  height: 90px;
  background: var(--panel-bg);
  border: 3px solid var(--border-color);
  border-radius: 50%;
  position: relative;
  touch-action: none;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: var(--glow-shadow);
}

.joystick-handle {
  width: 38px;
  height: 38px;
  background: radial-gradient(circle, var(--accent-color) 0%, rgba(255, 255, 255, 0.8) 100%);
  border-radius: 50%;
  position: absolute;
  touch-action: none;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* Boost Button */
.boost-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}

.boost-btn {
  width: 76px;
  height: 76px;
  background: radial-gradient(circle, #fbbf24 0%, #f59e0b 100%);
  border: 4px solid #fff;
  border-radius: 50%;
  box-shadow: 0 6px 12px rgba(245, 158, 11, 0.25);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: transform 0.1s;
  touch-action: none;
}

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

.boost-icon {
  font-size: 1.5rem;
}

.boost-label {
  font-family: var(--font-retro);
  font-size: 0.38rem;
  color: #fff;
  margin-top: 0.15rem;
}

.boost-bar-container {
  width: 90px;
  height: 10px;
  background: rgba(0,0,0,0.05);
  border: 2px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}

.boost-bar-fill {
  height: 100%;
  background: #f59e0b;
  transition: width 0.1s ease;
}

/* Show joystick and boost button layout on touch screens */
body.touch-device .joystick-zone {
  display: block;
}

/* --- FOOTER --- */
.clash-footer {
  text-align: center;
  margin-top: 0.25rem;
}

.credit-link {
  font-family: var(--font-retro);
  font-size: 0.55rem;
  color: #94a3b8;
  text-decoration: none;
  letter-spacing: 0.5px;
  transition: color 0.3s;
}

.credit-link:hover {
  color: var(--accent-color);
}

/* --- RESPONSIVE SCALING --- */
@media (max-width: 768px) {
  body {
    padding: 0.5rem;
  }
  .clash-container {
    height: 96vh;
    gap: 0.5rem;
  }
  .hud-dashboard {
    padding: 0.5rem 0.75rem;
  }
  .timer-display {
    font-size: 0.95rem;
  }
  .level-badge {
    font-size: 0.65rem;
    padding: 0.4rem 0.6rem;
  }
  .leaderboard-panel {
    width: 130px;
  }
}

@media (max-width: 480px) {
  .character-grid {
    grid-template-columns: 1fr;
    gap: 0.4rem;
    max-height: 160px;
    overflow-y: auto;
  }
  .char-card {
    flex-direction: row;
    padding: 0.5rem 1rem;
    justify-content: flex-start;
  }
  .char-avatar {
    width: 36px;
    height: 36px;
  }
  .char-desc {
    display: none;
  }
}
