/* ==========================================
   移动端响应式布局优化
   ========================================== */

@media screen and (max-width: 768px) {
    /* 基础布局调整 */
    body {
        font-size: 14px;
        overflow-x: hidden;
    }
    
    /* 移动端游戏区域调整 - 为虚拟键盘留出空间 */
    .time-meteors-container {
        height: calc(100vh - 200px);
        overflow: hidden;
    }
    
    /* 调整字母显示位置，避免被虚拟键盘遮挡 */
    .time-letters-container {
        top: calc(50% - 100px);
        font-size: 24px !important;
        padding: 15px;
        margin: 15px 0;
    }
    
    /* 开始界面移动端优化 */
    .start-content {
        padding: 20px;
        margin: 10px;
        width: calc(100% - 20px);
        box-sizing: border-box;
        position: relative;
    }
    
    /* 移动端主菜单按钮布局优化 */
    .main-actions-column {
        gap: 15px;
        margin: 20px 0;
    }
    
    .top-actions-group {
        flex-direction: row;
        gap: 15px;
        align-items: center;
        justify-content: center;
        position: relative;
    }
    
    /* 确保教学按钮在移动端正确显示 */
    .tutorial-container {
        position: static !important;
        margin: 0;
    }
    
    .tutorial-button {
        position: static !important;
        left: auto;
        top: auto;
        width: 35px;
        height: 35px;
        font-size: 18px;
    }
    
    .dictionary-manager-button {
        padding: 10px 20px;
        font-size: 16px;
        min-width: 120px;
    }
    
    /* 移动端设置图标重定位 - 固定在右上角 */
    .start-screen .settings-icon {
        position: fixed !important;
        top: 20px;
        right: 20px;
        bottom: auto;
        left: auto;
        width: 40px;
        height: 40px;
        z-index: 2010;
    }
    
    /* 移动端教学界面优化 */
    .tutorial-modal {
        padding: 20px 10px;
    }
    
    .tutorial-title {
        font-size: 20px;
        margin-bottom: 15px;
        text-align: center;
    }
    
    .tutorial-image-container {
        width: 95%;
        height: 50vh;
        margin-bottom: 15px;
    }
    
    .tutorial-nav-button {
        width: 50px;
        height: 50px;
        font-size: 18px;
    }
    
    .tutorial-close-button {
        width: 40px;
        height: 40px;
        font-size: 16px;
        top: 10px;
        right: 10px;
    }
    
    .tutorial-counter {
        font-size: 14px;
        margin-top: 10px;
    }
    
    .logo {
        max-width: 250px;
        width: 80vw;
    }
    
    .start-button {
        font-size: 20px;
        padding: 15px 30px;
        width: 100%;
        max-width: 200px;
    }
    
    /* 游戏界面移动端优化 */
    .time-ui-container {
        padding: 10px;
        flex-direction: column;
        gap: 10px;
    }
    
    .time-status-bar {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    
    .time-lives-container,
    .time-score-container {
        justify-content: center;
        margin: 5px 0;
    }
    
    .time-letters-container {
        margin: 15px 0;
        padding: 15px 10px;
        font-size: 80px !important;
    }
    
    /* 增大移动端已键入字母的大小 */
    .time-letter {
        font-size: 32px;
        font-weight: bold;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    }
    
    /* 陨石样式移动端调整 */
    .time-meteor {
        font-size: 20px;
        padding: 10px 15px;
        font-weight: bold;
    }
    
    /* 游戏结束界面移动端优化 */
    .time-game-over {
        padding: 10px;
        align-items: flex-start;
        padding-top: 5vh;
        overflow-x: hidden; /* 防止水平滚动 */
    }
    
    .time-game-over-content {
        width: calc(100vw - 30px) !important; /* 使用视口宽度确保不溢出 */
        min-width: unset;
        max-width: unset;
        padding: 20px 15px;
        margin: 0 15px;
        max-height: calc(100vh - 10vh);
        border-radius: 15px;
        box-sizing: border-box; /* 确保padding计算在宽度内 */
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important; /* 防止外层容器滚动 */
    }
    
    .time-game-over h1 {
        font-size: 28px;
        margin-bottom: 15px;
    }
    
    .time-final-score-container {
        font-size: 20px;
        margin: 15px 0;
    }
    
    .time-final-score-value {
        font-size: 36px;
    }
    
    .time-wrong-words {
        max-height: 30vh;
        width: 100%;
        max-width: unset;
        margin: 0; /* 移除margin，因为标题现在单独管理 */
        overflow-y: auto !important; /* 只有错词列表可以滚动 */
        overflow-x: hidden; /* 防止水平滚动 */
        box-sizing: border-box;
        flex-shrink: 1 !important; /* 允许错词容器被压缩 */
    }
    
    /* 移动端独立错词标题样式 - 固定不滚动 */
    .time-game-over-content > h3 {
        font-size: 18px;
        margin-bottom: 10px;
        margin-top: 15px;
        padding: 0 15px; /* 移动端调整padding */
        flex-shrink: 0 !important; /* 防止标题被压缩 */
        position: relative;
        z-index: 10; /* 确保标题在上层 */
    }
    
    .time-wrong-item {
        padding: 10px 12px;
        font-size: 14px;
        word-wrap: break-word; /* 长单词自动换行 */
        word-break: break-all; /* 确保超长内容不会溢出 */
    }
    
    /* 移动端提示文本优化 - 固定在底部 */
    .time-game-over-hint {
        font-size: 0.8em;
        margin: 10px 5px 15px 5px;
        padding: 8px;
        flex-shrink: 0 !important; /* 防止提示文本被压缩 */
    }
    
    .game-over-buttons-container {
        flex-direction: column;
        gap: 12px;
        margin-top: 20px;
        width: 100%;
        flex-shrink: 0 !important; /* 防止按钮区域被压缩 */
    }
    
    .time-restart-btn,
    .time-leaderboard-btn,
    .time-submit-score-btn {
        width: 100%;
        min-width: unset;
        max-width: unset;
        padding: 12px 20px;
        font-size: 16px;
        margin: 0;
        border-radius: 25px; /* 调整为圆角按钮 */
    }
}

/* 横屏模式优化 */
@media screen and (max-height: 500px) and (orientation: landscape) {
    /* 横屏模式下的Game Over界面优化 */
    .time-game-over {
        padding-top: 2vh;
    }
    
    .time-game-over-content {
        width: calc(100vw - 60px); /* 使用视口宽度 */
        margin: 0 30px;
        padding: 15px 20px;
        max-height: calc(100vh - 4vh);
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        overflow-x: hidden; /* 防止水平滚动 */
    }
    
    .time-wrong-words {
        max-height: 20vh;
        flex-shrink: 0;
    }
    
    .game-over-buttons-container {
        flex-direction: row;
        justify-content: space-around;
        margin-top: 15px;
    }
    
    .time-restart-btn,
    .time-leaderboard-btn,
    .time-submit-score-btn {
        width: auto;
        min-width: 120px;
        padding: 8px 16px;
        font-size: 14px;
        border-radius: 20px; /* 调整为圆角按钮 */
    }
}

/* 中等屏幕设备优化 */
@media screen and (max-width: 600px) and (min-width: 481px) {
    .time-game-over-content {
        width: calc(100vw - 40px); /* 使用视口宽度 */
        margin: 0 20px;
        padding: 18px 12px;
        box-sizing: border-box;
        overflow: hidden !important; /* 防止外层容器滚动 */
        display: flex !important;
        flex-direction: column !important;
    }
    
    .time-game-over h1 {
        font-size: 26px;
    }
    
    .time-final-score-value {
        font-size: 32px;
    }
    
    /* 中等屏幕设备按钮优化 */
    .start-screen .settings-icon {
        width: 38px;
        height: 38px;
        top: 18px;
        right: 18px;
    }
    
    .tutorial-button {
        width: 32px;
        height: 32px;
        font-size: 17px;
    }
}

/* 小屏幕设备进一步优化 */
@media screen and (max-width: 480px) {
    /* 小屏幕设备陨石字体优化 */
    .time-meteor {
        font-size: 18px;
        padding: 8px 12px;
        font-weight: bold;
    }
    
    .start-content {
        padding: 15px;
    }
    
    .logo {
        max-width: 200px;
    }
    
    /* 小屏幕设备按钮位置优化 */
    .start-screen .settings-icon {
        top: 15px;
        right: 15px;
        width: 35px;
        height: 35px;
    }
    
    .tutorial-button {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }
    
    /* 小屏幕设备的Game Over界面进一步优化 */
    .time-game-over-content {
        width: calc(100vw - 20px); /* 使用视口宽度 */
        margin: 0 10px;
        padding: 15px 10px;
        box-sizing: border-box;
        overflow: hidden !important; /* 防止外层容器滚动 */
        display: flex !important;
        flex-direction: column !important;
    }
    
    .time-game-over h1 {
        font-size: 24px;
        margin-bottom: 10px;
    }
    
    .time-final-score-container {
        font-size: 16px;
        margin: 10px 0;
    }
    
    .time-final-score-value {
        font-size: 28px;
    }
    
    .time-wrong-words {
        max-height: 25vh;
    }
    
    /* 小屏幕设备独立错词标题样式 - 固定不滚动 */
    .time-game-over-content > h3 {
        font-size: 16px;
        margin-top: 10px;
        padding: 0 10px; /* 小屏幕设备更小padding */
        flex-shrink: 0 !important; /* 防止标题被压缩 */
        position: relative;
        z-index: 10; /* 确保标题在上层 */
    }
    
    .time-wrong-item {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    /* 小屏幕设备提示文本优化 - 固定在底部 */
    .time-game-over-hint {
        font-size: 0.75em;
        margin: 8px 3px 12px 3px;
        padding: 6px;
        flex-shrink: 0 !important; /* 防止提示文本被压缩 */
    }
}

/* 防止缩放和选择 */
@media screen and (max-width: 768px) {
    * {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    input, textarea {
        -webkit-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }
}