:root {
  --bg: #faf8ef;
  --text: #776e65;
  --board: #bbada0;
  --cell-empty: rgba(238, 228, 218, 0.35);
  --btn: #8f7a66;
  --btn-hover: #9f8b76;
  --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;
  --tile-super: #3c3a32;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.app-shell {
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
}

.container {
  width: min(100%, 500px);
}

.game-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.title-block h1 {
  margin: 4px 0 0;
  font-size: clamp(48px, 12vw, 72px);
  line-height: 0.9;
  font-weight: 700;
}

.brand-mark {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--btn);
}

.score-panel {
  display: flex;
  gap: 8px;
}

.score-box {
  min-width: 70px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--btn);
  color: #fff;
  text-align: center;
}

.score-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  opacity: 0.9;
}

.score-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.message {
  margin: 0 0 12px;
  font-size: 15px;
  line-height: 1.4;
}

.actions {
  margin-bottom: 16px;
}

.btn {
  border: 0;
  border-radius: 6px;
  padding: 10px 18px;
  background: var(--btn);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:hover {
  background: var(--btn-hover);
}

.btn-secondary {
  background: #f2b179;
  color: #fff;
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-width: 500px;
  margin: 0 auto;
  touch-action: none;
}

.grid {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 10px;
  border-radius: 8px;
  background: var(--board);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  touch-action: none;
}

.cell {
  border-radius: 6px;
  background: var(--cell-empty);
}

.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-weight: 700;
  transition: transform 120ms ease-in-out;
  z-index: 1;
}

.tile.spawn {
  animation: pop 150ms ease-out;
}

@keyframes pop {
  0% {
    transform: scale(0.5);
    opacity: 0.5;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.tile[data-value="2"] { background: var(--tile-2); color: var(--text); }
.tile[data-value="4"] { background: var(--tile-4); color: var(--text); }
.tile[data-value="8"] { background: var(--tile-8); color: #f9f6f2; }
.tile[data-value="16"] { background: var(--tile-16); color: #f9f6f2; }
.tile[data-value="32"] { background: var(--tile-32); color: #f9f6f2; }
.tile[data-value="64"] { background: var(--tile-64); color: #f9f6f2; }
.tile[data-value="128"] { background: var(--tile-128); color: #f9f6f2; }
.tile[data-value="256"] { background: var(--tile-256); color: #f9f6f2; }
.tile[data-value="512"] { background: var(--tile-512); color: #f9f6f2; }
.tile[data-value="1024"] { background: var(--tile-1024); color: #f9f6f2; }
.tile[data-value="2048"] { background: var(--tile-2048); color: #f9f6f2; }
.tile.tile-super { background: var(--tile-super); color: #f9f6f2; }

.hint {
  margin: 16px 0 0;
  text-align: center;
  font-size: 13px;
  opacity: 0.75;
}

.mobile-hint {
  display: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(238, 228, 218, 0.72);
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(90%, 320px);
  padding: 24px;
  border-radius: 10px;
  background: var(--bg);
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 28px;
}

.overlay-card p {
  margin: 0 0 16px;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (max-width: 640px) {
  .desktop-hint {
    display: none;
  }

  .mobile-hint {
    display: block;
  }
}

@media (hover: none) and (pointer: coarse) {
  .desktop-hint {
    display: none;
  }

  .mobile-hint {
    display: block;
  }
}
