/* ========================================
   TiltBall Arena — Premium Styles
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700&display=swap');

/* ── CSS Custom Properties ── */
:root {
  --neon-cyan: #00f5ff;
  --neon-cyan-dim: rgba(0, 245, 255, 0.3);
  --neon-cyan-glow: rgba(0, 245, 255, 0.15);
  --neon-magenta: #ff00e5;
  --neon-magenta-dim: rgba(255, 0, 229, 0.3);
  --neon-magenta-glow: rgba(255, 0, 229, 0.15);
  --neon-green: #39ff14;
  --neon-green-dim: rgba(57, 255, 20, 0.3);
  --bg-dark: #0a0a1a;
  --bg-darker: #06060f;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --text: #e0e0e0;
  --text-dim: rgba(224, 224, 224, 0.5);
  --text-bright: #ffffff;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --transition-fast: 0.15s ease;
  --transition-med: 0.3s ease;
  --transition-slow: 0.6s ease;
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --shadow-neon-cyan: 0 0 20px rgba(0, 245, 255, 0.25), 0 0 60px rgba(0, 245, 255, 0.1);
  --shadow-neon-magenta: 0 0 20px rgba(255, 0, 229, 0.25), 0 0 60px rgba(255, 0, 229, 0.1);
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

input {
  font-family: inherit;
  outline: none;
  border: none;
}

ul {
  list-style: none;
}

/* ── Animated Background — Gradient Mesh ── */
.bg-gradient-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 600px 400px at 20% 30%, rgba(0, 245, 255, 0.07), transparent),
    radial-gradient(ellipse 500px 500px at 80% 70%, rgba(255, 0, 229, 0.06), transparent),
    radial-gradient(ellipse 400px 300px at 50% 50%, rgba(57, 255, 20, 0.04), transparent);
  animation: meshShift 12s ease-in-out infinite alternate;
}

@keyframes meshShift {
  0% {
    background:
      radial-gradient(ellipse 600px 400px at 20% 30%, rgba(0, 245, 255, 0.07), transparent),
      radial-gradient(ellipse 500px 500px at 80% 70%, rgba(255, 0, 229, 0.06), transparent),
      radial-gradient(ellipse 400px 300px at 50% 50%, rgba(57, 255, 20, 0.04), transparent);
  }
  50% {
    background:
      radial-gradient(ellipse 700px 500px at 70% 60%, rgba(0, 245, 255, 0.08), transparent),
      radial-gradient(ellipse 600px 400px at 30% 20%, rgba(255, 0, 229, 0.05), transparent),
      radial-gradient(ellipse 500px 400px at 60% 80%, rgba(57, 255, 20, 0.05), transparent);
  }
  100% {
    background:
      radial-gradient(ellipse 500px 600px at 40% 80%, rgba(0, 245, 255, 0.06), transparent),
      radial-gradient(ellipse 700px 300px at 60% 30%, rgba(255, 0, 229, 0.07), transparent),
      radial-gradient(ellipse 300px 500px at 20% 60%, rgba(57, 255, 20, 0.04), transparent);
  }
}

/* ── Floating Particles (CSS only) ── */
.bg-particles {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.particle {
  position: absolute;
  border-radius: 50%;
  opacity: 0;
  animation: particleFloat linear infinite;
}

.particle-1 {
  width: 4px;
  height: 4px;
  background: var(--neon-cyan);
  box-shadow: 0 0 8px var(--neon-cyan);
  left: 10%;
  animation-duration: 18s;
  animation-delay: 0s;
}

.particle-2 {
  width: 3px;
  height: 3px;
  background: var(--neon-magenta);
  box-shadow: 0 0 6px var(--neon-magenta);
  left: 30%;
  animation-duration: 22s;
  animation-delay: 3s;
}

.particle-3 {
  width: 5px;
  height: 5px;
  background: var(--neon-green);
  box-shadow: 0 0 10px var(--neon-green);
  left: 55%;
  animation-duration: 20s;
  animation-delay: 6s;
}

.particle-4 {
  width: 3px;
  height: 3px;
  background: var(--neon-cyan);
  box-shadow: 0 0 6px var(--neon-cyan);
  left: 75%;
  animation-duration: 25s;
  animation-delay: 2s;
}

.particle-5 {
  width: 4px;
  height: 4px;
  background: var(--neon-magenta);
  box-shadow: 0 0 8px var(--neon-magenta);
  left: 90%;
  animation-duration: 19s;
  animation-delay: 8s;
}

.particle-6 {
  width: 2px;
  height: 2px;
  background: var(--neon-green);
  box-shadow: 0 0 5px var(--neon-green);
  left: 45%;
  animation-duration: 24s;
  animation-delay: 5s;
}

@keyframes particleFloat {
  0% {
    transform: translateY(110vh) translateX(0);
    opacity: 0;
  }
  10% {
    opacity: 0.7;
  }
  50% {
    opacity: 0.4;
  }
  90% {
    opacity: 0.6;
  }
  100% {
    transform: translateY(-10vh) translateX(30px);
    opacity: 0;
  }
}

/* ── Landing Page ── */
.landing-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.landing-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 440px;
}

.landing-card {
  width: 100%;
  padding: 40px 32px;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Logo Section ── */
.logo-section {
  text-align: center;
  margin-bottom: 8px;
}

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

.logo-ball {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #b0f5ff, var(--neon-cyan));
  box-shadow: 0 0 16px var(--neon-cyan), 0 0 40px rgba(0, 245, 255, 0.3);
  animation: ballBounce 2.5s ease-in-out infinite;
}

.logo-ring {
  position: absolute;
  inset: 0;
  border: 2px solid var(--neon-cyan-dim);
  border-radius: 50%;
  animation: ringPulse 2.5s ease-in-out infinite;
}

@keyframes ballBounce {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -60%) scale(1.1); }
}

@keyframes ringPulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.15); opacity: 0.2; }
}

.game-title {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text-bright);
  text-shadow:
    0 0 10px rgba(0, 245, 255, 0.5),
    0 0 30px rgba(0, 245, 255, 0.2),
    0 0 60px rgba(0, 245, 255, 0.1);
  animation: titleGlow 3s ease-in-out infinite alternate;
  line-height: 1.1;
}

.title-accent {
  display: block;
  font-size: 1.6rem;
  letter-spacing: 8px;
  color: var(--neon-cyan);
  text-shadow:
    0 0 10px rgba(0, 245, 255, 0.6),
    0 0 30px rgba(0, 245, 255, 0.3),
    0 0 60px rgba(0, 245, 255, 0.15);
}

@keyframes titleGlow {
  0% { text-shadow: 0 0 10px rgba(0, 245, 255, 0.5), 0 0 30px rgba(0, 245, 255, 0.2); }
  100% { text-shadow: 0 0 15px rgba(0, 245, 255, 0.7), 0 0 40px rgba(0, 245, 255, 0.3), 0 0 80px rgba(0, 245, 255, 0.15); }
}

.tagline {
  margin-top: 10px;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

/* ── Input Styles ── */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.neon-input {
  width: 100%;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-bright);
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-med), box-shadow var(--transition-med), background var(--transition-med);
}

.neon-input::placeholder {
  color: rgba(224, 224, 224, 0.25);
}

.neon-input:focus {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 0 3px var(--neon-cyan-glow), inset 0 0 12px rgba(0, 245, 255, 0.05);
  background: rgba(255, 255, 255, 0.06);
}

.room-code-input {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 8px;
  text-transform: uppercase;
}

.room-code-input:focus {
  border-color: var(--neon-magenta);
  box-shadow: 0 0 0 3px var(--neon-magenta-glow), inset 0 0 12px rgba(255, 0, 229, 0.05);
}

/* ── Button Styles ── */
.btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 16px 24px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  border-radius: var(--radius-md);
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-med),
    background var(--transition-med);
  overflow: hidden;
}

.btn:active {
  transform: scale(0.97);
}

.btn.loading .btn-text {
  opacity: 0;
}

.btn.loading .btn-loader {
  display: block;
}

.btn-loader {
  display: none;
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Primary Button (Cyan) */
.btn-primary {
  color: var(--bg-dark);
  background: linear-gradient(135deg, var(--neon-cyan), #00c4cc);
  box-shadow: var(--shadow-neon-cyan);
}

.btn-primary:hover {
  box-shadow:
    0 0 30px rgba(0, 245, 255, 0.4),
    0 0 80px rgba(0, 245, 255, 0.15);
}

.btn-glow-cyan {
  animation: glowPulseCyan 2.5s ease-in-out infinite;
}

@keyframes glowPulseCyan {
  0%, 100% {
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.25), 0 0 60px rgba(0, 245, 255, 0.1);
  }
  50% {
    box-shadow: 0 0 30px rgba(0, 245, 255, 0.4), 0 0 80px rgba(0, 245, 255, 0.2);
  }
}

/* Secondary Button (Magenta) */
.btn-secondary {
  color: var(--text-bright);
  background: linear-gradient(135deg, var(--neon-magenta), #cc00b8);
  box-shadow: var(--shadow-neon-magenta);
}

.btn-secondary:hover {
  box-shadow:
    0 0 30px rgba(255, 0, 229, 0.4),
    0 0 80px rgba(255, 0, 229, 0.15);
}

.btn-glow-magenta {
  animation: glowPulseMagenta 2.5s ease-in-out infinite;
}

@keyframes glowPulseMagenta {
  0%, 100% {
    box-shadow: 0 0 20px rgba(255, 0, 229, 0.25), 0 0 60px rgba(255, 0, 229, 0.1);
  }
  50% {
    box-shadow: 0 0 30px rgba(255, 0, 229, 0.4), 0 0 80px rgba(255, 0, 229, 0.2);
  }
}

/* ── Divider ── */
.divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 4px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
}

.divider-text {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Join Section ── */
.join-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Error Message ── */
.error-message {
  font-size: 0.85rem;
  color: #ff6b6b;
  text-align: center;
  min-height: 1.2em;
  transition: opacity var(--transition-med);
  opacity: 0;
}

.error-message.visible {
  opacity: 1;
}

/* ── Footer ── */
.landing-footer {
  margin-top: 24px;
  text-align: center;
}

.landing-footer p {
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

/* ========================================
   GAME PAGE STYLES
   ======================================== */

.game-page {
  overflow: hidden;
  background: var(--bg-dark);
  width: 100vw;
  height: 100vh;
  position: fixed;
  inset: 0;
}

/* ── Canvas ── */
#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  background: var(--bg-dark);
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ── HUD Overlay ── */
.hud-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  padding: 12px;
}

.hud-panel {
  pointer-events: auto;
  padding: 8px 14px;
  background: rgba(10, 10, 26, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.hud-label {
  display: block;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.hud-value {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-bright);
}

/* Top Left — Room Code */
.hud-top-left {
  position: fixed;
  top: 12px;
  left: 12px;
}

.hud-room-code {
  font-size: 1.2rem;
  letter-spacing: 4px;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px rgba(0, 245, 255, 0.4);
}

/* Top Center — Timer */
.hud-top-center {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 20px;
}

.hud-timer {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-bright);
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
  min-width: 50px;
  text-align: center;
  display: block;
}

.hud-timer.warning {
  color: #ff6b6b;
  text-shadow: 0 0 12px rgba(255, 107, 107, 0.5);
  animation: timerPulse 0.5s ease-in-out infinite alternate;
}

@keyframes timerPulse {
  from { opacity: 1; }
  to { opacity: 0.6; }
}

/* Top Right — Scoreboard */
.hud-top-right {
  position: fixed;
  top: 12px;
  right: 12px;
  min-width: 120px;
}

.hud-scoreboard {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hud-scoreboard li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.scoreboard-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 4px currentColor;
}

.scoreboard-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80px;
}

.scoreboard-score {
  font-weight: 700;
  color: var(--text-bright);
  min-width: 20px;
  text-align: right;
}

/* Bottom Left — Connection Status */
.hud-bottom-left {
  position: fixed;
  bottom: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: background var(--transition-med), box-shadow var(--transition-med);
}

.connection-dot.connected {
  background: var(--neon-green);
  box-shadow: 0 0 6px var(--neon-green);
}

.connection-dot.disconnected {
  background: #ff6b6b;
  box-shadow: 0 0 6px #ff6b6b;
  animation: dotBlink 1.5s ease-in-out infinite;
}

@keyframes dotBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.connection-text {
  font-size: 0.7rem;
}

/* ── Motion Permission Button ── */
.motion-perm-container {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn-motion-perm {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 32px 40px;
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid var(--neon-cyan-dim);
  border-radius: var(--radius-lg);
  color: var(--text-bright);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  animation: motionBtnPulse 2s ease-in-out infinite;
  cursor: pointer;
  transition: transform var(--transition-fast);
}

.btn-motion-perm:active {
  transform: scale(0.96);
}

.motion-perm-icon {
  font-size: 2.5rem;
}

.motion-perm-text {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.motion-perm-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 400;
}

@keyframes motionBtnPulse {
  0%, 100% {
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.15), 0 0 60px rgba(0, 245, 255, 0.05);
    border-color: var(--neon-cyan-dim);
  }
  50% {
    box-shadow: 0 0 30px rgba(0, 245, 255, 0.3), 0 0 80px rgba(0, 245, 255, 0.1);
    border-color: var(--neon-cyan);
  }
}

/* ── Round End Overlay ── */
.round-end-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 26, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: overlayFadeIn 0.4s ease-out;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.round-end-card {
  width: 90%;
  max-width: 400px;
  padding: 32px 28px;
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: cardSlideUp 0.5s ease-out;
}

@keyframes cardSlideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.round-end-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-bright);
  margin-bottom: 20px;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.2);
}

.leaderboard-container {
  margin-bottom: 24px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.leaderboard-table td {
  padding: 10px 4px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.lb-rank {
  width: 30px;
  text-align: center;
}

.lb-name {
  text-align: left;
}

.lb-score {
  width: 60px;
  text-align: right;
}

.leaderboard-table tbody tr:first-child td {
  color: var(--neon-cyan);
  font-size: 1rem;
}

.leaderboard-table .lb-player-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lb-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.btn-ready {
  margin-top: 8px;
  margin-bottom: 8px;
}

.ready-status {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ── Score Notification ── */
.score-notification {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
  font-size: 2rem;
  font-weight: 700;
  color: var(--neon-green);
  text-shadow: 0 0 20px var(--neon-green);
  pointer-events: none;
  animation: scorePopAnim 1.2s ease-out forwards;
}

@keyframes scorePopAnim {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.5);
  }
  30% {
    transform: translate(-50%, -50%) scale(1.3);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -80%) scale(1);
  }
}

/* ── Utility / Responsive ── */
@media (max-width: 480px) {
  .landing-card {
    padding: 32px 22px;
    border-radius: var(--radius-lg);
  }

  .game-title {
    font-size: 1.8rem;
  }

  .title-accent {
    font-size: 1.3rem;
    letter-spacing: 6px;
  }

  .hud-top-right {
    max-width: 110px;
  }

  .scoreboard-name {
    max-width: 50px;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  .hud-top-center {
    top: 4px;
  }

  .hud-timer {
    font-size: 1.2rem;
  }

  .hud-panel {
    padding: 4px 10px;
  }
}
