* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.game-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 100%;
    width: 100%;
    max-height: 100vh;
    overflow: hidden;
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-header h1 {
    color: #333;
    margin-bottom: 15px;
    font-size: 24px;
}

.game-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.control-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
}

.control-btn:hover {
    background: #45a049;
    transform: translateY(-2px);
}

.forbidden-hand-control,
.ai-mode-control {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    color: #333;
}

.forbidden-hand-control input[type="checkbox"],
.ai-mode-control input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.timer-container {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.timer {
    background: #f0f0f0;
    padding: 12px 20px;
    border-radius: 10px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
}

.timer-label {
    font-weight: bold;
    color: #555;
    margin-right: 8px;
}

.timer-display {
    font-size: 20px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
}

.black-timer .timer-display {
    color: #000;
}

.white-timer .timer-display {
    color: #666;
}

.game-board-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    background: #f5f5f5;
    border-radius: 10px;
    padding: 10px;
    overflow: auto;
}

.game-canvas {
    background: #d6b37a;
    border-radius: 5px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    touch-action: none;
    /* 确保Canvas可以接收点击事件 */
    pointer-events: auto;
    /* 确保Canvas不会被其他元素覆盖 */
    z-index: 1;
}

.game-info {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    background: #f0f0f0;
    padding: 15px;
    border-radius: 10px;
}

/* 默认隐藏竖屏控制面板，只在竖屏模式下显示 */
.portrait-controls,
.portrait-game-info {
    display: none;
}

.current-player, .game-status {
    font-size: 16px;
    font-weight: bold;
    color: #333;
}

.player-indicator {
    font-size: 18px;
    font-weight: bold;
}

.player-indicator.black {
    color: #000;
}

.player-indicator.white {
    color: #666;
}

.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 90%;
    width: 400px;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: #333;
    margin-bottom: 20px;
}

.modal-content p {
    font-size: 18px;
    color: #555;
    margin-bottom: 25px;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

.modal-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    min-width: 120px;
}

.modal-btn:hover {
    background: #45a049;
    transform: translateY(-2px);
}

/* 再来一局按钮样式 */
#restartGameBtn {
    background: #2196F3;
}

#restartGameBtn:hover {
    background: #0b7dda;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 20px;
    top: 15px;
}

.close:hover {
    color: #000;
}

/* 响应式设计 - 竖屏模式优化 */
@media (orientation: portrait) {
    .game-container {
        display: flex;
        flex-direction: column;
        padding: 10px;
        height: calc(100vh - 40px);
        overflow: hidden;
    }
    
    /* 竖屏模式下隐藏左右面板，让棋盘占据整个宽度 */
    .left-panel, .right-panel {
        display: none;
    }
    
    /* 横屏模式下隐藏竖屏控制面板 */
    .portrait-controls,
    .portrait-game-info {
        display: block;
    }
    
    /* 中间面板占据整个宽度 */
    .center-panel {
        width: 100%;
        display: flex;
        flex-direction: column;
        height: 100%;
    }
    
    /* 棋盘最大化，占据整个可用空间 */
    .game-board-container {
        flex: 1;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0;
        padding: 5px;
        background: #f5f5f5;
        border-radius: 10px;
        overflow: hidden;
    }
    
    /* 确保画布在竖屏模式下充满容器 */
    .game-canvas {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
    
    /* 游戏控制区域垂直居中显示在顶部 */
    .game-header {
        text-align: center;
        margin-bottom: 15px;
    }
    
    .game-header h1 {
        font-size: 22px;
        text-align: center;
    }
    
    .game-controls {
        justify-content: center;
        gap: 15px;
        margin-bottom: 15px;
    }
    
    .timer-container {
        flex-direction: row;
        justify-content: center;
        gap: 20px;
        margin-bottom: 15px;
    }
    
    .timer {
        padding: 10px 15px;
    }
    
    .timer-display {
        font-size: 18px;
    }
    
    /* 棋盘最大化 */
    .game-board-container {
        flex: 1;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0;
        padding: 5px;
        background: #f5f5f5;
        border-radius: 10px;
        overflow: hidden;
    }
    
    .game-canvas {
        /* 竖屏模式下棋盘宽度接近屏幕宽度 */
        width: 100%;
        height: 100%;
        object-fit: contain;
    }
    
    .game-info {
        margin-top: 15px;
        flex-direction: row;
        justify-content: space-around;
        padding: 12px;
    }
    
    .current-player, .game-status {
        font-size: 16px;
    }
    
    /* 平板竖屏优化 */
    @media (min-width: 768px) and (orientation: portrait) {
        .game-header {
            margin-bottom: 20px;
        }
        
        .game-header h1 {
            font-size: 32px;
            text-align: center;
            margin-bottom: 15px;
        }
        
        .game-controls {
            margin-bottom: 20px;
        }
        
        .timer-container {
            margin-bottom: 20px;
        }
        
        .timer-display {
            font-size: 24px;
        }
        
        /* 平板竖屏：最大化棋盘容器 */
        .game-board-container {
            flex: 1;
            padding: 5px;
            margin: 0;
        }
        
        .current-player, .game-status {
            font-size: 20px;
        }
        
        .game-info {
            margin-top: 20px;
        }
    }
    
    /* 手机竖屏优化 */
    @media (max-width: 480px) {
        .game-container {
            padding: 5px;
        }
        
        .game-header h1 {
            font-size: 18px;
        }
        
        .game-controls {
            gap: 10px;
        }
        
        .timer-container {
            gap: 10px;
        }
        
        .timer {
            padding: 8px 12px;
        }
        
        .timer-display {
            font-size: 16px;
        }
        
        .current-player, .game-status {
            font-size: 14px;
        }
    }
    
    .modal-content {
        padding: 20px;
        width: 95%;
    }
}

/* 横屏适配 */
@media (orientation: landscape) {
    .game-container {
        display: flex;
        flex-direction: row;
        padding: 10px;
        height: calc(100vh - 40px);
        overflow: hidden;
    }
    
    .left-panel, .right-panel {
        width: 200px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 10px;
    }
    
    .center-panel {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 10px;
    }
    
    .game-header {
        margin-bottom: 20px;
    }
    
    .game-header h1 {
        font-size: 20px;
        margin-bottom: 20px;
    }
    
    .game-controls {
        flex-direction: column;
        gap: 15px;
    }
    
    .timer-container {
        flex-direction: column;
        gap: 15px;
        margin-bottom: 20px;
    }
    
    .timer {
        width: 100%;
        max-width: none;
        padding: 10px;
    }
    
    .timer-display {
        font-size: 18px;
    }
    
    .game-board-container {
        flex: 1;
        width: 100%;
        max-height: calc(100vh - 80px);
        margin: 0;
    }
    
    .game-canvas {
        max-width: 100%;
        max-height: 100%;
    }
    
    .game-info {
        margin-top: 20px;
        flex-direction: column;
        gap: 15px;
    }
    
    .current-player, .game-status {
        font-size: 16px;
    }
    
    /* 小屏幕横屏优化 */
    @media (max-height: 500px) {
        .left-panel, .right-panel {
            width: 150px;
            padding: 5px;
        }
        
        .game-header h1 {
            font-size: 18px;
        }
        
        .timer {
            padding: 8px;
        }
        
        .timer-display {
            font-size: 16px;
        }
    }
}