:root {
  --bg: #07111f;
  --bg-2: #0d1c34;
  --panel: rgba(11, 22, 46, 0.88);
  --panel-2: rgba(16, 29, 60, 0.95);
  --line: rgba(120, 160, 255, 0.18);
  --text: #f8fbff;
  --muted: #9fb0d1;
  --blue: #4f46e5;
  --blue-2: #2563eb;
  --purple: #7c3aed;
  --green: #22c55e;
  --gold: #ffd54a;
  --danger: #ef4444;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --radius: 20px;

  --tile-empty: #0b1220;
  --tile-2: #1f2937;
  --tile-4: #243244;
  --tile-8: #f59e0b;
  --tile-16: #f97316;
  --tile-32: #ef4444;
  --tile-64: #dc2626;
  --tile-128: #a78bfa;
  --tile-256: #8b5cf6;
  --tile-512: #6366f1;
  --tile-1024: #22c55e;
  --tile-2048: #16a34a;
  --tile-super: #ffd54a;
}

* {
  box-sizing: border-box;
}

.site-header,
.game-shell,
.site-footer {
  width: min(1280px, calc(100% - 32px));
  margin-inline: auto;
}

@media (max-width: 640px) {
  .site-logo {
    height: 52px;
  }
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 900;
  text-decoration: none;
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
}

.nav-link,
.primary-btn,
.secondary-btn {
  text-decoration: none;
  border-radius: 14px;
  padding: 12px 16px;
  font-weight: 800;
  color: white;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    filter 0.18s ease;
}

.nav-link,
.secondary-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
}

.nav-link:hover,
.primary-btn:hover,
.secondary-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.secondary-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

.stat-card,
.board-panel,
.side-panel .info-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.stat-card {
  padding: 16px;
}

.stat-value.small {
  font-size: 1rem;
  line-height: 1.4;
}

.content-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 18px;
}

.board-panel {
  padding: 18px;
}

.panel-header h2 {
  margin: 0 0 6px;
}

.panel-header p {
  margin: 0;
  color: var(--muted);
}

.board-wrap {
  position: relative;
}

#board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 12px;
  border-radius: 20px;
  background: rgba(6, 14, 35, 0.95);
  border: 1px solid var(--line);
  touch-action: none;
}

.cell {
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: clamp(1.3rem, 4vw, 2rem);
  background: var(--tile-empty);
  color: #e5e7eb;
  user-select: none;
  transition:
    transform 0.1s ease,
    background 0.15s ease,
    color 0.15s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.cell.pop {
  transform: scale(1.07);
}

.tile-0 {
  background: var(--tile-empty);
  color: transparent;
}

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

.side-panel {
  display: grid;
  gap: 18px;
}

.side-panel .info-card {
  padding: 18px;
}

.info-card h3 {
  margin: 0 0 12px;
}

.info-card p,
.info-card li {
  color: var(--muted);
  line-height: 1.65;
}

.info-card ul {
  margin: 0;
  padding-left: 18px;
}

.feedback.success {
  color: var(--green);
}

.feedback.warning {
  color: var(--gold);
}

.feedback.danger {
  color: var(--danger);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 7, 18, 0.55);
  border-radius: 20px;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(360px, calc(100% - 24px));
  border-radius: 20px;
  background: rgba(11, 22, 46, 0.96);
  border: 1px solid var(--line);
  padding: 22px;
  text-align: center;
  box-shadow: var(--shadow);
}

.overlay-card h3 {
  margin: 0 0 10px;
  font-size: 1.8rem;
}

.overlay-card p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.6;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

@media (max-width: 1050px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 560px) {
  body {
    padding: 14px;
  }

  .topbar {
    grid-template-columns: 1fr;
  }
}
