/* ═══════════════════════════════════════════════════════
   [C] 国际象棋棋盘
       .chess-* / .fen-* / .fullscreen-controls / .promotion-*
   ═══════════════════════════════════════════════════════ */

/* =================================
   国际象棋棋盘样式（修复版）
   ================================= */

/* 棋盘全屏模式样式 */
.chess-fullscreen {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
    padding: 15px;
    box-sizing: border-box;
    background-color: var(--surface-color);
    overflow-y: auto;
}

.chess-fullscreen.active {
    display: flex;
}

.chess-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 0;
}

.chess-board-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    justify-content: flex-start;
    min-height: 0;
    overflow-y: auto;
}

/* 棋盘基础样式 */
.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 3px solid #333;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: #f5f5f5;
    flex-shrink: 0;
    /* 桌面端尺寸 */
    width: min(50vw, 500px);
    height: min(50vw, 500px);
}

.chess-square {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(8vw, 40px);
    position: relative;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    transition: background-color 0.2s ease;
}

.chess-square.light {
    background-color: #f0d9b5;
}

.chess-square.dark {
    background-color: #b58863;
}

.chess-square.highlight {
    background-color: rgba(255, 255, 0, 0.4);
}

.chess-square.selected {
    background-color: rgba(0, 255, 0, 0.4);
}

.chess-piece-label {
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 10px;
    color: rgba(0, 0, 0, 0.5);
}

/* 信息面板样式 */
.chess-info-panel {
    background: var(--surface-color);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 16px var(--shadow-color);
    width: 100%;
}

.chess-info-panel h3 {
    margin: 0 0 15px 0;
    color: var(--primary-color);
    text-align: center;
    font-size: 1.5em;
}

/* FEN显示区域 */
.fen-display {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.fen-display label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-color);
    font-size: 1.1em;
}

.fen-text {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--surface-color);
    color: var(--text-color);
    font-family: monospace;
    resize: vertical;
    min-height: 80px;
    font-size: 14px;
    box-sizing: border-box;
    line-height: 1.4;
}

.fen-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.fen-actions .action-button {
    flex: 1;
    min-width: 100px;
    text-align: center;
    padding: 12px 8px;
    font-size: 14px;
}

/* 全屏控制按钮 - 固定在底部 */
.fullscreen-controls {
    display: flex;
    justify-content: center;
    padding: 15px;
    border-top: 1px solid var(--border-color);
    margin-top: auto; /* 关键：推到容器底部 */
    background: var(--surface-color);
    flex-shrink: 0; /* 防止被压缩 */
}

.fullscreen-controls .action-button {
    min-width: 200px;
    padding: 15px;
    font-size: 16px;
    font-weight: 600;
}

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

/* 手机端专用样式 */
@media (max-width: 768px) {
    .chess-fullscreen {
        padding: 10px;
    }
    
    .chess-board-area {
        gap: 15px;
        justify-content: flex-start;
    }
    
    /* 棋盘在手机上适应屏幕 - 关键修复 */
    .chess-board {
        width: 75vw !important; /* 使用 !important 确保覆盖其他样式 */
        height: 75vw !important;
        max-width: 75vw !important;
        max-height: 75vw !important;
        order: 1; /* 棋盘放在上面 */
        margin: 0 auto; /* 居中显示 */
    }
    
    /* 信息面板在棋盘下面 */
    .chess-info-panel {
        order: 2;
        margin-top: 10px;
    }
    
    /* FEN操作按钮垂直排列 */
    .fen-actions {
        flex-direction: column;
    }
    
    .fen-actions .action-button {
        min-width: 100%;
        margin-bottom: 5px;
    }
    
    /* 手机端字体调整 */
    .chess-info-panel h3 {
        font-size: 1.3em;
    }
    
    .fen-display label {
        font-size: 1em;
    }
    
    .fen-text {
        min-height: 70px;
        font-size: 13px;
        padding: 10px;
    }
    
    .fen-actions .action-button {
        padding: 10px 6px;
        font-size: 13px;
    }
    
    /* 手机端棋子字体大小 */
    .chess-square {
        font-size: min(10vw, 35px);
    }
    
    /* 手机端切换到聊天按钮 */
    .fullscreen-controls {
        position: sticky;
        bottom: 0;
        padding: 10px;
        margin-top: 20px; /* 恢复与上方内容的间距 */
        border-top: 1px solid var(--border-color);
    }
    
    .fullscreen-controls .action-button {
        min-width: 100%;
        padding: 12px;
        font-size: 15px;
    }
}

/* 平板端样式 */
@media (min-width: 768px) and (max-width: 1024px) {
    .chess-board-area {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
    }
    
    .chess-info-panel {
        width: 300px;
        flex-shrink: 0;
    }
    
    .chess-board {
        width: min(60vw, 500px);
        height: min(60vw, 500px);
    }
}

/* 桌面端样式 */
@media (min-width: 1025px) {
    .chess-board-area {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
    }
    
    .chess-info-panel {
        width: 350px;
        flex-shrink: 0;
        margin-left: 20px;
    }
    
    .chess-board {
        width: min(50vw, 500px); /* 限制最大宽度为500px */
        height: min(50vw, 500px);
    }
}

@media (min-width: 769px) and (max-width: 1200px) and (orientation: landscape) {
    /* 1. 让棋盘继续用正方形，但尺寸由“格子”决定 */
    .chess-board {
        width: unset !important;
        height: unset !important;
        grid-template-columns: repeat(8, 52px); /* 每格 60 px */
        grid-template-rows: repeat(8, 52px);
        margin-left: -30px;   /* 往左挪 20 px */
    }

    /* 2. 棋子图标同步缩小，防止溢出 */
    .chess-square {
        font-size: 40px; /* 原来 min(8vw,40px) → 固定 40 px */
    }

    @media (min-width: 769px) and (max-width: 1200px) and (orientation: landscape) {
    /* 1. 棋盘已放大，现在推 FEN 面板 */
    .chess-info-panel {
        width: 300px !important;        /* 原来 240→280，变大 */
        margin-left: 20px !important;   /* 再往右推 30 px */
        flex-shrink: 0 !important;
    }
}
}

/* 升变选项样式 */
.promotion-option {
    background-color: #ffeb3b !important;
    border: 2px solid #ff9800 !important;
}

.promotion-piece {
    transform: scale(1.2);
    cursor: pointer;
}

.promotion-piece:hover {
    transform: scale(1.3);
    transition: transform 0.2s;
}

/* 国际象棋游戏结束模态框样式 */
.chess-game-over-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.chess-game-over-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.chess-game-over-content h2 {
    margin: 0 0 1rem 0;
    color: #333;
}

.chess-game-over-content p {
    margin: 0 0 2rem 0;
    font-size: 1.2rem;
    color: #666;
}

.chess-game-over-buttons {
    margin-top: 1rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.chess-btn-primary {
    background: #007bff;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.chess-btn-primary:hover {
    background: #0056b3;
}

.chess-btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.chess-btn-secondary:hover {
    background: #545b62;
}
/* Chess AI Button Styles */
.chess-ai-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 8px;
    width: 100%;
    transition: background 0.3s ease, opacity 0.3s ease;
}

.chess-ai-button:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.chess-ai-button:disabled {
    background: #999;
    cursor: not-allowed;
    opacity: 0.7;
}
/* AI走法选择模态框样式 */
.chess-ai-choice-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1001; /* 比游戏结束模态框更高一级 */
}

.chess-ai-choice-content {
    background: #ffffff;
    padding: 1.5rem 2rem;
    border-radius: 12px;
    text-align: left;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chess-ai-choice-content h2 {
    margin: 0 0 0.5rem 0;
    color: #2c3e50;
    text-align: center;
    font-size: 1.5rem;
}

.ai-analysis-container {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    max-height: 200px;
    overflow-y: auto;
}

.ai-analysis-container p {
    margin: 0 0 0.5rem 0;
    font-weight: bold;
    color: #495057;
}

.ai-analysis-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #343a40;
    white-space: pre-wrap; /* 保留换行和空格 */
}

.ai-move-choices {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ai-move-choices p {
    margin: 0;
    font-weight: bold;
    color: #495057;
}

.ai-move-choice {
    display: block;
    background-color: #f1f3f5;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s;
    border: 1px solid #dee2e6;
}

.ai-move-choice:hover {
    background-color: #e9ecef;
}

.ai-move-choice input[type="radio"] {
    margin-right: 0.75rem;
    transform: scale(1.2);
}

.chess-ai-choice-buttons {
    margin-top: 1rem;
    display: flex;
    gap: 1rem;
    justify-content: flex-end; /* 按钮靠右对齐 */
}

/* 继承已有的按钮样式，并为禁用状态添加特定样式 */
.chess-btn-primary:disabled {
    background-color: #a0c7ff;
    cursor: not-allowed;
}

/* ===== 棋局保存加载样式 ===== */

/* 模态框基础样式 */
.chess-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.7);
    align-items: center;
    justify-content: center;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

.chess-modal-content {
    background-color: #2d3748;
    color: #e2e8f0;
    padding: 24px;
    border: 1px solid #4a5568;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.chess-modal-content h2 {
    margin: 0 0 20px 0;
    color: #f7fafc;
    font-size: 1.5rem;
    border-bottom: 2px solid #4a5568;
    padding-bottom: 10px;
}

/* 搜索框样式 */
.search-container {
    margin-bottom: 16px;
}

#chess-load-search {
    width: 100%;
    padding: 12px 16px;
    background-color: #4a5568;
    border: 1px solid #718096;
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 14px;
    transition: all 0.2s ease;
}

#chess-load-search:focus {
    outline: none;
    border-color: #63b3ed;
    box-shadow: 0 0 0 3px rgba(99, 179, 237, 0.1);
}

#chess-load-search::placeholder {
    color: #a0aec0;
}

/* 游戏列表样式 */
.chess-load-list {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
    margin-bottom: 20px;
    border: 1px solid #4a5568;
    border-radius: 8px;
    background-color: #1a202c;
}

.chess-load-item {
    padding: 16px;
    border-bottom: 1px solid #4a5568;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.chess-load-item:hover {
    background-color: #2d3748;
    transform: translateX(4px);
}

.chess-load-item:last-child {
    border-bottom: none;
}

.game-info {
    flex: 1;
}

.game-name {
    display: block;
    font-weight: 600;
    color: #f7fafc;
    margin-bottom: 4px;
    font-size: 1rem;
}

.game-date {
    font-size: 0.875rem;
    color: #a0aec0;
}

.load-game-btn {
    background-color: #4299e1;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}

.load-game-btn:hover {
    background-color: #3182ce;
}

.no-games {
    text-align: center;
    color: #a0aec0;
    padding: 40px 20px;
    font-style: italic;
}

/* 模态框按钮组 */
.chess-modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.chess-btn-secondary {
    background-color: #718096;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background-color 0.2s ease;
}

.chess-btn-secondary:hover {
    background-color: #4a5568;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .chess-modal-content {
        width: 95%;
        padding: 16px;
    }
    
    .chess-load-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .game-actions {
        align-self: flex-end;
    }
}

/* 按钮加载状态 */
.action-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.action-button .fa-spinner {
    margin-right: 8px;
}

/* --- 国际象棋加载模态框按钮样式优化 --- */

/* 1. 为所有按钮设置一个统一的基础样式 */
.game-actions .load-game-btn,
.game-actions .rename-game-btn,
.game-actions .delete-game-btn {
    padding: 8px 16px;       /* 统一内边距 */
    border: none;            /* 移除边框 */
    border-radius: 5px;      /* 统一圆角 */
    color: white;            /* 统一文字颜色 */
    font-size: 14px;         /* 统一字体大小 */
    font-weight: bold;       /* 字体加粗 */
    cursor: pointer;
    margin-left: 8px;        /* 按钮之间的间距 */
    transition: background-color 0.2s ease, transform 0.1s ease; /* 平滑过渡效果 */
    white-space: nowrap;     /* 防止文字换行 */
}

/* 鼠标悬停时轻微放大效果 */
.game-actions .load-game-btn:hover,
.game-actions .rename-game-btn:hover,
.game-actions .delete-game-btn:hover {
    transform: scale(1.05);
}

/* 2. 定义不同按钮的功能性颜色 */

/* 加载按钮 (主操作) - 使用您已有的 .chess-btn-primary 类 */
.game-actions .chess-btn-primary {
    background-color: #007bff; /* 蓝色 */
}
.game-actions .chess-btn-primary:hover {
    background-color: #0056b3; /* 深蓝色 */
}

/* 重命名按钮 (次要操作) - 使用您已有的 .chess-btn-secondary 类 */
.game-actions .chess-btn-secondary {
    background-color: #6c757d; /* 灰色 */
}
.game-actions .chess-btn-secondary:hover {
    background-color: #5a6268; /* 深灰色 */
}

/* 删除按钮 (危险操作) - 使用您已有的 .chess-btn-danger 类 */
.game-actions .chess-btn-danger {
    background-color: #dc3545; /* 红色 */
}
.game-actions .chess-btn-danger:hover {
    background-color: #c82333; /* 深红色 */
}