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

html,
body {
  height: 100%;
  width: 100%;
  font-family: 'Outfit', sans-serif;
  background: #1a1127;
  color: #f0e6d3;
  overflow: hidden;
  touch-action: none;
  /* prevent pull-to-refresh / scroll */
  -webkit-user-select: none;
  user-select: none;
}

/* ===== Game Container ===== */
#game-container {
  position: relative;
  max-width: 420px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px 12px 24px;
}

/* ===== HUD ===== */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 16px;
}

.game-title {
  font-weight: 800;
  font-size: 2.0rem;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, #f7b733, #fc4a1a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-transform: uppercase;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
}

.hud-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.55;
}

#score,
#timer {
  font-weight: 800;
  font-size: 1.7rem;
}

/* Score flash animation */
.score-flash {
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  font-weight: 800;
  font-size: 1rem;
  color: #7df9a0;
  pointer-events: none;
  animation: flashUp 0.8s ease-out forwards;
}

@keyframes flashUp {
  0% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }

  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-28px);
  }
}

/* ===== Grid ===== */
#grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* ===== Cell / Tile ===== */
.cell {
  position: relative;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  overflow: hidden;
}

/* Positive (green) tile */
.cell.positive {
  background: linear-gradient(145deg, #2ad47d 0%, #1a9a5a 100%);
  box-shadow: 0 4px 12px rgba(42, 212, 125, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

/* Negative (red) tile */
.cell.negative {
  background: linear-gradient(145deg, #f45c6c 0%, #c0392b 100%);
  box-shadow: 0 4px 12px rgba(244, 92, 108, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.cell:active,
.cell.selected {
  transform: scale(0.92);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35);
}

.tile-num {
  font-weight: 800;
  font-size: clamp(1.6rem, 6vw, 2.8rem);
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

/* Subtle idle shimmer */
.cell.positive::before,
.cell.negative::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.12) 50%, transparent 70%);
  background-size: 200% 200%;
  animation: shimmer 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

/* ===== Tile Fall & Spawn Animations ===== */

/* Gravity fall – tile slides down from its old position */
.cell.tile-fall {
  animation: tileFall 250ms cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes tileFall {
  0% {
    transform: translateY(var(--fall-distance, 0));
    opacity: 0.85;
  }

  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* New tile spawn – pops in from nothing */
.cell.tile-spawn {
  animation: tileSpawn 200ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes tileSpawn {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===== Score Particles ===== */
.score-particle {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 0 6px currentColor;
  will-change: left, top, transform, opacity;
}

/* Score box pulse when particles arrive */
#score-box.score-pulse {
  animation: scorePulse 300ms ease-out;
}

@keyframes scorePulse {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scale(1.18);
    filter: brightness(1.5);
  }

  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

/* ===== Drag Animation ===== */

/* Floating ghost clone that follows the pointer */
.drag-ghost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(1.08);
  opacity: 0.92;
  filter: brightness(1.15);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45),
    0 0 16px rgba(255, 255, 255, 0.12);
  transition: none;
  will-change: left, top;
}

/* Source cell becomes a ghost while dragging */
.cell.dragging-source {
  opacity: 0.3;
  transform: scale(0.94);
  filter: grayscale(0.4);
}

/* Target neighbor highlight */
.cell.drag-target {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.7),
    0 0 18px rgba(255, 255, 255, 0.25);
  transform: scale(1.04);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

/* ===== Hint Animation ===== */

/* Pulsing glow on hint tiles */
.cell.hint-glow {
  animation: hintPulse 1.2s ease-in-out infinite;
  z-index: 2;
}

@keyframes hintPulse {

  0%,
  100% {
    box-shadow: 0 0 0 3px rgba(247, 183, 51, 0.0),
      0 0 12px rgba(247, 183, 51, 0.0);
  }

  50% {
    box-shadow: 0 0 0 4px rgba(247, 183, 51, 0.6),
      0 0 18px rgba(247, 183, 51, 0.35);
  }
}

/* Hint ghost gets a subtle golden tint */
.drag-ghost.hint-ghost {
  filter: brightness(1.2) saturate(1.1);
  opacity: 0.88;
}

/* ===== Overlay ===== */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 20, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  border-radius: 18px;
  z-index: 10;
}

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

.overlay-card {
  text-align: center;
}

.overlay-card h2 {
  font-size: 2rem;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #f7b733, #fc4a1a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.overlay-card p {
  font-size: 0.9rem;
  opacity: 0.6;
}

.big-score {
  font-weight: 800;
  font-size: 3.2rem !important;
  opacity: 1 !important;
  margin: 4px 0 20px;
}


/* ===== Leaderboard ===== */
.leaderboard-container {
  margin: 10px 0 20px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  padding: 12px;
}

.leaderboard-container h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
  text-align: center;
  color: #f7b733;
}

#leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
}

.leaderboard-score {
  min-width: 60px;
  text-align: right;
  padding-right: 25px;
  font-weight: 800;
  color: #fff;
}

.leaderboard-date {
  opacity: 0.7;
  font-size: 0.85rem;
}

.leaderboard-empty {
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.6;
  padding: 10px 0;
}

#restart-btn {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  padding: 12px 36px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: linear-gradient(135deg, #f7b733, #fc4a1a);
  color: #fff;
  box-shadow: 0 4px 16px rgba(252, 74, 26, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(252, 74, 26, 0.5);
}

#restart-btn:active {
  transform: scale(0.96);
}

/* ===== Start Overlay ===== */
#start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 20, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  border-radius: 18px;
  z-index: 20;
  /* Higher than game over overlay */
}

#start-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

#start-btn {
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 1.2rem;
  padding: 16px 48px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  background: linear-gradient(135deg, #2ad47d, #1a9a5a);
  color: #fff;
  box-shadow: 0 4px 16px rgba(42, 212, 125, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 16px;
}

#start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(42, 212, 125, 0.5);
}

#start-btn:active {
  transform: scale(0.96);
}