:root {
  --bg: #faf8ef;
  --board-bg: #bbada0;
  --cell-bg: #cdc1b4;
  --text-dark: #776e65;
  --text-light: #f9f6f2;
  --tile-2: #eee4da;
  --tile-4: #ede0c8;
  --tile-8: #f2b179;
  --tile-16: #f59563;
  --tile-32: #f67c5f;
  --tile-64: #f65e3b;
  --tile-128: #edcf72;
  --tile-256: #edcc61;
  --tile-512: #edc850;
  --tile-1024: #edc53f;
  --tile-2048: #edc22e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-dark);
  display: flex;
  justify-content: center;
  padding: 24px 16px;
}

.container {
  width: 100%;
  max-width: 480px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

h1 {
  font-size: 48px;
  margin: 0;
  font-weight: 700;
}

.scores {
  display: flex;
  gap: 8px;
}

.score-box {
  background: var(--board-bg);
  color: var(--text-light);
  border-radius: 6px;
  padding: 8px 16px;
  text-align: center;
  min-width: 60px;
}

.score-box .label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  color: #eee4da;
}

.score-box span:last-child {
  display: block;
  font-size: 20px;
  font-weight: 700;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.instructions {
  margin: 0;
  font-size: 14px;
  color: #776e65;
}

button {
  background: #8f7a66;
  color: var(--text-light);
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}

button:hover {
  background: #9f8b76;
}

.board-wrapper {
  position: relative;
}

.board {
  background: var(--board-bg);
  border-radius: 8px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  aspect-ratio: 1 / 1;
}

.cell {
  background: rgba(238, 228, 218, 0.35);
  border-radius: 4px;
}

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: 700;
  background: var(--tile-2);
  color: var(--text-dark);
  transition: top 0.1s ease-in-out, left 0.1s ease-in-out;
}

.tile[data-value="2"]
{ background: var(--tile-2); }

.tile[data-value="4"]
{ background: var(--tile-4); }

.tile[data-value="8"]
{ background: var(--tile-8); color: var(--text-light); }

.tile[data-value="16"]
{ background: var(--tile-16); color: var(--text-light); }

.tile[data-value="32"]
{ background: var(--tile-32); color: var(--text-light); }

.tile[data-value="64"]
{ background: var(--tile-64); color: var(--text-light); }

.tile[data-value="128"]
{ background: var(--tile-128); color: var(--text-light); font-size: 0.9em; }

.tile[data-value="256"]
{ background: var(--tile-256); color: var(--text-light); font-size: 0.9em; }

.tile[data-value="512"]
{ background: var(--tile-512); color: var(--text-light); font-size: 0.9em; }

.tile[data-value="1024"]
{ background: var(--tile-1024); color: var(--text-light); font-size: 0.8em; }

.tile[data-value="2048"]
{ background: var(--tile-2048); color: var(--text-light); font-size: 0.8em; }

.message {
  position: absolute;
  inset: 8px;
  background: rgba(238, 228, 218, 0.85);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

.message.hidden {
  display: none;
}

.message p {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
}

footer {
  text-align: center;
  margin-top: 16px;
  font-size: 12px;
  color: #999;
}