/* Base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  background-color: #faf8ef;
  color: #776e65;
  font-size: 18px;
  margin: 0;
  padding: 0;
}


.container {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: 20px;
}

/* Heading */
.heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.title {
  font-size: 80px;
  font-weight: bold;
  margin: 0;
  display: block;
}

.scores-container {
  display: flex;
  gap: 10px;
}

.score-container,
.best-container {
  position: relative;
  display: inline-block;
  background: #bbada0;
  padding: 15px 15px;
  font-size: 25px;
  height: 50px;
  line-height: 47px;
  font-weight: bold;
  border-radius: 3px;
  color: white;
  text-align: center;
  min-width: 100px;
}

.score-title {
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  text-transform: uppercase;
  font-size: 13px;
  line-height: 13px;
  text-align: center;
  color: #eee4da;
}

/* Game intro */
.game-intro {
  margin-bottom: 20px;
  line-height: 1.65;
}

/* Game container */
.game-container {
  position: relative;
  background: #bbada0;
  border-radius: 6px;
  width: 100%;
  height: 500px;
  padding: 15px;
  margin-bottom: 15px;
  touch-action: none;
}

.grid-container {
  position: absolute;
  z-index: 20;
  width: calc(100% - 30px);
  height: calc(100% - 30px);
}

.grid-row {
  display: flex;
  margin-bottom: 15px;
  height: calc(25% - 11.25px);
}

.grid-row:last-child {
  margin-bottom: 0;
}

.grid-cell {
  width: 25%;
  height: 100%;
  margin-right: 15px;
  background: rgba(238, 228, 218, 0.35);
  border-radius: 3px;
}

.grid-cell:last-child {
  margin-right: 0;
}

.tile-container {
  position: absolute;
  z-index: 20;
  width: calc(100% - 30px);
  height: calc(100% - 30px);
}

.tile {
  position: absolute;
  width: calc(25% - 11.25px);
  height: calc(25% - 11.25px);
  border-radius: 3px;
  background: #eee4da;
  text-align: center;
  font-weight: bold;
  z-index: 20;
  font-size: 55px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 100ms ease-in-out, opacity 100ms ease-in-out;
}


.tile.tile-merged {
  z-index: 20;
}

.tile.tile-new {
  animation: appear 200ms ease-in-out;
}

.tile.tile-merged {
  animation: pop 200ms ease-in-out;
}

@keyframes appear {
  0% {
    opacity: 0;
    transform: scale(0);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.8);
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
  }
}

/* Tile colors */
.tile-2 {
  background: #eee4da;
  color: #776e65;
}

.tile-4 {
  background: #ede0c8;
  color: #776e65;
}

.tile-8 {
  background: #f2b179;
  color: #f9f6f2;
}

.tile-16 {
  background: #f59563;
  color: #f9f6f2;
}

.tile-32 {
  background: #f67c5f;
  color: #f9f6f2;
}

.tile-64 {
  background: #f65e3b;
  color: #f9f6f2;
}

.tile-128 {
  background: #edcf72;
  color: #f9f6f2;
  font-size: 45px;
}

.tile-256 {
  background: #edcc61;
  color: #f9f6f2;
  font-size: 45px;
}

.tile-512 {
  background: #edc850;
  color: #f9f6f2;
  font-size: 45px;
}

.tile-1024 {
  background: #edc53f;
  color: #f9f6f2;
  font-size: 35px;
}

.tile-2048 {
  background: #edc22e;
  color: #f9f6f2;
  font-size: 35px;
}

/* Game message */
.game-message {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(238, 228, 218, 0.73);
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  animation: fade-in 800ms ease;
}

.game-message p {
  font-size: 60px;
  font-weight: bold;
  margin-bottom: 30px;
}

.game-message.game-won {
  background: rgba(237, 194, 46, 0.5);
  color: #f9f6f2;
}

.game-message .lower {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 30px;
}

.retry-button {
  background: #8f7a66;
  border-radius: 3px;
  padding: 0 20px;
  color: #f9f6f2;
  height: 40px;
  line-height: 40px;
  display: block;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  font-weight: bold;
  font-size: 18px;
}

.retry-button:hover {
  background: #9f8b77;
}

.game-explanation {
  margin-top: 20px;
}

@keyframes fade-in {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

/* Responsive design */
@media screen and (max-width: 520px) {
  .container {
    padding: 10px;
  }

  .heading {
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
  }

  .title {
    font-size: 50px;
    margin-bottom: 10px;
  }

  .game-container {
    height: 400px;
  }

  .tile {
    font-size: 40px;
  }

  .tile-128,
  .tile-256,
  .tile-512 {
    font-size: 35px;
  }

  .tile-1024,
  .tile-2048 {
    font-size: 25px;
  }

  .game-message p {
    font-size: 40px;
  }
}

@media screen and (max-width: 320px) {
  .game-container {
    height: 320px;
  }

  .tile {
    font-size: 30px;
  }

  .tile-128,
  .tile-256,
  .tile-512 {
    font-size: 25px;
  }

  .tile-1024,
  .tile-2048 {
    font-size: 20px;
  }
}