:root {
  color-scheme: light;
  --page: #f7f0df;
  --ink: #2d2721;
  --muted: #756b5d;
  --board: #9d8d7b;
  --cell: #cbbca6;
  --tile-text: #372f28;
  --white-tile: #fff8ea;
  --accent: #2c7a7b;
  --accent-dark: #205e5f;
  --danger: #9f3a38;
  font-family: Arial, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(44, 122, 123, 0.16), transparent 35%),
    var(--page);
  color: var(--ink);
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  padding: 0 18px;
}

button:hover,
button:focus-visible {
  background: var(--accent-dark);
  outline: 3px solid rgba(44, 122, 123, 0.22);
  outline-offset: 2px;
}

.app {
  width: min(94vw, 560px);
  padding: 24px 0;
}

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

h1 {
  margin: 0;
  font-size: clamp(44px, 10vw, 72px);
  line-height: 0.9;
}

.subtitle {
  color: var(--muted);
  margin: 10px 0 0;
}

.scores {
  display: flex;
  gap: 8px;
}

.score-box {
  min-width: 74px;
  border-radius: 8px;
  background: #3d342c;
  color: #fff;
  padding: 10px 12px;
  text-align: center;
}

.score-box span {
  display: block;
  color: #eadfca;
  font-size: 12px;
  font-weight: 700;
}

.score-box strong {
  display: block;
  font-size: 22px;
  line-height: 1.2;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 60px;
  margin: 18px 0;
}

.status {
  color: var(--muted);
  margin: 0;
  text-align: right;
}

.board-wrap {
  position: relative;
}

.board {
  aspect-ratio: 1;
  background: var(--board);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, 1fr);
  padding: 10px;
  touch-action: none;
}

.cell {
  aspect-ratio: 1;
  border-radius: 6px;
  background: var(--cell);
  display: grid;
  place-items: center;
  font-size: clamp(28px, 9vw, 56px);
  font-weight: 800;
  line-height: 1;
  color: var(--tile-text);
  user-select: none;
}

.tile-0 {
  color: transparent;
}

.tile-2,
.tile-4 {
  background: var(--white-tile);
}

.tile-8 {
  background: #f2b56b;
  color: #fff;
}

.tile-16 {
  background: #e89155;
  color: #fff;
}

.tile-32 {
  background: #d96f52;
  color: #fff;
}

.tile-64 {
  background: #c94b3d;
  color: #fff;
}

.tile-128 {
  background: #f0d66d;
}

.tile-256 {
  background: #d9c85c;
}

.tile-512 {
  background: #b8bf62;
}

.tile-1024 {
  background: #7fb069;
  font-size: clamp(22px, 7vw, 42px);
}

.tile-2048 {
  background: #2c7a7b;
  color: #fff;
  font-size: clamp(22px, 7vw, 42px);
}

.message {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: rgba(247, 240, 223, 0.9);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}

.message[hidden] {
  display: none;
}

.message strong {
  font-size: 36px;
}

.message span {
  color: var(--muted);
}

.mobile-controls {
  display: none;
  grid-template-columns: repeat(3, 56px);
  grid-template-areas:
    ". up ."
    "left down right";
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.mobile-controls [data-dir="up"] {
  grid-area: up;
}

.mobile-controls [data-dir="left"] {
  grid-area: left;
}

.mobile-controls [data-dir="right"] {
  grid-area: right;
}

.mobile-controls [data-dir="down"] {
  grid-area: down;
}

@media (max-width: 520px) {
  body {
    align-items: start;
  }

  .app {
    width: min(94vw, 430px);
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .scores {
    width: 100%;
  }

  .score-box {
    flex: 1;
  }

  .actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .status {
    min-height: 20px;
    text-align: left;
  }

  .board {
    gap: 8px;
    padding: 8px;
  }

  .mobile-controls {
    display: grid;
  }
}
