/* ================= GLOBAL ================= */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Orbitron', sans-serif;
  background: radial-gradient(circle at center, #020617, #000814);
  color: #00f5ff;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  animation: fadeIn 0.6s ease forwards;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ================= HEADER ================= */

.header {
  width: 100%;
  padding: 20x 60px 10px 60px;
  display: flex;
  justify-content: space-between;
  align-items: left;
}

.logo {
  font-size: clamp(2rem, 4vw, 3.5rem);
  font-weight: 800;
  letter-spacing: 2px;
}

.user-row {
  margin-top: 7px;
  /* 🔥 increase vertical gap */
}


/* Animated neon gradient logo */
@supports (background-clip: text) or (-webkit-background-clip: text) {
  .logo {
    background-image: linear-gradient(to right,
        #00f5ff,
        #00aaff,
        #ff00ff,
        #8a2be2,
        #00f5ff);
    background-size: 200%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: animateLogo 4s linear infinite;
  }

  @keyframes animateLogo {
    to {
      background-position: 200%;
    }
  }
}

/* ===== USER SECTION ===== */

.user-container {
  display: flex;
  align-items: center;
  gap: 15px;
}

#userDisplay {
  font-size: 16px;
  color: #00f5ff;
  text-shadow: 0 0 8px #00f5ff;
}

.logout-btn {
  background: transparent;
  border: 1px solid #ff00ff;
  color: #ff00ff;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: 0.3s;
  font-family: 'Orbitron', sans-serif;
}

.logout-btn:hover {
  background: #ff00ff;
  color: black;
  box-shadow: 0 0 12px #ff00ff;
}

/* ================= GAME SECTION ================= */

.game-section {
  width: min(90vw, 390px);
  margin-top: 80px;
}

/* ================= GAME HEADER ================= */

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.scores {
  display: flex;
  gap: 18px;
}

.score-box {
  background: #0b1c2d;
  padding: 10px 18px;
  border-radius: 10px;
  min-width: 80px;
  text-align: center;
  box-shadow: 0 0 12px rgba(0, 245, 255, 0.4);
}

.label {
  font-size: 11px;
  opacity: 0.6;
}

.new-game {
  padding: 10px 20px;
  background: #ff00ff;
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  box-shadow: 0 0 15px #ff00ff;
  transition: 0.2s ease;
}

.new-game:hover {
  transform: scale(1.05);
  box-shadow: 0 0 25px #ff00ff;
}

/* ================= BOARD ================= */

.board-container {
  position: relative;
  background: #071826;
  width: 100%;
  padding: 4%;
  border-radius: 18px;
  box-shadow: inset 0 0 25px rgba(0, 245, 255, 0.6);
  overflow: hidden;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  transition: transform 0.3s ease;
}

.board-container.overlay-active .board {
  transform: scale(0.95);
}

/* ================= TILE ================= */

.tile {
  aspect-ratio: 1;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: bold;
  color: white;
  background: #102a43;
  transition: 0.15s ease;
}

/* TILE COLORS */

.tile-2 {
  background: #00f5ff;
  color: #002;
}

.tile-4 {
  background: #00ff99;
  color: #002;
}

.tile-8 {
  background: #ff00ff;
}

.tile-16 {
  background: #ff0077;
}

.tile-32 {
  background: #ff4500;
}

.tile-64 {
  background: #ffcc00;
  color: #000;
}

.tile-128 {
  background: #00ffcc;
  color: #002;
}

.tile-256 {
  background: #ff0099;
}

.tile-512 {
  background: #ff00cc;
}

.tile-1024 {
  background: #00ffff;
  color: #002;
}

.tile-2048 {
  background: #ffffff;
  color: #000;
}

.tile-2,
.tile-4,
.tile-8,
.tile-16,
.tile-32,
.tile-64,
.tile-128,
.tile-256,
.tile-512,
.tile-1024,
.tile-2048 {
  box-shadow: 0 0 12px rgba(0, 255, 255, 0.35);
}

/* ================= OVERLAY ================= */

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 10, 20, 0.55);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: 0.35s ease;
  border-radius: 18px;
}

.game-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.overlay-content h2 {
  font-size: 32px;
  letter-spacing: 3px;
  margin-bottom: 20px;
}

.overlay-content.win h2 {
  color: #00ff99;
  text-shadow: 0 0 20px #00ff99;
}

.overlay-content.lose h2 {
  color: #ff3b3b;
  text-shadow: 0 0 20px #ff3b3b;
}

/* ================= LOGIN MODAL ================= */

.login-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.login-box {
  background: #071826;
  padding: 30px;
  border-radius: 16px;
  box-shadow: 0 0 25px #00f5ff;
  width: 300px;
  text-align: center;
}

.login-box input {
  width: 100%;
  padding: 10px;
  margin: 10px 0;
  background: #102a43;
  border: 1px solid #00f5ff;
  color: white;
  border-radius: 8px;
  outline: none;
}

.login-box button {
  width: 100%;
  padding: 10px;
  margin-top: 10px;
  background: #ff00ff;
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
}

.login-switch {
  margin-top: 10px;
  color: #00f5ff;
  cursor: pointer;
  font-size: 13px;
}

#loginError {
  color: red;
  margin-top: 10px;
}

/* ================= MOBILE ================= */

@media (max-width: 768px) {

  .header {
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px;
  }

  .logo {
    font-size: 28px;
  }

  .game-section {
    margin-top: 40px;
  }

  .tile {
    font-size: 22px;
  }

  .score-box {
    padding: 8px 12px;
    min-width: 60px;
  }

  .new-game {
    padding: 8px 14px;
    font-size: 12px;
  }
}

/* ================= TILE SPAWN ANIMATION ================= */

.tile.new {
  animation: appear 0.25s ease;
}

@keyframes appear {
  from {
    transform: scale(0.7);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ================= SHAKE ANIMATION ================= */

@keyframes shake {
  0% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-8px);
  }

  40% {
    transform: translateX(8px);
  }

  60% {
    transform: translateX(-6px);
  }

  80% {
    transform: translateX(6px);
  }

  100% {
    transform: translateX(0);
  }
}

.board-container.shake {
  animation: shake 0.5s ease;
}

/* ================= OVERLAY ENHANCED ================= */

.game-overlay {
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* Confetti canvas */
#confettiCanvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

/* Overlay content above canvas */
.overlay-content {
  position: relative;
  z-index: 2;
  text-align: center;
}

/* Overlay heading */
.overlay-content h2 {
  font-size: 34px;
  letter-spacing: 4px;
  margin-bottom: 25px;
  white-space: nowrap;
  overflow: hidden;
  border-right: 3px solid;
}

/* Typing cursor blink */
@keyframes blink {
  50% {
    border-color: transparent;
  }
}

.overlay-content.typing h2 {
  animation: blink 0.8s infinite;
}

/* WIN STYLE */
.overlay-content.win h2 {
  color: #00ff99;
  text-shadow:
    0 0 10px #00ff99,
    0 0 25px #00ff99,
    0 0 50px #00ff99;
  border-color: #00ff99;
}

/* LOSE STYLE */
.overlay-content.lose h2 {
  color: #ff3b3b;
  text-shadow:
    0 0 10px #ff3b3b,
    0 0 25px #ff3b3b,
    0 0 50px #ff3b3b;
  border-color: #ff3b3b;
}

/* Overlay buttons */
.overlay-content button {
  padding: 10px 22px;
  background: #ff00ff;
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  box-shadow: 0 0 15px #ff00ff;
  transition: 0.2s ease;
  font-family: 'Orbitron', sans-serif;
  margin: 5px;
}

.overlay-content button:hover {
  transform: scale(1.08);
  box-shadow: 0 0 30px #ff00ff;
}