:root {
  --bg: #f5f5f5;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #d1d5db;
  --grid-bg: #bbada0;
  --cell-empty: #cdc1b4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.panel {
  width: min(92vw, 420px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

h1 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}

.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: normal;
  margin-right: 0.25rem;
}

.back:hover {
  color: var(--text);
}

.meta {
  display: flex;
  justify-content: space-between;
  margin: 0 0 0.75rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--grid-bg);
  border-radius: 8px;
  padding: 8px;
  touch-action: none;
  user-select: none;
}

.tile {
  aspect-ratio: 1;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(0.9rem, 4vw, 1.5rem);
  transition: background 0.08s;
}

.tile[data-v="0"]   { background: var(--cell-empty); color: transparent; }
.tile[data-v="2"]   { background: #eee4da; color: #776e65; }
.tile[data-v="4"]   { background: #ede0c8; color: #776e65; }
.tile[data-v="8"]   { background: #f2b179; color: #f9f6f2; }
.tile[data-v="16"]  { background: #f59563; color: #f9f6f2; }
.tile[data-v="32"]  { background: #f67c5f; color: #f9f6f2; }
.tile[data-v="64"]  { background: #f65e3b; color: #f9f6f2; }
.tile[data-v="128"] { background: #edcf72; color: #f9f6f2; font-size: clamp(0.8rem, 3.5vw, 1.3rem); }
.tile[data-v="256"] { background: #edcc61; color: #f9f6f2; font-size: clamp(0.8rem, 3.5vw, 1.3rem); }
.tile[data-v="512"] { background: #edc850; color: #f9f6f2; font-size: clamp(0.8rem, 3.5vw, 1.3rem); }
.tile[data-v="1024"]{ background: #edc53f; color: #f9f6f2; font-size: clamp(0.7rem, 3vw, 1.1rem); }
.tile[data-v="2048"]{ background: #edc22e; color: #f9f6f2; font-size: clamp(0.7rem, 3vw, 1.1rem); }

.actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

#status {
  font-size: 0.9rem;
  color: var(--muted);
}

#status.won {
  color: #16a34a;
  font-weight: 600;
}

#status.lost {
  color: #dc2626;
  font-weight: 600;
}

.hint {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
