@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

/* --- RESET + CHỐNG CUỘN --- */
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  font-family: 'Press Start 2P', cursive;
  background: linear-gradient(to bottom right, #1c1b27, #2e7568);
  color: #fff;
  justify-content: center;
  align-items: center;
  touch-action: manipulation;
}

body {
  overflow-y: auto;
}

/* --- GAME CONTAINER --- */
.game-container {
  text-align: center;
  background: #2b2b3c;
  padding: 20px;
  border: 4px solid #00ffcc;
  border-radius: 16px;
  box-shadow: 0 0 20px rgba(0, 255, 204, 0.8);
  max-width: 420px;
  width: 100%;
  position: relative;
  box-sizing: border-box;
  margin: 0 auto;
}

/* --- TITLE & SCORE --- */
.title {
  font-size: 1.3rem;
  margin-bottom: 12px;
  color: #00ffcc;
  user-select: none;
}

.score-box {
  font-size: 0.75rem;
  background: #1f1f2e;
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 10px;
  color: #00ffcc;
  border: 2px solid #00ffcc;
  display: flex;                /* 👈 Dùng flex layout */
  justify-content: space-between;
  align-items: center;
  gap: 8px;                     /* 👈 Khoảng cách giữa các phần */
  white-space: nowrap;         /* 👈 Không cho xuống dòng */
  overflow: hidden;
  text-overflow: ellipsis;     /* 👈 Hiển thị "..." nếu quá dài */
  max-width: 100%;             /* 👈 Không vượt quá khung cha */
  box-sizing: border-box;  

}



/* --- GRID & TILE --- */
#grid-container {
  width: 100%;
  aspect-ratio: 1; /* giữ hình vuông toàn khung */
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 1fr;
  gap: 4px;
  margin-bottom: 20px;
  overflow: hidden;
  align-content: stretch;
  justify-content: stretch;
  position: relative;
  /* background: linear-gradient(to bottom, #fffafc, #eaffff);  */
}


.tile {
  width: 100%;
  aspect-ratio: 1 / 1; /* đảm bảo hình vuông */
  background-color: #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}


/* --- TILE IMAGES --- */
.tile img, .tile-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  display: block;
  transform: none !important;
}

/* --- MASCOT MODE OVERRIDES --- */
.mascot-mode .tile img {
  transform: none !important;
  animation: none !important;
}

/* --- TILE POP ANIMATION --- */
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* --- BUTTONS --- */
button {
  background: #00ffcc;
  color: #000;
  border: none;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: bold;
  cursor: pointer;
  margin: 4px;
  box-shadow: 0 0 10px #00ffcc;
  transition: background 0.3s;
  user-select: none;
}

button:hover {
  background: #00e6b8;
}

#music-btn.muted {
  background: #ff4c4c;
  color: #fff;
  box-shadow: 0 0 10px #ff4c4c;
}

/* --- INFO --- */
.info {
  font-size: 0.6rem;
  opacity: 0.8;
  margin-top: 5px;
  user-select: none;
}

/* --- TOAST --- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  background: #00ffcc;
  color: #000;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: bold;
  opacity: 0;
  transition: all 0.4s ease;
  z-index: 9999;
  user-select: none;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* --- PULSE --- */
.pulse {
  animation: pulseAnim 1s infinite;
}

@keyframes pulseAnim {
  0% { box-shadow: 0 0 5px #00ffcc; }
  50% { box-shadow: 0 0 20px #00ffcc; }
  100% { box-shadow: 0 0 5px #00ffcc; }
}

/* --- LEADERBOARD --- */
.leaderboard-box {
  font-size: 0.6rem;
  background: #111a1a;
  border: 2px solid #00ffcc;
  padding: 10px;
  margin-top: 10px;
  border-radius: 10px;
  color: #00ffcc;
  user-select: none;
}

.leaderboard-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  /* border-bottom: 1px dashed #00ffcc; */
  font-size: 0.65rem;
  color: #e0f7f5;
}

.leaderboard-entry .rank {
  width: 1.2em;
  text-align: right;
  margin-right: 6px;
  color: #00ffff;
  font-weight: bold;
}

.leaderboard-entry .name {
  flex-grow: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-entry .score {
  min-width: 3em;
  text-align: right;
  font-family: monospace;
}

/* --- GAME OVER --- */
.game-over {
  font-size: 1.2rem;
  font-weight: bold;
  color: #ff3333;
  margin-top: 15px;
  user-select: none;
  animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* --- MASCOT OVERLAY --- */
#mascot-overlay {
  position: absolute;
  width: 320px;
  height: 320px;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: transparent;
  border-radius: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  user-select: none;
  pointer-events: none;
}

#mascot-overlay img {
  max-width: 90%;
  max-height: 90%;
  pointer-events: none;
  transition: transform 0.3s ease;
}

#mascot-overlay:hover img {
  animation-play-state: paused;
  transform: scale(1.05) rotate(3deg);
}

#mascot-overlay.hidden {
  display: none;
}

@keyframes mascot-wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(5deg); }
  75% { transform: rotate(-5deg); }
}

.wiggle {
  animation: mascot-wiggle 1.2s infinite ease-in-out;
  transform-origin: bottom center;
}

/* --- MODAL --- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(28, 27, 39, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
  display: none;
}

.modal-content {
  background: #1f1f2e;
  border: 2px solid #00ffcc;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  width: 90%;
  max-width: 320px;
  box-shadow: 0 0 20px rgba(0, 255, 204, 0.6);
}

.modal-content h3 {
  font-size: 0.9rem;
  color: #00ffcc;
  margin-bottom: 12px;
}

.modal-content input[type="text"] {
  width: 90%;
  padding: 10px;
  margin-bottom: 12px;
  font-size: 1rem;
  border-radius: 8px;
  border: 2px solid #00ffcc;
  background: #2b2b3c;
  color: #fff;
  font-family: 'Press Start 2P', cursive;
  text-align: center;
  box-sizing: border-box;
}

#player-name-input {
  font-size: 16px;
  padding: 10px;
  width: 100%;
  box-sizing: border-box;
}

.modal-content button {
  padding: 8px 16px;
  font-size: 0.7rem;
}

.control-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 10px;
}

.control-buttons button {
  white-space: nowrap; 
  flex: 1 1 calc(33.33% - 10px);
  min-width: 0;
}




/* --- RESPONSIVE --- */
/* --- RESPONSIVE --- */

@media (max-width: 600px) {

  html,
  body {
    touch-action: none;
    overscroll-behavior: contain;
  }

  .top-players {
    max-height: 100px;
    overflow-y: auto;
  }

  .game-board,
  #grid-container {
    padding-bottom: 100px;
    padding-bottom: 10px; /* đảm bảo hàng cuối không bị che */
  }

  .game-container {
    touch-action: pan-y;
    max-width: 100vw; 
    padding: 10px;
    box-sizing: border-box;
  }

  #grid-container {
    width: 100%;
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    overflow: hidden;
    aspect-ratio: 1; /* giữ tỷ lệ vuông */
    touch-action: none;

  }

  .tile {
    font-size: 4.5vw;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    transition: transform 0.15s ease-out, background-color 0.2s ease;
    will-change: transform;
  }

}

.leaderboard-box a {
  text-decoration: none;     /* ❌ bỏ gạch chân */
  color: #00ffcc !important; /* ✅ dùng màu như "Top Players" */
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.plays {
  font-size: 0.6rem;
  color: #00ffcc;
}

.share-btn {
  background: #00ffcc;
  color: #000;
  border: none;
  padding: 4px 8px;
  font-size: 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 0 5px #00ffcc;
  transition: background 0.3s;
}

.share-btn:hover {
  background: #00e6b8;
}

/* Floating Sticker Styles */
.bouncing-sticker {
  position: absolute;
  width: 36px;
  height: 36px;
  pointer-events: none;
  z-index: 10;
  transform: translate(0, 0);
  transition: transform 0s;
  will-change: transform;
}


.floating-sticker:hover {
  transform: scale(1.3);
}

@keyframes floatMove {
  0% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(10deg); }
  100% { transform: translateY(0px) rotate(-10deg); }
}

.leaderboard-box {
  position: relative;  /* Cần có dòng này để chứa sticker */
  overflow: hidden;
}

@keyframes explode {
  0% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  50% {
    transform: scale(1.8) rotate(180deg);
    opacity: 0.8;
  }
  100% {
    transform: scale(0) rotate(360deg);
    opacity: 0;
  }
}

.bouncing-sticker.explode-effect {
  animation: explode 0.5s ease forwards;
  pointer-events: none; /* Không cho click tiếp sau khi đã nổ */
}

.leaderboard-entry {
  border-bottom: none !important;
}
