:root {
  --bg-top: #fff5f9;
  --bg-bottom: #eef7ff;
  --card-bg: #ffffff;
  --card-border: #f2dce8;
  --text-main: #3e2b47;
  --text-soft: #786285;
  --pink: #ff82b2;
  --pink-soft: #ffe3ef;
  --mint: #5cd6a9;
  --mint-soft: #def9ef;
  --aqua: #5ac8fa;
  --aqua-soft: #dff4ff;
  --lavender: #9b82f3;
  --lavender-soft: #ece6ff;
  --gold: #ffb84d;
  --gold-soft: #fff1d6;
  --shadow-soft: 0 6px 18px rgba(84, 52, 104, 0.1);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Fredoka', 'Nunito', 'Comic Sans MS', 'Chalkboard SE', system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--text-main);
}

button, input {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.svg-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  line-height: 1;
}

.svg-slot svg {
  display: block;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 540px;
  height: 100dvh;
  margin: 0 auto;
  padding: 8px 10px 10px;
  gap: 6px;
  position: relative;
}

/* Top Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  z-index: 20;
}

.pet-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 999px;
  padding: 4px 8px 4px 10px;
  box-shadow: var(--shadow-soft);
}

.pet-name {
  font-weight: 800;
  font-size: 0.95rem;
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-pill-btn {
  border: 2px solid #ead8f2;
  background: #fdf8ff;
  border-radius: 999px;
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.icon-pill-btn:active {
  transform: scale(0.92);
}

.time-pill-wrap {
  position: relative;
}

.time-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--card-bg);
  border: 2px solid #dcd3f8;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 0.82rem;
  color: var(--text-main);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.clock-text {
  color: var(--text-soft);
  font-size: 0.76rem;
  font-weight: 700;
}

.time-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: 245px;
  background: #ffffff;
  border: 3px solid #dcd3f8;
  border-radius: 20px;
  padding: 10px;
  box-shadow: 0 12px 28px rgba(62, 43, 71, 0.22);
  z-index: 60;
}

.popover-title {
  font-weight: 800;
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 8px;
}

.time-mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.time-mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 2px solid #e6defa;
  background: #f9f6ff;
  border-radius: 12px;
  padding: 7px 6px;
  font-weight: 800;
  font-size: 0.8rem;
  color: var(--text-main);
  cursor: pointer;
}

.time-mode-btn[data-time-mode="real"] {
  grid-column: span 2;
}

.time-mode-btn.is-active {
  background: var(--lavender);
  color: #ffffff;
  border-color: var(--lavender);
}

.top-right-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.coins-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--gold-soft);
  border: 2px solid #f7c96e;
  border-radius: 999px;
  padding: 5px 10px;
  font-weight: 900;
  font-size: 0.95rem;
  color: #7c4d00;
  box-shadow: var(--shadow-soft);
}

/* Needs HUD */
.hud-panel {
  display: flex;
  flex-direction: column;
  gap: 5px;
  z-index: 10;
}

.needs-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.need-card {
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--card-border);
  border-radius: 14px;
  padding: 5px 7px;
  box-shadow: 0 3px 8px rgba(84, 52, 104, 0.06);
}

.need-card.is-low {
  border-color: #ff6b8b;
  background: #fff0f4;
  animation: pulseBounce 1.1s infinite ease-in-out;
}

.need-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-bottom: 4px;
}

.need-title {
  font-size: 0.76rem;
  font-weight: 800;
}

.meter-track {
  width: 100%;
  height: 9px;
  background: #f0e8f5;
  border-radius: 999px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease, background-color 0.35s ease;
}

.fill-hunger { background: linear-gradient(90deg, #ff8ba7, #ff5e8e); }
.fill-bathroom { background: linear-gradient(90deg, #56ccf2, #2f80ed); }
.fill-energy { background: linear-gradient(90deg, #b388ff, #7c4dff); }
.fill-happy { background: linear-gradient(90deg, #ffd166, #ff9f1c); }

.care-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid #e9d8f4;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--text-main);
}

.care-banner.is-night {
  background: #2c2255;
  border-color: #6654b8;
  color: #fff6c2;
}

/* 3D Stage */
.stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 250px;
  border-radius: 26px;
  overflow: hidden;
  border: 3px solid #ffffff;
  box-shadow: 0 10px 26px rgba(84, 52, 104, 0.15);
  background: #d9f0ff;
}

#scene-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

.stage-badges {
  position: absolute;
  bottom: 10px;
  left: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  z-index: 8;
  pointer-events: none;
}

.stage-badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid #edd9f7;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
}

.speech-bubble {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #ffbad2;
  border-radius: 20px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 0.88rem;
  color: var(--text-main);
  box-shadow: 0 6px 16px rgba(62, 43, 71, 0.14);
  z-index: 9;
  pointer-events: none;
  animation: floatBubble 2.4s infinite ease-in-out;
}

.floating-fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 12;
}

.float-emoji {
  position: absolute;
  animation: riseAndFade 1.25s ease-out forwards;
}

/* Overlays for Vet Office & Fancy Restaurant */
.scene-overlay {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 18;
}

.overlay-card {
  background: rgba(255, 255, 255, 0.96);
  border: 3px solid #d4f0e8;
  border-radius: 22px;
  padding: 10px 12px;
  box-shadow: 0 10px 26px rgba(32, 60, 55, 0.22);
}

.restaurant-card {
  border-color: #f8d28c;
  background: rgba(255, 251, 242, 0.97);
}

.overlay-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.overlay-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 900;
  font-size: 1rem;
}

.mini-close-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 2px solid #e3d6ec;
  background: #fff5fb;
  border-radius: 999px;
  padding: 4px 11px;
  font-weight: 800;
  font-size: 0.82rem;
  color: var(--text-main);
  cursor: pointer;
}

.vet-prompt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.vet-task-prompt {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 800;
  font-size: 0.9rem;
  color: #1f6e58;
}

.vet-steps {
  display: flex;
  gap: 5px;
}

.vet-step-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #eef7f4;
  border: 2px solid #b8e2d4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 900;
}

.vet-step-dot.is-done {
  background: #5cd6a9;
  border-color: #36b385;
  color: #ffffff;
}

.vet-tools-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.vet-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: #f2fcf9;
  border: 3px solid #bfead9;
  border-radius: 16px;
  padding: 8px 4px;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.vet-tool-btn.is-target {
  background: #fff4c8;
  border-color: #ffa834;
  box-shadow: 0 0 0 3px rgba(255, 168, 52, 0.28);
  animation: pulseBounce 0.95s infinite ease-in-out;
}

.tool-label {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-main);
}

.vet-complete-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 2px dashed #c8ece0;
}

.vet-reward-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 900;
  font-size: 0.95rem;
  color: #167a5b;
}

.primary-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: linear-gradient(135deg, #42d392, #2bb673);
  color: #ffffff;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 900;
  font-size: 0.88rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(43, 182, 115, 0.3);
}

.restaurant-subtitle {
  font-size: 0.85rem;
  font-weight: 800;
  color: #8a5a18;
  margin-bottom: 8px;
}

.restaurant-menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.dish-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: #ffffff;
  border: 3px solid #f5cf87;
  border-radius: 16px;
  padding: 9px 6px;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.dish-btn:active {
  transform: scale(0.94);
}

.dish-name {
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
  color: var(--text-main);
}

/* Bottom Controls Dock */
.controls-dock {
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 15;
}

.meals-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.meal-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: #ffffff;
  border: 2.5px solid #f4cfe0;
  border-radius: 16px;
  padding: 7px 4px;
  min-height: 60px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(84, 52, 104, 0.08);
  transition: transform 0.14s ease, border-color 0.2s ease;
}

.meal-btn:active, .action-btn:active {
  transform: scale(0.93);
}

.meal-btn.is-now-meal {
  border-color: #ff7aa8;
  background: #fff4f8;
  box-shadow: 0 0 0 3px rgba(255, 122, 168, 0.22);
}

.meal-check {
  position: absolute;
  top: 4px;
  right: 5px;
}

.actions-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.action-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 18px;
  padding: 8px 4px;
  min-height: 68px;
  border: 2.5px solid transparent;
  cursor: pointer;
  box-shadow: 0 5px 12px rgba(84, 52, 104, 0.1);
  transition: transform 0.14s ease;
}

.action-btn.is-alert {
  animation: pulseBounce 1s infinite ease-in-out;
}

.tone-aqua {
  background: var(--aqua-soft);
  border-color: #8fd9fb;
}

.tone-lavender {
  background: var(--lavender-soft);
  border-color: #bfb0f8;
}

.tone-mint {
  background: var(--mint-soft);
  border-color: #8ee5c4;
}

.tone-pink {
  background: var(--pink-soft);
  border-color: #ffa8ca;
}

.tone-gold {
  background: var(--gold-soft);
  border-color: #f8ca72;
}

.btn-label {
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.btn-badge {
  position: absolute;
  top: -5px;
  right: -3px;
  background: #ff6b9d;
  color: #ffffff;
  border: 2px solid #ffffff;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 0.65rem;
  font-weight: 900;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(52, 34, 68, 0.52);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 100;
}

.modal-sheet {
  width: 100%;
  max-width: 440px;
  max-height: 92dvh;
  overflow-y: auto;
  background: #ffffff;
  border: 4px solid #f3d5e6;
  border-radius: 28px;
  padding: 16px;
  box-shadow: 0 18px 42px rgba(42, 24, 56, 0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.modal-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 1.32rem;
  font-weight: 900;
}

.modal-lead {
  margin: 0 0 12px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-soft);
}

/* Animal Picker Grid */
.animal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-bottom: 14px;
}

.animal-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #fdf7fb;
  border: 3px solid #edd8e6;
  border-radius: 20px;
  padding: 10px 6px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.animal-card.is-selected {
  background: #fff0f7;
  border-color: #ff65a3;
  box-shadow: 0 0 0 4px rgba(255, 101, 163, 0.22);
  transform: translateY(-2px) scale(1.03);
}

.animal-title {
  font-size: 0.92rem;
  font-weight: 900;
  color: var(--text-main);
}

.name-box {
  background: #f9f5ff;
  border: 2.5px solid #e4d9f7;
  border-radius: 20px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.name-label {
  display: block;
  font-weight: 900;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.name-input {
  width: 100%;
  border: 2.5px solid #d5c4f3;
  border-radius: 14px;
  padding: 9px 12px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  background: #ffffff;
  outline: none;
}

.name-input:focus {
  border-color: var(--lavender);
}

.name-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.name-chip {
  border: 2px solid #dfd3f8;
  background: #ffffff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text-main);
  cursor: pointer;
}

.name-chip:active {
  background: var(--lavender-soft);
}

.big-cta-btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 13px 18px;
  font-size: 1.15rem;
  font-weight: 900;
  color: #ffffff;
  background: linear-gradient(135deg, #ff70a6, #ff9770);
  box-shadow: 0 8px 18px rgba(255, 112, 166, 0.35);
  cursor: pointer;
}

.big-cta-btn:disabled {
  background: #d8cfe0;
  box-shadow: none;
  cursor: not-allowed;
}

/* Shop Modal */
.shop-coins-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--gold-soft);
  border: 2px solid #f7c96e;
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 900;
  color: #7c4d00;
}

.shop-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 10px 0 12px;
}

.shop-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 2.5px solid #ead8f2;
  background: #faf5fd;
  border-radius: 16px;
  padding: 9px 6px;
  font-weight: 900;
  font-size: 0.88rem;
  color: var(--text-main);
  cursor: pointer;
}

.shop-tab.is-active {
  background: var(--pink);
  border-color: var(--pink);
  color: #ffffff;
}

.shop-items-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
}

.shop-item-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: #fdf9fc;
  border: 2.5px solid #edd9e8;
  border-radius: 20px;
  padding: 11px 8px;
  text-align: center;
}

.shop-item-card.is-active-item {
  border-color: #48c78e;
  background: #f1fdf7;
}

.shop-item-card.is-wide {
  grid-column: span 2;
}

.shop-item-title {
  font-weight: 900;
  font-size: 0.92rem;
}

.shop-item-sub {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-soft);
}

.shop-buy-btn {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: none;
  border-radius: 999px;
  padding: 8px 10px;
  font-weight: 900;
  font-size: 0.84rem;
  cursor: pointer;
  background: linear-gradient(135deg, #ffb84d, #ff9233);
  color: #ffffff;
}

.shop-buy-btn.is-owned {
  background: #ece4f6;
  color: var(--text-main);
}

.shop-buy-btn.is-equipped {
  background: #48c78e;
  color: #ffffff;
}

.shop-buy-btn:disabled {
  background: #e2dce8;
  color: #9b8fa6;
  cursor: not-allowed;
}

@keyframes pulseBounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

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

@keyframes riseAndFade {
  0% { opacity: 1; transform: translateY(0) scale(0.8); }
  100% { opacity: 0; transform: translateY(-75px) scale(1.25); }
}
