body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
    font-family: 'Microsoft YaHei', '微软雅黑', 'PingFang SC', 'Noto Sans CJK SC', 'Segoe UI', Arial, sans-serif;
    background: #b8e8c1;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    box-sizing: border-box;
    padding: 76px 18px max(18px, env(safe-area-inset-bottom));
    isolation: isolate;
    overflow: hidden;
    background: #d9efba;
}

.scene-background {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    pointer-events: none;
    user-select: none;
    transform: scale(1.002);
}

#game-container::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(255, 251, 222, 0.08) 0 55%, rgba(98, 67, 25, 0.12) 100%);
}

#game-container > .back-btn {
    z-index: 6;
}

#warmth-meter {
    position: absolute;
    top: 26px;
    left: 50%;
    transform: translateX(-50%);
    width: min(72vw, 360px);
    display: flex;
    align-items: center;
    gap: 12px;
    color: #7a4a00;
    font-size: 22px;
    font-weight: 800;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55);
    z-index: 4;
}

#collection-badge {
    position: absolute;
    top: 22px;
    right: max(18px, env(safe-area-inset-right));
    z-index: 4;
    padding: 8px 13px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    color: #7a4a00;
    box-shadow: 0 5px 14px rgba(97, 74, 27, 0.14);
    font-size: clamp(13px, 2.2vw, 17px);
    font-weight: 900;
}

#collection-badge.complete {
    background: #fff2a6;
    color: #b64d19;
}

#meter-track {
    flex: 1;
    height: 18px;
    border: 3px solid rgba(122, 74, 0, 0.38);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.56);
    overflow: hidden;
}

#meter-fill {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #ffcf56, #ff7b54);
    transition: width 0.18s ease;
}

#stage {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    place-items: center;
    position: relative;
    z-index: 2;
}

#nest,
#baby {
    grid-area: 1 / 1;
}

#nest {
    position: relative;
    width: min(70vmin, 54vh, 460px);
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nest-visual {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 112%;
    height: auto;
    pointer-events: none;
    user-select: none;
    transform: translateX(-50%);
}

.nest-back {
    z-index: 1;
    filter: drop-shadow(0 17px 15px rgba(67, 45, 20, 0.28));
}

.nest-front {
    z-index: 3;
    clip-path: inset(55% 0 0 0);
}

#egg-button {
    z-index: 2;
    width: 64%;
    height: 84%;
    border: 0;
    background: transparent;
    position: relative;
    display: grid;
    place-items: center;
    cursor: pointer;
    touch-action: none;
    transform-origin: bottom center;
    transform: translateY(-3%);
}

#egg-button.needs-guide::after {
    content: "☝";
    position: absolute;
    right: -3%;
    bottom: 34%;
    z-index: 3;
    font-size: clamp(42px, 9vmin, 72px);
    filter: drop-shadow(0 5px 5px rgba(70, 52, 31, 0.22));
    animation: eggGuide 1.15s ease-in-out infinite;
}

#egg {
    display: block;
    position: relative;
    z-index: 2;
    font-size: min(46vmin, 42vh, 270px);
    line-height: 1;
    filter: drop-shadow(0 12px 11px rgba(77, 48, 19, 0.25));
    transition: transform 0.18s ease;
}

#egg-button:active #egg,
#egg-button.warming #egg {
    transform: scale(1.06) rotate(-4deg);
}

#crack-line {
    position: absolute;
    z-index: 4;
    top: 33%;
    left: 43%;
    width: 6px;
    height: 0;
    border-radius: 999px;
    background: #9b6a38;
    transform: rotate(22deg);
    opacity: 0;
    transition: height 0.2s ease, opacity 0.2s ease;
}

#egg-button.cracked #crack-line {
    height: 36%;
    opacity: 1;
}

#hint {
    text-align: center;
    font-size: clamp(20px, 5vw, 32px);
    color: #6e4a24;
    font-weight: 800;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55);
}

#baby {
    z-index: 2;
    width: min(46vmin, 38vh, 310px);
    height: min(46vmin, 38vh, 310px);
    display: grid;
    place-items: center;
    font-size: min(40vmin, 34vh, 250px);
    line-height: 1;
    transform: scale(0);
    animation: babyPop 0.5s cubic-bezier(0.22, 1.35, 0.36, 1) forwards;
    filter: drop-shadow(0 14px 18px rgba(70, 70, 70, 0.24));
}

#baby img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#game-footer {
    flex: 0 0 auto;
    width: min(92vw, 560px);
    min-height: clamp(112px, 17vh, 164px);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-align: center;
    position: relative;
    z-index: 2;
}

#result-copy {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: #5d3a1d;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.6);
}

#result-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

#baby-name {
    font-size: clamp(23px, 4.6vw, 34px);
}

#baby-rarity {
    border: 2px solid rgba(93, 58, 29, 0.22);
    border-radius: 999px;
    padding: 3px 10px;
    background: rgba(255, 255, 255, 0.72);
    font-size: clamp(14px, 2.8vw, 18px);
    font-weight: 900;
}

#baby-rarity[data-rarity="稀有"] {
    color: #7552b7;
    background: #f1e9ff;
}

#baby-rarity[data-rarity="传说"] {
    color: #b64d19;
    background: linear-gradient(135deg, #fff2a6, #ffd3a0);
}

#baby-line {
    font-size: clamp(16px, 3.4vw, 21px);
    font-weight: 800;
}

#again-btn {
    border: 0;
    border-radius: 999px;
    padding: 12px 30px;
    background: #ff7b54;
    color: #fff;
    font: inherit;
    font-size: 26px;
    font-weight: 900;
    box-shadow: 0 7px 0 #c9492f;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

#again-btn:active {
    transform: translateY(5px);
    box-shadow: 0 2px 0 #c9492f;
}

#confetti-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 5;
}

.confetti {
    position: absolute;
    width: 11px;
    height: 18px;
    border-radius: 4px;
    animation: confettiFly 900ms ease-out forwards;
}

.hidden {
    display: none !important;
}

@keyframes babyPop {
    0% {
        transform: scale(0) rotate(-12deg);
    }

    70% {
        transform: scale(1.12) rotate(4deg);
    }

    100% {
        transform: scale(1) rotate(0);
    }
}

@keyframes confettiFly {
    0% {
        opacity: 1;
        transform: translate(0, 0) rotate(0deg) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(var(--x), var(--y)) rotate(var(--r)) scale(0.72);
    }
}

@keyframes eggGuide {
    0%, 100% { transform: translate(0, 0) rotate(-18deg) scale(.94); }
    50% { transform: translate(-12px, -18px) rotate(-18deg) scale(1.06); }
}

@media (max-width: 640px) {
    #game-container {
        padding-top: 64px;
    }

    #warmth-meter {
        top: 18px;
        width: calc(100vw - 140px);
        font-size: 18px;
    }

    #collection-badge {
        top: 66px;
        right: 10px;
    }

    #game-footer {
        min-height: 122px;
        gap: 8px;
    }

    #again-btn {
        padding: 10px 26px;
        font-size: 22px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #egg-button.needs-guide::after { animation: none; }
}

@media (max-height: 620px) {
    #game-container {
        padding-top: 58px;
    }

    #warmth-meter {
        top: 14px;
    }

    #game-footer {
        min-height: 108px;
    }

    #baby-line {
        display: none;
    }
}
