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

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: #ffe9f0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
}

img {
    -webkit-user-drag: none;
    user-select: none;
    pointer-events: none;
}

button {
    border: 0;
    background: none;
    padding: 0;
    cursor: pointer;
    font: inherit;
}

#app {
    position: fixed;
    inset: 0;
    overflow: hidden;
}

#backdrop {
    position: absolute;
    inset: 0;
    transition: background 0.6s;
}

#stage {
    position: absolute;
    left: 0;
    top: 0;
    height: 1000px;
    transform-origin: 0 0;
}

#scene, #catLayer, #front, #fx, #dragLayer {
    position: absolute;
    inset: 0;
}

#catLayer, #fx, #dragLayer {
    pointer-events: none;
}

#dragLayer > * {
    pointer-events: auto;
}

#fx {
    z-index: 30;
}

#dragLayer {
    z-index: 40;
}

#front {
    z-index: 20;
    pointer-events: none;
}

#front > * {
    pointer-events: auto;
}

#catLayer {
    z-index: 10;
}

/* ---------- cat rig ---------- */
.cat {
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
}

.bone {
    position: absolute;
    left: 0;
    top: 0;
    width: 466px;
    height: 726px;
    transform-origin: 0 0;
    will-change: transform;
    pointer-events: none;
}

.bone img, .bone svg {
    position: absolute;
}

.cat-shadow {
    position: absolute;
    width: 300px;
    height: 46px;
    margin-left: -150px;
    margin-top: -23px;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(90, 50, 40, 0.32), rgba(90, 50, 40, 0));
    will-change: transform;
}

/* ---------- fx ---------- */
.fx {
    position: absolute;
    left: 0;
    top: 0;
    will-change: transform, opacity;
    pointer-events: none;
}

.foam {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff 0 35%, #eaf6ff 60%, #cfe9fb 100%);
    box-shadow: inset -3px -4px 6px rgba(120, 170, 210, 0.35), 0 2px 4px rgba(0, 0, 0, 0.06);
    pointer-events: none;
}

.bubble-fx {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 0.95) 0 14%, rgba(200, 235, 255, 0.25) 40%, rgba(150, 200, 255, 0.35) 100%);
    border: 2px solid rgba(255, 255, 255, 0.8);
}

.drop {
    position: absolute;
    width: 14px;
    height: 20px;
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    background: radial-gradient(circle at 35% 35%, #fff 0 18%, #8fd3ff 45%, #3aa6f0 100%);
}

/* ---------- HUD ---------- */
#hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 50;
}

.hud-btn {
    position: absolute;
    pointer-events: auto;
    transition: transform .15s;
}

.hud-btn:active {
    transform: scale(0.9);
}

#btnHome {
    left: max(16px, env(safe-area-inset-left));
    top: max(14px, env(safe-area-inset-top));
    width: 92px;
    transition: transform .2s, opacity .3s;
}

#btnHome img {
    width: 100%;
    filter: drop-shadow(0 6px 8px rgba(120, 40, 70, 0.3));
}

#btnHome.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(.5);
}

#btnMusic {
    right: max(16px, env(safe-area-inset-right));
    top: max(14px, env(safe-area-inset-top));
    width: 76px;
}

#btnMusic img {
    width: 100%;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2));
}

@keyframes houseBreath {
    0%, 100% {
        transform: scale(1) rotate(-2deg);
    }
    50% {
        transform: scale(1.05) rotate(2deg);
    }
}

#btnHome.hint img {
    animation: houseHint .9s ease-in-out infinite;
}

.yard-spot {
    transition: transform .15s;
}

.yard-spot.need {
    animation: tilePulse 1s ease-in-out infinite;
    filter: drop-shadow(0 0 18px rgba(255, 240, 120, 1));
}

.tray {
    position: absolute;
    border-radius: 46px;
    pointer-events: none;
    background: linear-gradient(rgba(255, 255, 255, .72), rgba(255, 244, 250, .6));
    box-shadow: 0 10px 30px rgba(120, 60, 90, .18), inset 0 3px 0 rgba(255, 255, 255, .9);
    border: 4px solid rgba(255, 255, 255, .85);
}

@keyframes houseHint {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.18) rotate(-4deg);
    }
}

/* need gauges */
#needs {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 25px;
    pointer-events: auto;
}

.gauge {
    --v: 100;
    --c: #5fd068;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    padding: 7px;
    position: relative;
    background: conic-gradient(var(--c) calc(var(--v) * 1%), rgba(255, 255, 255, .6) 0);
    box-shadow: 0 5px 12px rgba(80, 40, 60, .22);
    transition: transform .15s;
}

.gauge:active {
    transform: scale(.9);
}

.gauge .in {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #fff;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gauge .icon {
    width: 80%;
    height: 80%;
    object-fit: contain;
}

.gauge.low {
    animation: gaugeBeg 1.1s ease-in-out infinite;
}

@keyframes gaugeBeg {
    0%, 100% {
        transform: scale(1) rotate(0);
    }
    20% {
        transform: scale(1.12) rotate(-8deg);
    }
    40% {
        transform: scale(1.12) rotate(8deg);
    }
    60% {
        transform: scale(1.05) rotate(0);
    }
}

@media (max-width: 560px) {
    .gauge {
        width: 54px;
        height: 54px;
        padding: 5px;
    }

    #needs {
        gap: 7px;
        top: 84px;
    }
}

/* need bubble: cloud (size set from WISH.cloudW in js/config.js) + wish icon + thought dots */
.need-bubble {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: auto;
    z-index: 25;
    transform-origin: 50% 80%;
}

.need-bubble .cloud {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* thin bluish outline + soft shadow: readable on a white wall too */
    filter: drop-shadow(0 0 1.5px rgba(80, 105, 160, .75)) drop-shadow(0 5px 8px rgba(0, 0, 0, 0.18));
}

.need-bubble.left .cloud {      /* on the left the cloud is mirrored, the icon is not */
    transform: scaleX(-1);
}

.need-bubble .icon {
    position: absolute;
    left: 20%;
    top: 16%;
    width: 60%;
    height: 64%;
    object-fit: contain;
}

.think-dot {
    position: absolute;
    left: 0;
    top: 0;
    border-radius: 50%;
    pointer-events: none;
    z-index: 24;
    transform-origin: 0 0;
    background: radial-gradient(circle at 35% 30%, #fff 0 45%, #eef2fa 100%);
    box-shadow: 0 0 0 1.5px rgba(80, 105, 160, .55), 0 3px 6px rgba(0, 0, 0, .14), inset 0 -2px 3px rgba(170, 185, 215, .35);
}


/* ---------- yard house (js/house.js) ----------
   The house fills the box the yard gives it (maxW x maxH in js/scenes/yard.js, passed in as
   --house-w / --house-h): the roof takes its height, the wall the rest; window columns and
   rows share the wall equally (1fr), so windows stretch to fill it. */
.house {
    --house-top-room: 70px;  /* space above the roof for the figure on the ridge */
    --house-roof-max: 230px; /* roof height limit (a wide house would get a very tall roof) */
    --house-roof-tuck: 34px; /* how far the roof covers the top of the wall */
    --house-gap: 20px;       /* between windows */
    --house-pad: 16px;       /* wall above / below the windows */
    --house-side: 18px;      /* wall left / right of the windows */
    --house-pillar: 40px;    /* corner pillars */
    --house-eave: 30px;      /* eave under the roof */
    --house-found: 44px;     /* foundation */
    --house-roof-over: 7%;   /* roof overhang on each side (of the house width) */
    position: absolute;
}

.house-in {
    position: absolute;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    width: var(--house-w);
    height: var(--house-h);
    padding-top: var(--house-top-room);
    padding-inline: calc(var(--house-w) * 0.061);   /* room for the roof overhang: the roof is exactly --house-w wide */
    filter: drop-shadow(0 16px 16px rgba(60, 40, 30, .22));
}

.h-part {
    position: absolute;
    pointer-events: none;
    user-select: none;
}

/* roof block: as wide as the house plus the overhang; the parts inside are placed in % of it */
.h-roofbox {
    position: relative;
    z-index: 2;
    flex: none;
    width: calc(100% + 2 * var(--house-roof-over));
    max-height: var(--house-roof-max);   /* lower than the picture -> a flatter roof */
    margin: 0 calc(-1 * var(--house-roof-over)) calc(-1 * var(--house-roof-tuck));
}

.h-roof {
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.h-chimney {        /* behind the roof, right of the ridge */
    height: 95%;
    left: 60%;
    bottom: 38%;
    z-index: 0;
}

.h-ear {            /* behind the roof, on the slopes; the right ear is the left one mirrored */
    height: 60%;
    bottom: 38%;
    left: 20%;
    transform: translateX(-50%) rotate(351deg);
    z-index: 0;
}


.h-ear-r {
    left: 80%;
    transform: translateX(-50%) scaleX(-1) rotate(351deg);
}

.h-ridge {          /* figure standing on the ridge */
    height: 42%;
    left: 50%;
    bottom: 90%;
    transform: translateX(-50%);
    z-index: 2;
}

.h-sign {           /* hangs under the ridge */
    height: 32%;
    left: 50%;
    top: 15%;
    transform: translateX(-50%);
    z-index: 3;
}

.h-attic {          /* round window low in the gable */
    height: 40%;
    left: 50%;
    top: 70%;
    transform: translate(-50%, -50%);
    z-index: 2;
}

/* body: the wall with the window grid; pillars, eave and foundation are drawn over its edges */
.h-body {
    position: relative;
    z-index: 1;
    flex: 1;
    min-height: 0;
    display: flex;
    padding: calc(var(--house-eave) / 2) calc(var(--house-pillar) / 2) calc(var(--house-found) / 2);
}

.h-wall {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-template-rows: repeat(var(--rows), minmax(0, 1fr));   /* minmax(0, ..): icons never push a row taller */
    gap: var(--house-gap);
    padding: calc(var(--house-pad) + var(--house-eave) / 2) calc(var(--house-side) + var(--house-pillar) / 2) calc(var(--house-pad) + var(--house-found) / 2);
    border-radius: 8px;
    background: repeating-linear-gradient(90deg, rgba(255, 255, 255, .22) 0 3px, transparent 3px 46px),
    linear-gradient(color-mix(in srgb, var(--wall) 92%, #fff), color-mix(in srgb, var(--wall) 88%, var(--accent)));
    box-shadow: inset 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent), inset 0 10px 18px rgba(0, 0, 0, .06);
}

.h-strip {
    position: absolute;
    z-index: 2;
    border-style: solid;
}

.h-pillar {
    top: 0;
    bottom: calc(var(--house-found) / 2);
    width: var(--house-pillar);
}

.h-pillar.l { left: 0; }
.h-pillar.r { right: 0; }

.h-eave {
    top: 0;
    left: calc(var(--house-pillar) * -0.3);
    right: calc(var(--house-pillar) * -0.3);
    height: var(--house-eave);
}

.h-foundation {
    bottom: 0;
    left: calc(var(--house-pillar) * -0.15);
    right: calc(var(--house-pillar) * -0.15);
    height: var(--house-found);
}

/* the character's extra decoration (characters.js house.extraPlace) */
.h-extra.behind {   /* pokes out from behind the right side (a tail): under the wall */
    right: 0;
    bottom: 10%;
    height: 62%;
    transform: translateX(55%);
    z-index: -1;
}

.h-extra.ground {   /* stands on the ground at the right corner of the house */
    right: 0;
    bottom: 0;
    height: 30%;
    transform: translateX(45%);
    z-index: 3;
}

.h-extra.eave {     /* a garland under the eave, in the middle */
    top: calc(var(--house-eave) * 0.55);
    left: 50%;
    width: 34%;
    transform: translateX(-50%);
    z-index: 3;
}

/* room windows: pastel rounded squares with the room icon */
.win {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    border-radius: 28px;
    cursor: pointer;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 50% 32%, #fff 0 18%, var(--room) 70%);
    border: 7px solid rgba(255, 255, 255, .92);
    box-shadow: inset 0 7px 14px rgba(60, 40, 60, .18), inset 0 -4px 8px rgba(255, 255, 255, .6), 0 4px 0 rgba(120, 80, 60, .12);
    transition: transform .15s;
}

.win img {          /* the room icon, kept inside the window whatever its shape */
    position: absolute;
    inset: 10%;
    width: 80%;
    height: 80%;
    object-fit: contain;
    pointer-events: none;
    filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .15));
}

.win:active {
    transform: scale(.93);
}

/* "the pet wants to go here": glow + pulse + 3 little rays */
.win.need {
    z-index: 3;
    box-shadow: inset 0 7px 14px rgba(60, 40, 60, .12), 0 0 0 6px #fff4a0, 0 0 30px 14px rgba(255, 210, 60, .9);
    animation: winPulse 1s ease-in-out infinite;
}

.win.need::before {
    content: "";
    position: absolute;
    left: 50%;
    top: -62px;
    width: 110px;
    height: 52px;
    transform: translateX(-50%);
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 110 52'%3E%3Cg stroke='%23ffc93c' stroke-width='9' stroke-linecap='round'%3E%3Cpath d='M55 8v30M20 18l14 22M90 18L76 40'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
    animation: winRays 1s ease-in-out infinite;
    pointer-events: none;
}

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

@keyframes winRays {
    0%, 100% {
        opacity: .55;
        transform: translateX(-50%) translateY(4px) scale(.9);
    }
    50% {
        opacity: 1;
        transform: translateX(-50%) translateY(-4px) scale(1.05);
    }
}

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

/* ---------- night ---------- */
#night {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 45;
    opacity: 0;
    transition: opacity 1.2s;
    background: radial-gradient(60% 60% at 50% 55%, rgba(30, 20, 80, 0.25), rgba(15, 10, 50, 0.72));
}

#night.on {
    opacity: 1;
}

/* ---------- character choice (start screen) ---------- */
#chooser {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% 40%, rgba(255, 246, 236, .82), rgba(255, 214, 230, .88));
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .35s;
}

#chooser.open {
    opacity: 1;
    pointer-events: auto;
}

.ch-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: clamp(20px, 5vw, 56px);
    padding: 24px;
}

.ch-btn {
    width: clamp(150px, 26vmin, 250px);
    height: clamp(150px, 26vmin, 250px);
    border-radius: 50%;
    overflow: hidden;
    background: radial-gradient(circle at 50% 35%, #fff7e8, #ffd9b0);
    border: 9px solid #fff;
    box-shadow: 0 14px 30px rgba(120, 60, 40, .25);
    animation: chBob 2.4s ease-in-out infinite;
    transition: transform .15s;
}

.ch-btn:nth-child(2) {
    animation-delay: -.8s;
}

.ch-btn:nth-child(3) {
    animation-delay: -1.6s;
}

.ch-btn:active {
    transform: scale(.92);
}

.ch-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ch-btn.on {
    border-color: #ffcf3f;
    box-shadow: 0 0 0 10px rgba(255, 207, 63, .35), 0 14px 30px rgba(120, 60, 40, .25);
}

@keyframes chBob {
    0%, 100% {
        transform: translateY(0) rotate(-2deg);
    }
    50% {
        transform: translateY(-12px) rotate(2deg);
    }
}

/* change-character button: held to open the choice (ring fills while held) */
#btnChar {
    right: max(16px, env(safe-area-inset-right));
    top: calc(max(14px, env(safe-area-inset-top)) + 118px);
    width: 70px;
    height: 70px;
    border-radius: 50%;
    padding: 6px;
    --p: 0;
    background: conic-gradient(#ffcf3f calc(var(--p) * 1turn), rgba(255, 255, 255, .9) 0);
    box-shadow: 0 6px 14px rgba(90, 50, 30, .25);
    touch-action: none;
}

#btnChar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    background: #fff3e0;
}

#btnChar .swap {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
    display: grid;
    place-items: center;
}

#btnChar .swap svg {
    width: 20px;
    height: 20px;
}

#btnChar.holding {
    transform: scale(1.12);
}

/* ---------- scene parts ---------- */
.abs {
    position: absolute;
}

.prop {
    position: absolute;
    touch-action: none;
    cursor: grab;
    transform-origin: 50% 50%;
}

.prop img, .prop svg {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    filter: drop-shadow(0 8px 6px rgba(70, 40, 30, 0.22));
}

.prop.dragging {
    cursor: grabbing;
    z-index: 50;
}

.prop.dragging img, .prop.dragging svg {
    filter: drop-shadow(0 18px 14px rgba(70, 40, 30, 0.28));
}

.wiggle {
    animation: wiggle 1.6s ease-in-out infinite;
}

@keyframes wiggle {
    0%, 80%, 100% {
        transform: rotate(0);
    }
    85% {
        transform: rotate(-8deg);
    }
    90% {
        transform: rotate(8deg);
    }
    95% {
        transform: rotate(-4deg);
    }
}

.hint-hand {
    position: absolute;
    width: 90px;
    height: 90px;
    pointer-events: none;
    z-index: 55;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, .95) 0 30%, rgba(190, 140, 255, .55) 32% 52%, rgba(190, 140, 255, 0) 54%);
}

/* garden: the plot the watering can pours on */
.hot.target img { filter: drop-shadow(0 0 14px rgba(110, 200, 255, .95)) brightness(1.08); }

/* garden: ring that fills while a ripe veg is held */
.pull-ring { position: absolute; width: 140px; height: 140px; border-radius: 50%; pointer-events: none; z-index: 32;
  background: conic-gradient(#5fd068 calc(var(--p, 0) * 1%), rgba(255,255,255,.55) 0);
  -webkit-mask: radial-gradient(circle, transparent 58px, #000 59px); mask: radial-gradient(circle, transparent 58px, #000 59px); }

/* ---------- playroom toy cabinet & mini-games ---------- */
.toy-btn {
    cursor: pointer;
    transition: transform .15s;
    filter: drop-shadow(0 6px 6px rgba(90, 50, 20, .25));
    animation: toyBob 3.2s ease-in-out infinite;
}
.toy-btn:nth-child(odd) { animation-delay: -1.6s; }
.toy-btn.picked { transform: scale(1.25); }
.toy-btn.wiggle { animation: wiggle 1.6s ease-in-out infinite; }
@keyframes toyBob {
    0%, 100% { transform: translateY(0) rotate(0); }
    50% { transform: translateY(-5px) rotate(-2deg); }
}
.game-bubble {
    position: absolute;
    left: 0;
    top: 0;
    border-radius: 50%;
    cursor: pointer;
    background:
        radial-gradient(circle at 30% 26%, rgba(255, 255, 255, .95) 0 9%, rgba(255, 255, 255, 0) 16%),
        radial-gradient(circle at 70% 75%, rgba(255, 255, 255, .5) 0 5%, rgba(255, 255, 255, 0) 10%),
        radial-gradient(circle at 50% 50%, rgba(190, 235, 255, .08) 55%, rgba(255, 150, 220, .35) 75%, rgba(120, 220, 255, .5) 90%, rgba(255, 240, 150, .6) 100%);
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .75), 0 4px 12px rgba(80, 140, 200, .15);
    touch-action: none;
}
.game-bubble.gold {
    background:
        radial-gradient(circle at 30% 26%, rgba(255, 255, 255, .95) 0 9%, rgba(255, 255, 255, 0) 16%),
        radial-gradient(circle at 50% 50%, rgba(255, 230, 120, .15) 50%, rgba(255, 200, 60, .55) 85%, rgba(255, 170, 40, .75) 100%);
    box-shadow: inset 0 0 0 4px rgba(255, 245, 200, .9), 0 0 24px rgba(255, 210, 80, .6);
}
.xylo-bar {
    position: absolute;
    border-radius: 26px;
    cursor: pointer;
    box-shadow: inset 0 -10px 0 rgba(0, 0, 0, .12), inset 0 8px 0 rgba(255, 255, 255, .35), 0 10px 14px rgba(80, 40, 20, .25);
    transform-origin: 50% 50%;
}
.xylo-bar::before, .xylo-bar::after {
    content: '';
    position: absolute;
    left: 50%;
    width: 18px;
    height: 18px;
    margin-left: -9px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .8);
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, .2);
}
.xylo-bar::before { top: 16px; }
.xylo-bar::after { bottom: 20px; }
.xylo-bar.lit { filter: brightness(1.25) saturate(1.2); }
