:root {
  --ink: #3b3247;
  --ink-soft: #7a6f8a;
  --pink: #ff8fb5;
  --pink-deep: #e8558a;
  --lav: #b18cff;
  --lav-deep: #8b63e6;
  --mint: #8fe3b6;
  --sky: #9fd8ff;
  --cream: #fffaf0;
  --screen: #f3fbe8;
  --shadow: 0 10px 30px rgba(120, 80, 160, .25);
  font-family: 'Fredoka', 'Nunito', 'Quicksand', system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  background: radial-gradient(circle at 20% 10%, #ffe3f1 0, transparent 40%),
              radial-gradient(circle at 85% 30%, #e3e8ff 0, transparent 45%),
              radial-gradient(circle at 50% 100%, #dff7ea 0, transparent 50%),
              #fdf3ff;
  display: flex;
  justify-content: center;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; cursor: pointer; }

.bg-dots {
  position: fixed; inset: 0; pointer-events: none; opacity: .5;
  background-image: radial-gradient(#e8c6ff 1.5px, transparent 1.6px), radial-gradient(#ffc6dc 1.5px, transparent 1.6px);
  background-size: 46px 46px, 46px 46px;
  background-position: 0 0, 23px 23px;
  animation: drift 40s linear infinite;
}
@keyframes drift { to { background-position: 460px 460px, 483px 483px; } }

.app { position: relative; width: min(94vw, 400px); padding: 18px 0 30px; display: flex; flex-direction: column; align-items: center; gap: 14px; }

.title {
  margin: 0; font-size: 2.2rem; font-weight: 700; letter-spacing: .5px;
  color: var(--pink-deep);
  text-shadow: 0 3px 0 #fff, 0 5px 0 #f6c6da;
}
.title span { color: var(--lav-deep); text-shadow: 0 3px 0 #fff, 0 5px 0 #d9c8ff; }

/* ---------- Device (guscio a forma di uovo) ---------- */
.device {
  position: relative;
  width: 100%;
  padding: 34px 22px 26px;
  border-radius: 50% 50% 44% 44% / 30% 30% 22% 22%;
  background: linear-gradient(160deg, #ffd6ea 0%, #f1c8ff 55%, #cdd9ff 100%);
  box-shadow: var(--shadow), inset 0 -10px 0 rgba(140, 90, 200, .18), inset 0 8px 0 rgba(255, 255, 255, .6);
}
.device-gloss {
  position: absolute; top: 18px; left: 18%; width: 30%; height: 40px;
  background: rgba(255, 255, 255, .55); border-radius: 50%; filter: blur(2px); transform: rotate(-12deg);
}

.screen {
  position: relative;
  background: var(--screen);
  border-radius: 26px;
  padding: 10px;
  box-shadow: inset 0 4px 10px rgba(80, 60, 110, .2), 0 0 0 6px #fff, 0 0 0 9px rgba(139, 99, 230, .25);
}

/* ---------- Statistiche ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 8px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.stat i { width: 24px; height: 24px; display: block; transition: transform .2s; }
.stat i svg { width: 100%; height: 100%; display: block; }
.bar { width: 100%; height: 8px; background: #fff; border-radius: 99px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,.12); }
.bar span { display: block; height: 100%; width: 100%; border-radius: 99px; background: linear-gradient(90deg, #7bdba5, #a8eec6); transition: width .6s ease, background .4s; }
.stat.mid .bar span { background: linear-gradient(90deg, #ffc94d, #ffe08a); }
.stat.low .bar span { background: linear-gradient(90deg, #ff6b8b, #ff9fb5); }
.stat.low i { animation: pulse .8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.2); } }

/* ---------- Stanza ---------- */
.room {
  position: relative;
  height: 250px;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(#d9f1ff 0%, #eef9ff 58%, #fff 58%);
  transition: filter .6s;
}
.room::before { /* carta da parati a pois */
  content: ''; position: absolute; inset: 0 0 42% 0;
  background-image: radial-gradient(rgba(255, 255, 255, .9) 2px, transparent 2.5px);
  background-size: 22px 22px;
}
.floor {
  position: absolute; left: 0; right: 0; bottom: 0; height: 42%;
  background: repeating-linear-gradient(90deg, #ffe9c9 0 28px, #ffe1b8 28px 56px);
  box-shadow: inset 0 4px 0 #f6cf9c;
}
.deco { position: absolute; width: 56px; height: 56px; opacity: .95; }
.deco svg { width: 100%; height: 100%; }
.deco.c1 { top: 8px; left: -60px; animation: cloud 26s linear infinite; }
.deco.c2 { top: 40px; left: -60px; width: 40px; height: 40px; animation: cloud 34s linear infinite 12s; }
@keyframes cloud { to { transform: translateX(460px); } }

.pet-wrap {
  --x: 0%;
  position: absolute; left: 50%; bottom: 10px; width: 150px; height: 150px;
  margin-left: -75px;
  transform: translateX(var(--x));
  transition: transform 1.6s cubic-bezier(.45, .05, .35, 1);
  z-index: 3;
}
.pet { width: 100%; height: 100%; cursor: pointer; }
.pet .pet-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.pet .body { transform-origin: 60px 108px; animation: bounce 1.4s ease-in-out infinite; }
.pet.flip .pet-svg { transform: scaleX(-1); }
.pet.sleeping .body { animation: breathe 3s ease-in-out infinite; }
.pet.dead .body { animation: none; opacity: .55; filter: grayscale(.8); }
.pet.egg .body { animation: eggIdle 2.4s ease-in-out infinite; transform-origin: 60px 105px; }
.pet.egg.hatching .body { animation: eggShake .5s ease-in-out infinite; }
.pet.wobble .body { animation: eggShake .25s ease-in-out 3; }
.pet.shake { animation: no .45s ease-in-out; }
.pet .eye { transform-box: fill-box; transform-origin: center; animation: blink 4.5s infinite; }
.pet .chomp { transform-box: fill-box; transform-origin: center; animation: chomp .3s ease-in-out infinite; }
.pet .tear { animation: tear 1.4s ease-in infinite; }
.mood-happy .body, .mood-love .body { animation-duration: .9s !important; }

@keyframes bounce { 0%, 100% { transform: translateY(0) scale(1, 1); } 45% { transform: translateY(-7px) scale(.97, 1.03); } 90% { transform: translateY(0) scale(1.04, .96); } }
@keyframes breathe { 50% { transform: scale(1.03, .97); } }
@keyframes eggIdle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
@keyframes eggShake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
@keyframes no { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
@keyframes chomp { 50% { transform: scaleY(.3); } }
@keyframes tear { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(12px); opacity: 0; } }

.speech {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: #fff; padding: 6px 12px; border-radius: 14px;
  width: max-content; max-width: 230px; text-align: center; line-height: 1.25;
  font-size: .9rem; font-weight: 500; box-shadow: 0 3px 0 rgba(139, 99, 230, .2);
  z-index: 5;
}
.speech::after { content: ''; position: absolute; top: 100%; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top-color: #fff; }
.speech.pop { animation: pop .3s cubic-bezier(.2, 1.6, .5, 1); }
@keyframes pop { from { transform: translateX(-50%) scale(.4); opacity: 0; } }

.attention {
  position: absolute; top: 4px; right: 6px; width: 26px; height: 26px; border-radius: 50%;
  background: #ff6b8b; color: #fff; font-weight: 700; display: grid; place-items: center;
  box-shadow: 0 2px 0 #d94470; animation: pulse .7s ease-in-out infinite; z-index: 4;
}

.zzz { position: absolute; right: -6px; top: 6px; opacity: 0; transition: opacity .5s; font-weight: 700; color: #8b63e6; z-index: 6; }
.zzz.on { opacity: 1; }
.zzz span { position: absolute; animation: zfloat 2.4s ease-in infinite; opacity: 0; }
.zzz span:nth-child(1) { font-size: .9rem; animation-delay: 0s; }
.zzz span:nth-child(2) { font-size: 1.1rem; animation-delay: .8s; }
.zzz span:nth-child(3) { font-size: 1.4rem; animation-delay: 1.6s; }
@keyframes zfloat { 0% { transform: translate(0, 10px); opacity: 0; } 30% { opacity: 1; } 100% { transform: translate(18px, -34px); opacity: 0; } }

/* Notte */
.night { position: absolute; inset: 0; background: linear-gradient(#2c2a5a, #4b3f7a 60%, #5d4c80); opacity: 0; transition: opacity .8s; pointer-events: none; z-index: 2; mix-blend-mode: multiply; }
.room.is-night .night { opacity: .85; }
.night-moon { position: absolute; top: 12px; right: 18px; width: 38px; height: 38px; filter: drop-shadow(0 0 8px #fff3a8); }
.night-moon svg { width: 100%; height: 100%; }
.night .star { position: absolute; color: #fff7c2; animation: twinkle 2s ease-in-out infinite; }
.night .s1 { top: 18px; left: 26px; } .night .s2 { top: 50px; left: 90px; animation-delay: .6s; } .night .s3 { top: 26px; left: 170px; animation-delay: 1.2s; }
@keyframes twinkle { 50% { opacity: .2; transform: scale(.7); } }
.room.is-night .pet-wrap { z-index: 3; }
.room.is-night .pet { filter: brightness(.85); }

.room.flash::after { content: ''; position: absolute; inset: 0; background: #fff; animation: flash .7s ease-out forwards; z-index: 9; pointer-events: none; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

/* Cacchine */
#poops { position: absolute; inset: 0; z-index: 2; }
.poop { position: absolute; width: 36px; height: 36px; cursor: pointer; animation: plop .4s cubic-bezier(.2, 1.6, .5, 1); }
.poop svg { width: 100%; height: 100%; }
.poop .stink { position: absolute; top: -12px; left: 12px; color: #b5a28a; font-weight: 700; animation: stink 1.6s ease-in-out infinite; }
@keyframes plop { from { transform: scale(0) translateY(-20px); } }
@keyframes stink { 0% { transform: translateY(4px); opacity: 0; } 50% { opacity: 1; } 100% { transform: translateY(-10px); opacity: 0; } }

/* Effetti fluttuanti */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 7; }
.fx { position: absolute; width: 24px; height: 24px; margin: -12px 0 0 -12px; animation: floatUp 1.5s ease-out forwards; }
.fx svg { width: 100%; height: 100%; }
.fx.food-float { width: 40px; height: 40px; margin: -20px 0 0 -20px; animation: foodIn 1.3s ease-in forwards; }
@keyframes floatUp {
  0% { transform: translate(0, 0) scale(.3) rotate(0); opacity: 0; }
  15% { opacity: 1; transform: translate(0, -10px) scale(1.1) rotate(var(--rot)); }
  100% { transform: translate(var(--dx), -90px) scale(.8) rotate(var(--rot)); opacity: 0; }
}
@keyframes foodIn { 0% { transform: translateY(-30px) scale(.5); opacity: 0; } 25% { transform: translateY(0) scale(1.1); opacity: 1; } 70% { transform: translateY(30px) scale(.9); opacity: 1; } 100% { transform: translateY(45px) scale(.1); opacity: 0; } }

/* Minigioco */
.minigame { position: absolute; inset: 0; z-index: 8; background: rgba(255, 246, 252, .93); display: flex; flex-direction: column; }
.mg-hud { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; font-weight: 600; font-size: .9rem; }
.mg-hud span { display: flex; align-items: center; gap: 4px; }
.mg-hud svg { width: 20px; height: 20px; }
.mg-title { color: var(--lav-deep); font-size: .8rem; }
.mg-field { position: relative; flex: 1; }
.mg-item { position: absolute; width: 46px; height: 46px; padding: 0; border: 0; background: none; animation: popIn .25s cubic-bezier(.2, 1.6, .5, 1); touch-action: manipulation; }
.mg-item svg { width: 100%; height: 100%; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .1)); }
.mg-item.hit { animation: hit .25s ease-out forwards; pointer-events: none; }
.mg-item.gone { animation: gone .3s ease-in forwards; pointer-events: none; }
@keyframes popIn { from { transform: scale(0); } }
@keyframes hit { to { transform: scale(1.8); opacity: 0; } }
@keyframes gone { to { transform: scale(0); opacity: 0; } }
.mg-result { margin: auto; text-align: center; padding: 10px; }
.mg-result h3 { margin: 4px 0; }
.mg-result p { margin: 0 0 10px; color: var(--ink-soft); }
.mg-trophy { width: 64px; height: 64px; margin: 0 auto; animation: bounce 1s ease-in-out infinite; }
.mg-trophy svg { width: 100%; height: 100%; }

/* Overlay (fine partita) */
.overlay { position: absolute; inset: 0; z-index: 10; background: rgba(243, 236, 255, .9); display: grid; place-items: center; padding: 12px; }
.overlay-card { text-align: center; }
.overlay-card h3 { margin: 6px 0 4px; font-size: 1.05rem; }
.overlay-card p { margin: 0 0 12px; color: var(--ink-soft); font-size: .9rem; }
.ghost-float { width: 70px; height: 70px; margin: 0 auto; animation: ghost 2.4s ease-in-out infinite; }
.ghost-float svg { width: 100%; height: 100%; }
@keyframes ghost { 50% { transform: translateY(-10px) rotate(4deg); } }

/* Info */
.infobar { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.infobar .name { font-weight: 700; font-size: 1.1rem; margin-inline-end: auto; color: var(--lav-deep); }
.chip { background: #fff; border-radius: 99px; padding: 2px 9px; font-size: .78rem; font-weight: 500; color: var(--ink-soft); box-shadow: 0 2px 0 rgba(139, 99, 230, .15); }

/* ---------- Azioni ---------- */
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 10px; margin-top: 20px; padding: 0 6px; }
.act {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: 0; padding: 0; font-weight: 600; font-size: .85rem; text-align: center; line-height: 1.15;
  transition: transform .12s;
}
.act i {
  width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #fff, #fff4fa 60%, #f7e3ff);
  box-shadow: 0 5px 0 #c9a6f5, 0 8px 14px rgba(139, 99, 230, .25);
  transition: transform .12s, box-shadow .12s;
}
.act i svg { width: 34px; height: 34px; transition: transform .2s; }
.act:hover i svg { transform: rotate(-8deg) scale(1.08); }
.act:active i { transform: translateY(4px); box-shadow: 0 1px 0 #c9a6f5, 0 3px 6px rgba(139, 99, 230, .25); }
.act:disabled { opacity: .45; cursor: default; }
.act.dim { opacity: .55; }
.act.urgent i { animation: urgent 1s ease-in-out infinite; }
@keyframes urgent { 0%, 100% { box-shadow: 0 5px 0 #c9a6f5, 0 0 0 0 rgba(255, 107, 139, .6); } 50% { box-shadow: 0 5px 0 #c9a6f5, 0 0 0 8px rgba(255, 107, 139, 0); } }

/* ---------- Selettore lingua ---------- */
.lang-picker {
  position: fixed; top: 10px; right: 10px; z-index: 40;
  display: flex; align-items: center; gap: 4px; padding: 3px 4px 3px 7px;
  background: rgba(255, 255, 255, .6); border-radius: 99px;
  box-shadow: 0 2px 0 rgba(139, 99, 230, .15);
  opacity: .7; transition: opacity .2s, background .2s; cursor: pointer;
}
.lang-picker:hover, .lang-picker:focus-within { opacity: 1; background: #fff; }
.lang-picker i { width: 16px; height: 16px; display: block; }
.lang-picker svg { width: 100%; height: 100%; display: block; }
.lang-picker select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent; outline: none;
  font: inherit; font-size: .78rem; font-weight: 500; color: var(--ink-soft);
  padding: 2px 6px 2px 2px; max-width: 120px; cursor: pointer;
}

/* ---------- Footer ---------- */
.footer { display: flex; gap: 10px; }
.pill-btn {
  display: flex; align-items: center; gap: 6px; padding: 7px 14px 7px 10px;
  border: 0; border-radius: 99px; background: #fff; font-weight: 500; font-size: .85rem;
  box-shadow: 0 3px 0 #e0cdfb;
}
.pill-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #e0cdfb; }
.pill-btn i { width: 22px; height: 22px; display: block; }
.pill-btn svg { width: 100%; height: 100%; display: block; }

/* ---------- Bottoni & modale ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 14px;
  padding: 10px 18px; font-weight: 600; font-size: .95rem; background: #f1e9ff; box-shadow: 0 4px 0 #d8c6fb;
}
.btn svg { width: 20px; height: 20px; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d8c6fb; }
.btn.primary { background: var(--pink); color: #fff; box-shadow: 0 4px 0 var(--pink-deep); }
.btn.danger { background: #ff6b8b; color: #fff; box-shadow: 0 4px 0 #d94470; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(59, 50, 71, .35); display: grid; place-items: center; z-index: 50; padding: 16px; backdrop-filter: blur(3px); }
.modal {
  width: min(92vw, 340px); background: var(--cream); border-radius: 26px; padding: 22px 20px 20px; text-align: center;
  box-shadow: 0 8px 0 #e6d3ff, var(--shadow); animation: modalIn .35s cubic-bezier(.2, 1.5, .5, 1);
}
@keyframes modalIn { from { transform: scale(.7) translateY(20px); opacity: 0; } }
.modal-icon { width: 56px; height: 56px; margin: -50px auto 6px; background: #fff; border-radius: 50%; padding: 8px; box-shadow: 0 4px 0 #e6d3ff; }
.modal-icon svg { width: 100%; height: 100%; }
.modal h2 { margin: 4px 0 8px; font-size: 1.3rem; }
.modal p { margin: 0 0 12px; color: var(--ink-soft); }
.modal input {
  width: 100%; font: inherit; font-size: 1.1rem; text-align: center; padding: 10px; border-radius: 14px;
  border: 2px solid #e6d3ff; outline: none; background: #fff; color: var(--ink); user-select: text;
}
.modal input:focus { border-color: var(--lav); }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.food-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.food {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 8px; border: 0; border-radius: 18px;
  background: #fff; box-shadow: 0 4px 0 #f0dcff; transition: transform .12s;
}
.food:hover { transform: translateY(-2px); }
.food:active { transform: translateY(2px); box-shadow: 0 1px 0 #f0dcff; }
.food svg { width: 48px; height: 48px; }
.food small { color: var(--ink-soft); }

@media (max-width: 600px) {
  .app { padding-top: 40px; }
}
@media (max-width: 380px) {
  .device { padding: 28px 14px 22px; }
  .room { height: 220px; }
  .act i { width: 52px; height: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
