* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== AI 思考指示器 ===== */
.ai-thinking-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    color: white;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    animation: thinkingPulse 1.5s ease-in-out infinite;
}

@keyframes thinkingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.thinking-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.thinking-text {
    font-weight: 500;
}

.thinking-progress {
    width: 60px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

.thinking-progress-bar {
    height: 100%;
    width: 0%;
    background: white;
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* 游戏头部布局调整 */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

/* ===== 音效开关 ===== */
.sound-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 100;
    transition: all 0.3s ease;
}

.sound-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

.sound-toggle.muted {
    background: #f5f5f5;
}

.sound-toggle.muted .sound-icon {
    opacity: 0.5;
}

.sound-icon {
    font-size: 20px;
    transition: all 0.3s ease;
}

/* ===== 训练数据生成器面板 ===== */
.data-generator-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    min-width: 400px;
    max-width: 90vw;
}

.data-generator-panel h3 {
    margin: 0 0 20px 0;
    font-size: 20px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.generator-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.generator-controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.generator-controls input[type="number"] {
    width: 80px;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.generator-controls button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

#generateDataBtn {
    background: #4CAF50;
    color: white;
}

#generateDataBtn:hover:not(:disabled) {
    background: #43A047;
}

#stopGenerateBtn {
    background: #f44336;
    color: white;
}

#stopGenerateBtn:hover:not(:disabled) {
    background: #e53935;
}

.generator-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.generator-progress progress {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
}

.generator-progress span {
    font-size: 13px;
    color: #666;
    min-width: 60px;
}

.generator-stats {
    background: #f5f5f5;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    line-height: 1.6;
    max-height: 150px;
    overflow-y: auto;
}

.generator-stats p {
    margin: 4px 0;
    color: #333;
}

.generator-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.generator-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

#downloadDataBtn {
    background: #2196F3;
    color: white;
}

#downloadDataBtn:hover:not(:disabled) {
    background: #1E88E5;
}

#downloadDataBtn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

#closeGeneratorBtn {
    background: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
}

#closeGeneratorBtn:hover {
    background: #e0e0e0;
}

/* 生成训练棋谱按钮 */
#generateNotationBtn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

#generateNotationBtn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#generateNotationBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 棋谱生成进度提示 */
.notation-progress {
    margin-top: 12px;
    padding: 10px 16px;
    background: #f0f4ff;
    border-radius: 8px;
    text-align: center;
    color: #667eea;
    font-size: 14px;
}

/* 训练棋谱信息条 */
.training-notation-banner {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
}

.training-notation-banner span {
    white-space: nowrap;
}

/* ===== 结束训练数据生成器面板 ===== */

body {
    font-family: 'Microsoft YaHei', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    margin: 0;
    overflow: hidden;
}

.game-container {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 1200px;
    width: 100%;
    max-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.game-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-header h1 {
    font-size: 28px;
    margin: 0;
}

.game-info {
    display: flex;
    gap: 20px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-item .label {
    font-size: 14px;
    opacity: 0.9;
}

.info-item .value {
    font-size: 18px;
    font-weight: bold;
}

.game-main {
    display: flex;
    gap: 20px;
    padding: 20px;
    background: #f5f5f5;
    flex: 1;
    overflow: hidden;
}

.game-area {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    min-height: 400px; /* 确保最小高度 */
}

#gameCanvas {
    background: #fff8dc;
    border: 3px solid #8b4513;
    border-radius: 5px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    max-width: 100%;
    height: auto;
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: 5px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 0;
}

.start-content,
.game-over-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 420px;
    width: 90%;
    min-height: 280px;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    position: relative;
    flex-shrink: 0;
}

.start-content h2,
.game-over-content h2 {
    color: #667eea;
    font-size: 32px;
    margin-bottom: 30px;
}

/* 开始界面 - 选择游戏模式提示 */
.start-content p {
    color: #666;
    font-size: 16px;
    margin: 0 0 30px;
}

.game-over-header {
    position: relative;
    margin-bottom: 15px;
}

.game-over-header h2 {
    margin: 0;
}

/* 游戏结束消息（获胜方） */
.game-over-content > p {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin: 25px 0 15px;
}

.close-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #e74c3c;
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.close-btn:hover {
    background: #c0392b;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.game-over-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.final-stats {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin: 25px 0 15px;
}

.final-stats p {
    margin: 12px 0;
    color: #333;
    font-size: 14px;
    line-height: 1.5;
}

.final-stats span {
    font-weight: bold;
    color: #667eea;
}

.start-content p {
    color: #666;
    margin: 10px 0 20px;
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.mode-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 10px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.mode-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
}

.mode-btn .btn-icon {
    font-size: 24px;
}

.mode-btn .btn-text {
    font-size: 18px;
}

.difficulty-selector {
    margin-top: 20px;
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 20px 0;
}

.difficulty-btn {
    background: #f0f0f0;
    color: #333;
    border: 2px solid #ddd;
    padding: 10px 25px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.difficulty-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.back-btn {
    background: #95a5a6;
    color: white;
    border: none;
    padding: 10px 25px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.back-btn:hover {
    background: #7f8c8d;
}

/* 导入棋谱后继续游戏 */
.import-continue-btn {
    padding: 12px 24px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
}

.import-continue-btn:hover {
    background: #667eea;
    color: white;
}

.import-step-selector {
    margin: 15px 0;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.import-step-selector label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 16px;
    color: #333;
}

.import-step-selector input[type="number"] {
    width: 70px;
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    text-align: center;
}

.import-step-selector small {
    display: block;
    margin-top: 8px;
    color: #888;
    font-size: 12px;
}

.restart-btn,
.menu-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0;
    flex: 1;
    min-width: 120px;
}

.restart-btn:hover,
.menu-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(102, 126, 234, 0.4);
}

.menu-btn {
    background: #95a5a6;
}

.menu-btn:hover {
    background: #7f8c8d;
}

.final-stats {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin: 15px 0;
}

.final-stats p {
    margin: 8px 0;
    color: #333;
}

.final-stats span {
    font-weight: bold;
    color: #667eea;
}

.game-footer {
    background: #f8f9fa;
    padding: 15px 30px;
    text-align: center;
    color: #666;
    border-top: 1px solid #e0e0e0;
}

.game-footer p {
    margin: 0;
    font-size: 14px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.start-content,
.game-over-content {
    animation: fadeIn 0.3s ease;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.mode-btn:hover {
    animation: pulse 1s infinite;
}

.notation-panel {
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    position: relative;
    width: 280px;
    min-width: 280px;
}

.panel-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    border-radius: 10px 10px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    margin: 0;
    font-size: 18px;
}

.game-ended-notice {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    padding: 12px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 0;
    animation: slideDown 0.3s ease;
}

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

.notice-text {
    flex: 1;
    font-weight: 500;
    font-size: 14px;
}

.notice-btn {
    background: white;
    color: #f5576c;
    border: none;
    padding: 6px 16px;
    border-radius: 15px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.notice-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 50px;
    }
}

.panel-controls {
    display: flex;
    gap: 8px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.notation-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    background: #fafafa;
}

.notation-empty {
    text-align: center;
    color: #999;
    padding: 40px 20px;
    font-size: 14px;
}

.notation-item {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.notation-item:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.notation-item.active {
    border-color: #667eea;
    background: #f0f3ff;
}

.notation-item.current {
    border-color: #667eea;
    background: #e8ecff;
    border-width: 2px;
}

.notation-number {
    background: #667eea;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
}

.notation-content {
    flex: 1;
    min-width: 0;
}

.notation-move {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.notation-color {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
}

.notation-color.red {
    color: #e74c3c;
}

.notation-color.black {
    color: #2c3e50;
}

.notation-text {
    font-size: 14px;
    color: #333;
    font-weight: 500;
}

.notation-annotation {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
    padding-left: 8px;
    border-left: 2px solid #ddd;
}

.annotation-input {
    padding: 10px;
    background: white;
    border-top: 1px solid #e0e0e0;
    border-radius: 0 0 10px 10px;
    display: flex;
    gap: 8px;
}

.annotation-input input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}

.annotation-input input:focus {
    border-color: #667eea;
}

.annotation-input button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#saveAnnotationBtn {
    background: #667eea;
    color: white;
}

#saveAnnotationBtn:hover {
    background: #5568d3;
}

#cancelAnnotationBtn {
    background: #95a5a6;
    color: white;
}

#cancelAnnotationBtn:hover {
    background: #7f8c8d;
}

.notation-item.has-annotation {
    border-left: 3px solid #f39c12;
}

.annotation-badge {
    font-size: 12px;
    color: #f39c12;
    background: #fef5e7;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
}

/* 滚动条样式 */
.notation-list::-webkit-scrollbar {
    width: 6px;
}

.notation-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.notation-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.notation-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ===== 移动端适配 ===== */

/* 平板及中等屏幕 */
@media (max-width: 900px) {
    body {
        padding: 10px;
        align-items: flex-start;
        overflow-y: auto;
    }

    .game-container {
        max-height: none;
    }

    .game-header {
        padding: 12px 16px;
    }

    .game-header h1 {
        font-size: 20px;
    }

    .info-item .value {
        font-size: 15px;
    }

    .game-main {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
        overflow: visible;
    }

    .game-area {
        width: 100%;
        min-height: 300px;
    }

    /* 游戏弹框适配：支持纵向滚动，确保难度选择可见 */
    .game-overlay {
        position: absolute;
        min-height: 100%;
        align-items: flex-start;
        padding: 30px 0;
    }

    .start-content,
    .game-over-content {
        padding: 24px 20px;
        margin: auto;
        min-height: unset;
        max-height: none;
    }

    /* 棋谱面板改为底部横向展示 */
    .notation-panel {
        width: 100%;
        min-width: unset;
        max-height: 220px;
    }

    .notation-list {
        max-height: 130px;
    }
}

/* iPad 专项适配（768px ~ 1024px）*/
@media (min-width: 601px) and (max-width: 1024px) {
    .game-overlay {
        align-items: flex-start;
        padding: 40px 0 20px;
    }

    .start-content,
    .game-over-content {
        padding: 30px 28px;
        min-height: unset;
        max-height: none;
        width: 85%;
        max-width: 460px;
    }

    .start-content h2,
    .game-over-content h2 {
        font-size: 26px;
        margin-bottom: 20px;
    }

    .mode-btn {
        padding: 14px 24px;
        font-size: 17px;
    }

    .difficulty-selector {
        margin-top: 16px;
    }

    .difficulty-buttons {
        gap: 10px;
        margin: 16px 0;
    }

    .difficulty-btn {
        padding: 12px 22px;
        font-size: 16px;
    }

    .back-btn {
        padding: 10px 22px;
        font-size: 15px;
    }
}

/* 手机端 */
@media (max-width: 600px) {
    body {
        padding: 6px;
        overflow-y: auto;
    }

    .game-header {
        padding: 10px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .game-header h1 {
        font-size: 18px;
    }

    .game-info {
        gap: 10px;
    }

    .info-item .label {
        font-size: 12px;
    }

    .info-item .value {
        font-size: 14px;
    }

    .game-main {
        padding: 6px;
        gap: 8px;
    }

    /* 开始/结束弹框适配 */
    .start-content,
    .game-over-content {
        padding: 20px 16px;
        max-width: 95%;
    }

    .start-content h2,
    .game-over-content h2 {
        font-size: 22px;
    }

    .mode-btn {
        padding: 12px 20px;
        font-size: 16px;
    }

    .mode-btn .btn-icon {
        font-size: 20px;
    }

    .difficulty-buttons {
        flex-wrap: wrap;
        gap: 8px;
    }

    .difficulty-btn {
        padding: 9px 16px;
        font-size: 14px;
    }

    .game-over-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .restart-btn,
    .menu-btn {
        min-width: unset;
        width: 100%;
    }

    /* 棋谱面板 */
    .notation-panel {
        max-height: 180px;
    }

    .panel-header h3 {
        font-size: 15px;
    }

    .panel-controls {
        gap: 4px;
    }

    .control-btn {
        padding: 6px 8px;
        font-size: 14px;
    }

    .notation-list {
        max-height: 100px;
    }

    .notation-item {
        padding: 8px;
    }

    .notation-text {
        font-size: 13px;
    }

    .game-footer {
        padding: 10px 12px;
    }

    .game-footer p {
        font-size: 12px;
    }

    /* 棋盘 canvas 铺满屏幕宽度，格子更大更好点 */
    .game-area {
        width: 100%;
        padding: 0;
    }

    #gameCanvas {
        width: 100% !important;
        height: auto !important;
        /* 禁止长按弹出系统菜单，避免误触 */
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: none;
    }

    /* 提示语改为触控友好文案 */
    .game-footer p::after {
        content: '';
    }
}

/* ===== 触控通用优化（所有移动端）===== */
@media (hover: none) and (pointer: coarse) {
    /* 防止 canvas 上的长按/双击触发系统行为 */
    #gameCanvas {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: none;
    }

    /* 棋谱按钮加大点击区域 */
    .control-btn {
        min-width: 40px;
        min-height: 40px;
    }
}
