

:root {

  --bg: #f7f7f5;
  --bg-accent: #eeeeeb;
  --ink: #1a1a19;
  --ink-soft: #8a8a84;
  --board: #ecebe6;
  --cell: #e2e0d8;
  --btn: #1a1a19;
  --btn-ink: #f7f7f5;

  /* Motion */
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --slide: 130ms;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Outfit', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

.wrapper {
  width: 100%;
  max-width: 480px;
  padding: 24px;
}

/* ========== HEADER ========== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.title {
  font-size: 3.8rem;
  font-weight: 900;
  color: var(--ink);
  line-height: 0.9;
  letter-spacing: -0.05em;
}

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

.score-box {
  position: relative;
  background: var(--bg-accent);
  border-radius: 14px;
  padding: 8px 16px;
  text-align: center;
  min-width: 84px;
}

.score-label {
  display: block;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 1px;
}

.score-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.score-value.bump {
  animation: score-bump 280ms var(--spring);
}

@keyframes score-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.22); color: var(--ink); }
  100% { transform: scale(1); }
}

/* ========== CONTROLS ========== */
.header-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 12px;
}

.subtitle {
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--ink-soft);
  line-height: 1.3;
}

.subtitle strong {
  font-weight: 700;
  color: var(--ink);
}

#new-game-btn,
.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--btn);
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  color: var(--btn-ink);
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 200ms var(--spring), opacity 150ms var(--ease);
}

#new-game-btn svg,
.retry-btn svg {
  width: 16px;
  height: 16px;
}

#new-game-btn:hover,
.retry-btn:hover {
  opacity: 0.88;
}

#new-game-btn:active,
.retry-btn:active {
  transform: scale(0.94);
}

#new-game-btn:focus-visible,
.retry-btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

/* ========== GAME CONTAINER ========== */
.game-container {
  position: relative;
}

.grid-container {
  position: relative;
  background: var(--board);
  border-radius: 18px;
  padding: 10px;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  overflow: hidden;
  outline: none;
}

.grid-cell {
  background: var(--cell);
  border-radius: 12px;
}

/* ========== TILES ========== */
.tile {
  position: absolute;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 12px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  transition:
    left var(--slide) var(--ease),
    top var(--slide) var(--ease);
}

.tile-new {
  animation: tile-appear 240ms var(--spring);
}

.tile-merged {
  animation: tile-pop 260ms var(--spring);
  z-index: 20;
}

@keyframes tile-appear {
  0% { opacity: 0; transform: scale(0.2); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes tile-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ========== TILE COLORS — minimal warm ramp ========== */
.tile-2 {
  background: #eeeeeb;
  color: #1a1a19;
}
.tile-4 {
  background: #e6e4dc;
  color: #1a1a19;
}
.tile-8 {
  background: #f2b179;
  color: #fff;
}
.tile-16 {
  background: #f19063;
  color: #fff;
}
.tile-32 {
  background: #f0774f;
  color: #fff;
}
.tile-64 {
  background: #eb5c39;
  color: #fff;
}
.tile-128 {
  background: #ecc850;
  color: #fff;
}
.tile-256 {
  background: #edc340;
  color: #fff;
}
.tile-512 {
  background: #eebd2c;
  color: #fff;
}
.tile-1024 {
  background: #edb400;
  color: #fff;
}
.tile-2048 {
  background: #1a1a19;
  color: #f7d34e;
}
.tile-super {
  background: #0f0f0e;
  color: #f7d34e;
}

/* ========== GAME OVER OVERLAY ========== */
.game-over-overlay {
  position: absolute;
  inset: 0;
  background: rgba(247, 247, 245, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 18px;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 320ms var(--ease);
}

.game-over-overlay.show {
  display: flex;
  opacity: 1;
}

.overlay-content {
  text-align: center;
  transform: scale(0.9) translateY(16px);
  opacity: 0;
  transition: transform 360ms var(--spring), opacity 320ms var(--ease);
}

.game-over-overlay.show .overlay-content {
  transform: scale(1) translateY(0);
  opacity: 1;
  transition-delay: 80ms;
}

.overlay-content h2 {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: var(--ink);
  margin-bottom: 6px;
}

.final-score {
  font-size: 1rem;
  color: var(--ink-soft);
  margin-bottom: 22px;
  font-weight: 500;
}

.retry-btn {
  font-size: 0.95rem;
  padding: 13px 26px;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 520px) {
  .wrapper {
    padding: 16px;
  }
  .title {
    font-size: 3rem;
  }
  .score-box {
    min-width: 70px;
    padding: 6px 12px;
  }
  .score-value {
    font-size: 1.25rem;
  }
  .subtitle {
    font-size: 0.85rem;
  }
  .overlay-content h2 {
    font-size: 1.7rem;
  }
}

@media (max-width: 380px) {
  .title {
    font-size: 2.4rem;
  }
  .score-box {
    min-width: 58px;
    padding: 5px 9px;
  }
  .score-value {
    font-size: 1.05rem;
  }
  .score-label {
    font-size: 0.52rem;
  }
  #new-game-btn span {
    display: none;
  }
  #new-game-btn {
    padding: 11px;
  }
}

/* ========== ACCESSIBILITY ========== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
