html, body {
  margin: 0;
  padding: 0;
  background: #faf8ef;
  color: #776e65;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 18px;
}

body {
  margin: 80px 0;
}

.heading {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

h1.title {
  font-size: 80px;
  font-weight: bold;
  margin: 0;
  text-align: center;
}

.scores-container {
  display: flex;
  gap: 10px;
}

.score-container, .best-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #bbada0;
  padding: 10px 20px;
  font-size: 18px;
  font-weight: bold;
  border-radius: 3px;
  color: white;
  min-width: 80px;
}

.score-label {
  font-size: 13px;
  text-transform: uppercase;
  color: #eee4da;
  margin-bottom: 2px;
}



.score, .best-score {
  display: block;
}

p {
  margin-top: 0;
  margin-bottom: 10px;
  line-height: 1.65;
}

a {
  color: #776e65;
  font-weight: bold;
  text-decoration: underline;
  cursor: pointer;
}

strong.important {
  text-transform: uppercase;
}

hr {
  border: none;
  border-bottom: 1px solid #d8d4d0;
  margin-top: 20px;
  margin-bottom: 30px;
}

.container {
  width: 350px;
  margin: 0 auto;
}

.game-container {
  margin-top: 40px;
  position: relative;
  padding: 10px;
  cursor: default;
  -webkit-touch-callout: none;
  -ms-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -ms-touch-action: none;
  touch-action: none;
  background: #bbada0;
  border-radius: 6px;
  width: 330px;
  height: 330px;
  box-sizing: border-box;
}

.game-container .game-message {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(238, 228, 218, 0.5);
  z-index: 100;
  text-align: center;
  border-radius: 6px;
  padding-top: 60px;
  box-sizing: border-box;
}

.game-container .game-message p {
  font-size: 60px;
  font-weight: bold;
  height: 60px;
  line-height: 60px;
  margin: 0;
  color: #776e65;
}

.game-container .game-message .lower {
  display: block;
  margin-top: 20px;
}

.game-container .game-message a {
  display: inline-block;
  background: #8f7a66;
  border-radius: 3px;
  padding: 0 20px;
  text-decoration: none;
  color: #f9f6f2;
  height: 40px;
  line-height: 42px;
  margin: 5px;
}

.game-container .game-message a.keep-playing-button {
  display: none;
}

.game-container .game-message.game-won {
  background: rgba(237, 194, 46, 0.5);
  color: #f9f6f2;
}

.game-container .game-message.game-won a.keep-playing-button {
  display: inline-block;
}

.game-container .game-message.game-won,
.game-container .game-message.game-over {
  display: block;
}

.grid-container {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
}

.grid-row {
  margin-bottom: 10px;
}

.grid-row:last-child {
  margin-bottom: 0;
}

.grid-row:after {
  content: "";
  display: block;
  clear: both;
}

.grid-cell {
  width: 70px;
  height: 70px;
  margin-right: 10px;
  float: left;
  border-radius: 3px;
  background: rgba(238, 228, 218, 0.35);
}

.grid-cell:last-child {
  margin-right: 0;
}

.tile-container {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
}

.tile, .tile .tile-inner {
  width: 70px;
  height: 70px;
  line-height: 70px;
}

/* Match original 2048: GPU-friendly translate3d + transform-only transition */
.tile.tile-position-1-1 { transform: translate3d(0px, 0px, 0); }
.tile.tile-position-1-2 { transform: translate3d(0px, 80px, 0); }
.tile.tile-position-1-3 { transform: translate3d(0px, 160px, 0); }
.tile.tile-position-1-4 { transform: translate3d(0px, 240px, 0); }
.tile.tile-position-2-1 { transform: translate3d(80px, 0px, 0); }
.tile.tile-position-2-2 { transform: translate3d(80px, 80px, 0); }
.tile.tile-position-2-3 { transform: translate3d(80px, 160px, 0); }
.tile.tile-position-2-4 { transform: translate3d(80px, 240px, 0); }
.tile.tile-position-3-1 { transform: translate3d(160px, 0px, 0); }
.tile.tile-position-3-2 { transform: translate3d(160px, 80px, 0); }
.tile.tile-position-3-3 { transform: translate3d(160px, 160px, 0); }
.tile.tile-position-3-4 { transform: translate3d(160px, 240px, 0); }
.tile.tile-position-4-1 { transform: translate3d(240px, 0px, 0); }
.tile.tile-position-4-2 { transform: translate3d(240px, 80px, 0); }
.tile.tile-position-4-3 { transform: translate3d(240px, 160px, 0); }
.tile.tile-position-4-4 { transform: translate3d(240px, 240px, 0); }

.tile {
  position: absolute;
  -webkit-transition: 100ms ease-in-out;
  -moz-transition: 100ms ease-in-out;
  transition: 100ms ease-in-out;
  -webkit-transition-property: -webkit-transform;
  -moz-transition-property: -moz-transform;
  transition-property: transform;
  /* Compositing: avoid subpixel shimmer during transform (original uses pure transform slide) */
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.tile .tile-inner {
  border-radius: 3px;
  background: #eee4da;
  text-align: center;
  font-weight: bold;
  z-index: 10;
  font-size: 35px;
}

.tile.tile-2 .tile-inner { background: #eee4da; color: #776e65; }
.tile.tile-4 .tile-inner { background: #ede0c8; color: #776e65; }
.tile.tile-8 .tile-inner { background: #f2b179; color: #f9f6f2; }
.tile.tile-16 .tile-inner { background: #f59563; color: #f9f6f2; }
.tile.tile-32 .tile-inner { background: #f67c5f; color: #f9f6f2; }
.tile.tile-64 .tile-inner { background: #f65e3b; color: #f9f6f2; }
.tile.tile-128 .tile-inner { background: #edcf72; color: #095f6b; font-size: 30px; }
.tile.tile-256 .tile-inner { background: #edcc61; color: #095f6b; font-size: 30px; }
.tile.tile-512 .tile-inner { background: #edc850; color: #f9f6f2; font-size: 30px; }
.tile.tile-1024 .tile-inner { background: #edc53f; color: #f9f6f2; font-size: 25px; }
.tile.tile-2048 .tile-inner { background: #edc22e; color: #3c3322; font-size: 25px; }
.tile.tile-4096 .tile-inner { background: #eee4da; color: #776e65; font-size: 25px; }
.tile.tile-8192 .tile-inner { background: #edc22e; color: #f9f6f2; font-size: 25px; }

/* Inner-only transforms so they never fight the tile wrapper translate3d */
@keyframes appear {
  0% {
    opacity: 0;
    transform: scale(0);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.tile-new .tile-inner {
  -webkit-animation: appear 200ms ease 100ms;
  animation: appear 200ms ease 100ms;
  -webkit-animation-fill-mode: backwards;
  animation-fill-mode: backwards;
}

@keyframes pop {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

.tile-merged .tile-inner {
  z-index: 20;
  -webkit-animation: pop 200ms ease 100ms;
  animation: pop 200ms ease 100ms;
  -webkit-animation-fill-mode: backwards;
  animation-fill-mode: backwards;
}

.above-game:after {
  content: "";
  display: block;
  clear: both;
}

.game-intro {
  float: left;
  line-height: 42px;
  margin-bottom: 0;
  display: none;
}

.restart-button {
  display: none;
  background: #8f7a66;
  border-radius: 3px;
  padding: 0 20px;
  text-decoration: none;
  color: #f9f6f2;
  height: 40px;
  line-height: 42px;
  text-align: center;
  float: right;
}

.game-explanation {
  margin-top: 50px;
  display: none;
}

.gametory-container {
  display: none;
}

@media screen and (max-width: 520px) {
  html, body {
    font-size: 15px;
  }

  body {
    margin: 20px 0;
    padding: 0 20px;
  }

  h1.title {
    font-size: 27px;
    margin-top: 15px;
  }

  .container {
    width: 280px;
    margin: 0 auto;
  }

  .game-container {
    margin-top: 17px;
    padding: 8px;
    width: 280px;
    height: 280px;
  }

  /* Board is 256px; content box is 264px (280 - 8*2 padding). Center the 8px slack so
     top/left/right/bottom insets match (12px to outer edge each side, vs 8+16 asymmetric). */
  .grid-container {
    top: 12px;
    left: 12px;
  }

  .tile-container {
    top: 12px;
    left: 12px;
  }

  .grid-row {
    margin-bottom: 8px;
  }

  .grid-cell {
    width: 58px;
    height: 58px;
    margin-right: 8px;
  }

  .tile, .tile .tile-inner {
    width: 58px;
    height: 58px;
    line-height: 58px;
  }

  .tile.tile-position-1-1 { transform: translate3d(0px, 0px, 0); }
  .tile.tile-position-1-2 { transform: translate3d(0px, 66px, 0); }
  .tile.tile-position-1-3 { transform: translate3d(0px, 132px, 0); }
  .tile.tile-position-1-4 { transform: translate3d(0px, 198px, 0); }
  .tile.tile-position-2-1 { transform: translate3d(66px, 0px, 0); }
  .tile.tile-position-2-2 { transform: translate3d(66px, 66px, 0); }
  .tile.tile-position-2-3 { transform: translate3d(66px, 132px, 0); }
  .tile.tile-position-2-4 { transform: translate3d(66px, 198px, 0); }
  .tile.tile-position-3-1 { transform: translate3d(132px, 0px, 0); }
  .tile.tile-position-3-2 { transform: translate3d(132px, 66px, 0); }
  .tile.tile-position-3-3 { transform: translate3d(132px, 132px, 0); }
  .tile.tile-position-3-4 { transform: translate3d(132px, 198px, 0); }
  .tile.tile-position-4-1 { transform: translate3d(198px, 0px, 0); }
  .tile.tile-position-4-2 { transform: translate3d(198px, 66px, 0); }
  .tile.tile-position-4-3 { transform: translate3d(198px, 132px, 0); }
  .tile.tile-position-4-4 { transform: translate3d(198px, 198px, 0); }

  .tile .tile-inner {
    font-size: 28px;
  }
}
