.play {
  height: 100%;
  display: flex;
  align-items: stretch;
  gap: 16px;
  padding: calc(max(14px, env(safe-area-inset-top)) + 78px) 20px 16px;
}

.side {
  width: clamp(170px, 19vw, 250px);
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.side .bubble {
  margin-bottom: 0;
  max-width: 100%;
  text-align: center;
  cursor: pointer;
}

.side .bubble::after {
  left: 50%;
  bottom: -12px;
  margin-left: -12px;
  border: 12px solid transparent;
  border-top-color: var(--card);
  border-bottom: 0;
}

.owl {
  width: clamp(90px, 12vw, 150px);
  animation: bob 2.6s ease-in-out infinite;
  filter: drop-shadow(0 8px 10px rgba(61, 58, 92, 0.18));
  cursor: pointer;
}

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.round-dots {
  display: flex;
  gap: 10px;
  flex: none;
}

.round-dots i {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
}

.round-dots i.now {
  box-shadow: 0 0 0 4px var(--butter-deep);
}

.round-dots i.ok {
  background: var(--butter-deep);
}

@media (orientation: portrait) {
  .play {
    flex-direction: column;
    gap: 12px;
  }
  .side {
    width: auto;
    height: 120px;
    flex-direction: row-reverse;
    justify-content: center;
    gap: 14px;
  }
  .side .bubble {
    max-width: min(460px, calc(100vw - 220px));
  }
  .side .bubble::after {
    left: -12px;
    bottom: 50%;
    margin: 0 0 -12px;
    border: 12px solid transparent;
    border-right-color: var(--card);
    border-left: 0;
  }
  .owl {
    width: auto;
    height: 112px;
  }
}

.grid {
  --gap: 16px;
  --pad: 18px;
  --cols: 4;
  --rows: 2;
  --free-w: calc(100vw - clamp(170px, 19vw, 250px) - 56px - var(--pad) * 2);
  --free-h: calc(100dvh - 156px - var(--pad) * 2);
  --size: min(230px, calc((var(--free-w) + var(--gap)) / var(--cols) - var(--gap)), calc((var(--free-h) + var(--gap)) / var(--rows) - var(--gap)));
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--size));
  gap: var(--gap);
  padding: var(--pad);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 40px;
  box-shadow: var(--shadow);
}

.grid[data-pairs="6"] {
  --rows: 3;
}

@media (orientation: portrait) {
  .grid {
    --cols: 2;
    --rows: 4;
    --free-w: calc(100vw - 40px - var(--pad) * 2);
    --free-h: calc(100dvh - 288px - var(--pad) * 2);
  }
  .grid[data-pairs="6"] {
    --cols: 3;
    --rows: 4;
  }
}

.card {
  width: var(--size);
  height: var(--size);
  padding: 0;
  background: none;
  border-radius: 26px;
  perspective: 900px;
  animation: pop-in 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) backwards;
}

.card .inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.3, 1.3, 0.5, 1);
}

@media (hover: hover) {
  .card:hover .inner {
    transform: translateY(-4px);
  }
}

.card.open .inner {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 26px;
  border: 6px solid #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 6px 0 rgba(61, 58, 92, 0.12), 0 12px 22px rgba(61, 58, 92, 0.12);
}

.back {
  background-color: var(--lav-deep);
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.55) 17%, transparent 19%), radial-gradient(circle, rgba(255, 255, 255, 0.3) 17%, transparent 19%);
  background-size: 36px 36px;
  background-position: 0 0, 18px 18px;
}

.back::after {
  content: "";
  width: 44%;
  height: 44%;
  border-radius: 50%;
  background: var(--butter);
  border: 6px solid #fff;
  box-shadow: 0 4px 0 rgba(61, 58, 92, 0.15);
}

.front {
  background: #fff;
  border-color: var(--sky);
  transform: rotateY(180deg);
}

.front img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: none;
}

.card.nope .front {
  border-color: var(--peach);
}

.card.matched .front {
  border-color: var(--mint-deep);
  background: #f3fff8;
}

.card.matched {
  animation: happy 0.8s ease;
}

body.kbd .card.focus {
  outline: 6px solid var(--butter-deep);
  outline-offset: 4px;
}

@keyframes happy {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  25% {
    transform: translateY(-16px) scale(1.08);
  }
  50% {
    transform: translateY(0) scale(0.97);
  }
  75% {
    transform: translateY(-8px) scale(1.04);
  }
}
