/* Removed tailwind setup */

:root {
  --font-sans: "System-ui", sans-serif;
}

/* 🛠️ 核心修復：使用 100dvh 與 fixed 鎖定，完美解決 Safari 網址列縮放與排版跑掉的問題 */
html {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background-color: #f8fafc;
}
body {
  margin: 0;
  width: 100%;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app-root {
  position: relative;
  min-height: 100dvh;
  width: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.pb-safe {
  padding-bottom: env(safe-area-inset-bottom);
}
.pt-safe {
  padding-top: env(safe-area-inset-top);
}

/* 🎨 V3.1 全新玻璃擬物特效 (Glassmorphism) */
.glass-panel {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.05);
}

/* 🎬 V3.1 彈出視窗動畫 */
@keyframes modalPop {
  0% {
    transform: scale(0.95);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
.animate-modal {
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* V6.3 導航按鈕 Active 狀態 */
.nav-active {
  transform: scale(1.1) translateY(-2px);
  box-shadow:
    0 0 15px rgba(255, 255, 255, 0.5),
    0 8px 25px rgba(0, 0, 0, 0.15);
  border-color: rgba(255, 255, 255, 0.7) !important;
}

/* --- V6.1 心情動畫系統 --- */
@keyframes breathe {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-4px) scale(1.02);
  }
}
.idle-normal {
  animation: breathe 3s ease-in-out infinite;
}

@keyframes happy-bounce-wiggle {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }
  25% {
    transform: translateY(-12px) rotate(-10deg);
  }
  50% {
    transform: translateY(0) rotate(0deg);
  }
  75% {
    transform: translateY(-6px) rotate(10deg);
  }
}
.idle-happy {
  animation: happy-bounce-wiggle 1.5s ease-in-out infinite;
}

@keyframes sad-droop {
  0%,
  100% {
    transform: translateY(0) rotate(10deg);
  }
  50% {
    transform: translateY(4px) rotate(18deg) scale(0.95);
  }
}
.idle-sad {
  animation: sad-droop 4s ease-in-out infinite;
}

@keyframes hungry-shake {
  0%,
  100% {
    transform: scaleX(1) scaleY(1);
  }
  50% {
    transform: scaleX(1.05) scaleY(0.95) translateY(5px);
  }
}
.idle-hungry {
  animation: hungry-shake 3s ease-in-out infinite;
  filter: grayscale(20%) sepia(10%);
}

/* --- V6.7 生病動畫 --- */
@keyframes sick-shiver {
  0%,
  100% {
    transform: translateX(0) scale(1) translateY(0);
  }
  25% {
    transform: translateX(-3px) scale(0.95) translateY(2px);
  }
  75% {
    transform: translateX(3px) scale(0.95) translateY(2px);
  }
}
.idle-sick {
  animation: sick-shiver 2.5s ease-in-out infinite;
}
.pet-sick .pet-idle {
  filter: grayscale(60%) sepia(20%) brightness(0.85);
}

/* --- V6.2 睡眠系統 --- */
@keyframes sleep-breathe {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}
.idle-sleep {
  animation: sleep-breathe 6s ease-in-out infinite;
}

@keyframes zzz-float {
  0% {
    transform: translateY(0) translateX(0) rotate(0deg);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    transform: translateY(-30px) translateX(10px) rotate(10deg);
    opacity: 0;
  }
}
.sleep-effect {
  position: absolute;
  top: -20px;
  right: -20px;
  font-size: 1.5rem;
  font-weight: bold;
  color: #60a5fa; /* blue-400 */
  opacity: 0;
  pointer-events: none;
}
.idle-sleep .sleep-effect {
  opacity: 1;
  animation: zzz-float 3s ease-in-out infinite 0.5s;
}

/* 寵物核心動畫 (動作) */
.pet {
  transition:
    left 1.5s ease-in-out,
    top 1.5s ease-in-out,
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  will-change: left, top;
}
@keyframes petJump {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  30% {
    transform: translateY(-40px) scale(1.15);
  }
  70% {
    transform: translateY(-10px) scale(1.05);
  }
}
.jumping {
  animation: petJump 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes petWiggle {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  25% {
    transform: rotate(-15deg) scale(1.1);
  }
  75% {
    transform: rotate(15deg) scale(1.1);
  }
}
.wiggling {
  animation: petWiggle 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ⚙️ 設定面板滑入動畫 */
@keyframes slideIn {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

/* 配件尺寸與位置 */
#pet-accessory {
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2.2rem;
  z-index: 20;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
  transition: all 0.3s;
}

/* 盲盒抽獎專屬動畫 */
@keyframes boxShake {
  0%,
  100% {
    transform: rotate(0) scale(1);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: rotate(-10deg) scale(1.1);
  }
  20%,
  40%,
  60%,
  80% {
    transform: rotate(10deg) scale(1.1);
  }
}
@keyframes boxOpen {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.5);
    opacity: 0.5;
    filter: brightness(2);
  }
  100% {
    transform: scale(2);
    opacity: 0;
  }
}
.box-anim {
  animation: boxShake 1.2s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
.box-burst {
  animation: boxOpen 0.5s ease-out forwards;
}

/* V7.6 Interactive Tutorial */
.tutorial-highlight {
  position: relative;
  z-index: 1001; /* Must be higher than the overlay */
  pointer-events: auto !important; /* Allow interaction with the highlighted element */
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.8),
    0 0 0 8px rgba(99, 102, 241, 0.8),
    0 0 30px 10px rgba(99, 102, 241, 0.6);
  border-radius: 1.5rem; /* Match the element's border-radius */
  transition: box-shadow 0.3s ease-in-out;
}

/* V7.4 UX 強化：金幣收集動畫 */
@keyframes coin-collect {
  0% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
  100% {
    transform: scale(0.5) translateY(-80px);
    opacity: 0;
  }
}
.coin-collected {
  animation: coin-collect 0.4s ease-out forwards;
  pointer-events: none;
}

@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translateY(0);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-60px);
  }
}
.float-msg {
  position: absolute;
  animation: floatUp 1.2s ease-out forwards;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
}

/* 場景主題庫 */
.theme-default {
  background: linear-gradient(to bottom, #bbf7d0, #86efac);
}
.theme-space {
  background: url("./images/theme_starry_space_bg.png") no-repeat center/cover;
}
.theme-forest {
  background: linear-gradient(to bottom, #86efac, #14532d);
}
.theme-beach {
  background: linear-gradient(to bottom, #7dd3fc, #fef08a);
}
.theme-castle {
  background: linear-gradient(to bottom, #cbd5e1, #475569);
}
.theme-candy {
  background: url("./images/theme_candy_wonderland_bg.png") no-repeat center/cover;
}

#yard,
.food-item,
.pet-instance {
  touch-action: none;
}

#food-bar {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  gap: 1rem;
}

.food-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  -webkit-user-drag: none;
  min-width: 64px;
  min-height: 64px;
}

.food-item.selected-food {
  box-shadow:
    0 0 0 4px rgba(99, 102, 241, 0.25),
    0 12px 24px rgba(79, 70, 229, 0.2);
  border-color: rgba(99, 102, 241, 0.55) !important;
  transform: translateY(-8px) scale(1.1);
}

#tutorial-overlay {
  overflow: hidden;
}

#tutorial-box {
  width: min(22rem, calc(100vw - 2rem));
  max-width: calc(100vw - 2rem);
  max-height: min(78dvh, 520px);
  overflow-y: auto;
}

.ghost-food {
  position: fixed;
  font-size: 4rem;
  filter: drop-shadow(0 15px 25px rgba(0, 0, 0, 0.3));
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: left, top;
}

@media (max-width: 768px) {
  .text-\[10px\] {
    font-size: 0.75rem !important; /* Force to 12px on small screens */
  }
}

@media (max-width: 480px) {
  #food-bar {
    height: auto;
    min-height: 100px;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.75rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  #game-ui {
    top: max(0.75rem, env(safe-area-inset-top));
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    gap: 0.5rem;
  }

  .food-item {
    width: 62px;
    height: 62px;
    min-width: 62px;
    padding: 0.5rem !important;
    font-size: 2rem !important;
    border-radius: 1.25rem !important;
  }
  
  .glass-panel {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 0.75rem !important;
  }

  .food-cost-label {
    top: -0.3rem !important;
    right: -0.3rem !important;
    font-size: 9px !important;
    padding: 1px 4px !important;
  }

  #tutorial-box {
    padding: 1rem !important;
  }

  /* 縮小頂部狀態欄尺寸以適應窄螢幕 */
  #display-name {
    max-width: 60px !important;
  }
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* 反饋表單專屬：表單元素聚焦時的平滑過渡 */
input,
select,
textarea {
  transition: all 0.3s ease;
}

/* ✨ 餵食特效與粒子噴發系統 ✨ */
.feed-particle {
  pointer-events: none;
  position: absolute;
  z-index: 150;
  font-size: 1.6rem;
  animation: particleFade var(--dur, 0.9s) cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
}

@keyframes particleFade {
  0% {
    transform: translate(0, 0) scale(0.3) rotate(0deg);
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(var(--scale, 1)) rotate(var(--rot, 360deg));
    opacity: 0;
  }
}

.ripple-circle {
  pointer-events: none;
  position: absolute;
  border-radius: 50%;
  z-index: 140;
  transform: translate(-50%, -50%);
  animation: ripple var(--dur, 0.9s) cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
}

@keyframes ripple {
  0% {
    width: 20px;
    height: 20px;
    border: 5px solid var(--ripple-color, rgba(251, 191, 36, 0.9));
    background: var(--ripple-bg, rgba(251, 191, 36, 0.35));
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.4);
    box-shadow: 0 0 15px var(--ripple-color, rgba(251, 191, 36, 0.9));
  }
  100% {
    width: 220px;
    height: 220px;
    border: 1px solid rgba(254, 240, 138, 0);
    background: rgba(254, 240, 138, 0);
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.2);
    box-shadow: 0 0 40px rgba(254, 240, 138, 0);
  }
}

.fav-text-pop {
  pointer-events: none;
  position: absolute;
  z-index: 160;
  font-weight: 900;
  font-family: inherit;
  font-size: 1.6rem;
  color: #fbbf24;
  text-shadow: 0 0 10px rgba(251, 191, 36, 1), 0 0 20px rgba(245, 158, 11, 0.8), 0 3px 6px rgba(0,0,0,0.3);
  transform: translate(-50%, -100%);
  animation: favPop 1.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes favPop {
  0% {
    transform: translate(-50%, 0) scale(0.3) rotate(-20deg);
    opacity: 0;
  }
  25% {
    transform: translate(-50%, -40px) scale(1.4) rotate(10deg);
    opacity: 1;
  }
  40% {
    transform: translate(-50%, -45px) scale(1.2) rotate(-8deg);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -100px) scale(0.7) rotate(0deg);
    opacity: 0;
  }
}

/* 🌙 全站深色模式 (Dark Mode) 套用 */
body.dark-mode {
  background-color: #0f172a !important; /* 深 slate 藍 bg */
  color: #f1f5f9 !important;
  background-blend-mode: multiply !important;
}

/* 卡片與容器覆寫 */
body.dark-mode .bg-white,
body.dark-mode .bg-slate-50,
body.dark-mode .bg-slate-100,
body.dark-mode .bg-amber-50,
body.dark-mode .bg-teal-50,
body.dark-mode .bg-indigo-50 {
  background-color: #1e293b !important; /* slate-800 */
  border-color: #334155 !important;
  color: #f1f5f9 !important;
}

body.dark-mode .glass-panel {
  background: rgba(15, 23, 42, 0.85) !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3) !important;
}

body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode .text-slate-800,
body.dark-mode .text-slate-700,
body.dark-mode .text-slate-600 {
  color: #f8fafc !important; /* ultra light slate */
}

body.dark-mode .text-slate-500,
body.dark-mode .text-slate-400 {
  color: #94a3b8 !important; /* secondary grey Muted */
}

body.dark-mode .border-slate-100,
body.dark-mode .border-slate-200,
body.dark-mode .border-indigo-100,
body.dark-mode .border-amber-200 {
  border-color: #334155 !important;
}

/* Modals 內部覆寫 */
body.dark-mode #settings-modal > div,
body.dark-mode #backpack-modal > div,
body.dark-mode #shop-modal > div,
body.dark-mode #vip-modal > div,
body.dark-mode #achievements-modal > div,
body.dark-mode #leaderboard-modal > div,
body.dark-mode #faq-modal > div,
body.dark-mode #daily-modal > div {
  background-color: #0f172a !important; /* slate-900 bg for modals */
  border-color: #334155 !important;
  color: #f1f5f9 !important;
}

body.dark-mode input[type="text"],
body.dark-mode input[type="range"] {
  background-color: #334155 !important;
  color: #f8fafc !important;
  border-color: #475569 !important;
}

body.dark-mode .text-indigo-600,
body.dark-mode .text-indigo-700 {
  color: #818cf8 !important; /* 適合深色的 indigo */
}

body.dark-mode .text-amber-700 {
  color: #fbbf24 !important;
}

body.dark-mode .text-emerald-700 {
  color: #34d399 !important;
}

body.dark-mode .bg-indigo-600 {
  background-color: #4f46e5 !important;
}

body.dark-mode .hover\:bg-indigo-700:hover {
  background-color: #6366f1 !important;
}

/* 🖼️ 確保 #yard 的動態最低高度及小螢幕底部的充足空間 */
#yard {
  min-height: 50vh;
}

/* 📱 手機版 RWD 優化：當寬度小於 768px 或在小視窗 iframe 中，強制轉為直立排列，防止內容擠壓 */
@media (max-width: 768px) {
  #login-screen {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem !important;
    padding-bottom: 4rem !important;
  }
  #intro-section {
    display: flex !important;
    flex-direction: column !important;
    order: 2 !important;
  }
}

/* 保障整個頁面及 body 在所有裝置上滾動條不被隱藏 */
html, body {
  overflow-y: auto !important;
  height: auto !important;
  min-height: 100dvh;
}

@keyframes floatUpAndFade {
  0% {
    transform: translateY(10px) scale(0.6);
    opacity: 0;
  }
  20% {
    transform: translateY(-20px) scale(1.15);
    opacity: 1;
  }
  80% {
    transform: translateY(-40px) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(-65px) scale(0.8);
    opacity: 0;
  }
}

.mood-bubble-anim {
  animation: floatUpAndFade 2.2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}



