:root {
  --bg: #101214;
  --panel: #1b1f23;
  --panel-2: #242a30;
  --line: #343b43;
  --text: #f6f0e6;
  --muted: #b8c1ca;
  --accent: #ffcc66;
  --accent-2: #72dbc3;
  --danger: #ff7a6e;
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.35);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(114, 219, 195, 0.10), transparent 32rem),
    linear-gradient(315deg, rgba(255, 204, 102, 0.10), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(320px, 520px);
  align-items: center;
  gap: 48px;
  padding: 48px 0;
}

.intro {
  display: grid;
  gap: 32px;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--accent-2);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(4.6rem, 13vw, 9.5rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.lede {
  max-width: 34rem;
  margin: 24px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 170px));
  gap: 12px;
}

.score-card {
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(27, 31, 35, 0.78);
  box-shadow: var(--shadow);
}

.score-card span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.score-card strong {
  display: block;
  margin-top: 6px;
  font-size: 2rem;
  line-height: 1;
}

.game-area {
  display: grid;
  gap: 16px;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 18px;
  background: var(--accent);
  color: #1b1609;
  cursor: pointer;
  font-weight: 850;
  transition:
    transform 140ms ease,
    background-color 140ms ease,
    opacity 140ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button-secondary {
  background: var(--panel-2);
  color: var(--text);
}

.board-wrap {
  position: relative;
}

.board {
  aspect-ratio: 1;
  width: min(100%, 520px);
  margin-left: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #2a3036;
  box-shadow: var(--shadow);
  touch-action: none;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #1f242a;
  color: #16120d;
  font-size: clamp(1.4rem, 7vw, 3.15rem);
  font-weight: 900;
  line-height: 1;
  user-select: none;
}

.cell[data-value=""] {
  color: transparent;
}

.cell[data-value="2"] { background: #f5ead8; }
.cell[data-value="4"] { background: #f1dfc3; }
.cell[data-value="8"] { background: #f6b26b; color: #fffaf2; }
.cell[data-value="16"] { background: #f18f5a; color: #fffaf2; }
.cell[data-value="32"] { background: #ed705e; color: #fffaf2; }
.cell[data-value="64"] { background: #e94e42; color: #fffaf2; }
.cell[data-value="128"] { background: #edd071; color: #fffaf2; font-size: clamp(1.15rem, 5.6vw, 2.6rem); }
.cell[data-value="256"] { background: #e8c456; color: #fffaf2; font-size: clamp(1.15rem, 5.6vw, 2.6rem); }
.cell[data-value="512"] { background: #dfb532; color: #fffaf2; font-size: clamp(1.15rem, 5.6vw, 2.6rem); }
.cell[data-value="1024"] { background: #75c9be; color: #08211e; font-size: clamp(0.95rem, 4.8vw, 2.15rem); }
.cell[data-value="2048"] { background: #38b2a6; color: #061d1a; font-size: clamp(0.95rem, 4.8vw, 2.15rem); }
.cell[data-super="true"] { background: #9ad971; color: #11210a; font-size: clamp(0.9rem, 4.5vw, 2rem); }

.cell.appear {
  animation: appear 160ms ease-out;
}

.cell.merge {
  animation: merge 180ms ease-out;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: rgba(16, 18, 20, 0.76);
  backdrop-filter: blur(6px);
}

.overlay[hidden] {
  display: none !important;
}

.overlay-panel {
  width: min(82%, 280px);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: center;
}

.overlay-panel p {
  margin: 0 0 18px;
  font-size: 1.5rem;
  font-weight: 900;
}

.hint {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

@keyframes appear {
  from {
    transform: scale(0.72);
    opacity: 0;
  }
}

@keyframes merge {
  50% {
    transform: scale(1.08);
  }
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 24px;
    padding: 26px 0 34px;
  }

  .intro {
    gap: 20px;
  }

  .scoreboard {
    grid-template-columns: repeat(2, 1fr);
  }

  .toolbar {
    justify-content: stretch;
  }

  .button {
    flex: 1;
  }

  .board {
    width: 100%;
  }

  .hint {
    flex-direction: column;
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
