* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app {
  min-height: 100dvh;
  width: 100%;
  display: grid;
  place-items: center;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.board {
  --cols: 7;
  --rows: 7;

  position: relative;
  width: min(92vw, 560px);
  aspect-ratio: 1 / 1;

  /* background: #060606;
  border: 1px solid #171717;
  border-radius: 12px;
  overflow: hidden;

  box-shadow:
    0 0 0 1px rgba(255,255,255,0.015) inset,
    0 24px 80px rgba(0,0,0,0.55); */
}

.tile {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  display: grid;
  place-items: center;

  transform:
    translate(
      calc(var(--col) * 100%),
      calc(var(--row) * 100%)
    );

  transition:
    transform 180ms cubic-bezier(.2,.8,.2,1),
    opacity 130ms ease,
    filter 130ms ease;

  will-change: transform, opacity;
  z-index: 1;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 2px;

  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0.008));
  border: 1px solid rgba(255,255,255,0.045);
}

.emoji {
  position: relative;
  z-index: 1;

  font-size: clamp(24px, 4vw, 48px);
  line-height: 1;

  transform: scale(1);
  transition:
    transform 120ms ease,
    filter 120ms ease,
    opacity 120ms ease;

  filter: saturate(1.04);
}

.tile.selected .emoji {
  transform: scale(1.16);
  filter: saturate(1.18) brightness(1.1);
}

.tile.selected::before {
  border-color: rgba(255,255,255,0.16);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.02));
}

.tile.matched {
  z-index: 3;
}

.tile.matched .emoji {
  animation: match-pop 180ms ease forwards;
}

.tile.matched::before {
  animation: cell-flash 180ms ease forwards;
}

.tile.spawn {
  transition: none;
}

.board.busy {
  pointer-events: none;
}

@keyframes match-pop {
  0% {
    transform: scale(1);
    opacity: 1;
    filter: brightness(1);
  }
  48% {
    transform: scale(1.28) rotate(3deg);
    opacity: 1;
    filter: brightness(1.35);
  }
  100% {
    transform: scale(0.25);
    opacity: 0;
    filter: brightness(1.7);
  }
}

@keyframes cell-flash {
  0% {
    background: rgba(255,255,255,0.02);
    border-color: rgba(255,255,255,0.05);
  }
  45% {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.22);
  }
  100% {
    background: rgba(255,255,255,0.01);
    border-color: rgba(255,255,255,0.03);
  }
}

@media (min-width: 700px) {
  .board {
    width: min(70vmin, 620px);
    border-radius: 12px;
  }

  .tile::before {
    inset: 2px;
    border-radius: 6px;
  }

  .emoji {
    font-size: clamp(24px, 4vmin, 52px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile {
    transition-duration: 1ms;
  }

  .tile.matched .emoji,
  .tile.matched::before {
    animation-duration: 1ms;
  }
}
