/**
 * game.css
 * ================================================
 * 游戏界面样式定义文件
 * ------------------------------------------------
 * 功能说明：
 * 1. 定义游戏容器的视觉样式和布局
 * 2. 实现游戏工具栏的交互元素（点赞、全屏等）
 * 3. 设计游戏控制弹出框样式
 * 4. 实现游戏加载动画和进度条
 * 5. 优化移动端游戏体验
 * 
 * 样式组织：
 * - 游戏容器 (.game-container, .game-frame-container)
 * - 游戏工具栏 (.game-toolbar, .toolbar-left, .toolbar-right)
 * - 交互按钮 (.like-btn, .controller-btn, .fullscreen-btn)
 * - 控制弹出框 (.controls-modal, .modal-overlay)
 * - 加载状态 (#loading, .loading-progress-bar)
 * - 全屏模式 (.fullscreen-mode)
 * - 响应式适配 (@media queries)
 * 
 * 交互特性：
 * - 按钮悬停效果和提示框
 * - 控制面板显示/隐藏动画
 * - 全屏模式切换
 * - 移动端触控优化
 * 
 * 版本: 1.0.4
 * 最后更新: 2025-01-XX
 */

/* 游戏容器样式 */
.game-container {
    width: 100%;
    height: 82vh; /* 游戏容器高度 */
    min-height: 480px; /* 最小高度 - 适当调整 */
    max-height: 580px; /* 最大高度 - 适当调整 */
    display: flex;
    flex-direction: column;
    background-color: var(--game-container-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    margin-top: 0 !important; /* 禁止顶部多余间距 */
    padding-top: 0 !important; /* 禁止顶部多余间距 */
}

/* 游戏标题栏 */
.game-title {
    height: 50px;
    background-color: var(--game-title-bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 游戏框架容器 */
.game-frame-container {
    flex-grow: 1;
    position: relative;
    background-color: #1f2937;
}

/* 游戏工具栏 */
.game-toolbar {
    height: 75px;
    background-color: var(--game-container-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 15; /* 确保工具栏在loading层之上 */
    position: relative; /* 确保z-index生效 */
    pointer-events: auto; /* 确保工具栏始终可点击 */
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 20px; /* 增加按钮之间的间距 */
    height: 100%;
}

/* 评分、点赞和不喜欢按钮 */
.rating, .like-btn, .dislike-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.like-btn, .dislike-btn, .controller-btn, .fullscreen-btn {
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    z-index: 20; /* 确保按钮在loading层之上 */
    pointer-events: auto; /* 确保按钮始终可点击 */
}

.like-btn:hover, .controller-btn:hover, .fullscreen-btn:hover, .dislike-btn:hover {
    color: var(--game-title-bg); /* H1标题栏的背景色 */
}

.like-btn.active, .controller-btn.active, .fullscreen-btn.active, .dislike-btn.active {
    color: var(--accent-color); /* 星级的黄色 */
}

.thumb-icon {
    font-size: 20px;
}

.controller-icon, .fullscreen-icon {
    font-size: 22px;
}

.rating {
    color: var(--accent-color);
}

/* 按钮点击时的数字计数器样式 */
.like-btn .count, .dislike-btn .count {
    transition: transform 0.2s;
}

.like-btn.active .count, .dislike-btn.active .count {
    transform: scale(1.1);
    color: var(--accent-color);
}

/* 调整游戏手柄按钮的提示，避免被遮挡 */
.controller-btn {
    position: relative;
}

/* 提示框样式 */
.tooltip {
    position: absolute;
    top: -50px; /* 增加距离，避免遮挡 */
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: var(--text-color);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 9999; /* 提高层级 */
    pointer-events: none;
}

.tooltip::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid rgba(0, 0, 0, 0.8);
}

/* 调整最右侧按钮的提示，避免被裁剪 */
.fullscreen-btn .tooltip {
    transform: translateX(-80%);
}

.fullscreen-btn .tooltip::after {
    left: 80%;
}

/* 特别调整控制器按钮的提示 */
.controller-btn .tooltip {
    top: -40px;
    transform: translateX(-80%); /* 向左偏移，避免右侧被遮挡 */
}

.controller-btn .tooltip::after {
    left: 80%; /* 调整箭头位置对应提示框偏移 */
}

.like-btn:hover .tooltip,
.dislike-btn:hover .tooltip,
.controller-btn:hover .tooltip,
.fullscreen-btn:hover .tooltip {
    opacity: 1;
    visibility: visible;
}

/* 游戏控制弹出框样式 */
.controls-modal {
    position: absolute;
    bottom: 10px; /* 使用固定像素值而不是百分比，更精确 */
    right: 10px; /* 与底部边距完全相同 */
    width: 400px; /* 使用固定宽度，避免计算错误 */
    height: 80%; /* 增加高度，以适应更大的游戏区域 */
    background-color: var(--game-container-bg);
    border-radius: 12px;
    padding: 20px;
    color: var(--text-color);
    z-index: 1000;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    display: none;
    opacity: 0;
    transform: translateY(10px); /* 初始状态下略微下移 */
    transition: opacity 0.3s, transform 0.3s;
    box-sizing: border-box; /* 确保padding包含在width内 */
}

.controls-modal.show {
    opacity: 1;
    transform: translateY(0);
}

/* 固定关闭按钮在右上角 */
.controls-modal .header {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    padding: 0;
    margin: 0;
    z-index: 1001;
    display: flex;
    justify-content: flex-end;
}

.controls-modal .close-btn {
    background: none;
    border: none;
    color: transparent; /* 将原内容颜色设为透明 */
    font-size: 0; /* 将原内容字体大小设为0 */
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
    background-color: rgba(33, 39, 50, 0.8); /* 更深的背景色 */
    position: relative; /* 添加相对定位 */
    overflow: hidden; /* 隐藏任何溢出内容 */
}

.controls-modal .close-btn::before {
    content: "×"; /* 使用乘号字符，比 X 更适合表示关闭按钮 */
    position: absolute;
    top: 46%; /* 稍微上移位置 */
    left: 50%;
    transform: translate(-50%, -50%); /* 确保水平居中 */
    font-size: 32px; /* 保持字体大小 */
    font-weight: normal; /* 移除加粗效果 */
    line-height: 0.8; /* 保持行高调整 */
    color: white; /* 确保文本颜色为白色 */
}

/* 移除原先尝试隐藏内容的CSS规则，因为可能没有效果 */
.controls-modal .close-btn span,
.controls-modal .close-btn i,
.controls-modal .close-btn * {
    display: none;
}

.controls-modal .close-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* 取消指向工具栏的箭头 */
.controls-modal::after {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
}

/* 控制模态框内部样式 - start */
.controls-modal h2 {
    text-align: center;
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-color);
    letter-spacing: 0.5px;
    font-family: 'Russo One', sans-serif;
    font-weight: 600;
}

.controls-modal h3 {
    font-size: 1rem;
    margin: 1rem 0 0.5rem;
    color: #d6fe51;/* 游戏控制文本框H3的颜色 */
    font-family: 'Russo One', sans-serif;
    font-weight: 600;
}

.controls-modal ul {
    list-style-type: disc;
    padding-left: 1.25rem; /* 与how-to-play区域一致 */
    margin-bottom: 1rem; /* 与how-to-play区域一致 */
}

.controls-modal li {
    margin-bottom: 0.25rem; /* 减小项目间距，与how-to-play区域一致 */
    font-size: 1rem; /* 减小文字大小，与how-to-play区域一致 */
    line-height: 1.5; /* 调整行高，与how-to-play区域一致 */
    color: #a0aec0; /* 与how-to-play区域文本颜色一致 */
}

.controls-modal li::marker {
    color: #d6fe51; /* 游戏控制文本框中的列表标记点使用标题栏的背景色 */
}

.controls-modal p {
    margin-bottom: 1rem; /* 与how-to-play区域一致 */
    color: #a0aec0; /* 与how-to-play区域文本颜色一致 */
    line-height: 1.5; /* 与how-to-play区域一致 */
    font-size: 1rem; /* 与how-to-play区域一致 */
}

/* 自定义滚动条 */
.controls-modal::-webkit-scrollbar {
    width: 8px;
}

.controls-modal::-webkit-scrollbar-track {
    background: #2d3748;
    border-radius: 4px;
}

.controls-modal::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 4px;
}

.controls-modal::-webkit-scrollbar-thumb:hover {
    background: #718096;
}
/* 控制模态框内部样式 - end */

/* 自定义控制器和全屏图标 */
.custom-controller-icon {
    width: 28px;
    height: 28px;
    display: inline-block;
    position: relative;
    vertical-align: middle;
}

.custom-fullscreen-icon {
    width: 22px;
    height: 22px;
    position: relative;
    display: inline-block;
    vertical-align: middle;
}

/* 全屏模式特定样式 */
.fullscreen-mode {
    background-color: #000;
    padding: 0;
    border-radius: 0;
}

.fullscreen-mode .game-frame-container {
    height: 100vh;
}

/* 点击全屏按钮后，工具栏处理(保留)：仍然显示在底部 */
/*
.fullscreen-mode .game-toolbar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(31, 41, 55, 0.8);
  z-index: 15; 
}
*/

/* 点击全屏按钮后，工具栏处理：隐藏，不显示在底部 */
.fullscreen-mode .game-toolbar {
    display: none; /* 全屏模式下隐藏工具栏 */
}

.controls-modal::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

/* 游戏加载遮罩层样式调整 */
#loading {
    z-index: 10;
    pointer-events: none; /* 允许点击穿透到下方元素 */
}

#game-frame {
    z-index: 0; /* 默认在loading层下方 */
    transition: opacity 0.3s ease-out;
}

#game-frame.loaded {
    z-index: 11; /* 加载完成后提升到loading层之上 */
}

#loading > div {
    pointer-events: auto; /* 恢复内部元素的点击事件 */
}

/* 进度条容器样式 */
.progress-container {
    width: 16rem; /* 256px */
    height: 0.5rem; /* 8px */
    background-color: rgba(55, 65, 81, 0.8); /* bg-gray-700 with opacity */
    border-radius: 9999px; /* rounded-full */
    overflow: hidden;
}

/* 进度条样式 */
.loading-progress-bar {
    height: 100%;
    background-color: white;
    transition: width 0.3s ease-out;
}

/* 加载文本样式 */
.loading-text {
    font-family: 'Nunito', sans-serif;
    font-size: 1.2rem;
    color: var(--text-color);
    text-align: center;
    margin-top: 1rem;
}

/* 游戏区适配移动端和平板端：响应式设计调整 */
@media (max-width: 768px) {
    /* 工具栏横向滚动及交互优化（去除笼罩层，仅保留滑动） */
    .game-toolbar {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        position: relative;
    }
    /* 移除左右渐变遮罩层相关样式 */
    .toolbar-left, .toolbar-right {
        flex-wrap: nowrap;
        gap: 8px;
        min-width: max-content;
    }
    .toolbar-left > *, .toolbar-right > * {
        flex-shrink: 0;
        min-width: 44px; /* 保证触控区域 */
    }
    .toolbar-left {
        margin-right: 12px;
    }
    .toolbar-right {
        margin-left: 12px;
    }
    .game-toolbar {
        scroll-snap-type: x mandatory;
    }
    .toolbar-left > *, .toolbar-right > * {
        scroll-snap-align: start;
    }
    .game-toolbar::-webkit-scrollbar {
        display: none;
    }
    .game-toolbar {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .controls-modal {
        bottom: 10px;
        right: 10px;
        left: 10px;
        width: auto;
        height: 70%;
    }
}

@media (max-width: 1024px) {
    /*
     * 移动端/平板端游戏区高度适配最佳实践
     * ---------------------------------------------
     * 1. 用 aspect-ratio 替代 padding-top，锁定高度为 16:9
     * 2. 保证页面滚动、iframe 加载前后高度不闪烁、不动态变化
     * 3. 兼容现代浏览器，体验与主流视频网站一致
     */
    .game-frame-container {
        width: 100%;
        aspect-ratio: 16 / 9; /* 固定16:9比例 */
        border-radius: 12px 12px 0 0;
        overflow: hidden;
        background: #000;
        position: relative;
        min-height: 240px; /* 防止极窄屏幕下过矮，可根据实际调整 */
        max-height: 80vh;  /* 防止超出视口，可根据实际调整 */
    }
    .game-frame-container iframe {
        width: 100%;
        height: 100%;
        border: 0;
        display: block;
        object-fit: contain;
        border-radius: 12px 12px 0 0;
        background: #000;
        position: absolute;
        top: 0; left: 0;
    }
    .game-toolbar {
        border-radius: 0 0 12px 12px;
        margin-top: 0;
        /* 可选：background: #1f2937; */
    }
} 