* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #faf8ef;
  color: #776e65;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  touch-action: manipulation;
}

.container {
  max-width: 500px;
  width: 100%;
  text-align: center;
}

h1 {
  font-size: 3rem;
  margin: 20px 0;
  color: #776e65;
}

h2 {
  font-size: 1.5rem;
  margin: 10px 0;
  color: #776e65;
}

/* Menu */
.game-menu {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 30px;
}

.game-card {
  background: #bbada0;
  border-radius: 12px;
  padding: 30px 25px;
  text-decoration: none;
  color: #f9f6f0;
  width: 180px;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

@media (max-width: 480px) {
  .game-card {
    width: 140px;
    padding: 20px 15px;
  }

  .game-icon {
    font-size: 1.5rem;
  }

  .game-card h2 {
    font-size: 1.2rem;
  }

  .game-card p {
    font-size: 0.8rem;
  }
}

.game-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.game-card.locked {
  opacity: 0.6;
  cursor: not-allowed;
}

.game-card.locked:hover {
  transform: none;
  box-shadow: none;
}

.game-icon {
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 10px;
}

.game-card p {
  font-size: 0.9rem;
  opacity: 0.8;
}

/* Game Header */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.back-link {
  color: #776e65;
  text-decoration: none;
  font-size: 1rem;
  font-weight: bold;
  padding: 8px 16px;
  background: #bbada0;
  border-radius: 6px;
  transition: background 0.2s;
}

.back-link:hover {
  background: #a0897c;
}

.score-container {
  display: flex;
  gap: 10px;
  align-items: center;
}

.score-box {
  background: #bbada0;
  border-radius: 6px;
  padding: 10px 20px;
  text-align: center;
  min-width: 80px;
}

.score-label {
  display: block;
  font-size: 0.7rem;
  color: #eee4da;
  text-transform: uppercase;
  font-weight: bold;
}

#score {
  display: block;
  font-size: 1.5rem;
  font-weight: bold;
  color: #fff;
}

.restart-btn {
  background: #8f7a66;
  color: #f9f6f0;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}

.restart-btn:hover {
  background: #706255;
}

/* Game Board */
.game-board-wrapper {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  aspect-ratio: 1;
}

.game-board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  background: #bbada0;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
}

.grid-cell {
  background: rgba(238, 228, 218, 0.35);
  border-radius: 6px;
}

.tile {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  border-radius: 6px;
  font-size: 2rem;
  pointer-events: none;
}

.tile-2 {
  background: #eee4da;
  color: #776e65;
}

.tile-4 {
  background: #ede0c8;
  color: #776e65;
}

.tile-8 {
  background: #f2b179;
  color: #f9f6f0;
}

.tile-16 {
  background: #f59563;
  color: #f9f6f0;
}

.tile-32 {
  background: #f67c5f;
  color: #f9f6f0;
}

.tile-64 {
  background: #f65e3b;
  color: #f9f6f0;
}

.tile-128 {
  background: #edcf72;
  color: #f9f6f0;
  font-size: 1.6rem;
}

.tile-256 {
  background: #edcc61;
  color: #f9f6f0;
  font-size: 1.6rem;
}

.tile-512 {
  background: #edc850;
  color: #f9f6f0;
  font-size: 1.6rem;
}

.tile-1024 {
  background: #edc53f;
  color: #f9f6f0;
  font-size: 1.3rem;
}

.tile-2048 {
  background: #edc22e;
  color: #f9f6f0;
  font-size: 1.3rem;
}

.tile-super {
  background: #3c3a32;
  color: #f9f6f0;
  font-size: 1.1rem;
}

/* Game Over / Win overlays */
.game-over {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(238, 228, 218, 0.73);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.game-over p {
  font-size: 3rem;
  font-weight: bold;
  color: #776e65;
  margin-bottom: 20px;
}

.hidden {
  display: none;
}

/* Responsive */
@media (max-width: 480px) {
  h1 {
    font-size: 2rem;
  }

  .tile {
    font-size: 1.4rem;
  }

  .tile-128,
  .tile-256,
  .tile-512 {
    font-size: 1.2rem;
  }

  .tile-1024,
  .tile-2048 {
    font-size: 1rem;
  }

  .tile-super {
    font-size: 0.9rem;
  }
}
