/* ===== 全局样式 ===== */
:root {
    --primary-color: #2c3e50;
    --accent-color: #3498db;
    --board-color: #e8d5a7;
    --board-line: #8b7355;
    --black-stone: #1a1a1a;
    --white-stone: #f5f5f5;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-pattern: radial-gradient(circle at 20% 80%, rgba(102, 126, 234, 0.1) 0%, transparent 50%),
                  radial-gradient(circle at 80% 20%, rgba(118, 75, 162, 0.1) 0%, transparent 50%);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
    --radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-gradient), var(--bg-pattern);
    color: var(--text-primary);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* 移动端全屏适配 */
    height: auto;
    min-height: -webkit-fill-available;
}

/* ===== 应用容器 ===== */
.app-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 16px;
    box-sizing: border-box;
    /* 移动端适配 */
    overflow-x: hidden;
    /* 确保内容撑开 */
    min-height: -webkit-fill-available;
    height: auto;
}

/* ===== 屏幕管理 ===== */
.screen {
    display: none;
    width: 100%;
    max-width: 800px;
    animation: fadeIn 0.4s ease-out;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== 欢迎界面 ===== */
.welcome-content {
    text-align: center;
    padding: 40px 24px;
}

.title {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    font-weight: 700;
    color: white;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.title-icon {
    font-size: 1.2em;
    animation: pulse 2s ease-in-out infinite;
}

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

.subtitle {
    font-size: clamp(1rem, 3vw, 1.25rem);
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 40px;
    font-weight: 300;
}

/* ===== 难度选择 ===== */
.difficulty-selector {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
}

.difficulty-selector h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 16px;
    font-weight: 500;
}

.difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.difficulty-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 16px 20px;
    background: white;
    border: 2px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    box-shadow: var(--shadow-sm);
}

.difficulty-btn:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.difficulty-btn.active {
    border-color: var(--accent-color);
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.05) 0%, rgba(155, 89, 182, 0.05) 100%);
}

.difficulty-label {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.difficulty-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ===== 设置区域 ===== */
.settings {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-top: 24px;
}

/* ===== 开关组件 ===== */
.switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.switch input {
    display: none;
}

.slider {
    position: relative;
    width: 50px;
    height: 26px;
    background: #ccc;
    border-radius: 13px;
    transition: var(--transition);
}

.slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .slider {
    background: var(--accent-color);
}

.switch input:checked + .slider::after {
    transform: translateX(24px);
}

.label-text {
    font-size: 0.95rem;
    color: white;
    font-weight: 400;
}

/* ===== 游戏界面 ===== */
.game-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 16px 8px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 8px;
}

.game-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    order: 1; /* 标题在最上方 */
}

.game-info {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    justify-content: center;
    order: 2; /* 状态信息在标题下方 */
}

.player-badge {
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--black-stone);
    color: white;
    transition: var(--transition);
}

.player-badge.white {
    background: white;
    color: var(--text-primary);
    border: 1px solid #ddd;
}

.difficulty-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    background: var(--accent-color);
    color: white;
    font-weight: 500;
}

.back-btn-container {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    order: 0; /* 返回按钮在最左边 */
}

.sound-btn-container {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    order: 3; /* 音效按钮在最右边 */
}

/* ===== 按钮样式 ===== */
.back-btn-container .icon-btn,
.sound-btn-container .icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: scale(1.05);
}

#sound-toggle-game svg {
    width: 20px;
    height: 20px;
}

/* ===== 游戏主区域 ===== */
.game-main {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 16px;
    box-shadow: var(--shadow-md);
    /* 确保棋盘有足够空间 */
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* 允许内容撑开，不限制固定高度 */
    min-height: 300px;
}

.board-container {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    /* 确保容器有足够空间，不限制最大高度 */
    min-height: 200px;
    /* 允许容器根据内容扩展 */
    flex: 1;
    /* 最大宽度限制，防止在大屏上过大 */
    max-width: 600px;
    margin: 0 auto;
}

#board {
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    touch-action: none;
    max-width: 100%;
    height: auto;
    /* 确保 canvas 可见 */
    display: block;
}

/* ===== 游戏控制 ===== */
.game-controls {
    display: flex;
    gap: 12px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-md);
    justify-content: center;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    background: white;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    border: 1px solid #e0e0e0;
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-color);
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn.primary {
    background: var(--bg-gradient);
    color: white;
    border: none;
}

.control-btn.primary:hover {
    box-shadow: var(--shadow-lg);
    border: none;
}

/* ===== 结果弹窗 ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease-out;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    padding: 40px 32px;
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes bounceIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.modal-title {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-weight: 600;
}

.modal-message {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.6;
}

.primary-btn {
    display: block;
    width: 100%;
    padding: 14px 24px;
    background: var(--bg-gradient);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.primary-btn:active {
    transform: translateY(0);
}

/* ===== 调试信息 ===== */
.debug-info {
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.85);
    color: #0f0;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
    max-width: calc(100% - 20px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    z-index: 100;
    /* 默认隐藏，只在调试模式显示 */
    display: none;
    pointer-events: none; /* 让点击穿透 */
}

.debug-info.show {
    display: block !important;
}

/* ===== 错误显示区域 ===== */
.error-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 0, 0, 0.9);
    color: white;
    padding: 20px;
    border-radius: 8px;
    font-size: 14px;
    max-width: 90%;
    text-align: center;
    z-index: 1001;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.error-display.show {
    display: block !important;
}

/* ===== 响应式调整 ===== */
@media (max-width: 640px) {
    .app-container {
        padding: 8px;
    }

    .welcome-content {
        padding: 30px 20px;
    }

    .difficulty-selector {
        padding: 20px;
    }

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

    .game-info {
        position: static;
        justify-content: center;
        margin-top: 8px;
        width: 100%;
    }

    .game-title {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }

    .game-main {
        padding: 10px;
    }

    .game-controls {
        padding: 12px;
        flex-direction: column;
    }

    .control-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-height: 700px) {
    .board-container {
        padding: 4px;
    }
}

/* ===== 高对比度模式 ===== */
@media (prefers-contrast: high) {
    :root {
        --accent-color: #0066cc;
        --board-line: #333;
    }
}

/* ===== 减少动画 ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}