* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft YaHei', 'SimHei', sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    background-image: url('images/background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    overflow: hidden;
    height: 100vh;
    min-height: -webkit-fill-available;
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 开场界面 */
#intro-screen {
    position: absolute;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    background-image: url('images/intro-background.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 1000;
    animation: fadeIn 1s ease-in;
    -webkit-overflow-scrolling: touch;
}

/* 为背景图片添加半透明遮罩，确保文字可读 */
#intro-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 32, 39, 0.2);
    z-index: -1;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.intro-title {
    font-size: 48px;
    font-weight: bold;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5), 2px 2px 8px rgba(0, 0, 0, 0.8);
    animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
    0%, 100% { text-shadow: 0 0 20px rgba(255, 255, 255, 0.5); }
    50% { text-shadow: 0 0 40px rgba(255, 255, 255, 0.8); }
}

.intro-subtitle {
    font-size: 24px;
    margin-bottom: 40px;
    color: #87CEEB;
    text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.8);
}

.intro-story {
    max-width: 800px;
    text-align: center;
    line-height: 1.8;
    font-size: 16px;
    margin-bottom: 40px;
    padding: 0 20px;
    color: #ffffff;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.9);
}

.start-button {
    padding: 15px 50px;
    font-size: 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50px;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    animation: buttonPulse 2s ease-in-out infinite;
}

@keyframes buttonPulse {
    0%, 100% {
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3), 0 0 0 0 rgba(102, 126, 234, 0.7);
    }
    50% {
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3), 0 0 0 15px rgba(102, 126, 234, 0);
    }
}

.start-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    animation: none;
}

/* 关卡选择界面 */
#level-select {
    display: none;
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0d2847 0%, #1e4d8b 50%, #2558a3 100%);
    background-image: url('images/level-select-background.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
}

#level-select::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(13, 40, 71, 0.3) 0%, rgba(30, 77, 139, 0.2) 50%, rgba(37, 88, 163, 0.1) 100%);
    z-index: -1;
}

.level-header {
    display: flex;
    align-items: center;
    gap: 30px;
    margin-bottom: 50px;
}

.level-title {
    font-size: 36px;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5), 2px 2px 6px rgba(0, 0, 0, 0.8);
}

.back-to-intro-button {
    padding: 10px 30px;
    font-size: 18px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid white;
    border-radius: 25px;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    backdrop-filter: blur(10px);
}

.back-to-intro-button:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.level-doors {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 1200px;
}

.door {
    width: 250px;
    height: 350px;
    background: linear-gradient(135deg, #1e4d8b 0%, #0d2847 100%);
    border: 3px solid #FFD700;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(30, 77, 139, 0.3);
}

.door::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.1) 0%, rgba(255, 215, 0, 0) 50%);
    pointer-events: none;
}

.door:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.6), 0 8px 25px rgba(30, 77, 139, 0.5);
    background: linear-gradient(135deg, #2558a3 0%, #0f3159 100%);
}

.door.completed::after {
    content: '✓';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    color: #0d2847;
    font-weight: bold;
    box-shadow: 0 2px 10px rgba(255, 215, 0, 0.5);
}

.door-character {
    font-size: 72px;
    margin-bottom: 20px;
    font-family: 'KaiTi', serif;
    color: #FFD700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5), 2px 2px 4px rgba(0, 0, 0, 0.8);
    font-weight: bold;
}

.door-title {
    font-size: 24px;
    margin-bottom: 10px;
    color: #FFFFFF;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
    font-weight: 600;
}

.door-subtitle {
    font-size: 14px;
    color: #E8F4FF;
    text-align: center;
    padding: 0 20px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
    line-height: 1.4;
}

/* 游戏画布 */
#game-canvas {
    display: none;
    position: absolute;
    width: 100%;
    height: 100%;
    background: transparent;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* 游戏UI */
.game-ui {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    color: white;
    font-size: 20px;
    z-index: 10;
}

.game-info {
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 10px;
}

.back-button {
    background: rgba(255, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.back-button:hover {
    background: rgba(255, 0, 0, 0.9);
}

/* 通关动画 */
#level-complete {
    display: none;
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 100;
}

.badge {
    width: 200px;
    height: 200px;
    margin-bottom: 30px;
    animation: badgeAppear 1s ease-out;
}

@keyframes badgeAppear {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.2) rotate(180deg);
    }
    100% {
        transform: scale(1) rotate(360deg);
        opacity: 1;
    }
}

.complete-title {
    font-size: 36px;
    margin-bottom: 20px;
}

.complete-narration {
    max-width: 800px;
    text-align: center;
    line-height: 1.8;
    font-size: 18px;
    margin-bottom: 30px;
    padding: 0 20px;
}

.continue-button {
    padding: 15px 40px;
    font-size: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50px;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
}

.continue-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

/* 结束界面 */
#ending-screen {
    display: none;
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    background-image: url('images/ending-background.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 1000;
}

#ending-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 32, 39, 0.2);
    z-index: -1;
}

.ending-title {
    font-size: 48px;
    margin-bottom: 30px;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5), 2px 2px 8px rgba(0, 0, 0, 0.8);
}

.ending-badges {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
}

.final-badge {
    width: 100px;
    height: 100px;
}

.ending-message {
    max-width: 800px;
    text-align: center;
    line-height: 1.8;
    font-size: 18px;
    margin-bottom: 30px;
    padding: 0 20px;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.9);
}

.replay-button {
    padding: 15px 40px;
    font-size: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50px;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
}

.replay-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

/* ========================================
   移动端适配
   ======================================== */

/* 通用移动端优化 */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    /* 开场界面移动端适配 */
    #intro-screen {
        padding: 30px 15px 80px 15px;
        overflow-y: auto;
        overflow-x: hidden;
        justify-content: flex-start;
        padding-top: 50px;
        -webkit-overflow-scrolling: touch;
    }

    .intro-title {
        font-size: 26px;
        padding: 0 15px;
        margin-bottom: 15px;
        line-height: 1.3;
    }

    .intro-subtitle {
        font-size: 17px;
        margin-bottom: 20px;
    }

    .intro-story {
        max-width: 90%;
        font-size: 13px;
        line-height: 1.6;
        margin-bottom: 35px;
        padding: 0 15px;
    }

    .start-button {
        padding: 18px 50px;
        font-size: 22px;
        touch-action: manipulation;
        min-height: 60px;
        min-width: 200px;
        z-index: 1001;
        position: relative;
        display: block;
        margin: 0 auto 60px auto;
        font-weight: 700;
        -webkit-appearance: none;
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
        box-shadow: 0 10px 30px rgba(102, 126, 234, 0.8);
        border: 3px solid rgba(255, 255, 255, 0.3);
    }

    /* 关卡选择界面移动端适配 */
    #level-select {
        padding: 20px 10px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 100;
        position: relative;
    }

    .level-header {
        flex-direction: column;
        gap: 10px;
        margin-bottom: 20px;
        z-index: 101;
        position: relative;
    }

    .level-title {
        font-size: 20px;
    }
    
    /* 手机版:排行榜按钮横向排列 */
    .level-header-buttons {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }
    
    /* 排行榜按钮横向容器 */
    .leaderboard-buttons-row {
        display: flex;
        gap: 8px;
        width: 100%;
    }
    
    .leaderboard-button {
        flex: 1;
        padding: 10px 8px;
        font-size: 14px;
        white-space: nowrap;
        cursor: pointer;
        touch-action: manipulation;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        border: none;
        border-radius: 8px;
        font-weight: 600;
        transition: transform 0.2s, box-shadow 0.2s;
    }
    
    .leaderboard-button:active {
        transform: scale(0.95);
    }

    .back-to-intro-button {
        padding: 8px 15px;
        font-size: 14px;
        cursor: pointer;
        touch-action: manipulation;
        width: 100%;
    }

    .level-doors {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 15px;
        padding: 0 10px;
        max-width: 100%;
        z-index: 101;
        position: relative;
    }

    .door {
        width: 100%;
        min-width: 0;
        height: 180px;
        padding: 15px 10px;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
        position: relative;
        z-index: 1;
    }

    .door:active {
        transform: scale(0.95);
        opacity: 0.9;
    }

    .door-character {
        font-size: 40px;
        margin-bottom: 10px;
        pointer-events: none;
    }

    .door-title {
        font-size: 16px;
        margin-bottom: 5px;
        pointer-events: none;
    }

    .door-subtitle {
        font-size: 11px;
        padding: 0 5px;
        pointer-events: none;
    }

    /* 游戏Canvas移动端适配 */
    #game-canvas {
        width: 100vw;
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
    }

    #game-canvas canvas {
        display: block;
        touch-action: none;
    }

    /* 游戏UI移动端适配 */
    .game-ui {
        position: fixed;
        top: 5px;
        left: 5px;
        right: 5px;
        font-size: 11px;
        flex-wrap: wrap;
        gap: 5px;
        z-index: 1000;
        pointer-events: none;
    }

    .game-ui > * {
        pointer-events: auto;
    }

    .game-info {
        padding: 5px 8px;
        font-size: 11px;
        background: rgba(0, 0, 0, 0.8);
        border-radius: 4px;
    }

    .game-info span {
        display: inline-block;
        margin: 0 3px !important;
    }

    .back-button {
        padding: 5px 10px;
        font-size: 11px;
    }

    /* 通关动画移动端适配 */
    .badge {
        width: 150px;
        height: 150px;
        margin-bottom: 20px;
    }

    .complete-title {
        font-size: 24px;
        margin-bottom: 15px;
    }

    .complete-narration {
        max-width: 90%;
        font-size: 14px;
        line-height: 1.6;
        margin-bottom: 20px;
        padding: 0 15px;
    }

    .continue-button {
        padding: 12px 30px;
        font-size: 16px;
    }

    /* 结束界面移动端适配 */
    .ending-title {
        font-size: 28px;
        margin-bottom: 20px;
        padding: 0 15px;
    }

    .ending-badges {
        gap: 10px;
        margin-bottom: 20px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .final-badge {
        width: 70px;
        height: 70px;
    }

    .ending-message {
        max-width: 90%;
        font-size: 14px;
        line-height: 1.6;
        margin-bottom: 20px;
        padding: 0 15px;
    }

    .replay-button {
        padding: 12px 30px;
        font-size: 16px;
    }
}

/* 小屏手机适配 (宽度 < 480px) */
@media (max-width: 480px) {
    #intro-screen {
        padding: 20px 10px 100px 10px;
        padding-top: 40px;
    }

    .intro-title {
        font-size: 22px;
    }

    .intro-subtitle {
        font-size: 15px;
    }

    .intro-story {
        font-size: 12px;
        margin-bottom: 30px;
    }

    .start-button {
        padding: 16px 40px;
        font-size: 20px;
        min-height: 58px;
        min-width: 180px;
        margin: 0 auto 80px auto;
        box-shadow: 0 10px 30px rgba(102, 126, 234, 0.9);
        border: 3px solid rgba(255, 255, 255, 0.4);
    }

    .level-title {
        font-size: 20px;
    }

    .door {
        width: 100%;
        max-width: 280px;
        height: 200px;
    }

    .door-character {
        font-size: 40px;
        margin-bottom: 10px;
    }

    .door-title {
        font-size: 16px;
    }

    .door-subtitle {
        font-size: 11px;
    }

    .game-ui {
        font-size: 12px;
    }

    .game-info {
        padding: 6px 10px;
        font-size: 12px;
    }

    .back-button {
        padding: 6px 12px;
        font-size: 12px;
    }

    .badge {
        width: 120px;
        height: 120px;
    }

    .complete-title {
        font-size: 20px;
    }

    .complete-narration {
        font-size: 13px;
    }

    .ending-title {
        font-size: 24px;
    }

    .final-badge {
        width: 60px;
        height: 60px;
    }

    .ending-message {
        font-size: 13px;
    }
}

/* 横屏模式优化 */
@media (max-height: 500px) and (orientation: landscape) {
    .intro-title {
        font-size: 24px;
        margin-bottom: 10px;
    }

    .intro-subtitle {
        font-size: 16px;
        margin-bottom: 15px;
    }

    .intro-story {
        font-size: 12px;
        margin-bottom: 15px;
        max-height: 150px;
        overflow-y: auto;
    }

    .start-button {
        padding: 10px 30px;
        font-size: 16px;
        min-height: 44px;
        min-width: 120px;
    }

    .level-doors {
        gap: 15px;
    }

    .door {
        width: 120px;
        height: 160px;
    }

    .door-character {
        font-size: 36px;
        margin-bottom: 8px;
    }

    .door-title {
        font-size: 14px;
        margin-bottom: 5px;
    }

    .door-subtitle {
        font-size: 10px;
    }

    .badge {
        width: 100px;
        height: 100px;
        margin-bottom: 10px;
    }

    .complete-title {
        font-size: 18px;
        margin-bottom: 10px;
    }

    .complete-narration {
        font-size: 12px;
        margin-bottom: 15px;
        max-height: 100px;
        overflow-y: auto;
    }

    .continue-button {
        padding: 8px 20px;
        font-size: 14px;
    }

    .ending-title {
        font-size: 20px;
        margin-bottom: 10px;
    }

    .ending-badges {
        gap: 8px;
        margin-bottom: 10px;
    }

    .final-badge {
        width: 50px;
        height: 50px;
    }

    .ending-message {
        font-size: 11px;
        margin-bottom: 15px;
        max-height: 120px;
        overflow-y: auto;
    }

    .replay-button {
        padding: 8px 20px;
        font-size: 14px;
    }
}

/* 触摸优化 - 增大可点击区域 */
@media (hover: none) and (pointer: coarse) {
    button, .door, .back-button {
        min-height: 44px;
        min-width: 44px;
    }

    .start-button {
        min-height: 56px;
        min-width: 180px;
        font-weight: bold;
        box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6) !important;
    }

    .door:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    button:active {
        transform: translateY(0);
        opacity: 0.9;
        background: linear-gradient(135deg, #5568d3 0%, #6a3f8f 100%);
    }

    .back-button:active {
        opacity: 1;
    }
}

/* ========================================
   静音按钮样式
   ======================================== */
.mute-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 3px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.mute-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.mute-button:active {
    transform: scale(0.95);
}

#mute-icon {
    user-select: none;
    pointer-events: none;
}

/* 移动端适配 */
@media (max-width: 768px) {
    .mute-button {
        width: 50px;
        height: 50px;
        bottom: 15px;
        right: 15px;
        font-size: 24px;
    }
}
