:root {
  --bg: #fff5f9;
  --ink: #3a3350;
  --muted: #8a84a3;
  --card: #ffffff;
  --accent: #ff6fa8;
  --accent-2: #7c6cf6;
  --line: #f1e4ee;
  --shadow: 0 6px 18px rgba(90, 60, 120, .12);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: var(--bg); color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
input { font: inherit; -webkit-user-select: text; user-select: text; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; }
.screen { height: 100%; display: flex; flex-direction: column; }

/* ---------- bottoni ---------- */
.btn {
  background: linear-gradient(180deg, #ff86b8, var(--accent)); color: #fff; font-weight: 800;
  padding: 12px 22px; border-radius: 999px; box-shadow: 0 4px 0 #e0508c, var(--shadow);
  transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #e0508c; }
.btn.big { font-size: 1.2rem; padding: 15px 34px; }
.btn.sm { padding: 7px 12px; font-size: .85rem; box-shadow: 0 3px 0 #e0508c; }
.btn-alt { background: linear-gradient(180deg, #9d90ff, var(--accent-2)); box-shadow: 0 4px 0 #5a4bd6, var(--shadow); }
.btn.sm.btn-alt { box-shadow: 0 3px 0 #5a4bd6; }
.btn.on { background: #e9fbe9; color: #2f9e55; box-shadow: 0 3px 0 #bfe8c8; }
.btn.dis { filter: grayscale(.8); opacity: .55; }
.icon-btn { width: 40px; height: 40px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); font-size: 1.15rem; position: relative; }
.icon-btn:active { transform: scale(.92); }
.icon-btn.badge::after { content: ''; position: absolute; top: 4px; right: 4px; width: 10px; height: 10px; border-radius: 50%; background: #ff4f6d; border: 2px solid #fff; animation: pulse 1.2s infinite; }
.pill { background: var(--card); border-radius: 999px; padding: 8px 12px; font-weight: 800; box-shadow: var(--shadow); white-space: nowrap; }

/* ---------- setup ---------- */
.setup {
  align-items: center; justify-content: center; text-align: center; gap: 12px;
  padding: calc(var(--sat) + 16px) 24px calc(var(--sab) + 16px);
  background: radial-gradient(circle at 50% 30%, #fff 0, #ffe9f3 55%, #ffe2d6 100%);
}
.setup h1 { margin: 0; font-size: 2rem; }
.setup p { margin: 0; color: var(--muted); }
.setup-pet { width: min(52vw, 230px, 32vh); }
.setup input {
  width: min(100%, 300px); padding: 14px 18px; border-radius: 18px; border: 3px solid var(--line);
  background: #fff; font-size: 1.15rem; text-align: center; outline: none; color: var(--ink);
}
.setup input:focus { border-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 320px; }
.swatch { width: 40px; height: 40px; border-radius: 50%; box-shadow: inset 0 -4px 0 rgba(0,0,0,.12), var(--shadow); border: 3px solid #fff; transition: transform .15s; }
.swatch.sel { transform: scale(1.18); border-color: var(--ink); }
.swatches.small .swatch { width: 34px; height: 34px; }

/* ---------- main ---------- */
.main { padding-top: var(--sat); padding-left: var(--sal); padding-right: var(--sar); background: var(--bg); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px 4px; gap: 8px; }
.who { min-width: 0; }
.pet-name { font-weight: 900; font-size: 1.3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pet-age { font-size: .78rem; color: var(--muted); font-weight: 700; }
.top-right { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

.needs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 6px 14px 10px; }
.need { background: var(--card); border-radius: 16px; padding: 6px 8px 5px; box-shadow: var(--shadow); text-align: center; }
.need .ni { font-size: 1.1rem; display: block; line-height: 1.2; }
.need .bar { height: 8px; border-radius: 99px; background: #f1ecf4; overflow: hidden; margin: 3px 0 2px; }
.need .bar i { display: block; height: 100%; width: 50%; border-radius: 99px; transition: width .6s, background .6s; }
.need .nl { font-size: .62rem; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.need.low { animation: shake 1.4s infinite; }
.need.low .ni { animation: pulse 1s infinite; }

/* ---------- stanza ---------- */
.room {
  position: relative; flex: 1; margin: 0 12px; border-radius: 28px; overflow: hidden;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.7), var(--shadow); touch-action: none; min-height: 0;
}
.room-sky, .room-floor { position: absolute; left: 0; right: 0; transition: background .4s; }
.room-sky { top: 0; bottom: 0; }
.room-floor { bottom: 0; height: 24%; }

.bg_home .room-sky { background: radial-gradient(circle, rgba(255,255,255,.7) 2px, transparent 3px) 0 0/28px 28px, linear-gradient(#ffe8f2, #fff2e3); }
.bg_home .room-floor { background: repeating-linear-gradient(90deg, #f0c9a3 0 46px, #e8bd94 46px 48px); border-top: 6px solid #e2b085; }
.bg_beach .room-sky { background: radial-gradient(circle at 80% 18%, #fff3a8 0 26px, transparent 28px), linear-gradient(#83d3ff, #e5f8ff 70%, #5fc4e8 70%); }
.bg_beach .room-floor { background: radial-gradient(circle, #f2cf88 2px, transparent 3px) 0 0/18px 14px, #ffe1a6; border-top: 6px solid #ffd58a; }
.bg_forest .room-sky { background: radial-gradient(ellipse at 15% 85%, #5cb870 0 60px, transparent 62px), radial-gradient(ellipse at 85% 82%, #4fa864 0 72px, transparent 74px), linear-gradient(#c4efcf, #eafbea); }
.bg_forest .room-floor { background: radial-gradient(circle, #6dbf7b 3px, transparent 4px) 0 0/22px 18px, #86d295; border-top: 6px solid #6cc07e; }
.bg_candy .room-sky { background: repeating-linear-gradient(45deg, #ffd6ec 0 22px, #fff0f8 22px 44px); }
.bg_candy .room-floor { background: repeating-linear-gradient(90deg, #ff9ccc 0 30px, #fff 30px 60px); border-top: 6px solid #ff7fb8; }
.bg_sunset .room-sky { background: radial-gradient(circle at 50% 78%, #ffe08a 0 40px, transparent 42px), linear-gradient(#ff8f8b, #ffc3a0 55%, #a58cd8); }
.bg_sunset .room-floor { background: linear-gradient(#6d5aa8, #4f3f86); border-top: 6px solid #8a74c9; }
.bg_space .room-sky { background: radial-gradient(circle, #fff 1px, transparent 2px) 0 0/40px 40px, radial-gradient(circle, rgba(255,255,255,.6) 1px, transparent 2px) 20px 13px/56px 56px, radial-gradient(circle at 78% 22%, #ffb3d9 0 22px, transparent 24px), radial-gradient(circle at 30% 30%, #4b3f8f, #151233); }
.bg_space .room-floor { background: radial-gradient(circle, #8d86b5 4px, transparent 5px) 0 0/34px 26px, #b3add3; border-top: 6px solid #cfc9ec; }

/* bagno */
.room.bath .room-sky { background: linear-gradient(rgba(255,255,255,.65) 2px, transparent 2px) 0 0/36px 36px, linear-gradient(90deg, rgba(255,255,255,.65) 2px, transparent 2px) 0 0/36px 36px, #bfe7f7; }
.room.bath .room-floor { background: #9fd8ee; border-top: 6px solid #fff; }

.pet-wrap {
  position: absolute; left: 50%; bottom: 9%; transform: translateX(-50%);
  width: min(64vw, 300px, 40vh); z-index: 2;
}
.setup-pet .pet, .pet-wrap .pet { width: 100%; height: auto; aspect-ratio: 200 / 235; display: block; overflow: visible; }

.bubble {
  position: absolute; left: 50%; top: 5%; transform: translateX(-50%); z-index: 5;
  background: #fff; padding: 10px 16px; border-radius: 20px; font-weight: 800; font-size: .98rem;
  max-width: 86%; text-align: center; box-shadow: var(--shadow); line-height: 1.3;
}
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -9px; margin-left: -9px; border: 9px solid transparent; border-bottom: 0; border-top-color: #fff; }
.bubble.pop { animation: popIn .3s cubic-bezier(.3, 1.6, .6, 1); }

.fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 6; overflow: hidden; }
.float { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 1.1rem; animation: floatUp 1.5s ease-out forwards; text-shadow: 0 2px 0 #fff; white-space: nowrap; }
.float.good { color: #2f9e55; } .float.bad { color: #e0475b; }
.float.zzz { color: #fff; font-size: 1.6rem; text-shadow: 0 0 8px rgba(160,150,255,.9); animation: zzz 2.4s ease-out forwards; }
.float.heart { font-size: 1.6rem; }
.float.coin { font-size: 1.6rem; animation: coinUp 1.2s ease-out forwards; }
.flying-food { position: absolute; font-size: 3rem; transition: transform .5s cubic-bezier(.4, -0.3, .6, 1), opacity .5s; z-index: 7; }
.drop { position: absolute; top: 14%; width: 6px; height: 14px; border-radius: 50% 50% 50% 50% / 30% 30% 70% 70%; background: #5bb9ff; opacity: .85; animation: drop .6s linear forwards; }

.soap, .shower { position: absolute; left: -24px; top: -24px; font-size: 3rem; pointer-events: none; z-index: 8; display: none; }
.soap.show { display: block; margin: -10px 0 0 -6px; filter: drop-shadow(0 4px 4px rgba(0,0,0,.15)); }
.shower.show { display: block; top: 6px; left: -28px; transform-origin: center; }
.shower.on { filter: drop-shadow(0 0 8px #8fd4ff); }

.darkness { position: absolute; inset: 0; background: radial-gradient(circle at 50% 60%, rgba(25,20,70,.55), rgba(10,8,40,.86)); opacity: 0; pointer-events: none; transition: opacity .6s; z-index: 4; }
.darkness .moon { position: absolute; right: 18px; top: 16px; font-size: 2.2rem; }
.room.dark .darkness { opacity: 1; }

.flies { display: none; position: absolute; left: 50%; bottom: 40%; z-index: 3; pointer-events: none; }
.room.stinky .flies { display: block; }
.flies span { position: absolute; font-size: 1.1rem; animation: fly 3s linear infinite; }
.flies span:nth-child(2) { animation-duration: 4.2s; animation-direction: reverse; }

/* ---------- barra azioni ---------- */
.actions {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
  padding: 10px 10px calc(10px + var(--sab));
}
.actions button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px;
  border-radius: 18px; background: var(--card); box-shadow: var(--shadow); font-size: .7rem; font-weight: 800; color: var(--muted);
}
.actions button b { font-weight: 800; }
.actions button span { font-size: 1.55rem; line-height: 1.1; }
.actions button:active { transform: scale(.92); }
.actions.sleeping button:not(.sleep-btn):not([data-act=shop]):not([data-act=wardrobe]) { opacity: .4; }
.actions.sleeping .sleep-btn { background: #fff7cc; color: #b48a00; }
.wash-bar { grid-template-columns: repeat(3, 1fr); }
.wash-bar .tool.active { background: #e2f4ff; color: #2a86c7; box-shadow: inset 0 0 0 3px #8fd4ff, var(--shadow); }

/* ---------- personaggio: stati ---------- */
.pet .body-wrap { transform-origin: 100px 192px; animation: breathe 2.6s ease-in-out infinite; }
.pet .eye { transform-box: fill-box; transform-origin: center; transition: transform .08s; }
.pet.blink .eyes-open .eye { transform: scaleY(.08); }
.pet .pupil { transition: transform .12s ease-out; }
.pet .arm-l { transform-origin: 36px 120px; animation: wave 2.6s ease-in-out infinite; }
.pet .arm-r { transform-origin: 164px 120px; animation: wave 2.6s ease-in-out infinite reverse; }
.pet .antenna { transform-origin: 100px 36px; animation: sway 3s ease-in-out infinite; }
.pet .foam-b { fill: #fff; stroke: #cdeeff; stroke-width: 2; opacity: .95; animation: bubbleIn .25s ease-out; transform-box: fill-box; transform-origin: center; }
.pet .dirt { opacity: 0; transition: opacity .4s; }

.pet .eyes-closed, .pet .eyes-happy, .pet .brows, .pet .lids, .pet .sick-tint,
.pet .mouth > * { display: none; }
.pet .m-smile { display: inline; }

.pet.is-sick .sick-tint { display: inline; }

.pet.mood-happy .m-smile { display: none; }
.pet.mood-happy .m-big { display: inline; }

.pet.mood-sad .m-smile, .pet.mood-sick .m-smile { display: none; }
.pet.mood-sad .m-sad { display: inline; }
.pet.mood-sad .brows, .pet.mood-sick .brows { display: inline; }
.pet.mood-sad .body-wrap { animation: sadBreathe 3.6s ease-in-out infinite; }
.pet.mood-sad .cheek { display: none; }
.pet.mood-sad .pupil, .pet.mood-sick .pupil { transform: translateY(4px); }

.pet.mood-sick .m-sick, .pet.mood-sick .lids { display: inline; }
.pet.mood-sick .body-wrap { animation: shiver 1.6s ease-in-out infinite; }
.pet.mood-sick .cheek { fill: #8fd35f; }

.pet.mood-sleep .eyes-open, .pet.mood-sleep .m-smile { display: none; }
.pet.mood-sleep .eyes-closed, .pet.mood-sleep .m-o { display: inline; }
.pet.mood-sleep .m-o { transform: scale(.6); transform-box: fill-box; transform-origin: center; }
.pet.mood-sleep .body-wrap { animation: breathe 4.5s ease-in-out infinite; }
.pet.mood-sleep .arm-l, .pet.mood-sleep .arm-r, .pet.mood-sleep .antenna { animation: none; }

/* animazioni temporanee */
.pet.mood-a-happy .eyes-open, .pet.mood-a-happy .m-smile { display: none; }
.pet.mood-a-happy .eyes-happy, .pet.mood-a-happy .m-big { display: inline; }
.pet.mood-a-happy .body-wrap { animation: hop .45s ease-in-out 2; }
.pet.mood-a-happy .arm-l { animation: cheerL .22s ease-in-out infinite alternate; }
.pet.mood-a-happy .arm-r { animation: cheerR .22s ease-in-out infinite alternate; }

.pet.mood-a-open .m-smile { display: none; }
.pet.mood-a-open .m-eat { display: inline; }
.pet.mood-a-open .body-wrap { animation: lean .5s ease-out forwards; }

.pet.mood-a-eat .m-smile { display: none; }
.pet.mood-a-eat .m-eat { display: inline; transform-box: fill-box; transform-origin: center; animation: chomp .26s ease-in-out infinite; }
.pet.mood-a-eat .eyes-open { display: none; }
.pet.mood-a-eat .eyes-happy { display: inline; }
.pet.mood-a-eat .body-wrap { animation: munch .26s ease-in-out infinite; }

.pet.mood-a-sad .m-smile { display: none; }
.pet.mood-a-sad .m-sad, .pet.mood-a-sad .brows { display: inline; }
.pet.mood-a-sad .body-wrap { animation: no .25s ease-in-out 3; }

@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.025, .975); } }
@keyframes sadBreathe { 0%, 100% { transform: scale(1, .97) translateY(4px); } 50% { transform: scale(1.03, .94) translateY(6px); } }
@keyframes shiver { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-2px) scale(1.01, .99); } 40% { transform: translateX(2px); } 60% { transform: translateX(-1px); } }
@keyframes hop { 0%, 100% { transform: translateY(0) scale(1, 1); } 20% { transform: translateY(0) scale(1.12, .86); } 55% { transform: translateY(-34px) scale(.94, 1.08); } 85% { transform: translateY(0) scale(1.08, .92); } }
@keyframes lean { to { transform: scale(1.04, .97); } }
@keyframes munch { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.05, .95); } }
@keyframes chomp { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(.25); } }
@keyframes no { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
@keyframes wave { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-6deg); } }
@keyframes cheerL { to { transform: rotate(40deg) translate(-4px, -6px); } }
@keyframes cheerR { to { transform: rotate(-40deg) translate(4px, -6px); } }
@keyframes sway { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes bubbleIn { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }
@keyframes shake { 0%, 90%, 100% { transform: translateX(0); } 93% { transform: translateX(-2px); } 96% { transform: translateX(2px); } }
@keyframes popIn { from { transform: translateX(-50%) scale(.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes floatUp { from { opacity: 1; transform: translate(-50%, -50%); } to { opacity: 0; transform: translate(-50%, -150%) translateY(-50px); } }
@keyframes zzz { from { opacity: 0; transform: translate(0, 0) scale(.6); } 20% { opacity: 1; } to { opacity: 0; transform: translate(30px, -80px) scale(1.4); } }
@keyframes coinUp { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -140px) scale(1.4); } }
@keyframes drop { from { transform: translateY(0); } to { transform: translateY(60vh); opacity: .3; } }
@keyframes fly { 0% { transform: rotate(0deg) translateX(110px) rotate(0deg); } 100% { transform: rotate(360deg) translateX(110px) rotate(-360deg); } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- foglio a comparsa ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(40, 30, 70, .35); animation: fadeIn .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 76%; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 28px 28px 0 0; box-shadow: 0 -10px 30px rgba(60, 40, 100, .2);
  animation: slideUp .28s cubic-bezier(.2, .9, .3, 1); padding-bottom: var(--sab);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.sheet-head h2 { margin: 0; font-size: 1.2rem; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 20px; overscroll-behavior: contain; touch-action: pan-y; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; touch-action: pan-x; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 8px 12px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-weight: 800; font-size: .85rem; white-space: nowrap; }
.tab.sel { background: var(--ink); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card { background: var(--card); border-radius: 18px; padding: 10px 6px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: .82rem; }
.card .em { font-size: 2.2rem; line-height: 1.1; }
.card .qty { color: var(--muted); font-weight: 700; font-size: .75rem; }
.card .fx { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; min-height: 1.1em; }
.card .fx i { font-style: normal; font-size: .68rem; font-weight: 800; padding: 1px 4px; border-radius: 6px; }
.card .fx i.p { background: #e9fbe9; color: #2f9e55; } .card .fx i.n { background: #ffecef; color: #d23a4f; }
.card.food:active, .card.wear:active { transform: scale(.95); }
.card.wear.sel { box-shadow: inset 0 0 0 3px var(--accent), var(--shadow); }
.itemprev { width: 64px; height: 44px; }
.bgprev { width: 64px; height: 44px; border-radius: 10px; display: block; box-shadow: inset 0 0 0 2px rgba(0,0,0,.06); }
.hint { color: var(--muted); font-size: .85rem; text-align: center; }
.hint a { color: var(--accent-2); font-weight: 800; }
.empty { text-align: center; font-size: 3rem; padding: 20px 0; }
.empty p { font-size: 1rem; color: var(--muted); }

.games-list { display: flex; flex-direction: column; gap: 10px; }
.game-item { display: flex; align-items: center; gap: 12px; background: var(--card); padding: 12px 14px; border-radius: 20px; box-shadow: var(--shadow); text-align: left; }
.game-item:active { transform: scale(.97); }
.gi-icon { font-size: 2.2rem; }
.gi-txt { flex: 1; display: flex; flex-direction: column; }
.gi-txt small { color: var(--muted); font-weight: 700; }
.gi-go { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: .9rem; }

.daily { text-align: center; padding-bottom: 8px; }
.daily-gift { font-size: 4.5rem; animation: hop .7s ease-in-out 2; }
.daily-amt { font-size: 2rem; font-weight: 900; margin: 4px 0; color: #e5a300; }
.streak { display: flex; gap: 6px; justify-content: center; margin: 10px 0; }
.streak span { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #f1ecf4; font-weight: 800; color: var(--muted); }
.streak span.on { background: #ffcf3f; color: #7a5600; }

.settings label { display: block; font-weight: 800; margin: 8px 0 6px; }
.settings label input { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 14px; border: 3px solid var(--line); background: #fff; outline: none; color: var(--ink); }
.settings .swatches { justify-content: flex-start; max-width: none; margin-bottom: 8px; }
.settings h3 { margin: 18px 0 8px; font-size: 1rem; }
.row-btn { display: block; width: 100%; text-align: left; padding: 13px 14px; margin-bottom: 8px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); font-weight: 700; }
.row-btn:active { transform: scale(.98); }
.row-btn.danger { color: #d23a4f; }
.stats { line-height: 1.7; font-size: .9rem; }
.ver { opacity: .6; }

/* ---------- mini-giochi ---------- */
.game { position: fixed; inset: 0; z-index: 60; background: #fff1f7; touch-action: none; }
.game canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.game-hud { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 8px; align-items: center; padding: calc(var(--sat) + 10px) 14px 10px; pointer-events: none; z-index: 2; }
.game-hud > * { pointer-events: auto; }
.game-hud #gameScore { margin-left: auto; }
.game-hud .pill:empty { display: none; }
.game-card {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(88vw, 340px); z-index: 3;
  background: #fff; border-radius: 28px; padding: 22px 20px; text-align: center; box-shadow: 0 20px 50px rgba(60, 40, 100, .25);
  animation: fadeIn .25s;
}
.game-card h2 { margin: 4px 0 8px; }
.game-card p { color: var(--muted); margin: 6px 0; line-height: 1.4; }
.gc-icon { font-size: 3.4rem; }
.gc-score { font-size: 2rem; font-weight: 900; color: var(--ink) !important; }
.gc-rec { font-weight: 700; }
.gc-btns { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.memory {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -46%);
  width: min(92vw, 62vh, 420px); display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.mcard { aspect-ratio: 1; perspective: 600px; padding: 0; }
.mc-in { position: relative; display: block; width: 100%; height: 100%; transition: transform .35s; transform-style: preserve-3d; }
.mcard.flip .mc-in, .mcard.done .mc-in { transform: rotateY(180deg); }
.mc-back, .mc-front { position: absolute; inset: 0; display: grid; place-items: center; border-radius: 16px; backface-visibility: hidden; -webkit-backface-visibility: hidden; box-shadow: var(--shadow); }
.mc-back { background: linear-gradient(135deg, #ff9cc6, #a594ff); color: #fff; font-weight: 900; font-size: 1.6rem; }
.mc-front { background: #fff; transform: rotateY(180deg); font-size: 2rem; }
.mcard.done .mc-front { background: #e9fbe9; animation: pulse .4s; }
/* nasconde il lato coperto a metà rotazione (backface-visibility non è affidabile su WebKit) */
.mc-front, .mc-back { transition: visibility 0s .17s; }
.mc-front { visibility: hidden; }
.mcard.flip .mc-front, .mcard.done .mc-front { visibility: visible; }
.mcard.flip .mc-back, .mcard.done .mc-back { visibility: hidden; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--sab) + 96px); transform: translate(-50%, 20px); z-index: 90;
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 16px; font-weight: 700; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* schermi bassi (iPhone SE) */
@media (max-height: 640px) {
  .need .nl { display: none; }
  .actions button span { font-size: 1.3rem; }
  .actions { padding-top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .pet .body-wrap, .pet .arm-l, .pet .arm-r, .pet .antenna { animation: none !important; }
}
