@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap');

:root {
  --bg: #0f172a;
  --panel: #0b1222;
  --card: #111a2f;
  --accent: #f97316;
  --accent-2: #22d3ee;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --tile-2: #e2e8f0;
  --tile-4: #cbd5e1;
  --tile-8: #fb923c;
  --tile-16: #f97316;
  --tile-32: #ef4444;
  --tile-64: #dc2626;
  --tile-128: #38bdf8;
  --tile-256: #0ea5e9;
  --tile-512: #2563eb;
  --tile-1024: #7c3aed;
  --tile-2048: #a855f7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(circle at 20% 20%, rgba(34,211,238,0.15), transparent 35%),
              radial-gradient(circle at 80% 20%, rgba(249,115,22,0.12), transparent 32%),
              radial-gradient(circle at 50% 80%, rgba(124,58,237,0.12), transparent 40%),
              var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 32px 16px 48px;
}

.page {
  width: min(1200px, 100%);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin: 0 auto;
}

.hero {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: linear-gradient(135deg, rgba(17,26,47,0.92), rgba(13,19,35,0.9));
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}

.title-stack h1 {
  margin: 4px 0 0;
  font-size: clamp(32px, 5vw, 48px);
  letter-spacing: -0.02em;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--accent-2);
  font-weight: 600;
  font-size: 12px;
  margin: 0;
}

.lede { margin: 8px 0 0; color: var(--muted); max-width: 720px; }

.score-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  align-items: end;
}

.score-card {
  background: var(--card);
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.06);
  color: var(--muted);
}

.score-card strong { font-size: 24px; color: var(--text); }

.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(249,115,22,0.4);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ghost:hover { background: rgba(249,115,22,0.12); }

.board-wrap {
  position: relative;
  background: var(--panel);
  border-radius: 18px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.04);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.board-meta {
  color: var(--muted);
  margin: 0;
  width: min(92vw, 520px);
}

.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  background: rgba(255,255,255,0.02);
  padding: 10px;
  border-radius: 12px;
  width: min(92vw, 520px);
  aspect-ratio: 1 / 1;
  touch-action: none;
}

.cell {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(18px, 3.2vw, 32px);
  color: #0f172a;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.04);
  transition: transform 120ms ease, background 160ms ease, color 160ms ease;
}

.cell.filled { box-shadow: 0 10px 24px rgba(0,0,0,0.25); }

.cell.spawn { animation: pop-in 180ms ease; }

.cell.v-2 { background: var(--tile-2); }
.cell.v-4 { background: var(--tile-4); }
.cell.v-8 { background: var(--tile-8); color: #0b1222; }
.cell.v-16 { background: var(--tile-16); color: #0b1222; }
.cell.v-32 { background: var(--tile-32); color: #f8fafc; }
.cell.v-64 { background: var(--tile-64); color: #f8fafc; }
.cell.v-128 { background: var(--tile-128); color: #0b1222; }
.cell.v-256 { background: var(--tile-256); color: #0b1222; }
.cell.v-512 { background: var(--tile-512); color: #f8fafc; }
.cell.v-1024 { background: var(--tile-1024); color: #f8fafc; }
.cell.v-2048 { background: var(--tile-2048); color: #f8fafc; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3,7,18,0.75);
  border-radius: 18px;
  backdrop-filter: blur(4px);
}

.overlay.hidden { display: none; }

.overlay-card {
  background: var(--card);
  padding: 20px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  text-align: center;
  box-shadow: 0 16px 36px rgba(0,0,0,0.35);
}

.overlay-card button {
  margin-top: 12px;
  background: var(--accent);
  color: #0b1222;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.controls {
  background: var(--panel);
  border-radius: 18px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.04);
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3,7,18,0.7);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}

.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 16px;
  width: min(420px, 100%);
  box-shadow: 0 16px 36px rgba(0,0,0,0.4);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.modal h2 { margin: 0; color: var(--text); }

.help-list {
  margin: 0 0 12px;
  padding-left: 20px;
  color: var(--text);
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.modal-actions button {
  background: var(--accent);
  color: #0b1222;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.footer {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 0 10px;
}

.footer-inner {
  width: min(1200px, 100%);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 6px;
  color: var(--muted);
  font-size: 13px;
  margin: 0 auto;
}

.control-pad {
  display: grid;
  gap: 8px;
  max-width: 220px;
}

.pad-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pad-spacer { display: block; }

.control-pad button {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 0;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, background 160ms ease;
}

.control-pad button:active { transform: translateY(1px); background: rgba(255,255,255,0.08); }

@media (min-width: 720px) {
  .hero { flex-direction: row; align-items: center; justify-content: space-between; }
  .score-panel { max-width: 360px; }
  .board-wrap { padding: 20px; }
  .grid { width: min(88vw, 520px); }
}

@media (min-width: 1024px) {
  body { padding: 48px 24px 64px; }
  .controls { max-width: 380px; }
  .grid { width: 480px; }
}

@keyframes pop-in {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 540px) {
  body { padding: 16px 10px 28px; }
  .hero { padding: 14px; }
  .board-wrap { padding: 12px; }
  .grid { width: min(94vw, 500px); }
  .footer { margin-top: 12px; }
  .footer-inner { flex-direction: column; align-items: flex-start; gap: 4px; }
}
