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

@font-face {
    font-family: 'LXGW WenKai';
    src: url('../assets/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.webp') 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 画，**不能用 ::before/::after**。
     *
     * 这里是个滚动容器（见下面的 overflow-y: auto）。绝对定位的伪元素，其包含块
     * 正是这个滚动容器本身，于是它属于「可滚动溢出区域」—— **边线会跟着内容一起滚**。
     * 表现为：一往下滚，装饰框的底边就往上漂，变成一条横穿正文的线（用户实测报告）。
     *
     * box-shadow 是元素自身的盒装饰，画在边框盒上，**不参与滚动**，因此始终贴着盒子。
     *
     * 代价：原来是 5px 内缩、8px 圆角的内框，box-shadow 做不出内缩，只能贴着边框内侧
     * （见下面第二条）。观感是双线边框，与原本几乎一致。
     */
    box-shadow:
        /* 装饰外框（原 ::before：2px、圆角 14px、不透明度 .3） */
        0 0 0 2px rgba(224, 216, 176, 0.3),
        /* 装饰内框（原 ::after：1px、不透明度 .2） */
        inset 0 0 0 1px rgba(230, 216, 176, 0.2),
        /* 以下是原有的投影与外发光，保持不变 */
        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`（2px 外框）与
 * `#opening-text::after, #story-text::after`（1px 内框，5px 内缩）。
 *
 * 它们是**绝对定位**，包含块就是这两个元素本身 —— 而 `#story-text` 是
 * `overflow-y: auto` 的滚动容器，所以这两条装饰线会**跟着正文一起滚动**：
 * 往下一滚，框的下边线就漂到正文中间，看起来像一条横线割断文字。
 *
 * 现已改用上面那条规则里的 **box-shadow** 实现（元素自身装饰，不参与滚动）。
 * **不要把它们改回伪元素** —— 除非同时把装饰挪出滚动容器（例如加一层不滚动的包裹层，
 * 但 `game.js` 用 `innerHTML` 覆写正文，包裹层会被清掉，所以那条路走不通）。
 */

.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;
}

/* 设置图标样式 */
.settings-icon {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    z-index: 50;
    transition: transform 0.3s;
    display: none;
}

.settings-icon:hover {
    transform: rotate(30deg);
}

/* 设置弹窗样式 */
.settings-modal-content {
    width: 80%;
    max-width: 300px;
}

.setting-item {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.setting-item label {
    margin-bottom: 10px;
    font-size: 16px;
    display: block;
}

.radio-group {
    display: flex;
    gap: 15px;
    margin-top: 10px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.radio-group input[type="radio"] {
    accent-color: #8b5a2b;
}

.volume-slider {
    width: 100%;
    margin: 10px 0;
    -webkit-appearance: none;
    height: 8px;
    background: #333;
    outline: none;
    border-radius: 4px;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e0d8b0;
    cursor: pointer;
}

#volume-value {
    font-size: 14px;
    color: #e0d8b0;
    margin-left: 10px;
}


.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: 540px;
        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: 500px) {
    #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(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* 响应式调整 - 小屏幕设备 (iPhone SE 375x667) */
@media (max-width: 500px) {
    #game-container {
        max-width: 100%;
        width: 100%;
    }
    
    #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(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* 花瓣飘落特效 */
.petal {
    position: fixed;
    pointer-events: none;
    z-index: 5;
    background: linear-gradient(45deg, #ff9a9e, #fad0c4);
    border-radius: 50% 5px 50% 5px;
    box-shadow: 0 2px 10px rgba(255, 154, 158, 0.3);
    transition: transform 0.3s ease-out;
}

/* 花瓣飘落动画 */
@keyframes fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    25% {
        transform: translateY(25vh) rotate(90deg);
    }
    50% {
        transform: translateY(50vh) rotate(180deg);
        opacity: 0.8;
    }
    75% {
        transform: translateY(75vh) rotate(270deg);
    }
    100% {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

/* 花瓣大小变体 */
.petal.small {
    width: 12px;
    height: 12px;
}

.petal.medium {
    width: 18px;
    height: 18px;
}

.petal.large {
    width: 25px;
    height: 25px;
}

/* 花瓣颜色变体 */
.petal.pink {
    background: linear-gradient(45deg, #ff9a9e, #fad0c4);
}

.petal.white {
    background: linear-gradient(45deg, #ffffff, #f0f0f0);
}

.petal.purple {
    background: linear-gradient(45deg, #a18cd1, #fbc2eb);
}

/* 响应式调整 - 超小屏幕设备 */
@media (max-width: 320px) {
    #game-container {
        max-width: 100%;
        width: 100%;
    }
    
    #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: 5px;
    }
}