* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* 添加硬件加速支持 */
    -webkit-transform: translateZ(0);
    -moz-transform: translateZ(0);
    -ms-transform: translateZ(0);
    -o-transform: translateZ(0);
    transform: translateZ(0);
    /* 优化高帧率动画 */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

html, body {
    overflow: hidden; /* 防止整个页面滚动 */
    width: 100%;
    height: 100%;
    /* 消除边距 */
    margin: 0;
    padding: 0;
    /* 防止iOS橡皮筋效果 */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

body {
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    max-height: 100vh;
    /* 使用var(--vh)变量修复iOS 100vh问题 */
    min-height: calc(var(--vh, 1vh) * 100);
    max-height: calc(var(--vh, 1vh) * 100);
    background-color: #87CEEB;
    overflow: hidden;
    margin: 0;
    padding: 0;
    touch-action: manipulation; /* 防止iOS上的双击缩放 */
    -webkit-touch-callout: none; /* 禁止长按菜单 */
    -webkit-user-select: none; /* 禁止文本选择 */
    user-select: none;
}

.game-container {
    position: fixed; /* 改为fixed确保始终固定在视口 */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: calc(var(--vh, 1vh) * 100); /* 使用CSS变量修复iOS的100vh问题 */
    max-width: 100%;
    max-height: 100vh;
    max-height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
    /* 添加硬件加速支持 */
    will-change: transform;
    /* 优化触摸操作 */
    touch-action: none;
    /* 优化动画性能 */
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    height: calc(var(--vh, 1vh) * 100);
    background-color: #87CEEB;
    position: absolute;
    top: 0;
    left: 0;
    /* 开启硬件加速 */
    will-change: transform;
    transform: translateZ(0);
    /* 优化图像渲染 */
    image-rendering: optimizeSpeed;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    text-align: center;
    z-index: 10;
    padding: 20px;
    overflow-y: auto; /* 允许屏幕内容滚动 */
    -webkit-overflow-scrolling: touch; /* 提供iOS上的平滑滚动 */
    box-sizing: border-box; /* 确保padding不会增加尺寸 */
}

#start-screen {
    display: flex;
}

#game-over-screen {
    display: none;
    overflow-y: auto;
    max-height: 100vh;
    padding-bottom: 20px; /* 减少底部填充 */
}

.game-over-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 20px;
    max-width: 600px; /* 限制最大宽度 */
}

.restart-button-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 30px;
    position: sticky;
    bottom: 20px; /* 在移动设备上保持在底部可见 */
}

.restart-button-container button {
    min-width: 200px;
    width: 80%;
    max-width: 300px;
}

h1, h2 {
    margin-bottom: 20px;
    font-size: 2.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

p {
    margin-bottom: 20px;
    font-size: 1.2rem;
    line-height: 1.4;
    max-width: 90%;
}

button {
    padding: 15px 30px;
    font-size: 1.2rem;
    background-color: #FFD700;
    color: #000;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 20px;
    font-weight: bold;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s, background-color 0.2s;
}

button:hover {
    background-color: #FFC107;
}

button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#score-display {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 42px;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
    z-index: 5;
}

.difficulty-text {
    color: #FFD700;
    font-weight: bold;
    font-size: 1.2rem;
    margin-bottom: 20px;
}

/* 响应式设计 - 横屏模式 */
@media (orientation: landscape) {
    .game-container {
        aspect-ratio: 16 / 9;
        max-height: 100vh;
        width: auto;
        margin: 0 auto;
    }
}

/* 响应式设计 - 竖屏模式 */
@media (orientation: portrait) {
    .game-container {
        aspect-ratio: auto;
        width: 100%;
        height: 100vh;
        margin: 0;
    }
    
    #score-display {
        top: 20px;
        right: 20px;
        font-size: 2.5rem;
    }
    
    h1, h2 {
        font-size: 2.8rem;
        margin-bottom: 30px;
    }
    
    p {
        font-size: 1.4rem;
        margin-bottom: 25px;
    }
    
    button {
        padding: 16px 36px;
        font-size: 1.5rem;
        border-radius: 10px;
        margin-top: 30px;
    }
}

/* 添加小屏幕手机适配 */
@media (max-height: 600px) and (orientation: portrait) {
    h1, h2 {
        font-size: 2.2rem;
        margin-bottom: 15px;
    }
    
    p {
        font-size: 1.2rem;
        margin-bottom: 15px;
    }
    
    button {
        padding: 12px 28px;
        font-size: 1.3rem;
        margin-top: 15px;
    }
}

/* 解决顶部安全区域问题 */
@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* 排行榜样式 */
#leaderboard-container {
    margin-top: 20px;
    max-width: 90%;
    width: 100%;
    max-height: 35vh; /* 降低高度，避免占用过多屏幕空间 */
    overflow-y: auto;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 30px; /* 增加底部间距，确保不遮挡按钮 */
}

#leaderboard-list table {
    width: 100%;
    border-collapse: collapse;
    color: white;
}

#leaderboard-list th, 
#leaderboard-list td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

#leaderboard-list th {
    background-color: rgba(0, 0, 0, 0.3);
    font-weight: bold;
}

/* 排行榜加载中状态样式 */
#leaderboard-list .loading-spinner {
    margin: 20px auto;
    width: 40px;
    height: 40px;
}

#leaderboard-list p {
    text-align: center;
    margin: 10px auto;
    color: #FFD700;
}

#player-name {
    padding: 10px;
    font-size: 16px;
    border: none;
    border-radius: 5px;
    margin-bottom: 10px;
    width: 80%;
    max-width: 300px;
}

#submit-score-button {
    display: block;
    margin: 10px auto;
}

#view-leaderboard-button {
    margin-top: 10px;
}

/* 移动设备上的特殊样式 */
@media (max-height: 700px) and (orientation: portrait) {
    #game-over-screen {
        padding-top: 60px;
        justify-content: flex-start;
    }
    
    #leaderboard-container {
        max-height: 28vh; /* 在小屏幕手机上进一步降低高度 */
        margin-bottom: 35px; /* 增加底部间距 */
    }
    
    #restart-button {
        position: relative;
        margin-top: 25px;
        margin-bottom: 20px;
        z-index: 20;
    }
}

/* 极小屏幕上的特殊处理 */
@media (max-height: 600px) {
    #leaderboard-container {
        max-height: 25vh; /* 更小的屏幕上进一步减少高度 */
        margin-bottom: 25px;
    }
    
    h1, h2 {
        font-size: 1.8rem;
        margin-bottom: 10px;
    }
    
    .game-over-content {
        padding-bottom: 10px;
    }
}

/* 添加加载界面样式 */
#loading-screen {
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 100;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #FFC107;
    margin: 20px auto;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-message {
    color: white;
    font-size: 16px;
    margin-top: 20px;
}

/* 更新通知样式 */
.notification {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(255, 193, 7, 0.9);
    color: #333;
    padding: 10px 20px;
    border-radius: 5px;
    z-index: 50;
    display: flex;
    align-items: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    max-width: 90%;
    animation: slideDown 0.5s ease-out;
}

@keyframes slideDown {
    from { top: -50px; opacity: 0; }
    to { top: 20px; opacity: 1; }
}

.notification p {
    margin: 0 10px 0 0;
}

#close-notification {
    background: none;
    border: none;
    color: #333;
    font-size: 18px;
    cursor: pointer;
    padding: 0 5px;
}

/* 游戏模式选择样式 */
.game-modes {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
    width: 100%;
    max-width: 400px;
}

.mode-button {
    width: 80%;
    margin: 10px 0;
    background-color: #4CAF50;
    color: white;
    padding: 15px;
    font-size: 18px;
    font-weight: bold;
    border-radius: 10px;
    transition: all 0.3s ease;
}

.mode-button:hover {
    transform: scale(1.05);
    background-color: #45a049;
}

#endless-mode-button {
    background-color: #2196F3;
    font-size: 16px;
    padding: 12px;
}

#endless-mode-button:hover {
    background-color: #0b7dda;
}

#daily-challenge-button {
    background-color: #ff9800;
    font-size: 20px;
    padding: 18px;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
}

#daily-challenge-button:hover {
    background-color: #e68a00;
    transform: scale(1.15);
}

.mode-description {
    font-size: 14px;
    color: #FFC107;
    margin-top: 5px;
    text-align: center;
}

/* 胜利界面样式 */
#victory-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    text-align: center;
    z-index: 10;
}

.victory-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

.victory-title {
    color: #FFD700;
    font-size: 3rem;
    margin-bottom: 20px;
    text-shadow: 0 0 10px #FFD700, 0 0 20px #FFD700;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* 挑战日期样式 */
.challenge-date {
    color: #FFC107;
    font-weight: bold;
    margin: 5px 0;
}

/* 单独调整日期文字颜色 */
#challenge-date-display, #victory-date-display {
    color: #FFC107;
    font-weight: bold;
}

/* 移动设备上的游戏结束屏幕优化 */
@media (max-width: 480px) {
    /* 确保游戏结束屏幕适合移动设备屏幕 */
    #game-over-screen, #victory-screen {
        padding: 10px 5px;
        overflow-y: auto;
        max-height: 100%;
        justify-content: flex-start;
        position: fixed; /* 防止内容溢出引起页面滚动 */
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    /* 进一步减少内容之间的间距 */
    .game-over-content, .victory-content {
        padding: 5px;
        margin-top: 10px;
        margin-bottom: 20px; /* 确保底部有足够空间 */
        height: auto; /* 高度自适应 */
        max-height: 100%; /* 最大高度100% */
    }
    
    /* 按钮改为垂直排列并调整尺寸 */
    .restart-button-container {
        flex-direction: column;
        width: 100%;
        align-items: center;
        gap: 10px;
        margin-top: 15px;
    }
    
    .restart-button-container button {
        width: 80%;
        max-width: 250px;
        white-space: nowrap;
        padding: 10px 15px;
        margin: 0;
        font-size: 1rem;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* 减少各元素间的间距 */
    #game-over-screen h2, #victory-screen h2 {
        font-size: 1.8rem;
        margin-bottom: 8px;
        margin-top: 8px;
    }
    
    #game-over-screen p, #victory-screen p {
        font-size: 0.95rem;
        margin-bottom: 5px;
        margin-top: 0;
    }
    
    /* 整体减少内容的上下间距 */
    .game-over-content > *, .victory-content > * {
        margin-top: 3px;
        margin-bottom: 3px;
    }
    
    /* 减少输入框容器和排行榜容器的内边距 */
    #name-input-container, #leaderboard-container {
        padding: 5px;
        margin-top: 8px;
    }
    
    /* 优化输入框样式 */
    #player-name {
        padding: 8px;
        font-size: 14px;
        margin-bottom: 5px;
    }
    
    /* 优化提交按钮样式 */
    #submit-score-button {
        padding: 8px 15px;
        font-size: 14px;
        margin: 5px auto;
    }
    
    /* 调整排行榜标题大小 */
    #leaderboard-container h3 {
        font-size: 1rem;
        margin: 5px 0;
    }
    
    /* 优化排行榜样式 */
    #leaderboard-container {
        max-height: 22vh;
        padding: 5px;
        margin-bottom: 8px;
    }
    
    #leaderboard-list table {
        font-size: 0.9rem;
    }
    
    #leaderboard-list th, 
    #leaderboard-list td {
        padding: 5px 8px;
    }
    
    /* 解决移动设备上的滚动问题 */
    .game-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
    }
}

/* 特别小的屏幕优化 */
@media (max-width: 320px) {
    .restart-button-container button {
        width: 90%;
        font-size: 1rem;
        padding: 10px 5px;
    }
    
    #game-over-screen h2, #victory-screen h2 {
        font-size: 1.6rem;
    }
    
    #game-over-screen p, #victory-screen p {
        font-size: 0.9rem;
    }
}

/* 修复iOS中的特殊滚动问题 */
@supports (-webkit-touch-callout: none) {
    body {
        /* 解决iOS上100vh问题 */
        height: -webkit-fill-available;
    }
    
    .game-container {
        height: -webkit-fill-available;
        max-height: -webkit-fill-available;
    }
    
    #game-canvas {
        height: -webkit-fill-available;
    }
}

/* 高度警告界面样式 */
#height-warning-screen {
    z-index: 30;
    display: none;
    background-color: rgba(0, 0, 0, 0.8);
}

.warning-content {
    text-align: center;
    background-color: #fff;
    border-radius: 15px;
    padding: 20px;
    max-width: 80%;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.warning-content h2 {
    color: #E74C3C;
    margin-bottom: 15px;
}

.warning-content p {
    margin-bottom: 10px;
    color: #333;
}

#back-to-menu-height-warning {
    margin-top: 20px;
    padding: 10px 20px;
    background-color: #2980B9;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

#back-to-menu-height-warning:hover {
    background-color: #3498DB;
}
