:root {
  --bg: #07111f;
  --panel: #0f172a;
  --line: rgba(148, 163, 184, 0.22);
  --text: #e8edf5;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-text: #93c5fd;
  --gold: #fbbf24;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: radial-gradient(ellipse at 50% 0%, #15233a 0%, var(--bg) 70%);
  color: var(--text);
  font-family: "Vazirmatn", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body { min-height: 100vh; min-height: 100dvh; }

.g-wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 12px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.g-mast {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.g-mast h1 { font-size: clamp(1.3rem, 5vw, 1.7rem); font-weight: 800; }
.g-mast p { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

.g-scores { display: flex; gap: 10px; }
.g-score {
  min-width: 64px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
}
.g-score .l { color: var(--muted); font-size: 0.68rem; }
.g-score .v { font-size: 1.05rem; font-weight: 800; color: var(--accent-text); }

.g-bar { display: flex; justify-content: flex-start; }
.g-actions { display: flex; gap: 8px; }

.gb {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.gb:hover { border-color: var(--accent); color: var(--accent-text); }
.gb.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.gb.primary:hover { background: #2f6fe0; color: #fff; }
.gb:disabled { opacity: 0.45; cursor: not-allowed; }

.g-frame { position: relative; }

.g-board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  touch-action: none;
}

.g-cell {
  position: relative;
  background: rgba(148, 163, 184, 0.08);
  border-radius: 10px;
}

.g-tile {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-weight: 800;
  font-size: clamp(1.1rem, 6vw, 1.7rem);
  background: #1c2942;
  color: var(--text);
  animation: pop 0.16s ease;
}
.g-tile.moved { animation: slide-in 0.14s ease; }

@keyframes pop { from { transform: scale(0.6); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }
@keyframes slide-in { from { opacity: 0.55; } to { opacity: 1; } }

.g-tile[data-v="2"]    { background: #233454; }
.g-tile[data-v="4"]    { background: #2b4066; }
.g-tile[data-v="8"]    { background: #2f5d94; }
.g-tile[data-v="16"]   { background: #3b82f6; color: #fff; }
.g-tile[data-v="32"]   { background: #2563eb; color: #fff; }
.g-tile[data-v="64"]   { background: #1d4ed8; color: #fff; }
.g-tile[data-v="128"]  { background: #6366f1; color: #fff; }
.g-tile[data-v="256"]  { background: #7c3aed; color: #fff; }
.g-tile[data-v="512"]  { background: #9333ea; color: #fff; }
.g-tile[data-v="1024"] { background: #b45309; color: #fff; }
.g-tile[data-v="2048"] { background: var(--gold); color: #1a1205; }

.g-overlay {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: rgba(7, 17, 31, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
}
.g-overlay[hidden] { display: none !important; }

.g-over-card { text-align: center; padding: 20px; }
.g-over-card h2 { font-size: 1.3rem; font-weight: 800; margin-bottom: 6px; }
.g-over-card h2.win { color: var(--gold); }
.g-over-card h2.lose { color: #f87171; }
.g-over-card p { color: var(--muted); font-size: 0.85rem; margin-bottom: 14px; }
.g-over-actions { display: flex; gap: 8px; justify-content: center; }

.g-help { color: var(--muted); font-size: 0.78rem; text-align: center; line-height: 1.9; }
