/* Mix Of 2048 — полностью адаптивная версия (mobile-first, все устройства) */
:root {
  --mix2048-bg: #f6f6f7;
  --mix2048-panel: #faf8ef;
  --mix2048-grid-bg: linear-gradient(180deg, #bbada0, #b59a87);
  --mix2048-accent: #f59563;
  --mix2048-text: #333;
  --mix2048-muted: #7a7a7a;
  --mix2048-tile-font: 1rem;
}

.mix2048-wrapper {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  margin: 0 auto;
  color: var(--mix2048-text);
  text-align: center;
  box-sizing: border-box;
  /* Allow parent containers (Gutenberg, themes) to control width easily */
}

/* Header */
.mix2048-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}

.mix2048-title {
  font-weight: 800;
  font-size: clamp(16px, 4vw, 22px);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.mix2048-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Score + Best */
.mix2048-score,
.mix2048-best {
  background: transparent;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  min-width: 68px;
  text-align: center;
  font-size: 12px;
}
.mix2048-score .label,
.mix2048-best .label {
  font-size: 10px;
  color: var(--mix2048-muted);
  display: block;
  line-height: 1;
}
.mix2048-score .value,
.mix2048-best .value {
  font-weight: 800;
  font-size: 16px;
  color: var(--mix2048-accent);
  line-height: 1.1;
  display: block;
}

.mix2048-best .value {
  color: #8f7a66;
}

/* Buttons */
.mix2048-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 0;
  cursor: pointer;
  background: linear-gradient(180deg, #ffffff, #f3f3f3);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05), inset 0 -1px 0 rgba(0, 0, 0, 0.03);
  color: var(--mix2048-text);
  font-weight: 600;
  font-size: 13px;
  line-height: 1;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.mix2048-btn:active {
  transform: translateY(1px);
}
.mix2048-btn:focus-visible {
  outline: 2px solid var(--mix2048-accent);
  outline-offset: 2px;
}

/* Game container */
.mix2048-game {
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  display: flex;
  justify-content: center;
  touch-action: none; /* important for swipe handling */
}

/* === The board (fully fluid) === */
.mix2048-grid {
  position: relative;
  width: 100%;
  max-width: 100%; /* controlled by parent .mix2048-wrapper */
  aspect-ratio: 1 / 1;
  background: var(--mix2048-grid-bg);
  border-radius: clamp(8px, 2.5vw, 16px);
  /* Fluid padding & gap — critical for responsiveness on all devices */
  padding: clamp(6px, 2.2vw, 14px);
  gap: clamp(4px, 1.6vw, 12px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  box-sizing: border-box;
  /* The grid itself drives the size; wrapper can limit via max-width */
}

/* Cells background grid (CSS Grid — perfect for any N×N) */
.mix2048-cells {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(var(--size, 4), 1fr);
  grid-template-rows: repeat(var(--size, 4), 1fr);
  gap: inherit; /* inherits the fluid gap from parent */
}
.mix2048-cells .cell {
  background: rgba(255, 255, 255, 0.13);
  border-radius: clamp(4px, 1vw, 10px);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.05);
}

/* Tiles layer (absolute inside the padded grid) */
.mix2048-tiles {
  position: absolute;
  /* Match the padding of the grid so % positioning works correctly */
  inset: clamp(6px, 2.2vw, 14px);
  z-index: 2;
  pointer-events: none;
}

/* Individual tile — fluid font size is set from JS via --mix2048-tile-font */
.mix2048-tiles .mix2048-tile {
  position: absolute;
  border-radius: clamp(4px, 1vw, 10px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #776e65;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  box-shadow: 0 3px 8px rgba(44, 39, 32, 0.18);
  /* Smooth movement + pop */
  transition: transform 160ms cubic-bezier(0.25, 0.1, 0.25, 1),
              left 160ms cubic-bezier(0.25, 0.1, 0.25, 1),
              top 160ms cubic-bezier(0.25, 0.1, 0.25, 1);
  font-size: var(--mix2048-tile-font, 1rem);
  will-change: transform, left, top;
}

/* New tile pop animation */
.mix2048-tile.is-new {
  animation: mix2048-pop 180ms ease-out;
}
@keyframes mix2048-pop {
  from { transform: scale(0.6); }
  to   { transform: scale(1); }
}

/* Merge pop (slightly bigger) */
.mix2048-tile.is-merge {
  animation: mix2048-merge-pop 220ms ease-out;
}
@keyframes mix2048-merge-pop {
  0%   { transform: scale(0.8); }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Tile colors (classic 2048 palette + good contrast) */
.mix2048-tile.tile-2    { background: #eee4da; color: #776e65; }
.mix2048-tile.tile-4    { background: #ede0c8; color: #776e65; }
.mix2048-tile.tile-8    { background: #f2b179; color: #f9f6f2; }
.mix2048-tile.tile-16   { background: #f59563; color: #f9f6f2; }
.mix2048-tile.tile-32   { background: #f67c5f; color: #f9f6f2; }
.mix2048-tile.tile-64   { background: #f65e3b; color: #f9f6f2; }
.mix2048-tile.tile-128  { background: #edcf72; color: #f9f6f2; }
.mix2048-tile.tile-256  { background: #edcc61; color: #f9f6f2; }
.mix2048-tile.tile-512  { background: #edc850; color: #f9f6f2; }
.mix2048-tile.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: calc(var(--mix2048-tile-font, 1rem) * 0.85); }
.mix2048-tile.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: calc(var(--mix2048-tile-font, 1rem) * 0.82); }

.mix2048-tile.tile-big {
  background: #3c3a32;
  color: #f9f6f2;
  font-size: calc(var(--mix2048-tile-font, 1rem) * 0.72);
}

/* Overlay (win / lose) */
.mix2048-overlay {
  position: absolute;
  inset: clamp(6px, 2.2vw, 14px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border-radius: clamp(8px, 2vw, 14px);
  z-index: 5;
  flex-direction: column;
  gap: 10px;
  padding: clamp(12px, 4vw, 22px);
  text-align: center;
}
.mix2048-overlay.hidden { display: none; }

.mix2048-message {
  font-size: clamp(16px, 5vw, 22px);
  font-weight: 800;
  line-height: 1.2;
}

.mix2048-overlay-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Footer hint */
.mix2048-footer {
  margin-top: 8px;
  color: var(--mix2048-muted);
  font-size: 12px;
  line-height: 1.3;
}

/* === Strong responsiveness for ALL devices === */

/* Very small phones (iPhone SE, old Android) */
@media (max-width: 360px) {
  .mix2048-header {
    flex-direction: column;
    align-items: stretch;
  }
  .mix2048-controls {
    justify-content: center;
  }
  .mix2048-score,
  .mix2048-best {
    min-width: 58px;
    padding: 5px 8px;
  }
  .mix2048-btn {
    padding: 7px 11px;
    font-size: 12px;
  }
}

/* Tablets and small desktops */
@media (min-width: 600px) and (max-width: 900px) {
  .mix2048-score,
  .mix2048-best {
    min-width: 78px;
    padding: 7px 12px;
  }
  .mix2048-score .value,
  .mix2048-best .value {
    font-size: 17px;
  }
}

/* Large screens — we still cap via the wrapper's max-width in HTML */
@media (min-width: 1024px) {
  .mix2048-title {
    font-size: 24px;
  }
}

/* Accessibility: high contrast focus + reduced motion respect */
@media (prefers-reduced-motion: reduce) {
  .mix2048-tiles .mix2048-tile,
  .mix2048-btn {
    transition: none !important;
  }
  .mix2048-tile.is-new,
  .mix2048-tile.is-merge {
    animation: none !important;
  }
}

.mix2048-wrapper:focus-visible,
.mix2048-game:focus-visible {
  outline: 3px solid var(--mix2048-accent);
  outline-offset: 3px;
  border-radius: 4px;
}
