@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

:root {
  --sage: #d8d8a3;
  --peach: #ffe1c5;
  --cream: #ffedcc;
  --brown: #b29586;
  --brownDark: #8a6e62;
  --white: #fffdf8;
  --shadow: rgba(178, 149, 134, 0.25);
  --shadowMd: rgba(178, 149, 134, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Nunito', sans-serif;
  background-color: var(--cream);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(216, 216, 163, 0.3) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(255, 225, 197, 0.4) 0%, transparent 50%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* ── Phone Shell ── */
.phoneShell {
  position: relative;
  width: 360px;
  height: 720px;
  background: var(--white);
  border-radius: 44px;
  box-shadow:
    0 8px 32px var(--shadowMd),
    0 2px 8px var(--shadow),
    inset 0 1px 0 rgba(255,255,255,0.9);
  overflow: hidden;
  border: 3px solid var(--peach);
}

/* notch */
.phoneShell::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 100px; height: 28px;
  background: var(--peach);
  border-radius: 0 0 20px 20px;
  z-index: 10;
}

/* ── Background Scene ── */
.sceneBg {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #fff8ef 0%, #ffedcc 60%, #ffe1c5 100%);
}

/* Floating bubbles */
.bubble {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  border: 1.5px solid rgba(255, 225, 197, 0.8);
  animation: floatBubble 4s ease-in-out infinite;
}
.bubble:nth-child(1) { width: 18px; height: 18px; top: 15%; left: 12%; animation-delay: 0s; }
.bubble:nth-child(2) { width: 12px; height: 12px; top: 30%; right: 18%; animation-delay: 1.2s; }
.bubble:nth-child(3) { width: 22px; height: 22px; top: 55%; left: 8%; animation-delay: 0.7s; }
.bubble:nth-child(4) { width: 10px; height: 10px; top: 68%; right: 10%; animation-delay: 2s; }

@keyframes floatBubble {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.6; }
  50% { transform: translateY(-10px) scale(1.05); opacity: 1; }
}

/* Floor */
.sceneFloor {
  position: absolute;
  bottom: 110px; left: 0; right: 0;
  height: 120px;
  background: linear-gradient(180deg, transparent 0%, rgba(216,216,163,0.15) 100%);
}

/* Rug */
.sceneRug {
  position: absolute;
  bottom: 130px;
  left: 50%; transform: translateX(-50%);
  width: 160px; height: 60px;
  background: radial-gradient(ellipse, #f5e6d3 60%, #ecdcc8 100%);
  border-radius: 50%;
  border: 3px solid rgba(178,149,134,0.3);
  box-shadow: 0 4px 12px var(--shadow);
}

/* ── Top Bar ── */
.topBar {
  position: absolute;
  top: 32px; left: 0; right: 0;
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 18px;
  z-index: 5;
}

.btnBack {
  width: 36px; height: 36px;
  background: var(--white);
  border: 2px solid var(--peach);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}
.btnBack:hover { transform: scale(1.08); box-shadow: 0 4px 12px var(--shadowMd); }
.btnBack svg { width: 16px; height: 16px; stroke: var(--brownDark); }

.petNameWrapper {
  flex: 1;
  display: flex;
  justify-content: center;
}

.petName {
  font-size: 17px;
  font-weight: 800;
  color: var(--brownDark);
  background: var(--white);
  border: 2px solid var(--peach);
  border-radius: 20px;
  padding: 4px 18px;
  box-shadow: 0 2px 8px var(--shadow);
  letter-spacing: 1px;
}

/* ── Stats Cluster ── */
.statsCluster {
  position: absolute;
  top: 80px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  z-index: 5;
}

.gemRow {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--white);
  border: 2px solid var(--sage);
  border-radius: 20px;
  padding: 4px 10px;
  box-shadow: 0 2px 8px var(--shadow);
}
.gemIcon { font-size: 14px; }
.gemValue {
  font-size: 13px;
  font-weight: 700;
  color: var(--brownDark);
  min-width: 28px;
  text-align: right;
  transition: transform 0.2s;
}

.statCard {
  background: var(--white);
  border: 2px solid var(--peach);
  border-radius: 14px;
  padding: 6px 10px;
  min-width: 110px;
  box-shadow: 0 2px 8px var(--shadow);
}

.statLabel {
  font-size: 10px;
  font-weight: 700;
  color: var(--brown);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.statLabel span { font-size: 12px; }

.barTrack {
  width: 100%;
  height: 8px;
  background: var(--cream);
  border-radius: 10px;
  overflow: hidden;
  border: 1.5px solid rgba(178,149,134,0.2);
}
.barFill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.5s ease;
}
.barFillExp {
  width: 0%;
  background: linear-gradient(90deg, var(--sage), #c4c47a);
}
.barFillHunger {
  width: 0%;
  background: linear-gradient(90deg, var(--peach), #ffb07c);
}

/* 數字顯示 */
.statNum {
  font-size: 9px;
  font-weight: 700;
  color: var(--brown);
  text-align: right;
  margin-top: 2px;
  letter-spacing: 0.3px;
}

/* ── Pet Character ── */
.petWrapper {
  position: absolute;
  bottom: 130px;
  left: 50%; transform: translateX(-50%);
  z-index: 6;
  animation: petBob 2.5s ease-in-out infinite;
  cursor: pointer;
}
.petWrapper:hover 

.petCharacter { transform: scale(1.06); }

@keyframes petBob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-8px); }
}

.petLayerWrap {
  position: relative;
  width: 110px;
  height: 110px;
  filter: drop-shadow(0 6px 12px rgba(178,149,134,0.35));
}

.petLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* deco 可以沒圖，隱藏空的 img */
.petLayerDeco[src=""] {
  display: none;
}

.petSpeech {
  position: absolute;
  bottom: 115px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  min-width: 80px;
  max-width: 160px;
  padding: 8px 12px;
  background: #fffdf8;
  color: var(--brownDark);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  border: 2px solid var(--peach);
  border-radius: 16px;
  box-shadow: 0 4px 12px var(--shadowMd);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 12;
}

.petSpeech::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%) rotate(45deg);
  width: 12px;
  height: 12px;
  background: #fffdf8;
  border-right: 2px solid var(--peach);
  border-bottom: 2px solid var(--peach);
}

.petSpeech.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Bottom Action Bar ── */
.actionBar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 110px;
  background: linear-gradient(180deg, rgba(255,237,204,0) 0%, var(--cream) 30%);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 24px 18px;
  z-index: 7;
}

.actionBtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.15s;
}
.actionBtn:hover { transform: translateY(-4px) scale(1.05); }

.actionCircle {
  width: 58px; height: 58px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px var(--shadowMd);
  transition: box-shadow 0.15s;
  border: 2.5px solid rgba(255,255,255,0.8);
}
.actionBtn:hover .actionCircle { box-shadow: 0 6px 18px var(--shadowMd); }

.actionCircleWardrobe {
  background: linear-gradient(135deg, #f5e6d3 0%, var(--peach) 100%);
}
.actionCircleFood {
  background: linear-gradient(135deg, #e8e8b8 0%, var(--sage) 100%);
}

.actionEmoji { font-size: 26px; }

.actionLabel {
  font-size: 11px;
  font-weight: 700;
  color: var(--brownDark);
  letter-spacing: 0.5px;
}

/* ── Tap ripple effect ── */
.petWrapper:active .petCharacter {
  transform: scale(0.93);
}

/* ── Heart pop on pet tap ── */
.heartPop {
  position: absolute;
  top: -20px; left: 100%; transform: translateX(-50%);
  font-size: 20px;
  pointer-events: none;
  animation: heartFloat 0.9s ease forwards;
  display: none;
}
.heartPop.active { display: block; }

@keyframes heartFloat {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(1.4); }
}

/* ══ Modal ══ */
.modalOverlay {
  position: absolute;
  inset: 0;
  background: rgba(178, 149, 134, 0.38);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.modalOverlay.active {
  opacity: 1;
  pointer-events: all;
}
.modalOverlay.closing .modalBox {
  transform: translateY(100%);
}

.modalBox {
  width: 100%;
  background: var(--white);
  border-radius: 28px 28px 0 0;
  padding: 0 0 24px;
  box-shadow: 0 -6px 32px var(--shadowMd);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.34, 1.3, 0.64, 1);
  max-height: 72%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modalOverlay.active .modalBox {
  transform: translateY(0);
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  flex-shrink: 0;
}

.modalTitle {
  font-size: 16px;
  font-weight: 800;
  color: var(--brownDark);
  letter-spacing: 0.5px;
}
.modalClose {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--peach);
  background: var(--cream);
  color: var(--brownDark);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  transition: transform 0.15s, background 0.15s;
  box-shadow: 0 2px 6px var(--shadow);
}
.modalClose:hover {
  transform: scale(1.12) rotate(8deg);
  background: var(--peach);
}

/* ── Item Grid ── */
.modalGrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 16px 16px 8px;
  overflow-y: auto;
  max-height: 240px;
}

.itemCard {
  position: relative;
  background: var(--cream);
  border: 2px solid var(--peach);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 8px 4px 6px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 6px var(--shadow);
  min-height: 82px;
}
.itemCard:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 6px 14px var(--shadowMd);
}
.itemCard:active {
  transform: scale(0.93);
  background: var(--peach);
}
.itemCard.itemLow {
  background: linear-gradient(135deg, #fff8ef 0%, #ffeedd 100%);
  border-color: var(--sage);
}
.itemCard.itemUsed {
  transform: scale(0.88);
  background: var(--peach);
}

.itemEmoji {
  font-size: 26px;
  line-height: 1;
  margin-bottom: 2px;
}
.itemBadge {
  position: absolute;
  top: 5px; right: 6px;
  background: var(--sage);
  color: var(--brownDark);
  font-size: 9px;
  font-weight: 800;
  border-radius: 8px;
  padding: 1px 5px;
  line-height: 1.4;
}
.badgeLow {
  background: var(--peach);
  color: var(--brownDark);
}
.itemName {
  font-size: 10px;
  font-weight: 700;
  color: var(--brownDark);
  text-align: center;
  line-height: 1.2;
}

/* 食物費用標籤 */
.itemCost {
  font-size: 8.5px;
  font-weight: 700;
  color: #a07a6a;
  margin-top: 1px;
  letter-spacing: 0.2px;
}
.itemCostLow {
  color: #c0905a;
}

/* ── Feed Effect ── */
.feedEffect {
  position: absolute;
  left: 50%;
  bottom: 200px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  animation: feedFloat 1.2s ease forwards;
  z-index: 30;
}
.feedEmoji {
  font-size: 28px;
  filter: drop-shadow(0 2px 6px rgba(178,149,134,0.5));
}
.feedGain {
  font-size: 11px;
  font-weight: 800;
  color: var(--brownDark);
  background: var(--white);
  border: 1.5px solid var(--peach);
  border-radius: 12px;
  padding: 2px 8px;
  white-space: nowrap;
  box-shadow: 0 2px 8px var(--shadow);
}

@keyframes feedFloat {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-60px) scale(1.1); }
}

/* ── Toast ── */
.gameToast {
  position: absolute;
  bottom: 130px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--brownDark);
  color: #fffdf8;
  font-size: 12px;
  font-weight: 700;
  border-radius: 20px;
  padding: 6px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 40;
  white-space: nowrap;
  box-shadow: 0 4px 12px var(--shadowMd);
}
.gameToast.toastActive {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#petAccessory {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  font-size: 36px;
  z-index: 10;
}

.itemCard.itemSelected {
  border-color: var(--brownDark);
  background: var(--peach);
  box-shadow: 0 4px 12px var(--shadowMd);
}

/* 把寵物圖縮進 itemEmoji 區域 */
.itemPetThumb {
  width: 38px;
  height: 38px;
  position: relative;
  margin-bottom: 2px;
}

.itemPetThumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ── Wardrobe Tabs ── */
.modalTabs {
  display: flex;
  gap: 8px;
  padding: 0 20px 12px;
  flex-shrink: 0;
}

.modalTab {
  flex: 1;
  padding: 6px 0;
  border-radius: 12px;
  border: 2px solid var(--peach);
  background: var(--cream);
  color: var(--brown);
  font-size: 12px;
  font-weight: 700;
  font-family: 'Nunito', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
}

.modalTab:hover {
  background: var(--peach);
  color: var(--brownDark);
}

.modalTab.tabActive {
  background: var(--brownDark);
  color: var(--white);
  border-color: var(--brownDark);
}

/* ── Wardrobe Panels ── */
.wardrobePanel {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 4px 16px 8px;
  overflow-y: auto;
  max-height: 240px;
}

.wardrobePanel.panelActive {
  display: grid;
}