/* 모아이 메모리 프렌즈 — 고유 스타일 */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: #FBF8FF;
  font-family: 'Galmuri11', monospace;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ── 섹션 공통 ── */
section {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}
.hidden { display: none !important; }

/* ── 홈 ── */
#home-mascot { width: 72px; height: 72px; margin-bottom: 8px; image-rendering: pixelated; }
#home-mascot svg, #home-mascot img { width: 100%; height: 100%; }

#home-title { font-size: 26px; font-weight: bold; color: #2E2548; text-align: center; line-height: 1.3; margin-bottom: 20px; }

#diff-btns { display: flex; gap: 10px; margin-bottom: 20px; }
.diff-btn {
  flex: 1; padding: 10px 14px; border: 2px solid #C5B8F0; border-radius: 12px;
  background: #fff; color: #2E2548; font-family: inherit; font-size: 14px;
  cursor: pointer; text-align: center; line-height: 1.4; transition: background 0.15s;
  min-width: 48px;
  min-height: 48px;
}
.diff-btn.active { background: #6B5BA8; color: #fff; border-color: #6B5BA8; }
.diff-btn small { font-size: 11px; opacity: 0.8; }

#start-btn {
  padding: 14px 48px; background: #6B5BA8; color: #fff;
  border: none; border-radius: 14px; font-family: inherit; font-size: 18px; font-weight: bold;
  cursor: pointer; box-shadow: 0 5px 0 #4A3D8C; transition: transform 0.1s, box-shadow 0.1s;
  min-width: 48px;
  min-height: 48px;
}
#start-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #4A3D8C; }

#best-display { margin-top: 14px; font-size: 12px; color: #8B7BC4; text-align: center; min-height: 18px; }

/* ── HUD ── */
#hud {
  width: 100%; max-width: 380px; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: #EDE8FF; border-radius: 14px; margin-bottom: 12px;
}
#hud-moves, #hud-timer { font-size: 15px; color: #2E2548; font-weight: bold; }
#pause-btn {
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: #6B5BA8;
  touch-action: manipulation;
}
#pause-btn::before,
#pause-btn::after {
  content: '';
  width: 5px;
  height: 18px;
  border-radius: 2px;
  background: currentColor;
}

/* ── 게임 보드 ── */
#board {
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 380px;
}
/* 컬럼 수는 JS에서 인라인 스타일로 설정 */

/* ── 카드 ── */
.card {
  aspect-ratio: 1;
  cursor: pointer;
  perspective: 600px;
  -webkit-tap-highlight-color: transparent;
}
.card__inner {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 0.38s ease;
  border-radius: 12px;
}
.card.flipped .card__inner,
.card.matched .card__inner {
  transform: rotateY(180deg);
}
.card__back, .card__front {
  position: absolute; inset: 0;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
/* 뒷면 */
.card__back {
  background: #6B5BA8;
  box-shadow: 0 4px 0 #4A3D8C;
}
.card__back-inner {
  width: 60%; height: 60%;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.card__back svg { width: 70%; height: 70%; opacity: 0.5; }

/* 앞면 */
.card__front {
  background: #EDE8FF;
  transform: rotateY(180deg);
  box-shadow: 0 4px 0 #C5B8F0;
  padding: 8%;
}
.card__front svg { width: 100%; height: 100%; image-rendering: pixelated; }

/* matched */
.card.matched .card__front { background: #D4F5E2; box-shadow: 0 4px 0 #A8E0C0; }
.card.matched .card__inner { animation: matchPop 0.35s ease; }
@keyframes matchPop {
  0% { transform: rotateY(180deg) scale(1); }
  40% { transform: rotateY(180deg) scale(1.12); }
  100% { transform: rotateY(180deg) scale(1); }
}

/* 오류 흔들기 */
.card.wrong .card__inner { animation: wrongShake 0.45s ease; }
@keyframes wrongShake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  20% { transform: rotateY(180deg) translateX(-6px); }
  50% { transform: rotateY(180deg) translateX(6px); }
  80% { transform: rotateY(180deg) translateX(-4px); }
}

/* ── 일시정지 오버레이 ── */
#pause-overlay {
  position: fixed; inset: 0; background: rgba(46,37,72,0.65);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#pause-box {
  background: #fff; border-radius: 18px; padding: 32px 40px;
  text-align: center; display: flex; flex-direction: column; gap: 12px;
}
#pause-label { font-size: 20px; color: #2E2548; font-weight: bold; }
#resume-btn, #quit-btn {
  padding: 12px 32px; border: none; border-radius: 10px;
  font-family: inherit; font-size: 15px; cursor: pointer; font-weight: bold;
  min-width: 48px;
  min-height: 48px;
}
#resume-btn { background: #6B5BA8; color: #fff; box-shadow: 0 4px 0 #4A3D8C; }
#quit-btn { background: #EDE8FF; color: #2E2548; box-shadow: 0 4px 0 #C5B8F0; }

/* ── 결과 ── */
#result { gap: 12px; }
#result-stars { display: flex; gap: 8px; justify-content: center; }
.result-star {
  display: inline-block;
  width: 30px;
  height: 30px;
  background: #D8D0EA;
  clip-path: polygon(50% 0%, 61% 34%, 98% 35%, 68% 56%, 79% 92%, 50% 70%, 21% 92%, 32% 56%, 2% 35%, 39% 34%);
}
.result-star.active { background: #F2B84B; }
#result-title { font-size: 24px; font-weight: bold; color: #2E2548; }
#result-detail { font-size: 14px; color: #6B5BA8; }
#result-btns { display: flex; gap: 12px; margin-top: 8px; }
#retry-btn, #home2-btn {
  padding: 12px 28px; border: none; border-radius: 12px;
  font-family: inherit; font-size: 15px; font-weight: bold; cursor: pointer;
  min-width: 48px;
  min-height: 48px;
}
#retry-btn { background: #6B5BA8; color: #fff; box-shadow: 0 4px 0 #4A3D8C; }
#home2-btn { background: #EDE8FF; color: #2E2548; box-shadow: 0 4px 0 #C5B8F0; }

/* ── 피날레 ── */
.card.finale .card__inner {
  animation: finaleSpin 0.6s ease forwards;
}
@keyframes finaleSpin {
  0% { transform: rotateY(180deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.18) rotate(-6deg); }
  100% { transform: rotateY(180deg) scale(1) rotate(0deg); }
}
