body { 
  margin: 0; 
  display: flex; 
  justify-content: center; 
  align-items: center; 
  height: 100vh; 
  background: #faf8ef; 
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif; 
}

.container { width: 500px; display: flex; flex-direction: column; }

/* Header Punteggi e Titolo */
.heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; width: 100%; }
.title { font-size: 60px; font-weight: bold; margin: 0; color: #776e65; line-height: 1; }
.scores-container { display: flex; gap: 5px; }
.score-container, .best-container { background: #bbada0; color: white; padding: 5px 20px; border-radius: 3px; font-weight: bold; text-align: center; position: relative; font-size: 25px; min-width: 50px; }
.score-container:after { content: "Score"; display: block; text-transform: uppercase; font-size: 13px; color: #eee4da; margin-top: -5px; }
.best-container:after { content: "Best"; display: block; text-transform: uppercase; font-size: 13px; color: #eee4da; margin-top: -5px; }

/* Animazione Punti + */
.score-addition { position: absolute; right: 30px; color: rgba(119, 110, 101, 0.9); font-size: 25px; line-height: 25px; font-weight: bold; z-index: 100; animation: move-up 600ms ease-in; animation-fill-mode: both; }
@keyframes move-up { 0% { top: 25px; opacity: 1; } 100% { top: -50px; opacity: 0; } }

/* Tasto New Game Esterno */
.above-game { display: flex; justify-content: flex-end; margin-bottom: 15px; width: 100%; }
.restart-button { background: #8f7a66; color: #f9f6f2; padding: 10px 20px; border-radius: 3px; font-weight: bold; cursor: pointer; border: none; font-size: 18px; text-decoration: none; display: inline-block; }

/* Area di Gioco */
.game-container { position: relative; width: 500px; height: 500px; background: #bbada0; border-radius: 6px; padding: 15px; box-sizing: border-box; touch-action: none; }
.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; border-radius: 6px; }
.game-message.game-won, .game-message.game-over { display: flex; }
.game-message p { font-size: 60px; font-weight: bold; margin: 0; color: #776e65; }

/* Pulsanti Fine Partita Interni */
.lower { display: flex; gap: 10px; margin-top: 20px; }
.retry-button, .keep-playing-button { background: #8f7a66; color: #f9f6f2; padding: 10px 20px; border-radius: 3px; font-weight: bold; cursor: pointer; border: none; font-size: 18px; }
.keep-playing-button { display: none; }
.game-won .keep-playing-button { display: inline-block; }

.grid-container { position: absolute; z-index: 1; }
.grid-row { margin-bottom: 15px; display: flex; }
.grid-row:last-child { margin-bottom: 0; }
.grid-cell { width: 106.25px; height: 106.25px; 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: 2; }
.tile { position: absolute; width: 106.25px; height: 106.25px; transition: 100ms ease-in-out; }
.tile .tile-inner { width: 100%; height: 100%; line-height: 106.25px; text-align: center; font-weight: bold; z-index: 10; font-size: 55px; border-radius: 3px; background: #eee4da; color: #776e65; }

/* Posizioni (Desktop) */
.tile-position-1-1 { transform: translate(0px, 0px); } .tile-position-2-1 { transform: translate(121px, 0px); } .tile-position-3-1 { transform: translate(242px, 0px); } .tile-position-4-1 { transform: translate(363px, 0px); }
.tile-position-1-2 { transform: translate(0px, 121px); } .tile-position-2-2 { transform: translate(121px, 121px); } .tile-position-3-2 { transform: translate(242px, 121px); } .tile-position-4-2 { transform: translate(363px, 121px); }
.tile-position-1-3 { transform: translate(0px, 242px); } .tile-position-2-3 { transform: translate(121px, 242px); } .tile-position-3-3 { transform: translate(242px, 242px); } .tile-position-4-3 { transform: translate(363px, 242px); }
.tile-position-1-4 { transform: translate(0px, 363px); } .tile-position-2-4 { transform: translate(121px, 363px); } .tile-position-3-4 { transform: translate(242px, 363px); } .tile-position-4-4 { transform: translate(363px, 363px); }

/* Colori tessere */
.tile-2 .tile-inner { background: #eee4da; } .tile-4 .tile-inner { background: #ede0c8; } .tile-8 .tile-inner { color: #f9f6f2; background: #f2b179; } .tile-16 .tile-inner { color: #f9f6f2; background: #f59563; }
.tile-32 .tile-inner { color: #f9f6f2; background: #f67c5f; } .tile-64 .tile-inner { color: #f9f6f2; background: #f65e3b; } .tile-128 .tile-inner { color: #f9f6f2; background: #edcf72; font-size: 45px; }
.tile-256 .tile-inner { color: #f9f6f2; background: #edcc61; font-size: 45px; } .tile-512 .tile-inner { color: #f9f6f2; background: #edc850; font-size: 45px; } .tile-1024 .tile-inner { color: #f9f6f2; background: #edc53f; font-size: 35px; }
.tile-2048 .tile-inner { color: #f9f6f2; background: #edc22e; font-size: 35px; }

.tile-merged .tile-inner { animation: pop 200ms ease 100ms; animation-fill-mode: backwards; }
.tile-new .tile-inner { animation: appear 200ms ease 100ms; animation-fill-mode: backwards; }
@keyframes appear { 0% { opacity: 0; transform: scale(0); } 100% { opacity: 1; transform: scale(1); } }
@keyframes pop { 0% { transform: scale(0); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* Mobile (sotto i 520px) */
@media screen and (max-width: 520px) {
  .container { width: 280px; }
  .title { font-size: 40px; }
  .score-container, .best-container { font-size: 18px; padding: 5px 10px; }
  .above-game { margin-bottom: 10px; }
  .restart-button { padding: 8px 15px; font-size: 16px; }
  .game-container { width: 280px; height: 280px; padding: 10px; }
  .grid-cell { width: 57.5px; height: 57.5px; margin-right: 10px; }
  .grid-row { margin-bottom: 10px; }
  .tile { width: 57.5px; height: 57.5px; }
  .tile .tile-inner { line-height: 57.5px; font-size: 35px; }
  .tile-position-1-1 { transform: translate(0px, 0px); } .tile-position-2-1 { transform: translate(67.5px, 0px); } .tile-position-3-1 { transform: translate(135px, 0px); } .tile-position-4-1 { transform: translate(202.5px, 0px); }
  .tile-position-1-2 { transform: translate(0px, 67.5px); } .tile-position-2-2 { transform: translate(67.5px, 67.5px); } .tile-position-3-2 { transform: translate(135px, 67.5px); } .tile-position-4-2 { transform: translate(202.5px, 67.5px); }
  .tile-position-1-3 { transform: translate(0px, 135px); } .tile-position-2-3 { transform: translate(67.5px, 135px); } .tile-position-3-3 { transform: translate(135px, 135px); } .tile-position-4-3 { transform: translate(202.5px, 135px); }
  .tile-position-1-4 { transform: translate(0px, 202.5px); } .tile-position-2-4 { transform: translate(67.5px, 202.5px); } .tile-position-3-4 { transform: translate(135px, 202.5px); } .tile-position-4-4 { transform: translate(202.5px, 202.5px); }
  .game-message p { font-size: 30px; }
}