:root {
  --bg: #faf6ef;
  --ink: #3a3229;
  --ink-soft: #8a8072;
  --board-bg: #d9cdb8;
  --cell-bg: #e9ded0;
  --accent: #e2795a;
  --radius: 10px;
  --font: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 480px;
  padding: 1.8rem 1.2rem 3rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.2rem;
  gap: 1rem;
}
.title {
  font-size: 2.6rem;
  font-weight: 900;
  margin: 0;
  color: var(--accent);
  letter-spacing: -.02em;
}
.subtitle { margin: .2rem 0 0; color: var(--ink-soft); font-size: .9rem; }

.scores { display: flex; gap: .6rem; }
.score-box {
  background: var(--board-bg);
  color: #fff;
  border-radius: 8px;
  padding: .5rem .9rem;
  text-align: center;
  min-width: 68px;
}
.score-box__label { display: block; font-size: .62rem; text-transform: uppercase; letter-spacing: .06em; opacity: .8; }
.score-box__value { display: block; font-size: 1.2rem; font-weight: 900; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
}
.hint { margin: 0; font-size: .8rem; color: var(--ink-soft); }

.btn {
  font-family: var(--font);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .6em 1.2em;
  font-weight: 700;
  font-size: .85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .2s ease;
}
.btn:hover { opacity: .88; }
.btn--primary { padding: .7em 1.6em; }

.board-wrap { position: relative; }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--board-bg);
  border-radius: 12px;
  padding: 12px;
  touch-action: none;
  user-select: none;
}

.grid-cells {
  position: absolute;
  inset: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 12px;
}
.grid-cells div {
  background: var(--cell-bg);
  border-radius: var(--radius);
}

.tiles {
  position: absolute;
  inset: 12px;
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  transition: transform .12s ease-in;
  will-change: transform;
}
.tile__face {
  width: 100%;
  height: 100%;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1.6rem;
  color: #fff;
}

.tile--new .tile__face { animation: popIn .18s ease; }
.tile--merged .tile__face { animation: popMerge .16s ease; }

@keyframes popIn {
  from { transform: scale(0); }
  to { transform: scale(1); }
}
@keyframes popMerge {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(250, 246, 239, .88);
  border-radius: 12px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  text-align: center;
}
.overlay.is-visible { display: flex; }
.overlay__title { font-size: 1.6rem; font-weight: 900; margin: 0; color: var(--ink); }

.footer { text-align: center; margin-top: 1.6rem; color: var(--ink-soft); font-size: .78rem; }

@media (max-width: 420px) {
  .title { font-size: 2.1rem; }
  .tile__face { font-size: 1.25rem; }
}
