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

:root {
  --board-bg: #3d6b35;
  --board-border: #2a4d24;
  --cell-bg: rgba(255, 255, 255, 0.15);
  --page-bg: #87CEEB;
  --text-dark: #2d5016;
  --text-light: #f9f6f2;
  --btn-bg: #4a7c3f;
  --btn-hover: #5a9a4c;
  --btn-text: #f9f6f2;
  --board-gap: 12px;
  --cell-radius: 8px;
  --tile-radius: 8px;
  --header-height: auto;
  --sky-top: #87CEEB;
  --sky-bottom: #b8e4f0;
  --mountain-far: #5b7e5a;
  --mountain-mid: #3d6b35;
  --mountain-near: #2d5016;
  --ground-color: #6b4c2a;
  --grass-color: #4a8c3a;
  --river-color: #3a9bd5;
}

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text-dark);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background: linear-gradient(180deg, #87CEEB 0%, #a8d8ea 40%, #c8e6c9 70%, #a5d6a7 100%);
  position: relative;
}

/* ═══════════════════════════════════════════
   NATURE BACKGROUND SCENE
   ═══════════════════════════════════════════ */
#nature-scene {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Sky */
#sky {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 55%;
  background: linear-gradient(180deg, #5ba3d9 0%, #87CEEB 30%, #a8d8ea 60%, #d4ecf7 100%);
}

/* Sun */
#sun {
  position: absolute;
  top: 40px;
  right: 12%;
  width: 70px;
  height: 70px;
  background: radial-gradient(circle, #ffe066 0%, #ffb347 50%, transparent 70%);
  border-radius: 50%;
  animation: sun-pulse 4s ease-in-out infinite;
}

#sun::after {
  content: '';
  position: absolute;
  top: -20px;
  left: -20px;
  width: 110px;
  height: 110px;
  background: radial-gradient(circle, rgba(255, 224, 102, 0.3) 0%, transparent 60%);
  border-radius: 50%;
  animation: sun-rays 3s ease-in-out infinite;
}

@keyframes sun-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.9; }
}

@keyframes sun-rays {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 0.3; }
}

/* Clouds */
.cloud {
  position: absolute;
  background: #fff;
  border-radius: 50px;
  opacity: 0.85;
}

.cloud::before, .cloud::after {
  content: '';
  position: absolute;
  background: #fff;
  border-radius: 50%;
}

.cloud-1 {
  width: 120px;
  height: 36px;
  top: 60px;
  left: -150px;
  animation: cloud-drift 25s linear infinite;
}

.cloud-1::before {
  width: 50px;
  height: 50px;
  top: -20px;
  left: 20px;
}

.cloud-1::after {
  width: 40px;
  height: 40px;
  top: -15px;
  left: 60px;
}

.cloud-2 {
  width: 160px;
  height: 40px;
  top: 100px;
  left: -200px;
  animation: cloud-drift 35s linear infinite;
  animation-delay: -12s;
  opacity: 0.7;
}

.cloud-2::before {
  width: 60px;
  height: 60px;
  top: -25px;
  left: 30px;
}

.cloud-2::after {
  width: 45px;
  height: 45px;
  top: -18px;
  left: 85px;
}

.cloud-3 {
  width: 100px;
  height: 30px;
  top: 140px;
  left: -130px;
  animation: cloud-drift 30s linear infinite;
  animation-delay: -20s;
  opacity: 0.6;
}

.cloud-3::before {
  width: 40px;
  height: 40px;
  top: -18px;
  left: 15px;
}

.cloud-3::after {
  width: 35px;
  height: 35px;
  top: -12px;
  left: 50px;
}

@keyframes cloud-drift {
  0% { transform: translateX(0); }
  100% { transform: translateX(calc(100vw + 300px)); }
}

/* Birds */
#birds {
  position: absolute;
  top: 50px;
  left: 15%;
}

.bird {
  position: absolute;
  font-size: 1.1rem;
  animation: bird-fly 12s linear infinite;
}

.b1 { top: 0; left: 0; animation-delay: 0s; }
.b2 { top: -15px; left: 30px; animation-delay: -4s; font-size: 0.8rem; }
.b3 { top: 10px; left: 55px; animation-delay: -8s; font-size: 0.9rem; }

@keyframes bird-fly {
  0% { transform: translate(0, 0) scaleX(1); }
  25% { transform: translate(40px, -8px) scaleX(1); }
  50% { transform: translate(80px, 0) scaleX(1); }
  75% { transform: translate(120px, -5px) scaleX(1); }
  100% { transform: translate(160px, 0) scaleX(1); }
}

/* Mountains */
#mountains {
  position: absolute;
  bottom: 45%;
  left: 0;
  width: 100%;
  height: 25%;
}

.mountain {
  position: absolute;
  bottom: 0;
  width: 0;
  height: 0;
  border-style: solid;
}

.mountain-far {
  border-width: 0 200px 140px 200px;
  border-color: transparent transparent #6b9e6a transparent;
  left: -5%;
  opacity: 0.6;
}

.mountain-mid {
  border-width: 0 160px 120px 160px;
  border-color: transparent transparent #4a8049 transparent;
  left: 30%;
  opacity: 0.7;
}

.mountain-near {
  border-width: 0 180px 100px 180px;
  border-color: transparent transparent #3d6b35 transparent;
  left: 55%;
  opacity: 0.8;
}

/* Tree line */
#treeline {
  position: absolute;
  bottom: 38%;
  left: 0;
  width: 100%;
  height: 60px;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  padding: 0 5%;
}

.tree {
  font-size: 2.8rem;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2));
}

.tree.t1 { font-size: 3.2rem; }
.tree.t2 { font-size: 2.5rem; }
.tree.t3 { font-size: 3rem; }
.tree.t4 { font-size: 2.8rem; }
.tree.t5 { font-size: 3.1rem; }
.tree.t6 { font-size: 2.4rem; }
.tree.t7 { font-size: 2.9rem; }

/* Ground */
#ground {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 38%;
  background: linear-gradient(180deg, #5a9e3e 0%, #4a8a32 15%, #6b4c2a 40%, #5a3d1e 100%);
}

/* River */
#river {
  position: absolute;
  bottom: 28%;
  left: 0;
  width: 100%;
  height: 18px;
  background: linear-gradient(180deg, #5bb8f0 0%, #3a9bd5 50%, #2d8ac4 100%);
  opacity: 0.7;
  overflow: hidden;
}

.water-shimmer {
  position: absolute;
  width: 40px;
  height: 6px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 3px;
  animation: water-flow 3s linear infinite;
}

.s1 { top: 3px; left: -40px; animation-delay: 0s; }
.s2 { top: 8px; left: -40px; animation-delay: -1s; }
.s3 { top: 5px; left: -40px; animation-delay: -2s; }

@keyframes water-flow {
  0% { transform: translateX(0); opacity: 0; }
  10% { opacity: 0.6; }
  90% { opacity: 0.6; }
  100% { transform: translateX(calc(100vw + 80px)); opacity: 0; }
}

/* Flowers */
#flowers {
  position: absolute;
  bottom: 10%;
  left: 0;
  width: 100%;
  height: 40px;
}

.flower {
  position: absolute;
  font-size: 1.2rem;
  animation: flower-sway 3s ease-in-out infinite;
}

.f1 { left: 5%; animation-delay: 0s; }
.f2 { left: 18%; animation-delay: -0.5s; font-size: 1rem; }
.f3 { left: 35%; animation-delay: -1s; }
.f4 { left: 55%; animation-delay: -1.5s; font-size: 1.4rem; }
.f5 { left: 75%; animation-delay: -2s; }
.f6 { left: 90%; animation-delay: -2.5s; font-size: 1rem; }

@keyframes flower-sway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

/* ═══════════════════════════════════════════
   GAME CONTAINER
   ═══════════════════════════════════════════ */
#game-container {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 12px 8px;
  gap: 10px;
  position: relative;
  z-index: 10;
}

/* ─── HEADER ─── */
#game-header {
  width: 100%;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

#game-title {
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--text-dark);
  line-height: 1;
  letter-spacing: -1px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

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

.score-box {
  background: var(--board-bg);
  border: 2px solid var(--board-border);
  border-radius: 8px;
  padding: 6px 16px;
  text-align: center;
  min-width: 72px;
  position: relative;
}

.score-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #a5d6a7;
}

.score-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 800;
  color: #fff;
  line-height: 1.2;
  transition: transform 0.15s ease;
}

.score-value.bump {
  animation: score-bump 0.3s ease;
}

@keyframes score-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.new-best {
  display: none;
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ff6b6b;
  color: #fff;
  font-size: 0.5rem;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  animation: pulse-badge 0.8s ease-in-out infinite;
}

.new-best.visible {
  display: block;
}

@keyframes pulse-badge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.header-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tagline {
  font-size: 0.8rem;
  color: var(--text-dark);
  opacity: 0.8;
}

.header-buttons {
  display: flex;
  gap: 6px;
}

/* ─── BUTTONS ─── */
.btn {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--btn-hover);
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: #4a7c3f;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.75rem;
}

/* ─── BOARD ─── */
#game-main {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#board-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
}

#board {
  position: relative;
  background: var(--board-bg);
  border: 3px solid var(--board-border);
  border-radius: 12px;
  padding: var(--board-gap);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  aspect-ratio: 1 / 1;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
}

.grid-bg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--board-gap);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  padding: var(--board-gap);
}

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

#tile-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: var(--board-gap);
  pointer-events: none;
}

/* ─── TILES ─── */
.tile {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 800;
  border-radius: var(--tile-radius);
  transition: top 0.12s ease, left 0.12s ease;
  will-change: top, left, transform;
  z-index: 10;
}

.tile.merged {
  z-index: 20;
}

/* Tile value styles — Jungle Nature Palette */
.tile-2 {
  background: linear-gradient(135deg, #c8e6c9, #a5d6a7);
  color: #2d5016;
  font-size: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.tile-4 {
  background: linear-gradient(135deg, #a5d6a7, #81c784);
  color: #1b5e20;
  font-size: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.tile-8 {
  background: linear-gradient(135deg, #8d6e63, #795548);
  color: var(--text-light);
  font-size: 2rem;
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
}

.tile-16 {
  background: linear-gradient(135deg, #ff9800, #f57c00);
  color: var(--text-light);
  font-size: 1.8rem;
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
}

.tile-32 {
  background: linear-gradient(135deg, #e53935, #c62828);
  color: var(--text-light);
  font-size: 1.8rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

.tile-64 {
  background: linear-gradient(135deg, #d81b60, #ad1457);
  color: var(--text-light);
  font-size: 1.8rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

.tile-128 {
  background: linear-gradient(135deg, #fdd835, #fbc02d);
  color: #5d4037;
  font-size: 1.5rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18), 0 0 14px rgba(253, 216, 53, 0.4);
}

.tile-256 {
  background: linear-gradient(135deg, #ffca28, #ffb300);
  color: #4e342e;
  font-size: 1.5rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18), 0 0 18px rgba(255, 202, 40, 0.45);
}

.tile-512 {
  background: linear-gradient(135deg, #ff8f00, #ff6f00);
  color: var(--text-light);
  font-size: 1.5rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 0 22px rgba(255, 143, 0, 0.45);
}

.tile-1024 {
  background: linear-gradient(135deg, #4caf50, #388e3c);
  color: var(--text-light);
  font-size: 1.2rem;
  box-shadow: 0 5px 18px rgba(0,0,0,0.22), 0 0 30px rgba(76, 175, 80, 0.5);
}

.tile-2048 {
  background: linear-gradient(135deg, #2e7d32, #1b5e20);
  color: #fdd835;
  font-size: 1.2rem;
  box-shadow: 0 5px 22px rgba(0,0,0,0.28), 0 0 45px rgba(46, 125, 50, 0.6);
  animation: tile-2048-glow 2s ease-in-out infinite;
}

@keyframes tile-2048-glow {
  0%, 100% { box-shadow: 0 5px 22px rgba(0,0,0,0.28), 0 0 45px rgba(46, 125, 50, 0.6); }
  50% { box-shadow: 0 5px 28px rgba(0,0,0,0.35), 0 0 65px rgba(46, 125, 50, 0.85); }
}

.tile-super {
  background: linear-gradient(135deg, #7b1fa2, #4a148c);
  color: #fdd835;
  font-size: 1rem;
  box-shadow: 0 5px 22px rgba(0,0,0,0.35), 0 0 50px rgba(123, 31, 162, 0.5);
  animation: tile-super-glow 1.5s ease-in-out infinite;
}

@keyframes tile-super-glow {
  0%, 100% { box-shadow: 0 5px 22px rgba(0,0,0,0.35), 0 0 50px rgba(123, 31, 162, 0.5); }
  50% { box-shadow: 0 5px 30px rgba(0,0,0,0.45), 0 0 70px rgba(123, 31, 162, 0.8); }
}

/* ─── TILE ANIMATIONS ─── */
@keyframes tile-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes tile-spawn {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.tile.pop {
  animation: tile-pop 0.2s ease-in-out;
  z-index: 30;
}

.tile.spawn {
  animation: tile-spawn 0.15s ease-out;
}

/* ─── GAME ACTIONS ─── */
#game-actions {
  display: flex;
  gap: 8px;
}

/* ─── MOBILE CONTROLS ─── */
#mobile-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.ctrl-row {
  display: flex;
  gap: 4px;
}

.ctrl-btn {
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 12px;
  background: var(--board-bg);
  border: 2px solid var(--board-border);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.ctrl-btn:active {
  background: #2a4d24;
  transform: scale(0.92);
}

/* ─── OVERLAYS ─── */
.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(45, 80, 22, 0.7);
  z-index: 100;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  padding: 20px;
}

.overlay.active {
  display: flex;
}

.overlay-content {
  background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  border: 2px solid var(--board-border);
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  animation: modal-in 0.25s ease-out;
}

@keyframes modal-in {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.overlay-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.overlay-title {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--text-dark);
  margin-bottom: 8px;
}

.overlay-score {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.overlay-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ─── HOW TO PLAY MODAL ─── */
.modal {
  background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  border: 2px solid var(--board-border);
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 440px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  animation: modal-in 0.25s ease-out;
}

.modal-title {
  font-size: 1.6rem;
  font-weight: 900;
  text-align: center;
  margin-bottom: 16px;
  color: var(--text-dark);
}

.howto-section {
  margin-bottom: 14px;
}

.howto-section h3 {
  font-size: 0.95rem;
  font-weight: 800;
  margin-bottom: 4px;
  color: var(--text-dark);
}

.howto-section p {
  font-size: 0.85rem;
  line-height: 1.5;
  color: #33691e;
}

kbd {
  background: var(--board-bg);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: inherit;
}

.merge-example {
  background: var(--board-bg);
  color: #fff;
  padding: 4px 12px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.85rem;
  margin: 3px 0;
  display: inline-block;
  margin-right: 4px;
}

/* ─── MAIN MENU ─── */
.main-menu {
  background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
  border: 3px solid var(--board-border);
  border-radius: 20px;
  padding: 48px 40px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 10px 50px rgba(0,0,0,0.35);
  animation: modal-in 0.3s ease-out;
}

.menu-logo {
  font-size: 4.5rem;
  font-weight: 900;
  color: var(--text-dark);
  line-height: 1;
  margin-bottom: 6px;
  letter-spacing: -2px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.menu-tagline {
  font-size: 1rem;
  color: var(--text-dark);
  opacity: 0.7;
  margin-bottom: 36px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.btn-menu {
  width: 220px;
  padding: 14px 24px;
  font-size: 1.05rem;
  font-weight: 800;
  border-radius: 12px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: 2px solid var(--board-border);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-menu:hover {
  background: var(--btn-hover);
}

.btn-menu:active {
  transform: scale(0.96);
}

.modal .btn {
  display: block;
  margin: 16px auto 0;
  min-width: 140px;
}

/* ─── CONFETTI CANVAS ─── */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 200;
}

/* ═══════════════════════════════════════════
   RESPONSIVE — LANDSCAPE DESKTOP
   ═══════════════════════════════════════════ */
@media (min-width: 769px) and (min-height: 500px) {
  body {
    align-items: center;
  }

  #game-container {
    max-width: 900px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 30px;
    padding: 20px 30px;
  }

  #game-header {
    width: 220px;
    flex-shrink: 0;
  }

  #game-title {
    font-size: 3.2rem;
  }

  .scores {
    flex-direction: column;
    gap: 8px;
  }

  .score-box {
    min-width: 100px;
    padding: 8px 18px;
  }

  .score-value {
    font-size: 1.4rem;
  }

  #game-main {
    width: auto;
  }

  #board-wrapper {
    width: 460px;
  }

  #game-actions {
    margin-top: 8px;
  }

  #mobile-controls {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════
   RESPONSIVE — LARGE DESKTOP / 4K
   ═══════════════════════════════════════════ */
@media (min-width: 1400px) {
  #board-wrapper {
    width: 560px;
  }

  :root {
    --board-gap: 14px;
  }

  .tile-2, .tile-4, .tile-8 { font-size: 2.4rem; }
  .tile-16, .tile-32, .tile-64 { font-size: 2.2rem; }
  .tile-128, .tile-256, .tile-512 { font-size: 1.8rem; }
  .tile-1024, .tile-2048 { font-size: 1.5rem; }
  .tile-super { font-size: 1.2rem; }
}

/* ═══════════════════════════════════════════
   RESPONSIVE — TABLETS
   ═══════════════════════════════════════════ */
@media (max-width: 768px) and (min-width: 501px) {
  #board-wrapper {
    width: 420px;
  }

  :root {
    --board-gap: 10px;
  }

  #game-title {
    font-size: 2.4rem;
  }

  #mobile-controls {
    display: flex;
  }

  .ctrl-btn {
    width: 56px;
    height: 56px;
  }
}

/* ═══════════════════════════════════════════
   RESPONSIVE — MOBILE PORTRAIT
   ═══════════════════════════════════════════ */
@media (max-width: 500px) {
  body {
    align-items: flex-start;
  }

  #game-container {
    max-width: 100%;
    padding: 10px 10px 6px;
    gap: 8px;
  }

  #game-header {
    width: 100%;
  }

  #game-title {
    font-size: 2rem;
  }

  .scores {
    gap: 6px;
  }

  .score-box {
    min-width: 60px;
    padding: 4px 10px;
  }

  .score-label {
    font-size: 0.55rem;
  }

  .score-value {
    font-size: 1rem;
  }

  #board-wrapper {
    width: 100%;
    max-width: 360px;
  }

  :root {
    --board-gap: 8px;
  }

  .tile-2, .tile-4 { font-size: 1.6rem; }
  .tile-8 { font-size: 1.6rem; }
  .tile-16, .tile-32, .tile-64 { font-size: 1.4rem; }
  .tile-128, .tile-256, .tile-512 { font-size: 1.15rem; }
  .tile-1024, .tile-2048 { font-size: 0.95rem; }
  .tile-super { font-size: 0.78rem; }

  #mobile-controls {
    display: flex;
  }

  .ctrl-btn {
    width: 54px;
    height: 54px;
    font-size: 1.2rem;
  }

  .tagline {
    display: none;
  }
}

/* ═══════════════════════════════════════════
   RESPONSIVE — VERY SMALL SCREENS
   ═══════════════════════════════════════════ */
@media (max-width: 360px) {
  :root {
    --board-gap: 6px;
  }

  #game-title {
    font-size: 1.6rem;
  }

  .score-box {
    min-width: 52px;
    padding: 3px 8px;
  }

  .score-value {
    font-size: 0.9rem;
  }

  .tile-2, .tile-4 { font-size: 1.3rem; }
  .tile-8 { font-size: 1.3rem; }
  .tile-16, .tile-32, .tile-64 { font-size: 1.1rem; }
  .tile-128, .tile-256, .tile-512 { font-size: 0.9rem; }
  .tile-1024, .tile-2048 { font-size: 0.75rem; }
  .tile-super { font-size: 0.62rem; }

  .ctrl-btn {
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
  }

  .btn {
    padding: 6px 12px;
    font-size: 0.75rem;
  }

  .btn-sm {
    padding: 4px 8px;
    font-size: 0.65rem;
  }
}

/* ═══════════════════════════════════════════
   LANDSCAPE MOBILE
   ═══════════════════════════════════════════ */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    align-items: center;
  }

  #game-container {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 16px;
    padding: 8px 16px;
    max-width: 100%;
  }

  #game-header {
    width: 160px;
    flex-shrink: 0;
  }

  #game-title {
    font-size: 1.8rem;
  }

  .scores {
    flex-direction: column;
    gap: 4px;
  }

  .score-box {
    padding: 3px 10px;
  }

  #board-wrapper {
    width: min(55vh, 320px);
  }

  :root {
    --board-gap: 6px;
  }

  .tile-2, .tile-4 { font-size: 1.2rem; }
  .tile-8 { font-size: 1.2rem; }
  .tile-16, .tile-32, .tile-64 { font-size: 1rem; }
  .tile-128, .tile-256, .tile-512 { font-size: 0.85rem; }
  .tile-1024, .tile-2048 { font-size: 0.7rem; }

  #mobile-controls {
    display: none !important;
  }

  #game-actions {
    flex-direction: column;
    gap: 4px;
  }
}
