/* ═══════════════════════════════════════════════════════════
   무당 캐릭터 — 픽셀 프레임 방식

   구조
     .mudang                상태 그릇 (data-pose 속성)
       .mudang__aura        뒤에 깔리는 신기(神氣)
       .mudang__stage       움직이는 무대. 프레임 img 들이 겹쳐 쌓인다.
         .mudang__layer     프레임 한 장 — JS가 .on 을 옮겨가며 보여준다

   픽셀 아트 움직임의 규칙:
     · 회전 금지, 부드러운 보간 금지 — 격자가 뭉개진다
     · 이동은 원본 1픽셀 단위(= 표시 배율만큼)로, steps() 로 딱딱 끊어서
     · 입/눈은 CSS가 아니라 JS가 프레임을 갈아끼운다 (mudang.js)
   ═══════════════════════════════════════════════════════════ */

.mudang {
  position: relative;
  /* 원본 48x72 의 6배 = 288x432. 정수 배율이어야 픽셀이 안 뭉개진다. */
  width: min(288px, 70vw);
  aspect-ratio: 2 / 3;
  margin: 0 auto 10px;

  /* 포즈별 흔들림 — 아래 [data-pose] 에서 덮어쓴다 */
  --bob-name: bob-idle;
  --bob-dur: 1.6s;
}

/* 접지 그림자 — 배경이 '방'이 된 뒤로는 이게 없으면 떠 보인다 */
.mudang::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 74%;
  height: 20px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse,
              rgba(0, 0, 0, 0.55) 0%, transparent 68%);
  filter: blur(2px);
}

.mudang__stage {
  position: absolute;
  inset: 0;
  animation: var(--bob-name) var(--bob-dur) steps(1, end) infinite;
}

/* 말하는 중엔 몸짓도 바빠진다 */
.mudang.is-speaking .mudang__stage {
  animation-duration: calc(var(--bob-dur) * 0.55);
}

.mudang__layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;       /* 핵심 — 이게 없으면 흐릿한 죽이 된다 */
  display: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 0 24px rgba(179, 18, 31, 0.35))
          drop-shadow(0 10px 20px rgba(0, 0, 0, 0.7));
}

.mudang__layer.on { display: block; }

/* ── 포즈별 흔들림 (전부 원본 1~2픽셀 = 6~12px 단위) ─────── */

@keyframes bob-idle {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

/* 호통 — 좌우로 부르르 */
.mudang[data-pose="shout"] { --bob-name: bob-shout; --bob-dur: 0.4s; }
@keyframes bob-shout {
  0%, 100% { transform: translate(0, 0); }
  25%      { transform: translate(-6px, 0); }
  50%      { transform: translate(0, -6px); }
  75%      { transform: translate(6px, 0); }
}

/* 못마땅 — 느릿하게 갸웃 (가로로 한 칸) */
.mudang[data-pose="tsk"] { --bob-name: bob-tsk; --bob-dur: 2.4s; }
@keyframes bob-tsk {
  0%, 100% { transform: translate(0, 0); }
  40%      { transform: translate(-6px, 6px); }
  70%      { transform: translate(0, 6px); }
}

/* 뜸 들임 — 거의 정지. 정적이 있어야 뜸이 산다. */
.mudang[data-pose="ponder"] { --bob-name: bob-idle; --bob-dur: 3.2s; }

/* 웃음 — 들썩들썩 */
.mudang[data-pose="laugh"] { --bob-name: bob-laugh; --bob-dur: 0.5s; }
@keyframes bob-laugh {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-12px); }
}

/* ── 포즈 전환 순간: 한 번 폴짝 ──────────────────────────── */
.mudang.is-swapping .mudang__stage {
  animation: pose-hop 0.24s steps(2, end);
}

@keyframes pose-hop {
  0%   { transform: translateY(-12px); }
  50%  { transform: translateY(-6px); }
  100% { transform: translateY(0); }
}

/* ── 아우라 ──────────────────────────────────────────────── */
.mudang__aura {
  position: absolute;
  inset: -10%;
  border-radius: 50%;
  background: radial-gradient(circle,
              rgba(179, 18, 31, 0.30) 0%,
              rgba(212, 160, 23, 0.12) 45%,
              transparent 70%);
  filter: blur(22px);
  animation: aura-pulse 3.6s ease-in-out infinite;
  pointer-events: none;
  transition: opacity 0.3s;
}

@keyframes aura-pulse {
  0%, 100% { transform: scale(1);    opacity: 0.55; }
  50%      { transform: scale(1.12); opacity: 0.9; }
}

.mudang[data-pose="shout"] .mudang__aura {
  background: radial-gradient(circle,
              rgba(230, 57, 70, 0.55) 0%,
              rgba(179, 18, 31, 0.28) 40%,
              transparent 72%);
  animation-duration: 0.5s;
}

.mudang[data-pose="tsk"] .mudang__aura { opacity: 0.35; }

.mudang[data-pose="ponder"] .mudang__aura {
  background: radial-gradient(circle,
              rgba(212, 160, 23, 0.30) 0%,
              rgba(29, 90, 138, 0.15) 45%,
              transparent 72%);
  animation-duration: 5s;
}

/* ═══ 말풍선 ═══════════════════════════════════════════════ */
/* 신탁이 적히는 족자 — 두 겹 금테(테두리+안쪽 실선)에 은은한 주사 기운 */
.speech {
  position: relative;
  min-height: 92px;
  margin: 0 auto;
  max-width: 560px;
  padding: 20px 24px;
  background: linear-gradient(180deg,
              rgba(42, 26, 22, 0.90) 0%, rgba(14, 8, 9, 0.94) 100%);
  border: 1px solid rgba(212, 160, 23, 0.45);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    inset 0 0 0 3px rgba(10, 6, 7, 0.9),      /* 안쪽 먹띠 */
    inset 0 0 0 4px rgba(212, 160, 23, 0.22), /* 안쪽 실선 → 두 겹 금테 */
    inset 0 0 46px rgba(179, 18, 31, 0.10),
    0 8px 32px rgba(0, 0, 0, 0.6);
}

.speech::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 16px;
  height: 16px;
  background: rgba(24, 14, 16, 0.9);
  border-left: 1px solid rgba(212, 160, 23, 0.3);
  border-top: 1px solid rgba(212, 160, 23, 0.3);
}

.speech__text {
  font-size: clamp(1.05rem, 3.4vw, 1.35rem);
  line-height: 1.75;
  text-align: center;
  color: var(--white-jade);
  text-shadow: 0 0 18px rgba(212, 160, 23, 0.3);
  text-wrap: balance;     /* 두 줄로 꺾일 때 길이를 비슷하게 나눈다 */
}

.speech__text.is-new { animation: speech-pop 0.4s ease-out both; }

@keyframes speech-pop {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.speech__text[data-emotion="shout"] {
  color: var(--red-bright);
  font-weight: 700;
  font-size: clamp(1.2rem, 4.2vw, 1.6rem);
  text-shadow: 0 0 24px rgba(230, 57, 70, 0.7);
}

.speech__text[data-emotion="sigh"] {
  color: var(--text-dim);
  font-style: italic;
}

/* ═══ 좁은 화면 ════════════════════════════════════════════ */
/* 6배(288px)는 폰에서 화면 절반을 먹는다. 4배(192px)로 한 단계 축소.
   배율은 정수여야 픽셀이 안 뭉개진다. 이 규칙은 반드시 이 파일(로드
   순서상 마지막 CSS)에 있어야 위의 기본 width를 이긴다. */
@media (max-width: 520px) {
  .mudang { width: 192px; }
}

