/* ─── CSS 변수: 폰트 스케일 시스템 + 스켈레톤 ─── */
:root {
  --fs-xs: 0.65rem;
  --fs-sm: 0.8rem;
  --fs-md: 1rem;
  --fs-lg: 1.4rem;
  --fs-xl: 2rem;
}

/* ─── 스켈레톤 로더 (JS 로드 전) ─── */
#skeleton-loader {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  pointer-events: none;
}
.skeleton-cat {
  font-size: 4rem;
  animation: skeletonPulse 1.2s ease-in-out infinite;
  margin-bottom: 12px;
}
.skeleton-text {
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.4);
  font-weight: bold;
  animation: skeletonPulse 1.2s ease-in-out infinite 0.3s;
}
@keyframes skeletonPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

/* ============================================ */
/* 0. Base Reset + Game Container               */
/* ============================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: #1a1a1a;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  font-family: 'Jua', 'Nunito', sans-serif;
}

/* ============================================ */
/* Game Container — 모바일 비율 고정 + dvh     */
/* ============================================ */
#game-container {
  width: 100%;
  max-width: 450px;
  height: 100vh;
  height: 100dvh;
  background: linear-gradient(180deg, #87CEEB 0%, #B0E0FF 22%, #98d85a 45%, #7ec850 58%, #5da83a 100%);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

/* ─── 배경 레이어: 구름 ─── */
#game-container::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 30%;
  z-index: 1;
  pointer-events: none;
  background:
    /* 구름 1 — 왼쪽 큰 구름 */
    radial-gradient(ellipse 80px 30px at 15% 20%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(ellipse 60px 22px at 22% 18%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(ellipse 50px 18px at 10% 22%, rgba(255,255,255,0.25) 0%, transparent 100%),
    /* 구름 2 — 오른쪽 */
    radial-gradient(ellipse 70px 25px at 75% 12%, rgba(255,255,255,0.3) 0%, transparent 100%),
    radial-gradient(ellipse 50px 18px at 82% 10%, rgba(255,255,255,0.25) 0%, transparent 100%),
    /* 구름 3 — 중앙 작은 구름 */
    radial-gradient(ellipse 40px 14px at 50% 25%, rgba(255,255,255,0.2) 0%, transparent 100%),
    /* 구름 4 — 왼쪽 끝 살짝 */
    radial-gradient(ellipse 55px 20px at 5% 10%, rgba(255,255,255,0.2) 0%, transparent 100%);
  animation: cloudsDrift 35s linear infinite;
}

@keyframes cloudsDrift {
  0% { transform: translateX(0); }
  50% { transform: translateX(8px); }
  100% { transform: translateX(0); }
}

/* ─── 배경 레이어: 울타리 ─── */
#game-container::after {
  content: '';
  position: absolute;
  bottom: 32%;
  left: 0;
  right: 0;
  height: 20px;
  z-index: 2;
  pointer-events: none;
  background:
    /* 울타리 기둥 */
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 22px,
      #8B5E3C 22px,
      #A0704C 24px,
      #8B5E3C 26px,
      transparent 26px,
      transparent 48px
    ),
    /* 울타리 가로대 위 */
    repeating-linear-gradient(
      90deg,
      transparent 0px,
      transparent 5px,
      #A0704C 5px,
      #8B5E3C 7px,
      transparent 7px,
      transparent 48px
    );
  background-size: 48px 20px, 48px 4px;
  background-repeat: repeat-x;
  background-position: 0 10px, 0 3px;
  mask-image: linear-gradient(90deg, transparent 3%, black 10%, black 90%, transparent 97%);
  -webkit-mask-image: linear-gradient(90deg, transparent 3%, black 10%, black 90%, transparent 97%);
}

/* ─── 잔디 디테일 (작은 풀잎) ─── */
.grass-blade {
  position: absolute;
  bottom: 28%;
  z-index: 2;
  pointer-events: none;
  width: 4px;
  height: 12px;
  background: linear-gradient(to top, #5da83a, #7ec850);
  border-radius: 50% 50% 0 0;
  transform-origin: bottom center;
}

.grass-blade:nth-child(odd) {
  transform: rotate(-8deg);
}
.grass-blade:nth-child(even) {
  transform: rotate(8deg);
}

/* ─── Game Container 원래 속성 (중복 제거됨) ─── */

/* ============================================ */
/* 1. Top HUD — 좌측 스택 + 우측 재화          */
/* 1. Top HUD — 좌측 스택 + 우측 재화, flex-shrink:0 */
#top-hud {
  flex-shrink: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 12px;
  padding-top: max(env(safe-area-inset-top, 0px), 10px);
  pointer-events: none;
}

/* 좌측 — 3줄 스택 (컨테이너 50% 너비) */
#stats-stack {
  width: 50%;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-icon {
  font-size: var(--fs-sm);
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
  white-space: nowrap;
}

.stat-bar-bg {
  flex: 1;
  height: 10px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.stat-bar-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: linear-gradient(90deg, #FF6B6B, #FF8E8E);
  box-shadow: 0 0 6px rgba(255, 107, 107, 0.4);
}

/* 우측 — 생선 카운터 */
#hud-fish {
  font-size: var(--fs-xl);
  font-weight: 800;
  color: #FFD700;
  background: rgba(0, 0, 0, 0.3);
  padding: 5px 14px;
  border-radius: 20px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  backdrop-filter: blur(4px);
}

#hud-fish span {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
}

/* ─── HUD BGM 버튼 (상단 우측) ─── */
.bgm-hud-btn {
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  pointer-events: auto;
  backdrop-filter: blur(4px);
  transition: all 0.15s ease;
  margin-left: 6px;
  font-family: inherit;
  touch-action: manipulation;
}
.bgm-hud-btn:active {
  transform: scale(0.88);
  background: rgba(0, 0, 0, 0.5);
}
.bgm-hud-btn.off {
  opacity: 0.4;
  color: #666 !important;
  border-color: rgba(255, 255, 255, 0.08);
}

/* ============================================ */
/* 2. Center Stage                              */
/* 2. Center Stage — flex:1, 남는 공간 유동 */
#center-stage {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
  position: relative;
}

/* 고양이 터치 영역 */
#cat-hitarea {
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  touch-action: none;
  -webkit-touch-callout: none;
  z-index: 12;
  margin-bottom: 10px;
}

.cat-sprite {
  width: 260px;
  height: 260px;
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(0 6px 20px rgba(0, 0, 0, 0.2));
  /* Idle 숨쉬기 — 3초 주기 미세 위아래 + 크기 변화 */
  animation: breathe 3s ease-in-out infinite;
  pointer-events: none;
  -webkit-user-drag: none;
  will-change: transform;
}

/* 숨쉬기 애니메이션 */
@keyframes breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-4px) scale(1.02); }
}

.cat-sprite.pressed {
  /* 찌그러짐 스쿼시 — 0.2초간 덮어쓰기 */
  animation: squish 0.2s ease-out !important;
}

@keyframes squish {
  0% { transform: scale(1.1, 0.9); }
  60% { transform: scale(1.05, 0.95); }
  100% { transform: translateY(0) scale(1); }
}

.cat-sprite.idle {
  animation: breathe 3s ease-in-out infinite;
}

/* ─── 고양이 래퍼 (이모지 + 캐릭터 묶음) ─── */
.cat-wrapper {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}

/* ─── 무무 상태 이모지 (고양이 머리 위 절대 고정) ─── */
#mumu-emotion {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 3rem;
  z-index: 10;
  pointer-events: none;
  text-shadow: 0px 4px 10px rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
#mumu-emotion.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}
#mumu-emotion.urgent {
  animation: mumuShake 0.5s ease-in-out infinite;
}
@keyframes mumuShake {
  0%, 100% { transform: translateX(-50%) translateY(-4px); }
  25% { transform: translateX(calc(-50% + 5px)) translateY(-4px); }
  75% { transform: translateX(calc(-50% - 5px)) translateY(-4px); }
}

@keyframes catIdle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* 안내 텍스트 — 고양이 위쪽 */
#hint-text {
  font-size: var(--fs-lg);
  color: #fff;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6);
  font-weight: bold;
  text-align: center;
  z-index: 11;
  margin-bottom: 150px;
  animation: hintPulse 2.5s ease-in-out infinite;
  opacity: 0.7;
  letter-spacing: 1px;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.9; }
}

/* ============================================ */
/* 3. Bottom Navigation Bar                     */
/* 3. Bottom Navigation Bar — flex-shrink:0 + Safe Area */
#bottom-nav {
  flex-shrink: 0;
  height: 80px;
  z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
}

/* ─── 액션 버튼 (쫀득한 프레스 애니메이션) ─── */
.action-button {
  flex: 1;
  height: 54px;
  margin: 0 3px;
  font-size: 1.1rem;
  font-weight: bold;
  border-radius: 16px;
  border: none;
  background: linear-gradient(135deg, rgba(255,255,255,0.15), rgba(255,255,255,0.08));
  color: #fff;
  cursor: pointer;
  transition: transform 0.08s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.08s ease;
  box-shadow: 0 6px 0 rgba(0,0,0,0.3);
  font-family: 'Jua', 'Nunito', sans-serif;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  -webkit-tap-highlight-color: transparent;
}
.action-button:active {
  transform: translateY(4px) scale(0.95);
  box-shadow: 0 2px 0 rgba(0,0,0,0.3);
}

/* ============================================ */
/* 4. 모달 (상점 / 업적)                        */
/* 4. 모달 (상점 / 업적) — absolute 기준 game-container */
#shop-overlay,
#achieve-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  animation: modalIn 0.2s ease-out;
}

#shop-overlay.open,
#achieve-overlay.open {
  display: flex;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

#shop-panel,
#achieve-panel {
  background: linear-gradient(135deg, #2d3436, #636e72);
  border-radius: 24px;
  padding: 0;
  width: 90%;
  max-width: 380px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  border: 2px solid rgba(255, 255, 255, 0.08);
}

#shop-panel::-webkit-scrollbar,
#achieve-panel::-webkit-scrollbar {
  display: none;
}

#shop-panel-header,
#achieve-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 10px;
  font-size: 1.2rem;
  font-weight: bold;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, #2d3436, #636e72);
  border-radius: 24px 24px 0 0;
}

#shop-close,
#achieve-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
  font-family: inherit;
}

#shop-close:active,
#achieve-close:active {
  background: rgba(255, 255, 255, 0.2);
}

#shop-content,
#achieve-content {
  padding: 12px 14px 16px;
}

/* 상점 아이템 */
.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  margin-bottom: 5px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.12s;
  touch-action: manipulation;
}

.shop-item:active {
  background: rgba(255, 255, 255, 0.12);
  transform: scale(0.98);
}

.shop-item.bought {
  opacity: 0.35;
  pointer-events: none;
}

.shop-item-icon {
  font-size: 1.6rem;
  width: 2.4rem;
  text-align: center;
  flex-shrink: 0;
}

.shop-item-info {
  flex: 1;
  min-width: 0;
}

.shop-item-name {
  font-size: var(--fs-md);
  font-weight: bold;
  color: #fff;
  margin-bottom: 2px;
}

.shop-item-desc {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.4);
}

.shop-item-price {
  font-size: var(--fs-md);
  font-weight: 700;
  color: #FFD700;
  white-space: nowrap;
  flex-shrink: 0;
}

/* 업적 아이템 */
.ach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  margin-bottom: 5px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 14px;
}

.ach-item.done {
  background: rgba(243, 156, 18, 0.12);
  border: 1px solid rgba(243, 156, 18, 0.2);
}

.ach-item-icon {
  font-size: 1.4rem;
  width: 2.4rem;
  text-align: center;
  flex-shrink: 0;
}

.ach-item:not(.done) .ach-item-icon {
  filter: grayscale(1);
  opacity: 0.35;
}

.ach-item-info { flex: 1; min-width: 0; }

.ach-item-name {
  font-size: var(--fs-sm);
  font-weight: bold;
  color: #fff;
  margin-bottom: 2px;
}

.ach-item.done .ach-item-name { color: #f39c12; }

.ach-item-desc {
  font-size: var(--fs-xs);
  color: rgba(255, 255, 255, 0.3);
}

.ach-item-badge {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: #f39c12;
  flex-shrink: 0;
}

/* ============================================ */
/* 5. 플로팅 텍스트 (터치 효과)                */
/* ============================================ */
.floating-text {
  position: fixed;
  z-index: 100;
  color: #FFD700;
  font-weight: bold;
  font-size: var(--fs-xl);
  pointer-events: none;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  animation: floatUp 0.8s ease-out forwards;
  font-family: 'Nunito', sans-serif;
}

@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(0.5); }
  40% { opacity: 1; transform: translateY(-30px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-60px) scale(0.7); }
}

/* ============================================ */
/* 6. 업적 알림 토스트                          */
/* ============================================ */
#ach-toast {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #f39c12, #e67e22);
  border-radius: 14px;
  padding: 8px 18px;
  box-shadow: 0 4px 20px rgba(243, 156, 18, 0.4);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) translateY(-20px) scale(0.8);
  white-space: nowrap;
}

#ach-toast.show {
  opacity: 1 !important;
  transform: translateX(-50%) translateY(0) scale(1) !important;
}

#ach-toast-icon { font-size: var(--fs-lg); }
#ach-toast-text { font-size: var(--fs-sm); font-weight: bold; color: #fff; }

/* ============================================ */
/* 7. 돌발 이벤트                               */
/* ============================================ */
#event-obj {
  position: absolute;
  z-index: 60;
  pointer-events: auto;
  cursor: pointer;
  touch-action: none;
  display: none;
}
#event-obj.visible { display: block; }

#event-emoji {
  font-size: 2.4rem;
  filter: drop-shadow(0 0 14px rgba(255, 215, 0, 0.6));
  animation: eventPulse 0.3s ease-in-out infinite alternate;
}

@keyframes eventPulse {
  from { transform: scale(1); }
  to { transform: scale(1.15); }
}

#event-timer {
  position: absolute;
  top: -1.4rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: #FFD700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}

/* ============================================ */
/* 8. 폭죽 파티클                               */
/* ============================================ */
.firework {
  position: fixed;
  font-size: 0.9rem;
  pointer-events: none;
  z-index: 55;
  animation: fireworkAnim 1s ease-out forwards;
}

@keyframes fireworkAnim {
  0% { opacity: 1; transform: translate(0, 0) scale(0.3); }
  100% { opacity: 0; transform: translate(var(--fw-x), var(--fw-y)) scale(1); }
}

/* ============================================ */
/* 8.5 — 액션 파티클 (밥주기/씻기기 피드백)      */
/* ============================================ */
.particle {
  position: absolute;
  pointer-events: none;
  z-index: 50;
  font-size: 1.2rem;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.3));
}

/* 밥주기 생선 — 아래→위 포물선 */
.particle-feed {
  animation: particleFeed 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes particleFeed {
  0% { opacity: 1; transform: translateY(0) scale(0.5); }
  40% { opacity: 1; transform: translate(var(--tx), -80px) scale(1.1); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0.8); }
}

/* 씻기기 비눗방울 — 위로 퐁퐁 + 터짐 */
.particle-bubble {
  animation: particleBubble 1.2s ease-out forwards;
}

@keyframes particleBubble {
  0% { opacity: 1; transform: translateY(0) scale(0.3); }
  30% { opacity: 1; transform: translateY(-30px) scale(1.2); }
  60% { opacity: 0.8; transform: translateY(-60px) scale(1.4); }
  100% { opacity: 0; transform: translateY(-90px) scale(1.8); }
}

/* ============================================ */
/* 9. 오프라인 팝업                             */
/* ============================================ */
.offline-popup {
  position: absolute;
  bottom: 30%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  background: rgba(0, 0, 0, 0.85);
  color: #FFD700;
  padding: 14px 20px;
  border-radius: 16px;
  font-size: var(--fs-sm);
  font-weight: bold;
  text-align: center;
  line-height: 1.5;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: popIn 0.3s ease-out;
  white-space: nowrap;
}

@keyframes popIn {
  from { opacity: 0; transform: translateX(-50%) scale(0.8); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}
