/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-deep: #0a0e1a;
  --bg-card: rgba(15, 25, 50, 0.85);
  --accent: #00d4ff;
  --accent-glow: rgba(0, 212, 255, 0.3);
  --accent2: #6c5ce7;
  --text: #e8ecf4;
  --text-dim: #8892a8;
  --success: #00e676;
  --danger: #ff5252;
  --water1: #0077b6;
  --water2: #00b4d8;
  --water3: #90e0ef;
  --radius: 16px;
  --font: 'Outfit', system-ui, sans-serif;
}

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

/* ─── Screens ──────────────────────────────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1;
}

.screen.active {
  display: flex;
}

/* ─── Lobby ────────────────────────────────────────────────────────────── */
#lobby-screen {
  background: linear-gradient(160deg, #0a0e1a 0%, #0d1b3e 50%, #0a2540 100%);
  flex-direction: column;
}

.lobby-container {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.logo {
  text-align: center;
}

.logo h1 {
  font-size: 56px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -1px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 18px;
  margin-top: 4px;
}

.lobby-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 440px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px var(--accent-glow);
  overflow: hidden;
}

.btn {
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 14px 24px;
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--accent-glow);
}

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-2px);
}

.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 14px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}

.join-group {
  display: flex;
  gap: 10px;
  align-items: stretch;
  width: 100%;
}

.join-group .btn-secondary {
  padding: 14px 18px;
}

#input-code {
  min-width: 0;
  flex: 1;
  font-family: var(--font);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 10px;
  text-align: center;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: var(--accent);
  padding: 12px;
  outline: none;
  transition: border-color 0.3s;
}

#input-code::placeholder {
  color: var(--text-dim);
  letter-spacing: 10px;
  font-weight: 400;
  font-size: 18px;
}

#input-code:focus {
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
}

.error-msg {
  color: var(--danger);
  font-size: 14px;
  text-align: center;
  min-height: 20px;
}

/* Water background animation */
.water-bg {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 30%;
  overflow: hidden;
  z-index: 1;
}

.wave {
  position: absolute;
  width: 200%;
  height: 100%;
  bottom: -50%;
  left: -50%;
  border-radius: 45%;
  animation: wave-rotate 8s linear infinite;
}

.wave1 {
  background: rgba(0, 119, 182, 0.15);
  animation-duration: 8s;
}

.wave2 {
  background: rgba(0, 180, 216, 0.1);
  animation-duration: 12s;
  animation-delay: -3s;
}

.wave3 {
  background: rgba(144, 224, 239, 0.08);
  animation-duration: 16s;
  animation-delay: -6s;
}

/* ─── Waiting Screen ──────────────────────────────────────────────────── */
#waiting-screen {
  background: linear-gradient(160deg, #0a0e1a, #0d1b3e);
  flex-direction: column;
}

.waiting-container {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.waiting-container h2 {
  font-size: 32px;
  font-weight: 800;
  color: var(--accent);
}

.code-display {
  font-size: 72px;
  font-weight: 800;
  letter-spacing: 16px;
  color: #fff;
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 40px;
  box-shadow: 0 0 40px var(--accent-glow);
  text-shadow: 0 0 20px var(--accent-glow);
}

.waiting-text {
  color: var(--text-dim);
  font-size: 16px;
}

.loader {
  width: 60px;
  height: 60px;
  position: relative;
}

.paddle-loader {
  width: 6px;
  height: 50px;
  background: var(--accent);
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: bottom center;
  animation: paddle-swing 1.5s ease-in-out infinite;
}

.waiting-sub {
  color: var(--text-dim);
  font-size: 14px;
  animation: pulse-text 2s ease-in-out infinite;
}

/* ─── Game Screen ─────────────────────────────────────────────────────── */
#game-screen {
  z-index: 0;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#game-hud {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}

.hud-badge {
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 999px;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.hud-hint {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 14px;
  border-radius: 8px;
  animation: pulse-text 3s ease-in-out infinite;
}

/* ─── Overlays ────────────────────────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 20;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
}

.overlay.active {
  display: flex;
}

.overlay-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.respawn-icon,
.victory-icon,
.left-icon {
  font-size: 64px;
}

.victory-content h2 {
  font-size: 48px;
  font-weight: 800;
  background: linear-gradient(135deg, #ffd700, #ff8c00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.victory-content p,
.left-content p {
  color: var(--text-dim);
  font-size: 18px;
}

/* ─── Animations ──────────────────────────────────────────────────────── */
@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

@keyframes wave-rotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@keyframes paddle-swing {

  0%,
  100% {
    transform: translate(-50%, -100%) rotate(-30deg);
  }

  50% {
    transform: translate(-50%, -100%) rotate(30deg);
  }
}

@keyframes pulse-text {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

@keyframes pop-in {
  from {
    transform: scale(0.8);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .lobby-card {
    width: 90vw;
    padding: 28px 20px;
  }

  .logo h1 {
    font-size: 40px;
  }

  .code-display {
    font-size: 48px;
    padding: 16px 24px;
    letter-spacing: 10px;
  }
}