/* 全局重置 + 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Microsoft YaHei", "Arial", sans-serif;
}

body {
    background-color: #1a1a2e; /* 深色背景，减少视觉疲劳 */
    color: #fff;
    min-height: 100vh;
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px; /* 元素间距统一 */
}

/* 头部样式 */
.game-header {
    text-align: center;
    width: 100%;
    max-width: 1000px; /* 适配左右布局的游戏容器宽度 */
}

.game-title {
    color: #ffd700; /* 金色标题，突出游戏感 */
    font-size: 2rem;
    margin-bottom: 10px;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
}

.score-container {
    font-size: 1.2rem;
    background-color: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.score-value {
    color: #39ff14; /* 绿色得分，醒目 */
    font-weight: bold;
    font-size: 1.3rem;
    transition: all 0.3s; /* 得分变化动画 */
}

.score-value:hover {
    transform: scale(1.1);
}

/* 游戏容器（Canvas+排行榜：大屏幕左右排列，小屏幕上下排列） */
.game-container {
    display: flex;
    align-items: flex-start; /* 顶部对齐，避免排行榜因内容短而居中 */
    gap: 20px;
    width: 100%;
    max-width: 1000px; /* 扩大容器宽度，容纳左右布局 */
    padding: 0 10px;
}

/* Canvas区域：占比60%，保持正方形 */
.canvas-area {
    width: 60%;
}

/* Canvas响应式适配 */
.canvas-wrapper {
    position: relative;
    width: 100%;
    padding-top: 100%; /* 1:1正方形比例，确保Canvas是正方形 */
    margin-bottom: 20px; /* 与下方控制按钮间距 */
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 3px solid #ffd700; /* 金色边框，呼应标题 */
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

/* 游戏状态提示（如“等待开始”） */
.game-tip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.8);
    background-color: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 10px;
    z-index: 10; /* 确保在Canvas上方 */
    transition: opacity 0.3s;
}

/* 道具效果提示（在Canvas上方，游戏提示下方） */
.prop-tip {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1rem;
    color: #fff;
    background-color: rgba(255, 165, 0, 0.9); /* 橙色半透明背景 */
    padding: 8px 16px;
    border-radius: 8px;
    z-index: 15; /* 比游戏提示层级高 */
    opacity: 0; /* 默认隐藏 */
    transition: opacity 0.3s;
    pointer-events: none; /* 不影响点击操作 */
}

/* 排行榜区域：占比35%，高度与Canvas一致 */
.leaderboard-area {
    width: 35%;
    max-height: calc(100% + 120px); /* 高度匹配Canvas+控制按钮区域 */
}

/* 排行榜样式（保留原有设计，调整宽度适配） */
.leaderboard-container {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    height: 100%;
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.leaderboard-title {
    color: #ff6b6b; /* 红色标题，突出排行榜 */
    font-size: 1.2rem;
}

.loading {
    color: #ffd700;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 5px;
}

.leaderboard-list {
    max-height: 400px; /* 限制高度，匹配Canvas高度 */
    overflow-y: auto; /* 滚动条 */
    padding-right: 5px;
}

.leaderboard-list ol {
    list-style-position: inside;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-list li {
    padding: 5px 10px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    transition: background-color 0.2s;
}

.leaderboard-list li:hover {
    background-color: rgba(255, 215, 0, 0.2); /* hover时高亮 */
}

/* 控制按钮样式：改为“上下左右”居中布局，尺寸放大 */
.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
    width: 100%;
}

/* 3x3网格布局：中间空，上下左右放按钮 */
.control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 15px; /* 按钮间距放大 */
    width: 350px; /* 网格整体宽度 */
    height: 350px; /* 网格整体高度（与宽度一致，确保按钮正方形） */
}

/* 按钮位置：上(1,2)、左(2,1)、右(2,3)、下(3,2) */
.control-btn.up {
    grid-area: 1 / 2 / 2 / 3;
}
.control-btn.left {
    grid-area: 2 / 1 / 3 / 2;
}
.control-btn.right {
    grid-area: 2 / 3 / 3 / 4;
}
.control-btn.down {
    grid-area: 3 / 2 / 4 / 3;
}

/* 控制按钮样式：尺寸放大，保留交互反馈 */
.control-btn {
    width: 100%;
    height: 100%;
    font-size: 1.8rem; /* 字体放大 */
    background-color: #16213e;
    color: #fff;
    border: 3px solid #ffd700; /* 边框加粗 */
    border-radius: 12px; /* 圆角放大 */
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation; /* 避免触摸时浏览器默认行为 */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 按钮交互反馈（适配放大后的尺寸） */
.control-btn:hover {
    background-color: #ffd700;
    color: #16213e;
    transform: scale(1.05);
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.6); /*  hover阴影增强 */
}

.control-btn:active {
    transform: scale(0.95); /* 按压时缩小，模拟物理反馈 */
    box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.4); /* 内阴影加深 */
}

/* 模态框样式（统一深色风格，避免冲突） */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100; /* 最上层 */
}

.modal-content {
    background-color: #16213e;
    padding: 30px 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border: 2px solid #ffd700;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
    text-align: center;
}

.modal-title {
    color: #ffd700;
    font-size: 1.5rem;
}

.name-input {
    padding: 12px 15px;
    border-radius: 5px;
    border: 2px solid #ddd;
    font-size: 1.1rem;
    outline: none;
    transition: border-color 0.2s;
    width: 80%;
    margin: 0 auto;
}

.name-input:focus {
    border-color: #ffd700; /* 焦点时金色边框 */
}

.btn {
    padding: 12px;
    border-radius: 5px;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    width: 80%;
    margin: 0 auto;
}

.start-btn {
    background-color: #ffd700;
    color: #16213e;
    font-weight: bold;
}

.start-btn:hover {
    background-color: #e6c200;
    transform: scale(1.02);
}

.start-btn:active {
    transform: scale(0.98);
}

/* 页脚样式 */
.game-footer {
    margin-top: auto; /* 推到页面底部 */
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    padding: 10px 0;
    width: 100%;
}

/* 滚动条美化（仅WebKit浏览器） */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #ffd700;
    border-radius: 3px;
}

/* 响应式适配：小屏幕（平板/手机）恢复上下布局 */
@media (max-width: 768px) {
    .game-container {
        flex-direction: column;
        align-items: center;
    }
    .canvas-area, .leaderboard-area {
        width: 100%;
        max-width: 500px; /* 小屏幕最大宽度限制 */
    }
    .leaderboard-area {
        margin-top: 20px;
        max-height: 300px;
    }
    .control-grid {
        width: 280px;
        height: 280px; /* 小屏幕缩小网格尺寸 */
    }
    .control-btn {
        font-size: 1.5rem; /* 小屏幕按钮字体缩小 */
        border-width: 2px;
    }
}

/* 超小屏幕（手机）适配 */
@media (max-width: 375px) {
    .game-title {
        font-size: 1.8rem;
    }
    .score-container {
        font-size: 1rem;
    }
    .control-grid {
        width: 240px;
        height: 240px;
    }
    .control-btn {
        font-size: 1.3rem;
    }
}