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

@font-face {
    font-family: 'LXGW WenKai';
    src: url('../font/LXGWWenKai-Regular.woff2') format('woff2');
    font-display: swap;
}

body {
    font-family: 'LXGW WenKai', "KaiTi", "STKaiti", serif;
    background: #000;
    color: #e0d8b0;
    height: 100vh;
    height: 100dvh; /* 使用动态视口高度 */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    /* 安全区域支持 */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    margin: 0;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('../assets/images/game-bg.png') center/cover no-repeat fixed;
    filter: blur(8px);
    z-index: -1;
    transform: scale(1.05);
}

#game-container {
    position: absolute;
    top: env(safe-area-inset-top, 0px);
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    /* max-width: 375px; */
    height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1;
    aspect-ratio: 5/9;
    background-color: rgba(0,0,0,0.7);
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
    border: 2px solid #3a2a16;
    border-radius: 8px;
    /* 安全区域支持 */
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    /* 性能优化 */
    contain: strict;
    will-change: transform;
    backface-visibility: hidden;
    /* 交互优化 */
    touch-action: manipulation;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    /* 防止内容溢出 */
    overflow-x: hidden;
    overflow-y: auto;
}

#background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    filter: none;
}

#loading-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #000;
    z-index: 10;
}

#loading-container div {
    color: #e0d8b0;
    font-family: "KaiTi", "STKaiti", serif;
    font-size: 18px;
}

#loading-bar {
    width: 80%;
    height: 20px;
    background-color: #333;
    margin-top: 20px;
    border-radius: 10px;
    overflow: hidden;
}

#loading-progress {
    height: 100%;
    width: 0;
    background-color: #8b5a2b;
    transition: width 0.3s;
}

#opening-text, #story-text {
    width: calc(100% - 40px);
    font-size: 20px;
    line-height: 1.8;
    margin: 10px auto;
    white-space: pre-line;
    text-align: center;
    max-height: 70vh;

    overflow-y: auto;
    padding: 15px;
    font-family: 'LXGW WenKai', "KaiTi", "STKaiti", serif;
    background: linear-gradient(145deg, rgba(139, 90, 43, 0.95), rgba(107, 69, 31, 0.95));
    border: 3px solid #a67c52;
    border-radius: 12px;
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.5),
        inset 0 0 20px rgba(230, 216, 176, 0.1);
    position: relative;
    backdrop-filter: none;
    display: none;
}

#opening-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 600px;
    margin: 0;
    min-height: 20px;
    max-height: 70vh;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 30px;
    box-sizing: border-box;
}

#story-text {
    font-size: 18px;
    text-align: left;
    max-height: 100vh;
}

/* 装饰边框效果 */
#opening-text::before, #story-text::before {
    content: "";
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #e0d8b0;
    border-radius: 14px;
    pointer-events: none;
    opacity: 0.3;
}

/* 内阴影效果 */
#opening-text::after, #story-text::after {
    content: "";
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border: 1px solid rgba(230, 216, 176, 0.2);
    border-radius: 8px;
    pointer-events: none;
}

.btn {
    padding: 12px 24px;
    margin: 10px;
    background: linear-gradient(180deg, #8b5a2b 0%, #6d451f 100%);
    color: #e0d8b0;
    border: 1px solid #a67c52;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    font-family: 'LXGW WenKai', "KaiTi", "STKaiti", serif;
}

.btn:hover {
    background: linear-gradient(180deg, #a67c52 0%, #8b5a2b 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

#options-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 60px;
    position: absolute;
    bottom: 10px;
    left: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0 10px;
}

.btn-option {
    flex: 0 0 auto;
    width: 80px;
    height: 50px;
    margin: 0 8px;
    padding: 5px 10px;
    white-space: nowrap;
}

.api-loading-container {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 20;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.api-loading-text {
    color: #e0d8b0;
    font-family: "KaiTi", "STKaiti", serif;
    font-size: 18px;
    margin-bottom: 20px;
}

.btn-disabled {
    opacity: 0.6;
    cursor: not-allowed;
}


.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #222;
    padding: 20px;
    border-radius: 8px;
    max-width: 300px;
    text-align: center;
}

.modal-options {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

/* 响应式调整 - 大屏幕设备 */
@media (min-width: 768px) {
    #game-container {
        max-width: 600px;
        width: 90%;
    }
    
    #story-text {
        font-size: 20px;
        max-height: 80vh;
    }
    
    .btn {
        font-size: 18px;
    }
}

/* 响应式调整 - 中等屏幕设备 (iPhone XR 414x896, iPhone 12 390x844) */
@media (max-width: 767px) and (min-width: 376px) {
    #game-container {
        /* max-width: 380px; */
        /* width: 92%; */
    }
    
    #story-text {
        font-size: 17px;
        max-height: 75vh;
        padding: 12px;
    }
    
    .btn {
        font-size: 15px;
        padding: 10px 20px;
    }
    
    .btn-option {
        width: 75px;
        height: 45px;
        margin: 0 6px;
        font-size: 13px;
    }
    
    #options-container {
        height: 55px;
        bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }
}

/* 响应式调整 - 小屏幕设备 (iPhone SE 375x667) */
@media (max-width: 375px) {
    #game-container {
        /* max-width: 350px; */
        /* width: 95%; */
    }
    
    #story-text {
        font-size: 16px;
        max-height: 75vh;
        padding: 10px;
        line-height: 1.6;
    }
    
    .btn {
        font-size: 14px;
        padding: 8px 16px;
    }
    
    .btn-option {
        width: 70px;
        height: 40px;
        margin: 0 5px;
        font-size: 12px;
    }
    
    #options-container {
        height: 50px;
        bottom: calc(5px + env(safe-area-inset-bottom, 0px));
    }
}

/* 响应式调整 - 超小屏幕设备 */
@media (max-width: 320px) {
    #game-container {
        max-width: 300px;
        width: 98%;
    }
    
    #story-text {
        font-size: 14px;
        max-height: 70vh;
        padding: 8px;
        line-height: 1.5;
    }
    
    .btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    .btn-option {
        width: 65px;
        height: 35px;
        margin: 0 4px;
        font-size: 11px;
    }
    
    #options-container {
        height: 45px;
        bottom: 3px;
    }
}