/* ============================================================
   style.css - 全局样式与布局
   ============================================================ */

/* --- 基础重置 --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background: var(--bg-gradient);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
    touch-action: manipulation;
    overscroll-behavior: none;
}

/* --- 全局布局 --- */
#app {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

/* --- 顶部标题栏 --- */
#header {
    text-align: center;
    padding: 20px 20px 10px;
    width: 100%;
}

#header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-dark);
    letter-spacing: 0.1em;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

#header .subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

#status-bar {
    margin-top: 10px;
    padding: 8px 20px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    display: inline-block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    box-shadow: var(--shadow-light);
    transition: all var(--transition-normal);
}

/* --- 主内容区 --- */
#main {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    justify-content: center;
    padding: 10px 20px 20px;
    width: 100%;
    max-width: 1200px;
    flex: 1;
}

/* --- 棋盘区域 --- */
#board-section {
    flex: 1;
    min-width: 0;
    max-width: 700px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#board-canvas {
    width: 100%;
    aspect-ratio: 1 / 1;
    cursor: pointer;
    touch-action: manipulation;
    border-radius: 6px;
    box-shadow: var(--shadow-medium);
    transition: box-shadow var(--transition-normal);
}

#board-canvas:hover {
    box-shadow: var(--shadow-heavy);
}

/* --- 侧边栏 --- */
#sidebar {
    width: 280px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex-shrink: 0;
}

/* --- 面板通用样式 --- */
.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: var(--panel-shadow);
    transition: all var(--transition-normal);
}

.panel h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--border-color);
}

/* --- 模式选择 --- */
.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 100%;
    padding: 12px;
    border: 2px solid var(--panel-border);
    border-radius: var(--border-radius);
    background: var(--panel-bg);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-family);
}

.mode-btn:hover:not(:disabled) {
    border-color: var(--primary-color);
    background: var(--panel-bg-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-light);
}

.mode-btn:active:not(:disabled) {
    transform: translateY(0);
}

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

.mode-btn .mode-icon {
    font-size: 1.5rem;
}

.mode-btn .mode-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
}

.mode-btn .mode-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- 计时器 --- */
.timer-item {
    padding: 8px 12px;
    margin-bottom: 6px;
    border-radius: 6px;
    background: var(--panel-bg);
    font-size: 0.9rem;
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid transparent;
    transition: all var(--transition-fast);
}

.timer-item.active-player {
    border-color: var(--primary-color);
    background: rgba(139, 94, 60, 0.08);
    color: var(--primary-dark);
    font-weight: 700;
    box-shadow: 0 0 8px rgba(139, 94, 60, 0.15);
}

.timer-item.time-warning {
    color: var(--danger-color) !important;
    animation: pulse-warning 1s infinite;
}

.timer-step {
    padding: 6px 12px;
    border-radius: 6px;
    background: var(--panel-bg);
    font-size: 0.85rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    text-align: center;
    margin-top: 4px;
}

.timer-step.time-danger {
    color: var(--danger-color);
    font-weight: 700;
    animation: pulse-danger 0.5s infinite;
}

@keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes pulse-danger {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* --- 控制按钮 --- */
.control-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ctrl-btn {
    width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
}

.ctrl-btn:disabled {
    background: var(--button-disabled-bg) !important;
    color: var(--button-disabled-text) !important;
    cursor: not-allowed;
    box-shadow: none !important;
    transform: none !important;
}

.btn-undo {
    background: var(--info-color);
    color: #fff;
}

.btn-undo:hover:not(:disabled) {
    background: #2471a3;
    box-shadow: var(--shadow-light);
    transform: translateY(-1px);
}

.btn-pause {
    background: var(--warning-color);
    color: #fff;
}

.btn-pause:hover:not(:disabled) {
    background: #d68910;
    box-shadow: var(--shadow-light);
    transform: translateY(-1px);
}

.btn-restart {
    background: var(--danger-color);
    color: #fff;
}

.btn-restart:hover:not(:disabled) {
    background: var(--danger-hover);
    box-shadow: var(--shadow-light);
    transform: translateY(-1px);
}

/* --- 落子记录 --- */
#history-container {
    max-height: 260px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#history-list {
    list-style: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: 1;
    min-height: 0;
    padding-right: 4px;
}

#history-list::-webkit-scrollbar {
    width: 6px;
}

#history-list::-webkit-scrollbar-track {
    background: transparent;
}

#history-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

#history-list li {
    padding: 4px 8px;
    font-size: 0.82rem;
    border-radius: 4px;
    margin-bottom: 2px;
    font-family: var(--font-mono);
    transition: background var(--transition-fast);
}

#history-list li:nth-child(odd) {
    background: rgba(0, 0, 0, 0.02);
}

.move-black {
    color: #1a1a1a;
}

.move-white {
    color: #888;
}

/* --- 弹窗 --- */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(3px);
}

#modal {
    background: #fff;
    border-radius: 12px;
    padding: 32px 40px;
    text-align: center;
    box-shadow: var(--shadow-heavy);
    max-width: 400px;
    width: 90%;
    animation: modal-in 0.3s ease;
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

#modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 12px;
}

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

#modal-close {
    padding: 10px 32px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all var(--transition-fast);
}

#modal-close:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-light);
}

/* --- 页脚 --- */
#footer {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    opacity: 0.7;
}

/* --- 响应式 --- */
@media (max-width: 900px) {
    #main {
        flex-direction: column;
        align-items: center;
        padding: 10px;
    }

    #board-section {
        max-width: 100%;
        width: 100%;
    }

    #board-canvas {
        max-width: 600px;
    }

    #sidebar {
        width: 100%;
        max-width: 600px;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
    }

    #sidebar .panel {
        flex: 1;
        min-width: 180px;
    }

    #history-container {
        flex-basis: 100%;
        max-height: 160px;
    }

    #history-list {
        max-height: 110px;
    }
}

@media (max-width: 500px) {
    #header h1 {
        font-size: 1.5rem;
    }

    #sidebar .panel {
        min-width: 100%;
    }

    #history-container {
        max-height: 130px;
    }

    #history-list {
        max-height: 90px;
    }

    .mode-buttons {
        flex-direction: row;
        gap: 6px;
    }

    .mode-btn {
        flex: 1;
        padding: 10px 6px;
    }

    .mode-btn .mode-label {
        font-size: 0.85rem;
    }
}
