body {
  background-color: #faf8ef;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  font-family: "Clear Sans", "Helvetica Neue";
  padding: 16px;
  box-sizing: border-box;
}

h1 {
  font-size: 56px;
  line-height: 0.7;
  color: #776e65;
  margin: 0px;
}

.container {
  width: 600px;
}

.info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.game-area {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

.grid {
  display: flex;
  flex-wrap: wrap;
  width: 456px;
  height: 456px;
  background-color: #bbada0;
  border: 7px solid #bbada0;
  border-radius: 6px;
}

.grid div {
  width: 100px;
  height: 100px;
  margin: 7px;
  border-radius: 3px;
  background-color: #eee4da;
  color: #afa192;
  font-weight: bold;
  text-align: center;
  font-size: 40px;
  line-height: 2.5;
  flex: 0 0 calc(25% - 14px);
  box-sizing: border-box;
}

.grid div:not([innerHTML="0"]) {
  line-height: 2.5;
}

.grid div[innerHTML="0"] {
  font-size: 0;
}

.grid div[innerHTML^="1"],
.grid div[innerHTML="2"],
.grid div[innerHTML="4"],
.grid div[innerHTML="8"] {
  font-size: 40px;
}

.grid div[innerHTML="16"],
.grid div[innerHTML="32"],
.grid div[innerHTML="64"] {
  font-size: 35px;
}

.grid div[innerHTML="128"],
.grid div[innerHTML="256"],
.grid div[innerHTML="512"] {
  font-size: 30px;
}

.grid div[innerHTML="1024"],
.grid div[innerHTML="2048"] {
  font-size: 25px;
}

.score-container {
  text-align: center;
  width: 70px;
  height: 60px;
  border-radius: 3px;
  background-color: #8f7a66;
  color: #ffffff;
}

#score {
  font-size: 30px;
}

.score-title {
  font-size: 16px;
}

.controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-left: 30px;
  gap: 18px;
}

/* New game / refresh button */
#refresh-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0 22px;
  margin: 0;
  border: none;
  border-radius: 10px;
  background-color: #8f7a66;
  color: #f9f6f2;
  font-family: inherit;
  font-size: 22px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 3px 0 #6f5d4e;
  transition: background-color 0.15s, transform 0.08s, box-shadow 0.08s;
}

#refresh-button:hover {
  background-color: #9f8a76;
}

#refresh-button:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 #6f5d4e;
}

/* Direction pad */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 56px);
  gap: 8px;
}

#up-button    { grid-column: 2; grid-row: 1; }
#left-button  { grid-column: 1; grid-row: 2; }
#down-button  { grid-column: 2; grid-row: 2; }
#right-button { grid-column: 3; grid-row: 2; }

.control-btn {
  width: 56px;
  height: 56px;
  margin: 0;
  border: none;
  border-radius: 12px;
  background-color: #bbada0;
  color: #f9f6f2;
  font-size: 26px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 3px 0 #9c8c7d;
  transition: background-color 0.15s, transform 0.08s, box-shadow 0.08s;
}

.control-btn:hover {
  background-color: #a89889;
}

.control-btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 #9c8c7d;
}

@media screen and (max-width: 800px) {
  .container {
    width: 95%;
  }

  .game-area {
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
  }

  h1 {
    font-size: 60px;
  }

  .grid {
    width: 280px;
    height: 280px;
    margin-right: 10px;
  }

  .grid div {
    width: 60px;
    height: 60px;
    margin: 5px;
    font-size: 25px;
    line-height: 2.4;
    flex: 0 0 calc(25% - 10px);
  }

  .grid div[innerHTML="16"],
  .grid div[innerHTML="32"],
  .grid div[innerHTML="64"] {
    font-size: 22px;
  }

  .grid div[innerHTML="128"],
  .grid div[innerHTML="256"],
  .grid div[innerHTML="512"] {
    font-size: 18px;
  }

  .grid div[innerHTML="1024"],
  .grid div[innerHTML="2048"] {
    font-size: 16px;
  }

  .controls {
    margin-left: 0;
    margin-top: 20px;
  }

  .dpad {
    grid-template-columns: repeat(3, 50px);
    grid-template-rows: repeat(2, 50px);
  }

  .control-btn {
    width: 50px;
    height: 50px;
    font-size: 24px;
  }

  #refresh-button {
    height: 44px;
    padding: 0 18px;
    font-size: 20px;
  }
}

@media screen and (max-width: 400px) {
  .grid {
    width: 240px;
    height: 240px;
  }

  .grid div {
    width: 50px;
    height: 50px;
    margin: 5px;
    font-size: 20px;
    line-height: 2.5;
  }
}
