:root {
  --bg-1: #1b2033;
  --bg-2: #0f1220;
  --panel: rgba(255, 255, 255, 0.06);
  --board-bg: #2b3350;
  --cell-bg: rgba(255, 255, 255, 0.05);
  --text: #eef1f8;
  --text-dim: #9aa3c0;
  --accent: #ff8a3d;
  --accent-2: #ff5d8f;
  --ok: #35d29a;
  --gap: 12px;
  --radius: 16px;
  --cell-radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 15% 0%, #262d4a 0%, transparent 55%),
              radial-gradient(900px 700px at 100% 100%, #3a2350 0%, transparent 50%),
              linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  display: flex;
  justify-content: center;
  padding: 24px 16px 48px;
}

.app {
  width: 100%;
  max-width: 540px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(40px, 12vw, 60px);
  font-weight: 800;
  letter-spacing: -2px;
  line-height: 1;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 18px rgba(255, 93, 143, 0.25));
}

.subtitle {
  margin: 6px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}

.scores {
  display: flex;
  gap: 10px;
}

.score-box {
  min-width: 88px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  backdrop-filter: blur(8px);
}

.score-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.score-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: transform 0.15s ease, color 0.15s ease;
}

.score-value.bump {
  transform: scale(1.18);
  color: var(--accent);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.difficulty {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}

.diff-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

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

.diff-btn.active {
  color: #1b1226;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px rgba(255, 93, 143, 0.35);
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-btn {
  border: 0;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  color: #1b1226;
  padding: 11px 20px;
  border-radius: 12px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px rgba(255, 93, 143, 0.3);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}

.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(255, 93, 143, 0.42); }
.primary-btn:active { transform: translateY(1px) scale(0.98); }

.ghost-btn {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 12px;
  transition: background 0.2s ease;
}

.ghost-btn:hover { background: rgba(255, 255, 255, 0.1); }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.2s ease;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.12); }

.icon-btn .sound-icon {
  filter: grayscale(1) opacity(0.45);
  transition: filter 0.2s ease;
}

.icon-btn .sound-icon.on { filter: none; }

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: var(--gap);
  border-radius: var(--radius);
  background: var(--board-bg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  touch-action: none;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
}

.cell {
  position: absolute;
  border-radius: var(--cell-radius);
  background: var(--cell-bg);
}

.tile {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: var(--cell-radius);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #4a3b2a;
  will-change: transform;
  transition: transform 0.12s ease;
  user-select: none;
}

.tile.spawn { animation: pop 0.18s ease; }
.tile.merge { animation: merge 0.22s ease; }

@keyframes pop {
  0% { transform: scale(0.1); opacity: 0.2; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes merge {
  0% { transform: scale(1); }
  45% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

.overlay {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: rgba(12, 15, 28, 0.72);
  backdrop-filter: blur(6px);
  z-index: 20;
  animation: fade 0.25s ease;
}

.overlay.hidden { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  text-align: center;
  padding: 26px 30px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  animation: rise 0.28s ease;
}

@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.overlay-card h2 {
  margin: 0 0 6px;
  font-size: 28px;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-card p { margin: 0 0 18px; color: var(--text-dim); }

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

.hint {
  margin: 16px 2px 0;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.6;
  text-align: center;
}

@media (max-width: 460px) {
  .topbar { flex-direction: column; }
  .scores { width: 100%; }
  .score-box { flex: 1; }
  .diff-btn { padding: 8px 10px; font-size: 12px; }
}
