:root { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { min-width: 320px; padding: 80px 20px 36px; background: #faf8ef; color: #776e65; font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif; font-size: 18px; }
.bot-trigger { position: fixed; top: 0; right: 0; z-index: 10; width: 56px; height: 56px; padding: 0; border: 0; background: transparent; cursor: default; }
.container { width: min(500px, 100%); margin: 0 auto; }
.heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font-size: 80px; line-height: 1; letter-spacing: -5px; font-weight: 700; }
.scores { display: flex; gap: 5px; }
.score-box { position: relative; min-width: 80px; min-height: 57px; padding: 8px 15px 7px; border-radius: 3px; background: #bbada0; color: #fff; text-align: center; font-weight: 700; }
.score-label { display: block; color: #eee4da; font-size: 13px; line-height: 17px; text-transform: uppercase; }
.score-value { display: block; min-height: 27px; font-size: 25px; line-height: 28px; }
.score-addition { position: absolute; top: 18px; left: 50%; z-index: 1; color: #776e65; font-size: 25px; line-height: 1; font-weight: 700; white-space: nowrap; pointer-events: none; animation: score-rise 650ms ease-out both; }
@keyframes score-rise { 0% { opacity: 0; transform: translate(-50%, 12px); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -44px); } }
.above-game { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.above-game p { margin: 0; line-height: 1.5; }
.button { flex: none; min-height: 40px; padding: 0 20px; border: 0; border-radius: 3px; background: #8f7a66; color: #f9f6f2; font: 700 18px/40px "Clear Sans", "Helvetica Neue", Arial, sans-serif; text-align: center; cursor: pointer; }
.button:hover, .button:focus-visible { background: #776452; }
.button:focus-visible { outline: 3px solid #edc22e; outline-offset: 3px; }
.board { position: relative; width: 100%; aspect-ratio: 1; margin-top: 40px; padding: 15px; border-radius: 6px; background: #bbada0; touch-action: none; user-select: none; }
.grid, .tile-layer { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); gap: 15px; }
.grid { width: 100%; height: 100%; }
.grid-cell { border-radius: 3px; background: rgba(238, 228, 218, .35); }
.tile-layer { position: absolute; inset: 15px; pointer-events: none; }
.tile { display: grid; place-items: center; min-width: 0; border-radius: 3px; background: #eee4da; color: #776e65; font-size: 55px; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; transition: transform 48ms ease-out; will-change: transform; }
.tile-new { animation: tile-appear 90ms ease-out both; }
.tile-merged { animation: tile-pop 90ms ease-out both; }
@keyframes tile-appear { from { opacity: 0; scale: .35; } to { opacity: 1; scale: 1; } }
@keyframes tile-pop { 0% { scale: 1; } 50% { scale: 1.18; } 100% { scale: 1; } }
@keyframes game-over-reveal { from { opacity: 0; } to { opacity: 1; } }
.tile[data-value="4"] { background: #ede0c8; }
.tile[data-value="8"] { background: #f2b179; color: #f9f6f2; }
.tile[data-value="16"] { background: #f59563; color: #f9f6f2; }
.tile[data-value="32"] { background: #f67c5f; color: #f9f6f2; }
.tile[data-value="64"] { background: #f65e3b; color: #f9f6f2; }
.tile[data-value="128"] { background: #edcf72; color: #f9f6f2; box-shadow: 0 0 30px 10px rgba(243, 215, 116, .24); }
.tile[data-value="256"] { background: #edcc61; color: #f9f6f2; box-shadow: 0 0 30px 10px rgba(243, 215, 116, .32); }
.tile[data-value="512"] { background: #edc850; color: #f9f6f2; box-shadow: 0 0 30px 10px rgba(243, 215, 116, .40); }
.tile[data-value="1024"] { background: #edc53f; color: #f9f6f2; box-shadow: 0 0 30px 10px rgba(243, 215, 116, .48); }
.tile[data-value="2048"] { background: #edc22e; color: #f9f6f2; box-shadow: 0 0 30px 10px rgba(243, 215, 116, .56); }
.tile[data-large="true"] { background: #3c3a32; color: #f9f6f2; }
.tile[data-digits="3"] { font-size: 45px; }
.tile[data-digits="4"] { font-size: 35px; }
.tile[data-digits="5"] { font-size: 30px; }
.game-message { position: absolute; z-index: 2; inset: 0; display: none; place-items: center; border-radius: 6px; background: rgba(238, 228, 218, .75); text-align: center; }
.game-message.visible { display: grid; }
.game-message.over { animation: game-over-reveal 700ms ease-out both; }
.game-message.won { background: rgba(237, 194, 46, .67); }
.message-title { margin: 0 0 22px; font-size: clamp(36px, 9vw, 60px); font-weight: 700; line-height: 1.1; }
.game-message.won .message-title { color: #f9f6f2; }
.instructions { margin: 47px 0 0; line-height: 1.65; }
hr { height: 0; border: 0; border-bottom: 1px solid #d8d4d0; margin: 20px 0 27px; }
.credit { margin: 0; line-height: 1.5; font-size: 16px; }
.credit a { color: inherit; font-weight: 700; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@media (prefers-reduced-motion: reduce) { .tile { transition: none; } .tile-new, .tile-merged, .game-message.over { animation: none; } .score-addition { display: none; } }
@media (max-width: 520px) {
  body { padding: 20px 20px 32px; font-size: 15px; }
  .container { width: min(100%, 360px); }
  h1 { margin-top: 11px; font-size: 52px; letter-spacing: -3px; }
  .score-box { min-width: 65px; min-height: 56px; padding: 8px 9px 6px; }
  .score-value { font-size: 21px; }
  .above-game { margin-top: 20px; }
  .above-game p { max-width: 58%; }
  .button { padding: 0 12px; font-size: 15px; }
  .board { margin-top: 19px; padding: 10px; }
  .grid, .tile-layer { gap: 10px; }
  .tile-layer { inset: 10px; }
  .tile { font-size: clamp(27px, 9vw, 45px); }
  .tile[data-digits="3"] { font-size: clamp(22px, 7vw, 36px); }
  .tile[data-digits="4"] { font-size: clamp(17px, 5.5vw, 28px); }
  .tile[data-digits="5"] { font-size: clamp(13px, 4.5vw, 23px); }
  .instructions { margin-top: 30px; }
}
