/* Modern CSS Reset and Base Styling */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}

:root {
  --primary: #5e60ce;
  --primary-light: #6930c3;
  --accent: #64dfdf;
  --accent-light: #80ffdb;
  --dark: #1a1a2e;
  --darker: #121220;
  --text: #ffffff;
  --text-muted: #c8c8c8;
  --danger: #e63946;
  --success: #06d6a0;
  --border-radius: 12px;
  --card-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  --transition: all 0.3s ease;
}

body {
  background: linear-gradient(135deg, var(--darker) 0%, var(--dark) 100%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

.app-container {
  width: 100%;
  max-width: 1200px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

/* Common Classes */
.hidden {
  display: none !important;
}

.screen {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Buttons */
.primary-btn {
  padding: 14px 20px;
  border-radius: var(--border-radius);
  border: none;
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    var(--primary-light) 100%
  );
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 10px rgba(94, 96, 206, 0.3);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(94, 96, 206, 0.5);
}

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

/* Login Screen */
.login-card {
  background: rgba(26, 26, 46, 0.8);
  backdrop-filter: blur(10px);
  border-radius: var(--border-radius);
  padding: 40px;
  text-align: center;
  box-shadow: var(--card-shadow);
  max-width: 400px;
  width: 100%;
}

.login-card h1 {
  color: var(--accent);
  margin-bottom: 10px;
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(
    90deg,
    var(--accent) 0%,
    var(--accent-light) 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  color: var(--text-muted);
  margin-bottom: 30px;
  font-size: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#player-name {
  padding: 15px;
  border-radius: var(--border-radius);
  border: 2px solid rgba(94, 96, 206, 0.3);
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 1rem;
  text-align: center;
  outline: none;
  transition: var(--transition);
}

#player-name:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(94, 96, 206, 0.3);
}

/* Color Selection */
.color-selection {
  margin-top: 15px;
  text-align: center;
}

.color-selection label {
  display: block;
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.color-swatches {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* Turnstile Loader */
#join-controls-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 50px; /* Ensure space for loader/button */
  margin-top: 10px; /* Add some space above */
}

#turnstile-loader {
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-left-color: var(--accent);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  animation: spin 1s linear infinite;
}

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

/* Game Screen */
#game-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto; /* Use minmax for content row */
  grid-template-areas:
    "header"
    "content"
    "powerups"
    "controls";
  gap: 15px;
}

.game-header {
  grid-area: header;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(26, 26, 46, 0.7);
  backdrop-filter: blur(10px);
  border-radius: var(--border-radius);
  padding: 12px 20px;
}

#player-info {
  display: flex;
  gap: 20px;
  font-size: 1.1rem;
  align-items: center; /* Vertically align items */
}

#player-name-display {
  font-weight: 600;
  color: var(--accent);
}

#player-score {
  min-width: 90px; /* Prevent resizing based on score digits */
  text-align: left;
}

#abilities {
  display: flex;
  gap: 12px;
}

.ability-button {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background-color: rgba(94, 96, 206, 0.2);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column; /* Stack elements vertically */
  padding-top: 5px; /* Add some padding for keybind */
  transition: var(--transition);
}

.ability-button:hover {
  background-color: rgba(94, 96, 206, 0.4);
  transform: translateY(-2px);
}

.ability-button.cooldown {
  cursor: not-allowed;
  opacity: 0.7;
}

.ability-icon {
  position: relative; /* Ensure icon is positioned relative to button */
  z-index: 1; /* Keep icon above overlay base */
  font-size: 1.5rem; /* Slightly larger icon */
  line-height: 1; /* Adjust line height for centering */
}

.keybind-display {
  position: absolute;
  bottom: 3px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  background-color: var(--darker);
  font-weight: 500;
  z-index: 3; /* Above overlay and timer */
}

.cooldown-timer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  z-index: 3; /* Above overlay */
  display: none; /* Hidden by default */
}

.ability-button.cooldown .cooldown-timer {
  display: block; /* Show timer when on cooldown */
}

.ability-button.cooldown .ability-icon {
  opacity: 0.3; /* Dim icon when on cooldown */
}
.cooldown-overlay {
  position: absolute;
  top: 0; /* Change from bottom to top */
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  height: 100%; /* Start fully covered */
  background-color: rgba(26, 26, 46, 0.85); /* Darker overlay */
  border-radius: 50%; /* Ensure it's circular */
  clip-path: inset(100% 0% 0% 0%); /* Start fully clipped (hidden from top) */
  transition: clip-path 0.1s linear; /* Animate the clip-path */
  z-index: 2; /* Position between icon and timer/keybind */
  background-color: rgba(0, 0, 0, 0.7);
  transition: height 0.1s linear;
  /* transition: height 0.1s linear; */ /* Remove old transition */
}

.game-content {
  grid-area: content;
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(200px, 1fr);
  gap: 15px;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.canvas-container {
  width: 100%;
  max-width: 100%; /* Ensure it doesn't overflow horizontally */
  max-height: 100%; /* Ensure it respects parent height */
  aspect-ratio: 1 / 1; /* Maintain square aspect ratio */
  position: relative;
  background-color: var(--darker);
  border-radius: var(--border-radius);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-canvas {
  /* position: absolute; Removed */
  /* top: 0; Removed */
  /* left: 0; Removed */
  width: 100%;
  height: 100%;
  object-fit: contain; /* Scale while preserving aspect ratio */
  max-width: 100%; /* Ensure it doesn't exceed container */
  max-height: 100%; /* Ensure it doesn't exceed container */
}

#leaderboard {
  background: rgba(26, 26, 46, 0.7);
  backdrop-filter: blur(10px);
  border-radius: var(--border-radius);
  padding: 15px;
  overflow-y: auto;
  width: 100%;
  height: 100%;
}

.leaderboard-header {
  color: var(--accent);
  text-align: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(100, 223, 223, 0.3);
  font-weight: 600;
  font-size: 1.1rem;
}

#leaderboard-list {
  list-style-type: none;
  padding: 0;
}

#leaderboard-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 5px;
  background: rgba(255, 255, 255, 0.05);
  transition: var(--transition);
}

#leaderboard-list li:hover {
  background: rgba(255, 255, 255, 0.1);
}

.leaderboard-name {
  /* Optional: styles for the name part */
  flex-grow: 1; /* Allow name to take up remaining space */
  margin-right: 10px; /* Add space between name and score */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  min-width: 50px; /* Prevent resizing based on score digits */
  text-align: right;
  font-weight: 600;
}

.power-up-container {
  grid-area: powerups;
  display: flex;
  justify-content: center;
  gap: 15px;
  padding: 10px 0;
}

.power-up-indicator {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(26, 26, 46, 0.7);
  border: 2px solid var(--accent);
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;
  box-shadow: 0 0 10px rgba(100, 223, 223, 0.3);
}

/* Mobile Controls */
#mobile-controls {
  grid-area: controls;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.horizontal-controls {
  display: flex;
  gap: 50px;
}

.control-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    var(--primary-light) 100%
  );
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 600;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 10px rgba(94, 96, 206, 0.3);
}

.control-btn:active {
  transform: scale(0.95);
  background: linear-gradient(
    135deg,
    var(--primary-light) 0%,
    var(--primary) 100%
  );
}

/* Game Over Screen */
.result-card {
  background: rgba(26, 26, 46, 0.8);
  backdrop-filter: blur(10px);
  border-radius: var(--border-radius);
  padding: 40px;
  text-align: center;
  box-shadow: var(--card-shadow);
  max-width: 400px;
  width: 100%;
}

.result-card h2 {
  color: var(--danger);
  margin-bottom: 20px;
  font-size: 2.5rem;
  font-weight: 700;
}

#final-score {
  font-size: 1.5rem;
  margin-bottom: 30px;
  color: var(--text);
}

/* Instructions Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

.modal-content {
  background: rgba(26, 26, 46, 0.95);
  margin: 5% auto;
  border-radius: var(--border-radius);
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  color: var(--text);
  box-shadow: var(--card-shadow);
  animation: modal-slide-in 0.3s ease;
}

@keyframes modal-slide-in {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h2 {
  color: var(--accent);
  font-size: 1.5rem;
  font-weight: 600;
}

.close-button {
  color: var(--text-muted);
  font-size: 1.8rem;
  font-weight: bold;
  cursor: pointer;
  transition: var(--transition);
}

.close-button:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px;
}

.info-section {
  margin-bottom: 25px;
}

.info-section h3 {
  color: var(--primary-light);
  margin-bottom: 12px;
  font-size: 1.2rem;
  font-weight: 600;
}

.info-section ul {
  padding-left: 20px;
  margin-bottom: 15px;
}

.info-section li {
  margin-bottom: 8px;
  line-height: 1.5;
}

.help-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    var(--primary-light) 100%
  );
  color: var(--text);
  font-size: 1.2rem;
  font-weight: bold;
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  box-shadow: 0 4px 15px rgba(94, 96, 206, 0.4);
  transition: var(--transition);
}

.help-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(94, 96, 206, 0.6);
}

/* Visual Effects */
.frozen {
  animation: freeze 0.5s;
}

@keyframes freeze {
  0% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.5) hue-rotate(180deg);
  }
  100% {
    filter: brightness(1);
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .game-content {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 3fr) minmax(0, 1fr);
  }

  #leaderboard {
    display: block;
    max-height: 200px;
  }

  .ability-button {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }

  .game-header {
    padding: 10px 15px;
  }

  #player-info {
    font-size: 1rem;
    gap: 10px;
  }

  .login-card,
  .result-card {
    padding: 30px 20px;
  }
}

@media (max-width: 480px) {
  .login-card h1,
  .result-card h2 {
    font-size: 2rem;
  }

  .ability-button {
    width: 35px;
    height: 35px;
    font-size: 1rem;
  }

  #abilities {
    gap: 8px;
  }

  #player-info {
    font-size: 0.9rem;
  }

  .modal-content {
    width: 90%;
    margin: 10% auto;
  }
}

/* Landscape Mode for Mobile */
@media (max-width: 768px) and (orientation: landscape) {
  #game-screen {
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "header header"
      "content controls"
      "powerups powerups";
  }

  .game-content {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100%;
  }

  .canvas-container {
    width: 100%;
    padding-bottom: 100%;
    max-height: 80vh;
  }

  #mobile-controls {
    height: 100%;
    width: 120px;
    margin-left: 10px;
  }

  .horizontal-controls {
    flex-direction: column;
    gap: 10px;
  }

  .control-btn {
    width: 50px;
    height: 50px;
    font-size: 1.2rem;
  }

  .login-card,
  .result-card {
    max-width: 300px;
  }
}
