﻿:root {
  color-scheme: light dark;
  --bg-color: #faf8ef;
  --primary-text: #776e65;
  --board-bg: #bbada0;
  --tile-empty-bg: rgba(238, 228, 218, 0.35);
  --stat-bg: rgba(187, 173, 160, 0.8);
  --stat-text: #f9f6f2;
  --accent: #8f7a66;
  --win: #edc22e;
  --lose: #776e65;
  --grid-size: 4;
  --grid-gap: 16px;
  --board-padding: 16px;
  --cell-size: 96px;
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg-color);
  color: var(--primary-text);
  display: flex;
  justify-content: center;
  padding: 40px 16px 80px;
}

button,
input,
textarea,
select {
  font: inherit;
}

.hidden {
  display: none !important;
}

.game-container {
  max-width: 480px;
  width: 100%;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}

.game-header h1 {
  font-size: 64px;
  line-height: 1;
  margin: 0;
  color: #776e65;
}

.subtitle {
  margin: 8px 0 0;
}

.stats {
  display: flex;
  gap: 12px;
}

.stat-box {
  background-color: var(--stat-bg);
  border-radius: 6px;
  padding: 8px 16px;
  text-align: center;
  min-width: 90px;
  color: var(--stat-text);
}

.stat-box .label {
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.stat-box .value {
  display: block;
  margin-top: 6px;
  font-weight: 700;
  font-size: 22px;
}

.controls {
  margin: 24px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

#new-game {
  background-color: #8f7a66;
  color: #f9f6f2;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  cursor: pointer;
  transition: transform 0.12s ease-in-out;
}

#new-game:focus-visible {
  outline: 3px solid rgba(143, 122, 102, 0.6);
  outline-offset: 2px;
}

#new-game:active {
  transform: scale(0.96);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}

.board-wrapper {
  position: relative;
}

.board-grid {
  position: relative;
  aspect-ratio: 1 / 1;
  background-color: var(--board-bg);
  border-radius: 8px;
  padding: var(--board-padding);
  display: grid;
  grid-template-columns: repeat(var(--grid-size), 1fr);
  grid-template-rows: repeat(var(--grid-size), 1fr);
  gap: var(--grid-gap);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.03);
  overflow: hidden;
}

.grid-cell {
  background-color: var(--tile-empty-bg);
  border-radius: 6px;
}

.tile {
  position: absolute;
  top: var(--board-padding);
  left: var(--board-padding);
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 700;
  font-size: 36px;
  color: #776e65;
  transition: transform 0.14s ease-in-out;
  z-index: 2;
}

.tile.new {
  animation: pop-in 0.18s ease-out;
}

.tile.merge {
  animation: pop-merge 0.2s ease-in-out;
}

.tile-2 {
  background-color: #eee4da;
}

.tile-4 {
  background-color: #ede0c8;
}

.tile-8 {
  background-color: #f2b179;
  color: #f9f6f2;
}

.tile-16 {
  background-color: #f59563;
  color: #f9f6f2;
}

.tile-32 {
  background-color: #f67c5f;
  color: #f9f6f2;
}

.tile-64 {
  background-color: #f65e3b;
  color: #f9f6f2;
}

.tile-128 {
  background-color: #edcf72;
  color: #f9f6f2;
  font-size: 32px;
}

.tile-256 {
  background-color: #edcc61;
  color: #f9f6f2;
  font-size: 32px;
}

.tile-512 {
  background-color: #edc850;
  color: #f9f6f2;
  font-size: 30px;
}

.tile-1024 {
  background-color: #edc53f;
  color: #f9f6f2;
  font-size: 28px;
}

.tile-2048 {
  background-color: #edc22e;
  color: #f9f6f2;
  font-size: 26px;
}

.tile-super {
  background-color: #3c3a32;
  color: #f9f6f2;
  font-size: 26px;
}

.game-message {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, 0.7);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 28px;
  color: var(--primary-text);
  text-align: center;
  padding: 16px;
  z-index: 3;
}

.game-message button {
  background-color: #8f7a66;
  color: #f9f6f2;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  cursor: pointer;
}

.game-message.win {
  background: rgba(237, 194, 46, 0.75);
}

.game-message.lose {
  background: rgba(119, 110, 101, 0.75);
  color: #f9f6f2;
}

.how-to-play {
  margin-top: 32px;
  background: rgba(238, 228, 218, 0.5);
  border-radius: 8px;
  padding: 16px;
}

.how-to-play h2 {
  margin-top: 0;
}

@keyframes pop-in {
  from {
    transform: scale(0.4);
  }
  to {
    transform: scale(1);
  }
}

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

@media (max-width: 560px) {
  body {
    padding: 32px 12px 64px;
  }

  .game-header h1 {
    font-size: 52px;
  }

  :root {
    --grid-gap: 12px;
    --board-padding: 12px;
  }

  .tile {
    font-size: 30px;
  }
}

.message-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

