.grid-container {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 6px;
  padding-bottom: 10px;
  position: relative;
  z-index: 5;
}

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 2px;
  width: 100%;
  max-width: 420px;
  height: 100%;
  max-height: 100%;
  padding: 6px;
  border-radius: 14px;
  background: var(--panel-bg);
  box-shadow: 0 4px 15px rgba(233, 30, 99, calc(var(--shadow) * 1.2));
  touch-action: none;
  user-select: none;
  position: relative;
  overflow: hidden;
  border: 2px solid var(--panel-border);
  z-index: 10;
}

.cell {
  position: relative;
  border-radius: 9px;
  background: var(--cell-color);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 4px rgba(0, 0, 0, 0.25),
    0 6px 12px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    border-color 0.12s ease,
    opacity 0.12s ease;
}

/* Телефони: менше тіней і без filter на «кризі» — дешевше для GPU */
@media (pointer: coarse) and (max-width: 900px) {
  .grid {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .cell {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.28),
      inset 0 -1px 3px rgba(0, 0, 0, 0.2),
      0 2px 6px rgba(0, 0, 0, 0.22);
    transition:
      transform 0.1s ease,
      box-shadow 0.1s ease,
      border-color 0.1s ease,
      opacity 0.1s ease;
  }

  .cell.selected {
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.45),
      0 0 0 2px rgba(255, 120, 160, 0.75),
      0 4px 12px rgba(255, 120, 160, 0.45);
  }

  .cell.frozen {
    filter: none;
    opacity: 0.72;
  }
}

.cell::before {
  content: '';
  display: block;
  padding-top: 100%;
}

.cell-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.8rem, 2.4vw, 1rem);
  font-weight: 800;
  color: var(--cell-number-color);
  pointer-events: none;
  transition:
    transform 0.12s ease,
    background 0.12s ease,
    color 0.12s ease;
}

.cell.selected {
  transform: scale(0.96);
  border-color: var(--secondary-color);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 0 0 2px rgba(255, 120, 160, 0.8),
    0 8px 18px rgba(255, 120, 160, 0.6);
}

.cell.selected .cell-inner {
  background: var(--secondary-color);
  color: #fff;
  border-radius: 7px;
}

/* Мобільний / lite: ланцюг «можна звести» — зелений, інакше (≥2 клітини) — червоний */
.cell.selected.chain-preview-valid {
  border-color: #1b5e20;
  transform: scale(0.96);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 0 0 3px rgba(76, 175, 80, 0.95),
    0 6px 16px rgba(76, 175, 80, 0.5);
}

.cell.selected.chain-preview-valid .cell-inner {
  background: linear-gradient(155deg, #66bb6a 0%, #2e7d32 100%);
  color: #fff;
  border-radius: 7px;
}

.cell.selected.chain-preview-invalid {
  border-color: #7f0000;
  transform: scale(0.96);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 0 0 3px rgba(229, 57, 53, 0.92),
    0 6px 16px rgba(211, 47, 47, 0.48);
}

.cell.selected.chain-preview-invalid .cell-inner {
  background: linear-gradient(155deg, #ef5350 0%, #b71c1c 100%);
  color: #fff;
  border-radius: 7px;
}

.cell.merged .cell-inner {
  animation: pop 0.22s ease;
}

.cell.popping {
  animation: bubbleOut 0.27s ease forwards;
}

.cell.carry .cell-inner {
  animation: carryIn 0.45s ease-out;
}

/* Заморозка: декор через .snowflake у JS (без ::after). */
.cell.frozen {
  position: relative;
  background-color: #bdc3c7 !important;
  filter: grayscale(1);
  pointer-events: none;
  opacity: 0.7;
}

.freeze-counter {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  font-weight: bold;
}

.snowflake {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  z-index: 2;
  opacity: 0.7;
}

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

@keyframes bubbleOut {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}

@keyframes carryIn {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }
  60% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes shuffleWiggle {
  0% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-3px, 2px);
  }
  40% {
    transform: translate(3px, -2px);
  }
  60% {
    transform: translate(-2px, -1px);
  }
  80% {
    transform: translate(2px, 2px);
  }
  100% {
    transform: translate(0, 0);
  }
}

.cell.shuffle-anim .cell-inner {
  animation: shuffleWiggle 0.35s ease;
}

/* Цвета чисел */
.cell[data-number='2'] {
  background: #9ee6a8;
}
.cell[data-number='4'] {
  background: #f3b1b8;
}
.cell[data-number='8'] {
  background: #f1d16a;
}
.cell[data-number='16'] {
  background: #8fc4f5;
}
.cell[data-number='32'] {
  background: #b9a0f2;
}
.cell[data-number='64'] {
  background: #ffb347;
}
.cell[data-number='128'] {
  background: #7ed957;
}
.cell[data-number='256'] {
  background: #ff70a6;
}
.cell[data-number='512'] {
  background: #70d6ff;
}
.cell[data-number='1024'] {
  background: #ff9770;
}
.cell[data-number='2048'] {
  background: #e9ff70;
}
.cell[data-number='4096'] {
  background: #ff70e9;
}
.cell[data-number='8192'] {
  background: #9770ff;
}
