:root {
  --sky1: #a9d7ff; --sky2: #d7f0e6; --ink: #2a3550;
  --card: #ffffff; --accent: #ff8a3d; --bar-bg: #e7edf5;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 62%, #cdeecb 100%);
  user-select: none;
}
#app {
  display: flex; flex-direction: column; height: 100dvh;
  max-width: 520px; margin: 0 auto; padding: env(safe-area-inset-top) 16px 16px;
}

.topbar { display: flex; gap: 8px; padding: 10px 0; align-items: center; }
.chip {
  background: var(--card); border-radius: 999px; padding: 7px 14px;
  font-weight: 800; font-size: 16px; box-shadow: 0 4px 12px rgba(40,60,90,.12);
}
.chip.stage { margin-left: auto; background: var(--accent); color: #fff; }

.scene {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 8px; min-height: 0;
}
.pet-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
.aura { position: absolute; top: 50%; left: 50%; width: 78vw; max-width: 380px; aspect-ratio: 1; transform: translate(-50%, -55%); border-radius: 50%; pointer-events: none; opacity: 0; transition: opacity .4s; filter: blur(12px); }
.aura.on { opacity: .55; animation: aurapulse 3s ease-in-out infinite; }
@keyframes aurapulse { 0%,100% { transform: translate(-50%,-55%) scale(.97); } 50% { transform: translate(-50%,-55%) scale(1.05); } }
.pet {
  width: 62vw; max-width: 300px; height: auto; image-rendering: auto;
  transform-origin: bottom center; will-change: transform;
  animation: breathe 2.6s ease-in-out infinite;
  filter: drop-shadow(0 10px 10px rgba(0,0,0,.22));
}
.shadow {
  width: 46vw; max-width: 210px; height: 22px; margin-top: -6px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.22), rgba(0,0,0,0) 70%);
}
.moodline { font-weight: 700; font-size: 17px; opacity: .8; min-height: 22px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; padding: 6px 0; }
.stat { display: flex; align-items: center; gap: 8px; font-size: 18px; }
.bar { flex: 1; height: 12px; background: var(--bar-bg); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 999px; transition: width .35s ease; }
#barHunger { background: #ff9f43; } #barEnergy { background: #ffd23f; }
#barHappy { background: #4fc978; } #barClean { background: #46b3ff; }

.xp { padding: 4px 0 8px; }
.xpbar { height: 14px; }
#barXp { background: linear-gradient(90deg, #b06bff, #7a5cff); }
.xplabel { text-align: center; font-weight: 700; font-size: 13px; opacity: .7; margin-top: 4px; }

.care { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.carebtn {
  border: 0; background: var(--card); border-radius: 20px; padding: 12px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 26px; box-shadow: 0 6px 0 rgba(40,60,90,.10); cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
}
.carebtn b { font-size: 13px; }
.carebtn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(40,60,90,.10); }

.devbar { text-align: center; padding-top: 10px; }
.devbar button { border: 0; background: rgba(255,255,255,.55); border-radius: 999px; padding: 8px 16px; font-weight: 700; font-size: 13px; }

/* evolve sheet */
.sheet { position: fixed; inset: 0; background: rgba(20,30,50,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 30; }
.sheet[hidden] { display: none; }
.sheet-card { background: #fff; width: 100%; max-width: 520px; border-radius: 26px 26px 0 0; padding: 22px 18px calc(18px + env(safe-area-inset-bottom)); text-align: center; animation: rise .3s ease; }
.sheet-card h2 { margin: 4px 0; }
.sheet-sub { opacity: .7; margin: 0 0 14px; }
.branches { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.branch { border: 3px solid var(--bar-bg); background: #f7faff; border-radius: 20px; padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; }
.branch:active { border-color: var(--accent); }
.branch-img { width: 40vw; max-width: 150px; height: auto; }
.branch b { font-size: 16px; } .branch small { opacity: .65; font-size: 12px; }

.toast { position: fixed; left: 50%; bottom: 22%; transform: translateX(-50%); background: rgba(20,30,50,.92); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 700; z-index: 40; animation: pop .3s ease; }
.toast[hidden] { display: none; }

/* ---- screens + bottom nav (Phase 3) ---- */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen[hidden] { display: none; }
#screen-shop, #screen-collect, #screen-learn, #screen-play { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
.screen-title { text-align: center; margin: 6px 0 10px; font-size: 22px; }
.dexcount { font-size: 14px; opacity: .6; font-weight: 700; }

.bottomnav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 6px 0 calc(4px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.6); border-radius: 22px; margin-top: 6px; }
.navbtn { border: 0; background: transparent; font-size: 22px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 0; color: var(--ink); opacity: .55; cursor: pointer; }
.navbtn span { font-size: 10px; font-weight: 800; }
.navbtn.active { opacity: 1; }
.navbtn.active span { color: var(--accent); }

.tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.tab { border: 0; background: rgba(255,255,255,.6); border-radius: 999px; padding: 7px 16px; font-weight: 800; font-size: 14px; cursor: pointer; }
.tab.active { background: var(--accent); color: #fff; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { background: var(--card); border-radius: 18px; padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: 0 4px 12px rgba(40,60,90,.10); }
.card .swatch { width: 100%; height: 60px; border-radius: 12px; }
.card .cname { font-weight: 800; font-size: 14px; }
.card .buy { border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 800; font-size: 13px; background: var(--accent); color: #fff; cursor: pointer; }
.card .buy.owned { background: #e7edf5; color: #7a869a; }
.card .buy.equipped { background: #4fc978; }
.card .buy.poor { background: #f0c0c0; color: #8a4a4a; }

.dexgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.dexcell { background: var(--card); border-radius: 14px; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.dexcell img { width: 100%; height: auto; }
.dexcell.locked img { filter: brightness(0) opacity(.18); }
.dexcell .dname { font-size: 10px; font-weight: 700; opacity: .8; }
.dexcell.locked .dname { opacity: .4; }

.quizcard { background: var(--card); border-radius: 22px; padding: 20px 16px; text-align: center; box-shadow: 0 6px 18px rgba(40,60,90,.12); }
.quiz-topic { font-size: 12px; font-weight: 800; color: var(--accent); text-transform: uppercase; letter-spacing: .5px; }
.quiz-q { font-size: 20px; font-weight: 800; margin: 8px 0 16px; }
.quiz-opts { display: flex; flex-direction: column; gap: 10px; }
.quiz-opt { border: 3px solid var(--bar-bg); background: #f7faff; border-radius: 16px; padding: 14px; font-weight: 800; font-size: 16px; cursor: pointer; }
.quiz-opt.right { border-color: #4fc978; background: #eafaef; }
.quiz-opt.wrong { border-color: #ff6b6b; background: #ffecec; }
.quiz-teach { margin-top: 14px; font-size: 14px; opacity: .8; min-height: 20px; }
.quiz-next { margin-top: 14px; border: 0; background: var(--accent); color: #fff; border-radius: 999px; padding: 10px 22px; font-weight: 800; cursor: pointer; }

.mg { display: flex; flex-direction: column; height: 100%; }
.mg-hud { text-align: center; font-weight: 800; font-size: 18px; margin-bottom: 6px; }
.mg-field { position: relative; flex: 1; min-height: 320px; background: rgba(255,255,255,.4); border-radius: 20px; overflow: hidden; }
.mg-target { position: absolute; font-size: 40px; cursor: pointer; user-select: none; transition: transform .05s; }
.mg-target:active { transform: scale(.8); }
.mg-start { border: 0; background: var(--accent); color: #fff; border-radius: 999px; padding: 12px; font-weight: 800; font-size: 16px; margin-top: 10px; cursor: pointer; }

/* ---- pet animations (ported from PetSprite.swift springs) ---- */
@keyframes breathe { 0%,100% { transform: scaleY(.99) scaleX(1.005); } 50% { transform: scaleY(1.02) scaleX(.995); } }
@keyframes rise { from { transform: translateY(40px); } to { transform: translateY(0); } }
@keyframes pop { from { transform: translateX(-50%) scale(.8); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

.pet.anim-wiggle { animation: wiggle .3s ease; }
.pet.anim-nom { animation: nom .34s ease; }
.pet.anim-hop { animation: hop .5s cubic-bezier(.3,1.4,.5,1); }
.pet.anim-shimmy { animation: shimmy .3s ease; }
.pet.anim-breath { animation: breath .55s ease; }
@keyframes wiggle { 0% { transform: rotate(0); } 30% { transform: rotate(12deg) scaleY(1.05); } 60% { transform: rotate(-9deg); } 100% { transform: rotate(0); } }
@keyframes nom { 0% { transform: scaleY(1) scaleX(1); } 35% { transform: scaleY(.86) scaleX(1.12) translateY(8px); } 70% { transform: scaleY(1.04) scaleX(.97); } 100% { transform: scaleY(1) scaleX(1); } }
@keyframes hop { 0% { transform: translateY(0) scale(1); } 45% { transform: translateY(-30px) scaleY(1.14) scaleX(.9); } 75% { transform: translateY(0) scaleY(.94) scaleX(1.06); } 100% { transform: translateY(0) scale(1); } }
@keyframes shimmy { 0%,100% { transform: translateX(0) rotate(0); } 25% { transform: translateX(-10px) rotate(-6deg); } 60% { transform: translateX(10px) rotate(6deg); } 85% { transform: translateX(-6px) rotate(-3deg); } }
@keyframes breath { 0%,100% { transform: scaleY(1) scaleX(1); } 50% { transform: scaleY(1.08) scaleX(.96); } }
