html, body {
  margin: 0;
  overflow: hidden;
}

.stage {
  box-sizing: border-box;
  min-height: 100vh;
  display: grid;
  place-items: center;
  margin: 0;
  background: #ffd23f;
  font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
  padding: clamp(8px, 4vw, 24px);
}

.mm {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 280px;
  height: 100%;
}

.mm__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mm__title {
  margin: 0;
  font-weight: 800;
  font-size: clamp(12px, 3vw, 15px);
  color: #17141a;
}

.mm__restart {
  display: grid;
  place-items: center;
  width: clamp(24px, 5vw, 28px);
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid rgba(23, 20, 26, 0.32);
  border-radius: 12px;
  background: none;
  color: #17141a;
  cursor: pointer;
}

.mm__restart svg {
  width: 62%;
  height: 62%;
}

.mm__restart:focus-visible {
  outline: 2px solid #17141a;
  outline-offset: 2px;
}

.mm__stats {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.mm__stat {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.mm__num {
  font-weight: 800;
  font-size: clamp(11px, 2.8vw, 14px);
  color: #17141a;
}

.mm__label {
  font-weight: 700;
  font-size: clamp(8px, 2.2vw, 10px);
  color: rgba(23, 20, 26, 0.72);
}

.mm__trophy {
  width: clamp(12px, 3vw, 14px);
  height: clamp(12px, 3vw, 14px);
  color: #c93000;
}

.mm__grid {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template: repeat(3, 1fr)/repeat(4, 1fr);
  gap: 8px;
}

.mm__card {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.mm__card:focus-visible {
  outline: 2px solid #17141a;
  outline-offset: 2px;
}

.mm__inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.mm__card.is-open .mm__inner,
.mm__card.is-matched .mm__inner {
  transform: rotateY(180deg);
}

.mm__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.mm__face svg {
  width: clamp(18px, 6vw, 26px);
  height: clamp(18px, 6vw, 26px);
}

.mm__face--back {
  background-color: #fff7e6;
  border: 2px solid rgba(23, 20, 26, 0.18);
  color: #0a4fe8;
}

.mm__face--front {
  background-color: #ffffff;
  border: 2px solid rgba(23, 20, 26, 0.14);
  transform: rotateY(180deg);
}

.mm__card[data-face=star] .mm__face--front,
.mm__card[data-face=lightning] .mm__face--front {
  color: #c93000;
}

.mm__card[data-face=heart] .mm__face--front {
  color: #c2361a;
}

.mm__card[data-face=moon] .mm__face--front,
.mm__card[data-face=flower] .mm__face--front {
  color: #0a4fe8;
}

.mm__card[data-face=rocket] .mm__face--front {
  color: #17141a;
}

.mm__card.is-matched {
  animation-name: mmPop;
  animation-duration: 420ms;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-iteration-count: 1;
}

.mm__card.is-matched .mm__face--front {
  border-color: #0a4fe8;
  box-shadow: 0 0 0 3px rgba(10, 79, 232, 0.22);
}

@keyframes mmPop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.09);
  }
  100% {
    transform: scale(1);
  }
}
.mm__clear {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  margin: 0;
  background-color: rgba(23, 20, 26, 0.55);
  border-radius: 8px;
}

.mm__clear[hidden] {
  display: none;
}

.mm__clear b {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 999px;
  background-color: #0a4fe8;
  color: #fff7e6;
  font-weight: 800;
  font-size: clamp(10px, 2.6vw, 13px);
  animation-name: mmClearIn;
  animation-duration: 600ms;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-iteration-count: 1;
  animation-fill-mode: both;
}

@keyframes mmClearIn {
  from {
    opacity: 0;
    transform: scale(0.82);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
.mm__ghost {
  display: none;
  position: absolute;
  z-index: 4;
  pointer-events: none;
}

.mm.is-demo .mm__ghost {
  display: block;
}

.mm__ghost--a {
  grid-area: 1/2;
}

.mm__ghost--b {
  grid-area: 3/3;
}

.mm__ghost--c {
  grid-area: 1/4;
}

.mm__ghost--d {
  grid-area: 2/1;
}

.mm__ghostInner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  animation-name: mmGhostFlip;
  animation-duration: 2s;
  animation-timing-function: steps(1, end);
  animation-iteration-count: infinite;
  animation-fill-mode: backwards;
}

.mm__ghost--a .mm__ghostInner {
  animation-delay: 100ms;
}

.mm__ghost--b .mm__ghostInner {
  animation-delay: 340ms;
}

.mm__ghost--c .mm__ghostInner {
  animation-delay: 1100ms;
}

.mm__ghost--d .mm__ghostInner {
  animation-delay: 1340ms;
}

.mm__ghost--a .mm__face--front,
.mm__ghost--b .mm__face--front {
  color: #c2361a;
}

.mm__ghost--c .mm__face--front,
.mm__ghost--d .mm__face--front {
  color: #c93000;
}

.mm__ghost--a, .mm__ghost--b {
  animation-name: mmGhostPulse1;
  animation-duration: 2s;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-iteration-count: infinite;
}

.mm__ghost--c, .mm__ghost--d {
  animation-name: mmGhostPulse2;
  animation-duration: 2s;
  animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-iteration-count: infinite;
}

@keyframes mmGhostFlip {
  0% {
    transform: rotateY(0deg);
  }
  3% {
    transform: rotateY(180deg);
  }
  90% {
    transform: rotateY(180deg);
  }
  94% {
    transform: rotateY(0deg);
  }
  100% {
    transform: rotateY(0deg);
  }
}
@keyframes mmGhostPulse1 {
  0%, 27% {
    transform: scale(1);
  }
  38% {
    transform: scale(1.1);
  }
  51%, 100% {
    transform: scale(1);
  }
}
@keyframes mmGhostPulse2 {
  0%, 78% {
    transform: scale(1);
  }
  86% {
    transform: scale(1.1);
  }
  97%, 100% {
    transform: scale(1);
  }
}
@media (max-width: 340px) {
  .mm {
    gap: 4px;
  }
  .mm__grid {
    gap: 4px;
  }
  .mm__stats {
    gap: 8px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .mm__inner {
    transition: none !important;
  }
  .mm__card.is-matched {
    animation: none !important;
  }
  .mm__clear b {
    animation: none !important;
  }
  .mm.is-demo .mm__ghost,
  .mm.is-demo .mm__ghostInner {
    animation: none !important;
  }
}
