/* =========================================================
   픽셀 마스코트 "와글이" (화면 오른쪽 아래 고정)
   - 방송 화면 구석의 버튜버처럼 페이지에 떠 있는 장식
   - 픽셀 그림은 js/core/mascot-art.js가 인라인 SVG로 그림 (방송 화면 와글이와 공용)
   ========================================================= */

.mascot {
  --px: 6px;                 /* 픽셀 한 칸 크기. 정수 px만 쓸 것 (16×15칸 → 96×90px) */
  --mascot-right: 24px;
  --mascot-bottom: 24px;

  position: fixed;
  right: var(--mascot-right);
  bottom: var(--mascot-bottom);
  z-index: 40;               /* 헤더(50)와 토스트(100)보다 아래 */
  display: flex;
  flex-direction: row-reverse;  /* 캐릭터는 오른쪽 끝, 말풍선은 그 왼쪽 위 */
  align-items: flex-start;
  gap: 16px;
  pointer-events: none;      /* 빈 영역은 뒤의 페이지를 클릭할 수 있게 */
}

/* ---------- 캐릭터 (클릭 영역) ---------- */
.mascot__char {
  position: relative;
  flex-shrink: 0;
  padding: 0;
  pointer-events: auto;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}

/* LIVE 배지: 캐릭터 왼쪽 위 */
.mascot__live {
  position: absolute;
  top: -9px;
  left: -9px;
  z-index: 1;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--color-pink);
  color: var(--color-on-pink);
  font-size: 10px;
  font-weight: var(--fw-black);
  line-height: 1.3;
  letter-spacing: 0.06em;
}

.mascot__jump,
.mascot__bob { display: block; }

/* 위아래로 천천히 흔들림 */
.mascot__bob { animation: mascot-bob 1.6s ease-in-out infinite; }
@keyframes mascot-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(calc(var(--px) * -1)); }
}

/* 클릭하면 살짝 점프 (js에서 .is-jump 추가) */
.mascot__jump.is-jump { animation: mascot-jump 0.45s cubic-bezier(0.3, 0.7, 0.4, 1); }
@keyframes mascot-jump {
  0%, 100% { transform: translateY(0); }
  40%      { transform: translateY(calc(var(--px) * -2.5)); }
  70%      { transform: translateY(2px); }
}

.mascot__svg {
  display: block;
  width: calc(var(--px) * 16);
  height: calc(var(--px) * 15);
  shape-rendering: crispEdges;   /* 픽셀(rect) 경계가 흐려지지 않게 */
  image-rendering: pixelated;
  /* 그림 자체가 원본 방향이라 뒤집지 않음 (js/core/mascot-art.js) */
  overflow: visible;
}

/* 눈 깜빡임: 위쪽 눈 줄을 몸통색으로 */
.mascot.is-blink .mascot__eye-top { fill: #FF4F8B; }

/* ---------- 말풍선 ---------- */
.mascot__bubble {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 8px 9px 14px;
  border-radius: var(--radius-md);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  pointer-events: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  margin-top: -16px;          /* 캐릭터보다 살짝 위 (왼쪽 위 말풍선) */
}
/* 캐릭터 쪽을 가리키는 꼬리 */
.mascot__bubble::before {
  content: '';
  position: absolute;
  right: -6px;
  top: 70%;
  width: 10px;
  height: 10px;
  margin-top: -5px;
  background: var(--color-card);
  border-right: 1px solid var(--color-border);
  border-top: 1px solid var(--color-border);
  transform: rotate(45deg);
}
.mascot__bubble[hidden] { display: none; }

.mascot__line {
  font-size: 14px;
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}
/* 대사가 바뀔 때 살짝 튀어나옴 */
.mascot__line.is-pop { animation: mascot-pop 0.25s var(--ease); }
@keyframes mascot-pop {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: none; }
}

/* 닫기(×) 버튼 */
.mascot__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--color-text-sub);
  font-size: 16px;
  line-height: 1;
  transition: background-color 0.2s, color 0.2s;
}
.mascot__close:hover { background: var(--color-border); color: var(--color-text); }

/* ---------- 본문·푸터와 겹치지 않도록 여백 확보 ---------- */
/* 페이지 맨 아래에서도 글자가 캐릭터(아래 24 + 높이 90 + 흔들림 6 + LIVE 배지) 위로 올라오게 */
body:has(.mascot) .site-footer,
body:has(.mascot) .app-main { padding-bottom: 150px; }

/* 태블릿 폭에서는 가운데 아래 토스트가 말풍선과 겹치므로 캐릭터 위로 올림 */
@media (max-width: 1024px) {
  body:has(.mascot) .toast { bottom: 140px; }
}

/* ---------- 모바일 (640px 이하) ---------- */
@media (max-width: 640px) {
  .mascot {
    --px: 4px;               /* 64×60px — 데스크톱(6px) 대비 약 0.6배 비율 유지 */
    --mascot-right: 12px;
    --mascot-bottom: 12px;
  }
  .mascot__bubble { display: none; }
  .mascot__live { top: -7px; left: -7px; padding: 1px 4px; font-size: 8px; }
  body:has(.mascot) .site-footer,
  body:has(.mascot) .app-main { padding-bottom: 104px; }
  /* 토스트가 캐릭터와 겹치지 않게 위로 (캐릭터 위 끝 약 80px) */
  body:has(.mascot) .toast { bottom: 92px; }
}

/* ---------- 움직임 줄이기: 흔들림·점프 끄기 ---------- */
@media (prefers-reduced-motion: reduce) {
  .mascot__bob,
  .mascot__jump.is-jump,
  .mascot__line.is-pop { animation: none; }
}

/* =========================================================
   홈 와글이 (.mascot--home)
   - data-place="hero": 히어로 오른쪽 자리(#heroMascotSlot) 안에 크게 (픽셀 한 칸 10px → 160×150, 모바일은 문구 위 7px)
   - data-place="dock": 오른쪽 아래 고정, 작게 (6px → 96×90, 모바일 4px)
   - 자리를 옮길 때는 js/mascot.js가 FLIP으로 0.6초 동안 이어 줌
   ========================================================= */
/* 픽셀 한 칸: 자리·화면 너비별 기본값(--px-base)만 여기서 정하고,
   실제 --px는 js/mascot.js(fitPixel)가 화면 배율까지 맞춰 넣음. JS 전에는 기본값 그대로 */
.mascot--home { display: block; --px-base: 6px; --px: var(--px-base); }
.mascot--home[data-place="hero"] {
  --px-base: 10px;
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 1;
}
.mascot--home[data-place="dock"] { --px-base: 6px; }

.mascot--home .mascot__char { display: block; border-radius: 12px; }
/* 움직임은 모두 transform으로만 (top·margin 등은 안 씀) */
.mascot--home .mascot__char,
.mascot--home .mascot__jump,
.mascot--home .mascot__bob { will-change: transform; }
.mascot--home .mascot__char:focus-visible { outline: 2px solid var(--color-pink); outline-offset: 4px; }

/* ---------- 홈 와글이 움직임 (js/mascot.js initHome) ----------
   steps()로 프레임이 뚝뚝 바뀌게 하고, 이동은 픽셀 한 칸(--px) 단위 */

/* 숨쉬기: 1.4초마다 1칸 위아래 */
.mascot--home .mascot__bob { animation: home-breathe 1.4s steps(1, end) infinite; }
@keyframes home-breathe {
  0%   { transform: translateY(0); }
  50%  { transform: translateY(calc(var(--px) * -1)); }
  100% { transform: translateY(0); }
}

/* 아래쪽 가운데를 기준으로 웅크리고 기울어짐 */
.mascot--home .mascot__jump { transform-origin: 50% 100%; }

/* 깡충: 웅크림(가로 +1칸·세로 −1칸) → 위로 4칸 → 착지(웅크림) → 제자리 */
.mascot--home .mascot__jump.is-hop { animation: home-hop 0.84s steps(1, end); }
@keyframes home-hop {
  0%     { transform: none; }
  14%    { transform: scale(1.0625, 0.9333); }
  28%    { transform: translateY(calc(var(--px) * -2)); }
  42%    { transform: translateY(calc(var(--px) * -4)); }
  57%    { transform: translateY(calc(var(--px) * -2)); }
  71%    { transform: scale(1.0625, 0.9333); }
  85%    { transform: none; }
  100%   { transform: none; }
}

/* 흔들기: ±7도 두 번 */
.mascot--home .mascot__jump.is-shake { animation: home-shake 0.64s steps(1, end); }
@keyframes home-shake {
  0%     { transform: none; }
  12.5%  { transform: rotate(-7deg); }
  37.5%  { transform: rotate(7deg); }
  62.5%  { transform: rotate(-7deg); }
  87.5%  { transform: rotate(7deg); }
  100%   { transform: none; }
}

/* 탭이 숨으면 전부 멈춤 */
.mascot.is-paused,
.mascot.is-paused * { animation-play-state: paused !important; }

/* 말풍선: 캐릭터 위 (2초 뒤 사라짐) */
.mascot--home .mascot__bubble {
  position: absolute;
  right: 30%;
  bottom: calc(100% + 10px);
  margin: 0;
  padding: 9px 14px;
}
.mascot--home .mascot__bubble::before {
  top: auto;
  right: 22px;
  bottom: -6px;
  margin: 0;
  border-top: 0;
  border-bottom: 1px solid var(--color-border);
}
.mascot--home .mascot__bubble.is-pop { animation: mascot-pop 0.25s var(--ease); }

/* ---------- 히어로 자리 ---------- */
/* 와글이가 오른쪽 아래로 떠나도 자리 크기는 그대로 (레이아웃이 흔들리지 않게). 오른쪽 칸 가운데 */
.hero__mascot {
  position: relative;
  width: 160px;
  height: 162px;
  justify-self: center;
}

/* 태블릿: 조금 작게 (8px → 128×120) */
@media (max-width: 960px) {
  .mascot--home[data-place="hero"] { --px-base: 8px; }
  .hero__mascot { width: 128px; height: 130px; }
}
/* 모바일: 문구 위에 중간 크기 (7px → 112×105), 말풍선은 아래로 */
@media (max-width: 640px) {
  .mascot--home[data-place="hero"] { --px-base: 7px; }
  .mascot--home[data-place="dock"] { --px-base: 4px; }
  .hero__mascot { width: 112px; height: 114px; justify-self: start; }
  .mascot--home[data-place="hero"] .mascot__bubble { top: calc(100% + 10px); bottom: auto; left: 0; right: auto; }
  .mascot--home[data-place="hero"] .mascot__bubble::before { top: -6px; bottom: auto; left: 30px; right: auto; border-bottom: 0; border-top: 1px solid var(--color-border); border-left: 1px solid var(--color-border); border-right: 0; }
  .mascot--home .mascot__bubble:not([hidden]) { display: flex; }
}

/* =========================================================
   작은 와글이 (404·"준비 중" 페이지 가운데 와글이, 숨쉬기만)
   ========================================================= */
.mini-mascot { --px: 3px; display: inline-block; flex-shrink: 0; }
.mini-mascot__bob { display: block; animation: mascot-bob 1.8s ease-in-out infinite; }
.mini-mascot__svg {
  display: block;
  width: calc(var(--px) * 16);
  height: calc(var(--px) * 15);
  shape-rendering: crispEdges;
}

/* ---------- 움직임 줄이기 → 와글이는 깜빡임만 ----------
   base.css가 모든 애니메이션을 끄므로 숨쉬기·깡충·흔들기는 멈추고, 깜빡임(눈 색만 바뀜)은 그대로.
   js/mascot.js도 행동(깡충·두리번·흔들기)을 하지 않음. 자리 옮김은 opacity만 */
@keyframes home-hop-soft {
  0%     { transform: none; }
  14%    { transform: scale(1.0625, 0.9333); }
  28%    { transform: translateY(calc(var(--px) * -1)); }
  42%    { transform: translateY(calc(var(--px) * -2)); }
  57%    { transform: translateY(calc(var(--px) * -1)); }
  71%    { transform: scale(1.0625, 0.9333); }
  85%    { transform: none; }
  100%   { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .mascot--home .mascot__bubble.is-pop,
  .mini-mascot__bob { animation: none; }
}

