/* Mergora — neon glassmorphism 2048 */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg1: #0d0620;
  --bg2: #1a0a3e;
  --bg3: #2a1058;
  --glass: rgba(255,255,255,0.08);
  --glass-border: rgba(255,255,255,0.22);
  --text: #ffffff;
  --muted: rgba(255,255,255,0.65);
  --board: rgba(12, 8, 32, 0.55);
  --cell: rgba(30, 20, 55, 0.65);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --gap: 10px;
  --radius: 16px;
  --tile-radius: 14px;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg1);
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: linear-gradient(180deg, #12082c 0%, #1a0a3e 40%, #2b1260 100%);
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100%;
  min-height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-t)) 16px calc(12px + var(--safe-b));
  gap: 14px;
  z-index: 1;
}

/* Particles */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.particle {
  position: absolute;
  border-radius: 50%;
  filter: blur(1px);
  opacity: 0.55;
  animation: float linear infinite;
}
.particle.star {
  background: transparent;
  filter: none;
  font-size: 10px;
  line-height: 1;
  color: #ff9ed8;
  text-shadow: 0 0 8px #ff6ec7;
  animation-name: twinkle;
}
@keyframes float {
  0% { transform: translateY(0) scale(1); opacity: 0.3; }
  50% { opacity: 0.7; }
  100% { transform: translateY(-40px) scale(1.15); opacity: 0.2; }
}
@keyframes twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.8) rotate(0deg); }
  50% { opacity: 0.9; transform: scale(1.2) rotate(20deg); }
}

/* Header / Title */
.header {
  width: 100%;
  text-align: center;
  flex-shrink: 0;
}
.title {
  position: relative;
  display: inline-block;
  margin: 4px 0 14px;
  line-height: 1;
}
.title-merge {
  display: block;
  font-size: clamp(2.4rem, 10vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ff6ec7 0%, #a78bfa 45%, #22d3ee 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(255,110,199,0.45)) drop-shadow(0 4px 12px rgba(0,0,0,0.4));
}
.star {
  position: absolute;
  top: 50%;
  font-size: 1.1rem;
  background: linear-gradient(135deg, #ff6ec7, #22d3ee);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 6px #ff6ec7);
}
.star-l { left: -1.4rem; transform: translateY(-50%); }
.star-r { right: -1.4rem; transform: translateY(-50%); }

.score-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  width: 100%;
}
.score-panel {
  flex: 1;
  background: linear-gradient(180deg, rgba(40,25,80,0.85), rgba(20,12,45,0.9));
  border: 1.5px solid rgba(255,255,255,0.18);
  border-radius: 14px;
  padding: 8px 12px 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.12);
  text-align: left;
}
.score-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 2px;
}
.score-value {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.coin {
  font-size: 1.05rem;
  filter: drop-shadow(0 0 4px #fbbf24);
}
.btn-pause {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  align-self: center;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #7c3aed, #4c1d95);
  box-shadow: 0 0 0 2px rgba(167,139,250,0.45), 0 0 20px rgba(124,58,237,0.55), inset 0 2px 4px rgba(255,255,255,0.25);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.btn-pause:active { transform: scale(0.94); }
.pause-icon {
  display: block;
  width: 14px;
  height: 16px;
  background:
    linear-gradient(#fff,#fff) left / 4px 100% no-repeat,
    linear-gradient(#fff,#fff) right / 4px 100% no-repeat;
  border-radius: 1px;
}

/* Board */
.board-wrap {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  padding: 4px 0 8px;
  margin-top: 4px;
}
.board-glass {
  width: min(100%, 100%);
  aspect-ratio: 1;
  padding: 12px;
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(255,255,255,0.16), rgba(255,255,255,0.04));
  border: 2px solid rgba(255,255,255,0.28);
  box-shadow:
    0 0 0 1px rgba(100,180,255,0.15),
    0 20px 50px rgba(0,0,0,0.45),
    inset 0 1px 0 rgba(255,255,255,0.35),
    inset 0 -1px 0 rgba(0,0,0,0.2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.board {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
  background: var(--board);
  border-radius: 20px;
  padding: var(--gap);
}
.cell {
  background: var(--cell);
  border-radius: var(--tile-radius);
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.35);
}
.tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--tile-radius);
  font-weight: 800;
  color: #fff;
  z-index: 2;
  transition: transform 120ms ease-out, left 120ms ease-out, top 120ms ease-out;
  will-change: transform, left, top;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
  box-shadow:
    0 6px 16px rgba(0,0,0,0.35),
    inset 0 2px 4px rgba(255,255,255,0.45),
    inset 0 -3px 6px rgba(0,0,0,0.2);
}
.tile.spawn { animation: spawn 180ms ease-out; }
.tile.merge { animation: pop 200ms ease-out; }
.tile.hammer-target { outline: 2px dashed #fff; outline-offset: 2px; cursor: pointer; animation: pulse 0.8s ease infinite; }
@keyframes spawn {
  0% { transform: scale(0); opacity: 0; }
  80% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}
@keyframes pulse {
  0%,100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}

/* Tile colors */
.tile.v2   { background: linear-gradient(145deg, #ff8ec8, #ff4fa0); box-shadow: 0 0 18px rgba(255,79,160,0.45), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.45); }
.tile.v4   { background: linear-gradient(145deg, #c084fc, #7c3aed); box-shadow: 0 0 18px rgba(124,58,237,0.5), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.4); }
.tile.v8   { background: linear-gradient(145deg, #fbbf24, #f59e0b); box-shadow: 0 0 18px rgba(245,158,11,0.5), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.45); }
.tile.v16  { background: linear-gradient(145deg, #67e8f9, #06b6d4); box-shadow: 0 0 18px rgba(6,182,212,0.5), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.45); }
.tile.v32  { background: linear-gradient(145deg, #86efac, #22c55e); box-shadow: 0 0 18px rgba(34,197,94,0.5), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.4); }
.tile.v64  { background: linear-gradient(145deg, #f472b6, #db2777); box-shadow: 0 0 20px rgba(219,39,119,0.55), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.4); }
.tile.v128 { background: linear-gradient(145deg, #60a5fa, #2563eb); box-shadow: 0 0 22px rgba(37,99,235,0.55), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.4); font-size: 0.9em; }
.tile.v256 { background: linear-gradient(145deg, #fb923c, #ea580c); box-shadow: 0 0 22px rgba(234,88,12,0.55), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.4); font-size: 0.9em; }
.tile.v512 { background: linear-gradient(145deg, #a3e635, #65a30d); box-shadow: 0 0 22px rgba(101,163,13,0.55), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.4); font-size: 0.9em; }
.tile.v1024 { background: linear-gradient(145deg, #e879f9, #c026d3); box-shadow: 0 0 24px rgba(192,38,211,0.6), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.4); font-size: 0.78em; }
.tile.v2048 { background: linear-gradient(145deg, #fde68a, #f59e0b 40%, #ef4444); box-shadow: 0 0 28px rgba(245,158,11,0.7), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.5); font-size: 0.78em; }
.tile.v4096, .tile.v8192, .tile.v16384, .tile.v32768, .tile.v65536 {
  background: linear-gradient(145deg, #f0abfc, #86198f);
  box-shadow: 0 0 28px rgba(134,25,143,0.65), 0 6px 16px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.4);
  font-size: 0.7em;
}

/* Power-ups */
.powerups {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  width: 100%;
  gap: 8px;
  padding-top: 8px;
  margin-top: auto;
  flex-shrink: 0;
}
.power-btn {
  flex: 1;
  max-width: 110px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: #fff;
  padding: 0;
}
.power-btn:disabled { opacity: 0.4; pointer-events: none; }
.power-btn:active:not(:disabled) .power-orb { transform: scale(0.92); }
.power-btn.active .power-orb {
  box-shadow: 0 0 0 3px #fff, 0 0 28px rgba(255,255,255,0.5);
}
.power-orb {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  transition: transform 100ms ease;
}
.power-orb::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.35), transparent 45%);
  pointer-events: none;
}
.power-orb.purple {
  background: radial-gradient(circle at 35% 30%, #a78bfa, #6d28d9 55%, #4c1d95);
  box-shadow: 0 0 0 3px rgba(167,139,250,0.4), 0 8px 20px rgba(109,40,217,0.55), 0 0 24px rgba(139,92,246,0.4);
}
.power-orb.green {
  background: radial-gradient(circle at 35% 30%, #86efac, #16a34a 55%, #14532d);
  box-shadow: 0 0 0 3px rgba(134,239,172,0.4), 0 8px 20px rgba(22,163,74,0.55), 0 0 24px rgba(34,197,94,0.4);
}
.power-orb.orange {
  background: radial-gradient(circle at 35% 30%, #fdba74, #ea580c 55%, #7c2d12);
  box-shadow: 0 0 0 3px rgba(253,186,116,0.4), 0 8px 20px rgba(234,88,12,0.55), 0 0 24px rgba(249,115,22,0.4);
}
.power-icon { width: 32px; height: 32px; }
.power-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.power-count {
  font-size: 0.7rem;
  font-weight: 700;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 999px;
  padding: 2px 10px;
  min-width: 36px;
}

.credit {
  margin-top: 8px;
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8,4,24,0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 24px;
}
.overlay.hidden { display: none; }
.overlay-card {
  width: min(100%, 320px);
  background: linear-gradient(160deg, rgba(50,30,100,0.95), rgba(20,10,45,0.98));
  border: 1.5px solid rgba(255,255,255,0.22);
  border-radius: 24px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.15);
}
.overlay-card.win h2 {
  background: linear-gradient(90deg, #fde68a, #f472b6, #67e8f9);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay-card h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 10px;
}
.overlay-score {
  color: var(--muted);
  margin-bottom: 18px;
  font-size: 1.05rem;
}
.overlay-score strong { color: #fff; }
.about-text {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 18px;
  font-size: 0.95rem;
}
.overlay-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 14px 16px;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.05));
  border: 1px solid rgba(255,255,255,0.18);
}
.overlay-btn.primary {
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(124,58,237,0.4);
}
.overlay-btn.share {
  background: linear-gradient(135deg, #22d3ee, #0891b2);
  border-color: transparent;
}
.overlay-btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-weight: 600;
}
.overlay-btn:active { transform: scale(0.98); }

.hammer-hint {
  position: fixed;
  bottom: calc(110px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
}
.hammer-hint.hidden { display: none; }

@media (max-height: 700px) {
  .title-merge { font-size: 2.1rem; }
  .power-orb { width: 54px; height: 54px; }
  .board-wrap { padding: 6px 0; }
}
