:root {
  --bg: #f6f4ef;
  --ink: #1c2024;
  --muted: #68737d;
  --line: rgba(28, 32, 36, 0.12);
  --accent: #0f766e;
  --tile-empty: #d9d3c7;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
}

button,
a {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.game-shell {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.game-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 18px;
  align-items: center;
}

.back-link {
  color: var(--accent);
  font-weight: 720;
}

.game-header p {
  margin: 0 0 4px;
  color: #c97a22;
  font-size: 0.78rem;
  font-weight: 780;
  text-transform: uppercase;
}

.game-header h1 {
  margin: 0;
  font-size: 2.4rem;
  line-height: 1;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 760;
}

.score-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 24px 0;
}

.score-row div {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.score-row span,
.score-row strong {
  display: block;
}

.score-row span {
  color: var(--muted);
  font-size: 0.86rem;
}

.score-row strong {
  margin-top: 6px;
  font-size: 1.7rem;
}

.board-wrap {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: min(100%, 560px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 10px;
  border-radius: 8px;
  background: #b9ad9f;
  touch-action: none;
  user-select: none;
  outline: none;
}

.tile {
  display: grid;
  place-items: center;
  min-width: 0;
  border-radius: 6px;
  background: var(--tile-empty);
  color: #776e65;
  font-size: clamp(1.4rem, 7vw, 3rem);
  font-weight: 860;
  line-height: 1;
  transition:
    background-color 140ms ease,
    color 140ms ease;
}

.tile.new {
  animation: pop-in 120ms ease-out;
}

.tile[data-value="2"] {
  background: #eee4da;
}

.tile[data-value="4"] {
  background: #ede0c8;
}

.tile[data-value="8"] {
  background: #f2b179;
  color: #fff;
}

.tile[data-value="16"] {
  background: #f59563;
  color: #fff;
}

.tile[data-value="32"] {
  background: #f67c5f;
  color: #fff;
}

.tile[data-value="64"] {
  background: #f65e3b;
  color: #fff;
}

.tile[data-value="128"],
.tile[data-value="256"],
.tile[data-value="512"] {
  background: #edcf72;
  color: #fff;
  font-size: clamp(1.25rem, 6vw, 2.5rem);
}

.tile[data-value="1024"],
.tile[data-value="2048"] {
  background: #edc22e;
  color: #fff;
  font-size: clamp(1rem, 5vw, 2.1rem);
}

.message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 18px;
  border-radius: 8px;
  background: rgba(246, 244, 239, 0.86);
  text-align: center;
}

.message[hidden] {
  display: none;
}

.message strong {
  font-size: 2rem;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.94);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile.new {
    animation: none;
    transition: none;
  }
}

@media (max-width: 620px) {
  .game-header {
    grid-template-columns: 1fr;
  }
}
