/* 基础重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    /* 移除点击高亮 */
}

/* 根元素设置 */
html,
body {
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    overflow: hidden;
    position: fixed;
    /* 防止滚动 */
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #000;
}

/* 主容器 */
.container {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 400px;
    max-height: 809px;
    margin: 0 auto;
}

/* 页面通用样式 */
.page {
    position: relative;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
    height: 100%;
    -webkit-background-size: cover;
    background-size: cover;
    background-attachment: fixed;
}

/* 第一页背景 */
#page1 {
    background: url(../images/bg-page1.webp) no-repeat center center;
    background-size: cover;
}

/* 第二页背景 */
#page2 {
    background: url(../images/bg-page2.webp) no-repeat center center;
    background-size: cover;
}

/* 背景图片 */
.bg-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    object-fit: cover;
    z-index: 0;
}

/* 覆盖层 */
.overlay {
    position: relative;
    z-index: 10;
    width: 100%;
    height: 100%;
    min-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 按钮样式 */
.btn {
    margin: 30px;
    padding: 16px 32px;
    font-size: 18px;
    border: none;
    border-radius: 12px;
    background-color: orange;
    color: white;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    min-width: 44px;
    /* Apple 推荐的最小触摸目标 */
    min-height: 44px;
}

/* 音乐切换按钮 */
.music-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 20;
    background: rgba(0, 47, 189, 1);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

/* 棍子样式 */
.stick {
    position: absolute;
    top: 38%;
    left: 50%;
    width: 10px;
    height: 100px;
    transform: translateX(-50%) rotate(0deg);
    transform-origin: bottom center;
    transition: transform 0.2s ease;
    z-index: 10;
}

/* 绳子样式 */
.canRope {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 100px;
    background: url(../images/pg2-rope.webp) no-repeat center top;
    background-size: contain;
    z-index: 8;
}

/* 罐子轨道 */
.jarTrack {
    display: flex;
    width: max-content;
    animation: scrollJars 6s linear infinite;
    -webkit-animation: scrollJars 6s linear infinite;
}

/* 罐子样式 */
.jar {
    flex-shrink: 0;
    margin: 0 10px;
    height: 150px;
    width: auto;
    animation: floatJar 2s ease-in-out infinite;
}

/* 摇晃的罐子 */
.jar.shake {
    animation: jarShake 0.3s ease;
}

/* 角色样式 */
.character {
    position: absolute;
    bottom: 19%;
    left: 46%;
    transform: translateX(-50%);
    width: 26%;
    z-index: 9;
}

/* 结果文本 */
#resultText {
    margin: 10px auto 20px auto;
    font-size: 12px;
    color: white;
    text-align: center;
    text-shadow: 1px 1px 3px black;
    z-index: 10;
    background: rgba(0, 0, 0, 0.3);
    padding: 10px 20px;
    border-radius: 15px;
    display: none;
}

/* 动画定义 */
@keyframes scrollJars {
    0% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(-50%);
    }
}

@-webkit-keyframes scrollJars {
    0% {
        -webkit-transform: translateX(0);
    }

    100% {
        -webkit-transform: translateX(-50%);
    }
}

@keyframes jarShake {

    0%,
    100% {
        transform: translateY(0);
    }

    25% {
        transform: translateY(-5px) rotate(-2deg);
    }

    50% {
        transform: translateY(5px) rotate(2deg);
    }

    75% {
        transform: translateY(-5px);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(2deg);
    }

    50% {
        transform: rotate(-2deg);
    }

    75% {
        transform: rotate(2deg);
    }
}

@keyframes popUp {
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes zoomBounce {

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

    50% {
        transform: scale(1.08);
    }
}

@keyframes popBroken {
    0% {
        transform: scale(1) rotate(0);
    }

    30% {
        transform: scale(1.2) rotate(10deg);
    }

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

/* 动画类 */
.animate-pop-up {
    opacity: 0;
    transform: scale(0.8);
    animation: popUp 0.6s ease-out forwards;
}

.delay-1 {
    animation-delay: 0.3s;
}

.delay-2 {
    animation-delay: 0.6s;
}

.delay-3 {
    animation-delay: 0.9s;
}

.delay-4 {
    animation-delay: 1.2s;
}

.animate-shake {
    animation: shake 1s infinite;
}

.shake {
    animation: shake 0.4s ease;
}

.zoom-loop {
    animation: zoomBounce 1.2s ease-in-out infinite;
}

.jar.broken {
    animation: popBroken 0.6s ease-out;
}

/* 悬停效果 */
#successOverlay button.btn:hover {
    background: #ff9900;
    transform: scale(1.05);
}

/* 平板和桌面布局 */
@media (min-width: 768px) {
    .container {
        width: 400px;
        max-height: 809px;
        height: 100%;
        margin: 0 auto;
    }

    .jar {
        height: 150px !important;
    }
}

/* iPhone 5/SE */
@media only screen and (min-device-width: 320px) and (max-device-width: 568px) {
    .jar {
        height: 100px !important;
    }

    .character {
        bottom: 15%;
        width: 30%;
    }
}

/* iPhone 6/7/8 */
@media only screen and (min-device-width: 375px) and (max-device-width: 667px) {
    .jar {
        height: 120px !important;
    }
}

/* iPhone X/11 Pro */
@media only screen and (min-device-width: 375px) and (max-device-width: 812px) and (-webkit-device-pixel-ratio: 3) {
    .stick {
        top: 35%;
    }
}

/* iPhone 特定调整 */
@supports (-webkit-touch-callout: none) {
    .container {
        height: -webkit-fill-available;
    }

    .page {
        height: -webkit-fill-available;
    }
}