/* 2048 — мобильная вёрстка */

:root {
  --bg: #faf8ef;
  --grid-bg: #bbada0;
  --cell-bg: #cdc1b4;
  --text-dark: #776e65;
  --text-light: #f9f6f2;
  --tile-2: #eee4da;
  --tile-4: #ede0c8;
  --tile-8: #f2b179;
  --tile-16: #f59563;
  --tile-32: #f67c5f;
  --tile-64: #f65e3b;
  --tile-128: #edcf72;
  --tile-256: #edcc61;
  --tile-512: #edc850;
  --tile-1024: #edc53f;
  --tile-2048: #edc22e;
  --tile-super: #3c3a32;
  --radius: 6px;
  --gap: 4px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-dark);
  font-family: var(--font);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  max-width: 100vw;
  min-height: 100vh;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.screen {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.screen-hidden {
  display: none !important;
}

.header {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.header-buttons {
  width: 100%;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.header-buttons .btn-new,
.header-buttons .btn-leaderboard {
  flex: 1;
  min-width: 0;
  max-width: none;
}

.title {
  font-size: 1.75rem;
  font-weight: bold;
  margin: 0;
  color: var(--text-dark);
}

.scores {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.score-box {
  background: var(--grid-bg);
  color: var(--text-light);
  padding: 6px 12px;
  border-radius: var(--radius);
  text-align: center;
  min-width: 60px;
}

.score-label {
  display: block;
  font-size: 0.7rem;
  opacity: 0.9;
}

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

.btn-new {
  width: 100%;
  max-width: 140px;
  padding: 10px 16px;
  background: #8f7a66;
  color: var(--text-light);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
}

.btn-new:active,
.btn-leaderboard:active {
  opacity: 0.9;
}

.btn-leaderboard {
  padding: 10px 16px;
  background: #8f7a66;
  color: var(--text-light);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
}

.swipe-zone {
  width: 100%;
  max-width: 360px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 200px;
  touch-action: none;
}

.game-container {
  width: 100%;
  max-width: 360px;
  margin-bottom: 0;
}

.grid {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: min(calc(100vw - 24px), 360px);
  background: var(--grid-bg);
  border-radius: var(--radius);
  padding: var(--gap);
  touch-action: none;
}

.board {
  position: absolute;
  inset: var(--gap);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
  border-radius: calc(var(--radius) - 2px);
}

.cell {
  background: var(--cell-bg);
  border-radius: 4px;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  border-radius: 4px;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.tile-new {
  animation: tileAppear 0.2s ease forwards;
}

@keyframes tileAppear {
  from {
    transform: scale(0);
    opacity: 0.6;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.tile-merge {
  animation: tileMerge 0.2s ease forwards;
}

@keyframes tileMerge {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
  }
}

.tile-moved {
  animation: tileMoved 0.2s ease forwards;
}

@keyframes tileMoved {
  from {
    opacity: 0.6;
  }
  to {
    opacity: 1;
  }
}

.tile-2 { background: var(--tile-2); color: var(--text-dark); font-size: clamp(1.5rem, 6vw, 2.5rem); }
.tile-4 { background: var(--tile-4); color: var(--text-dark); font-size: clamp(1.5rem, 6vw, 2.5rem); }
.tile-8 { background: var(--tile-8); color: var(--text-light); font-size: clamp(1.5rem, 6vw, 2.5rem); }
.tile-16 { background: var(--tile-16); color: var(--text-light); font-size: clamp(1.4rem, 5.5vw, 2.2rem); }
.tile-32 { background: var(--tile-32); color: var(--text-light); font-size: clamp(1.4rem, 5.5vw, 2.2rem); }
.tile-64 { background: var(--tile-64); color: var(--text-light); font-size: clamp(1.4rem, 5.5vw, 2.2rem); }
.tile-128 { background: var(--tile-128); color: var(--text-light); font-size: clamp(1.2rem, 5vw, 2rem); }
.tile-256 { background: var(--tile-256); color: var(--text-light); font-size: clamp(1.2rem, 5vw, 2rem); }
.tile-512 { background: var(--tile-512); color: var(--text-light); font-size: clamp(1.2rem, 5vw, 2rem); }
.tile-1024 { background: var(--tile-1024); color: var(--text-light); font-size: clamp(1rem, 4vw, 1.6rem); }
.tile-2048 { background: var(--tile-2048); color: var(--text-light); font-size: clamp(1rem, 4vw, 1.6rem); }
.tile-super { background: var(--tile-super); color: var(--text-light); font-size: clamp(0.9rem, 3.5vw, 1.4rem); }

.screen-leaderboard {
  padding: 0 12px;
}

.header-leaderboard {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.btn-back {
  padding: 8px 14px;
  background: #8f7a66;
  color: var(--text-light);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: bold;
  cursor: pointer;
}

.btn-back:active {
  opacity: 0.9;
}

.screen-leaderboard .leaderboard-title {
  margin: 0;
  font-size: 1.25rem;
}

.leaderboard-list {
  margin: 0;
  padding: 0 0 0 24px;
  list-style: decimal;
  width: 100%;
}

.leaderboard-list li {
  padding: 8px 0;
  font-size: 1rem;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(238, 228, 218, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.overlay-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-content {
  background: var(--bg);
  padding: 24px;
  border-radius: var(--radius);
  text-align: center;
  max-width: 90%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.overlay-message {
  margin: 0 0 16px 0;
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--text-dark);
}

.btn-overlay {
  padding: 12px 24px;
  background: #8f7a66;
  color: var(--text-light);
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
}

.btn-overlay:active {
  opacity: 0.9;
}
