/* home.css — 홈(서식지) 화면 */

/* ── 알(온보딩) ─────────────────────── */
.egg-view {
  position: absolute;
  left: 20px;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  z-index: 5;
}

.egg-onboard-img {
  width: 120px;
  height: auto;
  margin: 0 auto;
  animation: egg-wobble 2.4s ease-in-out infinite;
  filter: drop-shadow(0 4px 4px rgba(20, 18, 10, 0.25));
}

.egg-guide {
  margin: 16px 0 20px;
  color: var(--color-text-sub);
  line-height: 1.6;
}

@keyframes egg-wobble {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-6deg); }
  75%      { transform: rotate(6deg); }
}

/* ── 서식지 (상단 영역 전체) ────────── */
#snail-view {
  position: absolute;
  inset: 0;
}

.snail-habitat {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: pointer;
  /* none: 브라우저 팬/줌이 제스처를 가로채면 드래그가 pointercancel로 끊긴다 (13차 Phase 3) */
  touch-action: none;
  /* 배경은 body가 그린다 — 서식지는 투명 */
  background: transparent;
}

/* 날씨 오버레이 (body[data-weather] 기준) */
.snail-habitat::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease;
}

body[data-weather="rain"] .snail-habitat::before {
  opacity: 0.5;
  /* 굵기 다른 빗줄기 2겹 — 얕은 시차감 */
  background:
    repeating-linear-gradient(75deg, transparent 0 10px, rgba(235, 242, 255, 0.55) 10px 11px),
    repeating-linear-gradient(75deg, transparent 0 23px, rgba(235, 242, 255, 0.3) 23px 25px);
  animation: rain-fall 0.45s linear infinite;
}

/* 비 갠 직후 무지개 (data-rainbow — 슬롯 전환 첫 1시간, 맑음일 때만) */
body[data-rainbow="1"] .snail-habitat::before {
  opacity: 0.55;
  background: radial-gradient(ellipse 130% 95% at 50% 128%,
    transparent 55%,
    rgba(235, 120, 110, 0.30) 56.5%,
    rgba(240, 185, 95, 0.30) 58.5%,
    rgba(240, 230, 140, 0.28) 60.5%,
    rgba(150, 205, 145, 0.28) 62.5%,
    rgba(130, 170, 230, 0.28) 64.5%,
    rgba(170, 140, 215, 0.26) 66.5%,
    transparent 68%);
  animation: rainbow-in 2.5s ease;
}

@keyframes rainbow-in {
  from { opacity: 0; }
  to   { opacity: 0.55; }
}

body[data-weather="fog"] .snail-habitat::before {
  opacity: 1;
  background: linear-gradient(180deg,
    rgba(255, 255, 255, 0.34),
    rgba(255, 255, 255, 0.12) 55%,
    rgba(255, 255, 255, 0.28));
}

@keyframes rain-fall {
  from { background-position: 0 0; }
  to   { background-position: -15px 56px; }
}

/* 점액 트레일 (Phase 5) — 달팽이 아래(z1), 서서히 사라진다 */
.slime-dot {
  position: absolute;
  width: 7px;
  height: 5px;
  border-radius: 50%;
  background: rgba(215, 235, 200, 0.4);
  z-index: 1;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: slime-fade 6s linear forwards;
}

@keyframes slime-fade {
  0%   { opacity: 0.9; }
  100% { opacity: 0; }
}

/* 두리번/하품 모션 (Phase 5) — motion 레이어에 잠깐 얹는 peek */
.snail-entity .snail-motion.peek {
  animation: snail-peek 1.3s ease-in-out;
}

@keyframes snail-peek {
  0%, 100% { transform: rotate(0deg); }
  25%      { transform: rotate(-6deg) translateY(-2px); }
  60%      { transform: rotate(5deg) translateY(-1px); }
}

/* 방문객 (나비/무당벌레/반딧불이) — 연출 전용, 클릭 통과 */
.visitor {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  transform: scaleX(var(--vflip, 1));
  filter: drop-shadow(0 2px 2px rgba(20, 18, 10, 0.2));
}

/* transform은 좌우 반전이 쓰므로 상하 모션은 margin으로 */
.visitor-butterfly {
  animation: visitor-flutter 0.9s ease-in-out infinite alternate;
}

@keyframes visitor-flutter {
  from { margin-top: -7px; }
  to   { margin-top: 7px; }
}

.visitor-ladybug {
  animation: visitor-waddle 0.5s ease-in-out infinite alternate;
}

@keyframes visitor-waddle {
  from { margin-top: 0; }
  to   { margin-top: -2px; }
}

.visitor-firefly {
  animation: firefly-glow 1.6s ease-in-out infinite alternate,
             visitor-flutter 2.8s ease-in-out infinite alternate;
}

@keyframes firefly-glow {
  from {
    filter: drop-shadow(0 0 3px rgba(255, 235, 130, 0.5));
    opacity: 0.55;
  }
  to {
    filter: drop-shadow(0 0 10px rgba(255, 235, 130, 0.95));
    opacity: 1;
  }
}

/* 바닥 디테일은 일러스트 배경이 담당한다 */

/*
 * 3계층 분리 (2차_MVP_구현계획.md §3)
 * entity: 좌표 이동(translate3d) · motion: 들썩임/먹기 · sprite: 크기/좌우 반전
 */
#snail-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.snail-entity {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
  pointer-events: none;
}

/* 서식지 알 오브젝트 (터치 → 이름 짓기) */
.egg-item {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  pointer-events: auto;
}

.egg-item-img {
  width: 46px;
  height: auto;
  animation: egg-wobble 2.4s ease-in-out infinite;
  filter: drop-shadow(0 2px 2px rgba(20, 18, 10, 0.25));
  -webkit-user-drag: none;
}

.egg-item-label {
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  background: rgba(45, 52, 40, 0.65);
  padding: 2px 8px;
  border-radius: 999px;
}

#food-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.snail-sprite {
  display: block;
  line-height: 1;
  transform: scaleX(var(--flip, 1));
}

.snail-entity .snail-motion {
  animation: snail-bob 3s ease-in-out infinite;
}

.snail-entity.state-wandering .snail-motion,
.snail-entity.state-seeking_food .snail-motion {
  animation: snail-crawl 0.9s ease-in-out infinite;
}

.snail-entity.state-eating .snail-motion {
  animation: snail-eat 0.45s ease-in-out infinite;
}

.snail-entity.state-napping .snail-motion {
  animation: snail-nap 3.2s ease-in-out infinite;
}

/* 드래그(집어 옮기기) — 들어올린 느낌: 모션 정지 + 그림자 깊게 */
.snail-entity.state-dragging {
  z-index: 5;
}

.snail-entity.state-dragging .snail-motion {
  animation: none;
}

.snail-entity.state-dragging .snail-img {
  filter: drop-shadow(0 10px 8px rgba(20, 18, 10, 0.35));
}

@keyframes snail-nap {
  0%, 100% { transform: scaleY(1); }
  50%      { transform: scaleY(0.94) translateY(2px); }
}


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

@keyframes snail-crawl {
  0%, 100% { transform: translateX(0) scaleY(1); }
  50%      { transform: translateX(2px) scaleY(0.95); }
}

@keyframes snail-eat {
  0%, 100% { transform: translateX(0); }
  50%      { transform: translateX(4px); }
}

/* 일러스트 스프라이트 — 성장 단계별 크기 */
.snail-img {
  display: block;
  height: auto;
  filter: drop-shadow(0 3px 3px rgba(20, 18, 10, 0.28));
  transition: filter 0.5s ease, transform 0.5s ease;
  pointer-events: none;
  -webkit-user-drag: none;
}

.snail-sprite.stage-baby .snail-img { width: 36px; }
.snail-sprite.stage-junior .snail-img { width: 52px; }
.snail-sprite.stage-adult .snail-img { width: 68px; }

/* 머리 위 스탯 배지 (배고픔/행복) */
.snail-badge {
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  background: rgba(45, 52, 40, 0.55);
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
}

/* 컨디션: 배고프면 시무룩(채도 다운 + 살짝 처짐), 행복하면 생기 */
.snail-sprite.cond-hungry .snail-img {
  filter: drop-shadow(0 3px 3px rgba(20, 18, 10, 0.28)) saturate(0.68) brightness(0.94);
  transform: rotate(-4deg) translateY(2px);
}

.snail-sprite.cond-happy .snail-img {
  filter: drop-shadow(0 3px 3px rgba(20, 18, 10, 0.28)) saturate(1.12) brightness(1.04);
}

/* 레어(연못) 변이: 은은한 반짝임 */
.snail-sprite.variant-pond .snail-img {
  animation: rare-glow 2.6s ease-in-out infinite;
}

@keyframes rare-glow {
  0%, 100% {
    filter: drop-shadow(0 3px 3px rgba(20, 18, 10, 0.28))
            drop-shadow(0 0 5px rgba(140, 200, 170, 0.45));
  }
  50% {
    filter: drop-shadow(0 3px 3px rgba(20, 18, 10, 0.28))
            drop-shadow(0 0 12px rgba(140, 200, 170, 0.9));
  }
}

.snail-sprite.pop {
  animation: sprite-pop 0.5s ease;
}

@keyframes sprite-pop {
  0%   { transform: scaleX(var(--flip, 1)) scale(1); }
  40%  { transform: scaleX(var(--flip, 1)) scale(1.25); }
  100% { transform: scaleX(var(--flip, 1)) scale(1); }
}

/* ── 홈 오버레이 (칩/FAB) ───────────── */
.home-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.chip {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: none;
  border-radius: 999px;
  background: var(--color-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text);
  pointer-events: auto;
}

.chip i {
  color: var(--color-primary-dark);
  font-size: 12px;
}

.chip-left {
  left: 12px;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  cursor: pointer;
  text-align: left;
}

.chip-gauges {
  font-size: 11px;
  color: var(--color-text-sub);
}

.chip-right {
  right: 62px; /* 설정 아이콘 자리만큼 왼쪽으로 */
}

.chip-settings {
  right: 12px;
  padding: 9px 12px;
}
.chip-settings i { font-size: 15px; }

.chip-missions {
  top: auto;
  bottom: 24px;
  left: 12px;
  cursor: pointer;
}

.chip-missions.all-done {
  background: rgba(150, 180, 120, 0.75);
  color: #fff;
}

.chip-missions.all-done i {
  color: #fff;
}

.fab-group {
  position: absolute;
  right: 16px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fab {
  width: 58px;
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  border-radius: 50%;
  background: var(--color-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  color: var(--color-text);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.1s ease;
}

.fab:active {
  transform: scale(0.94);
}

.fab i {
  font-size: 18px;
  color: var(--color-primary-dark);
}

/* ── 먹이 ───────────────────────────── */
.food-item {
  position: absolute;
  line-height: 1;
  transform: translate(-50%, -50%);
  animation: food-drop 0.5s cubic-bezier(0.3, 1.4, 0.6, 1);
}

.food-item svg {
  display: block;
  filter: drop-shadow(0 2px 2px rgba(20, 18, 10, 0.25));
}

/* 먹히는 동안 점점 작아지고 흐려짐 (EAT_DURATION과 맞춤) */
.food-item.eaten {
  transition: transform 1.8s ease, opacity 1.8s ease;
  transform: translate(-50%, -50%) scale(0.2);
  opacity: 0.1;
}

@keyframes food-drop {
  0%   { transform: translate(-50%, -300%); opacity: 0; }
  55%  { transform: translate(-50%, -50%); opacity: 1; }
  75%  { transform: translate(-50%, -85%); }
  100% { transform: translate(-50%, -50%); }
}

/* ── 개체 팝업 ──────────────────────── */
.snail-popup {
  text-align: center;
}

.popup-img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  margin: 0 auto 4px;
  filter: drop-shadow(0 3px 3px rgba(20, 18, 10, 0.25));
}

.popup-img.popup-rare {
  filter: drop-shadow(0 3px 3px rgba(20, 18, 10, 0.25))
          drop-shadow(0 0 8px rgba(140, 200, 170, 0.8));
}

.snail-popup h3 {
  margin: 0 0 2px;
}

.popup-sub {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-sub);
  margin-bottom: 2px !important;
}

.popup-desc {
  font-size: 12px;
  color: var(--color-primary-dark);
  margin-bottom: 6px !important;
}

.popup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.popup-graduate {
  margin-top: 10px;
}

.popup-close {
  margin-top: 10px;
}

/* ── 플로팅 텍스트 (+EXP) ───────────── */
.float-text {
  position: absolute;
  font-size: 14px;
  font-weight: 800;
  color: var(--color-exp);
  pointer-events: none;
  animation: float-up 1.1s ease forwards;
  z-index: 3;
}

@keyframes float-up {
  0%   { transform: translate(-50%, 0); opacity: 0; }
  15%  { opacity: 1; }
  100% { transform: translate(-50%, -28px); opacity: 0; }
}

/* ── 라이브 이벤트 / 공지 배너 ─────────────── */
.live-banner {
  margin: 0 0 10px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, rgba(242, 215, 135, 0.28), rgba(140, 200, 170, 0.22));
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text);
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ── 이모트 잔류 버블 (11차 생태계) ─────────── */
.snail-emote {
  position: absolute;
  transform: translate(-50%, -100%);
  font-size: 18px;
  pointer-events: none;
  z-index: 6;
  animation: emote-pop 0.3s ease, emote-fade 0.4s ease 2.1s forwards;
}
@keyframes emote-pop {
  from { opacity: 0; transform: translate(-50%, -80%) scale(0.6); }
  to   { opacity: 1; transform: translate(-50%, -100%) scale(1); }
}
@keyframes emote-fade { to { opacity: 0; } }

/* ── 밤 오버레이 ─────────────────────────────── */
body[data-daytime="night"] #snail-habitat::after {
  content: '🌙';
  position: absolute;
  inset: 0;
  /* 홈만 색감이 달라 보이지 않게 은은하게 (0.30 → 0.10) — 달 아이콘이 밤의 주 신호 */
  background: rgba(24, 34, 78, 0.10);
  font-size: 22px;
  text-align: right;
  padding: 10px 12px;
  box-sizing: border-box;
  pointer-events: none;
  border-radius: inherit;
  z-index: 3;
}

/* 온보딩 안내 (13차) */
.egg-intro {
  font-size: 13px;
  color: var(--color-text-sub);
  line-height: 1.6;
  margin-top: -4px;
  margin-bottom: 6px;
}
