:root {
  color-scheme: light;
  --bg: #f7efe2;
  --ink: #27221c;
  --muted: #70665b;
  --panel: #fffaf2;
  --line: #d7c8b7;
  --board: #b9a894;
  --cell: #cec0af;
  --accent: #2f7d6f;
  --accent-dark: #216457;
  --danger: #9f4938;
  --radius: 8px;
  --gap: clamp(8px, 2vw, 14px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  align-items: center;
  background:
    radial-gradient(circle at top left, rgba(47, 125, 111, 0.14), transparent 34rem),
    linear-gradient(135deg, #fbf4e8 0%, var(--bg) 46%, #edf4ee 100%);
  color: var(--ink);
  display: flex;
  justify-content: center;
  margin: 0;
  padding: 24px;
}

button {
  appearance: none;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 44px;
  padding: 0 18px;
  transition: background 140ms ease, transform 140ms ease, opacity 140ms ease;
}

button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.shell {
  display: grid;
  gap: 16px;
  max-width: 560px;
  width: min(100%, 560px);
}

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

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

h1 {
  font-size: clamp(3.25rem, 14vw, 5.6rem);
  letter-spacing: 0;
  line-height: 0.9;
  margin: 0;
}

.scoreboard {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(78px, 1fr));
}

.scorebox {
  background: #4f463d;
  border-radius: var(--radius);
  color: white;
  min-width: 78px;
  padding: 10px 12px;
  text-align: center;
}

.scorebox span {
  color: #e6d9ca;
  display: block;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.scorebox strong {
  display: block;
  font-size: clamp(1.2rem, 4vw, 1.55rem);
  line-height: 1.1;
}

.controls {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.controls button:last-child {
  background: #675d52;
}

.controls button:last-child:hover {
  background: #51483f;
}

.game-panel {
  background: rgba(255, 250, 242, 0.72);
  border: 1px solid rgba(215, 200, 183, 0.78);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  padding: clamp(10px, 2vw, 14px);
  box-shadow: 0 20px 70px rgba(66, 53, 39, 0.14);
}

.board-wrap {
  aspect-ratio: 1;
  position: relative;
  width: 100%;
}

.board {
  background: var(--board);
  border-radius: var(--radius);
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(4, 1fr);
  height: 100%;
  padding: var(--gap);
  touch-action: none;
  width: 100%;
}

.cell {
  align-items: center;
  aspect-ratio: 1;
  background: var(--cell);
  border-radius: 6px;
  display: flex;
  font-size: clamp(1.8rem, 9vw, 4.5rem);
  font-weight: 900;
  justify-content: center;
  line-height: 1;
  min-width: 0;
  user-select: none;
}

.tile-0 {
  color: transparent;
}

.tile-2 { background: #eee4da; color: #4d463d; }
.tile-4 { background: #eadcc7; color: #4d463d; }
.tile-8 { background: #f1a563; color: #fff8ef; }
.tile-16 { background: #ef8354; color: #fff8ef; }
.tile-32 { background: #dd6b55; color: #fff8ef; }
.tile-64 { background: #c95344; color: #fff8ef; }
.tile-128 { background: #e3c35c; color: #fff8ef; font-size: clamp(1.55rem, 7vw, 3.75rem); }
.tile-256 { background: #d7b43f; color: #fff8ef; font-size: clamp(1.55rem, 7vw, 3.75rem); }
.tile-512 { background: #bd9a31; color: #fff8ef; font-size: clamp(1.55rem, 7vw, 3.75rem); }
.tile-1024 { background: #348d83; color: #fff8ef; font-size: clamp(1.22rem, 5.8vw, 3.1rem); }
.tile-2048 { background: #236f74; color: #fff8ef; font-size: clamp(1.22rem, 5.8vw, 3.1rem); }
.tile-super { background: #29384d; color: #fff8ef; font-size: clamp(1.05rem, 5vw, 2.7rem); }

.message {
  align-items: center;
  background: rgba(255, 250, 242, 0.84);
  border-radius: var(--radius);
  display: flex;
  inset: 0;
  justify-content: center;
  position: absolute;
}

.message.hidden {
  display: none;
}

.message-card {
  align-items: center;
  display: grid;
  gap: 14px;
  justify-items: center;
  padding: 24px;
  text-align: center;
}

.message-card p {
  color: var(--ink);
  font-size: clamp(1.7rem, 8vw, 3.4rem);
  font-weight: 950;
  line-height: 1;
  margin: 0;
}

.hint-row {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.9rem;
  font-weight: 750;
  gap: 8px;
  justify-content: center;
}

.hint-row span {
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(215, 200, 183, 0.86);
  border-radius: 999px;
  padding: 6px 10px;
}

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

  .topbar {
    align-items: stretch;
    display: grid;
  }

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