:root {
  --bg: #03040a;
  --card: #111421;
  --panel-border: #1f2937;
  --accent: #d8b4fe;
  --green: #4ade80;
  --yellow: #f59e0b;
  --bloodshot: #ef4444;
  --gold: #facc15;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body {
  margin: 0;
  background: var(--bg);
  color: #e5e7eb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 420px;
  min-height: 100vh;
  padding: 20px 20px 90px 20px; /* Space at bottom for fixed nav bar */
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  text-transform: uppercase;
}

.level-badge {
  background: rgba(216, 180, 254, 0.1);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8em;
  border: 1px solid var(--panel-border);
  font-weight: 600;
}

.coin-badge {
  background: rgba(250, 204, 21, 0.1);
  color: var(--gold);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85em;
  border: 1px solid rgba(250, 204, 21, 0.3);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Page Toggling */
.page { 
  display: flex; 
  flex-direction: column; 
  gap: 16px; 
  width: 100%;
}

.page.hidden { 
  display: none !important; 
}

/* Room Styling */
.pet-room {
  background: radial-gradient(circle, #1a2238 0%, var(--bg) 100%);
  border-radius: 28px;
  height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: inset 0 0 50px rgba(0,0,0,0.8), 0 10px 30px rgba(0,0,0,0.6);
  border: 1px solid var(--panel-border);
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.pet-room.drag-hover {
  border-color: var(--green);
  box-shadow: inset 0 0 50px rgba(74, 222, 128, 0.2), 0 10px 30px rgba(0,0,0,0.6);
}

#cj-avatar-container {
  width: 200px;
  height: 200px;
  cursor: pointer;
  animation: floatBreathing 4s ease-in-out infinite;
  transition: transform 0.2s ease, filter 0.3s ease;
}

.eating { animation: chewAnimation 0.4s ease-in-out 3 !important; }

@keyframes chewAnimation {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.08, 0.92) translateY(5px); }
}

@keyframes floatBreathing {
  0%, 100% { transform: translateY(0px) scale(1); }
  50% { transform: translateY(-8px) scale(1.02); }
}

.mood-chip {
  position: absolute; top: 15px; right: 15px;
  background: var(--card); padding: 6px 14px; border-radius: 20px;
  font-size: 0.85em; font-weight: 600; border: 1px solid var(--panel-border); color: var(--accent);
}

/* Stats */
.stats {
  background: var(--card); border-radius: 20px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--panel-border);
}
.stat-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.85em; color: #9ca3af; font-weight: 600; }
.bar { width: 60%; height: 10px; background: #1f2937; border-radius: 5px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.4); }
.fill { height: 100%; background: var(--green); transition: width 0.4s ease, background-color 0.3s ease; border-radius: 5px; }
.fill.medium { background-color: var(--yellow); }
.fill.low { background-color: var(--bloodshot); }

/* Item Grid */
.drag-instruction { font-size: 0.75em; color: #6b7280; text-align: center; margin-bottom: -6px; text-transform: uppercase; letter-spacing: 0.5px; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.item-card {
  background: var(--card); border: 1px solid var(--panel-border); border-radius: 18px;
  padding: 10px 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  cursor: grab; transition: transform 0.15s ease; touch-action: none;
}
.item-card svg { width: 34px; height: 34px; pointer-events: none; }
.item-card span { font-size: 0.7rem; font-weight: 600; color: #d1d5db; pointer-events: none; }

/* Shop & Sleep Grids */
.shop-title { font-size: 1.1rem; font-weight: 700; color: var(--accent); margin: 0 0 5px 0; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.shop-item { background: var(--card); border: 1px solid var(--panel-border); border-radius: 20px; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.shop-item svg { width: 48px; height: 48px; }
.shop-item h4 { margin: 0; font-size: 0.95rem; }
.shop-item p { margin: 0; font-size: 0.75rem; color: #9ca3af; }

.buy-btn {
  background: var(--green); color: #000; border: none; padding: 8px 16px;
  border-radius: 14px; font-weight: 700; font-size: 0.85rem; cursor: pointer;
  display: flex; align-items: center; gap: 4px; width: 100%; justify-content: center; margin-top: 4px;
}
.buy-btn:active { transform: scale(0.95); }

.dragging-clone {
  position: fixed; pointer-events: none; z-index: 1000; width: 50px; height: 50px;
  transform: translate(-50%, -50%) scale(1.1); filter: drop-shadow(0 10px 20px rgba(0,0,0,0.5));
}

.feed-log { font-size: 0.8em; color: #6b7280; text-align: center; margin-top: -4px; font-style: italic; }

/* Fixed Navigation Bar (3 Buttons even distribution) */
.nav-bar {
  position: fixed; 
  bottom: 0; 
  left: 50%; 
  transform: translateX(-50%); 
  width: 100%; 
  max-width: 420px;
  height: 65px; 
  background: rgba(17, 20, 33, 0.95); 
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--panel-border); 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  z-index: 999;
}

/* Changed width: 50% to flex: 1 so each of the 3 buttons takes exactly 33.3% without overlapping */
.nav-btn { 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  gap: 4px; 
  background: none; 
  border: none; 
  color: #6b7280; 
  font-size: 0.75rem; 
  font-weight: 600; 
  cursor: pointer; 
  flex: 1; 
  padding: 8px 0; 
}

.nav-btn.active { color: var(--accent); }
.nav-btn svg { width: 22px; height: 22px; fill: currentColor; }