/* 全局样式 */
body {
    font-family: 'Press Start 2P', cursive; /* 像素风格字体 */
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 30px;
    background-color: #2c3e50; /* 深蓝灰色背景 */
    color: #ecf0f1; /* 浅灰色文字 */
    user-select: none; /* 禁止文本选择 */
}

/* 移动端适配 */
@media (max-width: 768px) {
    body {
        margin-top: 15px;
    }
    
    h1 {
        font-size: 1.5em;
        margin-bottom: 10px;
    }
    
    .board {
        grid-template-columns: repeat(3, 80px);
        grid-template-rows: repeat(3, 80px);
        gap: 6px;
    }
    
    .cell {
        width: 80px;
        height: 80px;
        font-size: 2.5em;
    }
    
    #status {
        font-size: 1.2em;
    }
    
    button {
        padding: 10px 20px;
        font-size: 0.9em;
        min-width: 120px;
    }
    
    /* 优化移动端触摸体验 */
    .cell:hover {
        transform: none;
    }
    
    .cell:active {
        transform: scale(0.95);
    }
}

h1 {
    color: #f1c40f; /* 金黄色标题 */
    text-shadow: 2px 2px #e74c3c; /* 红色阴影 */
    margin-bottom: 20px;
}

/* 游戏棋盘 */
.board {
    display: grid;
    grid-template-columns: repeat(3, 100px);
    grid-template-rows: repeat(3, 100px);
    gap: 8px; /* 增大格子间隙 */
    margin: 20px 0;
    background-color: #34495e; /* 稍浅的蓝灰色棋盘背景 */
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* 棋盘格子 */
.cell {
    width: 100px;
    height: 100px;
    position: relative;
    background-color: #95a5a6; /* 灰色格子背景 */
    border: 3px solid #7f8c8d; /* 深灰色边框 */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3.5em; /* 增大 X/O 字体 */
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease-out, box-shadow 0.2s ease;
    overflow: hidden;
    border-radius: 3px;
    color: #2c3e50; /* 深蓝灰色 X/O */
    text-shadow: 1px 1px #ecf0f1; /* 浅灰色文字阴影 */
}

.cell:hover {
    background-color: #bdc3c7; /* 悬停时变亮 */
    transform: scale(1.05);
    border-color: #95a5a6;
    box-shadow: 0 0 10px rgba(236, 240, 241, 0.5); /* 悬停时发光效果 */
}

.cell:active {
    transform: scale(0.95);
    background-color: #7f8c8d; /* 点击时变暗 */
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* 区分 X 和 O 的样式 (如果需要可以覆盖 .cell 的 color) */
.cell.x {
   /* color: #3498db; */ /* 蓝色 X (可选) */
}

.cell.o {
   /* color: #e74c3c; */ /* 红色 O (可选) */
}

/* 玩家颜色标识 (用于状态栏等) */
.player-x {
    color: #3498db; /* 蓝色 */
    font-weight: bold;
}

.player-o {
    color: #e74c3c; /* 红色 */
    font-weight: bold;
}

/* 获胜格子动画 */
@keyframes winPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.7); /* 金黄色光晕 */
    }
    70% {
        transform: scale(1.08);
        box-shadow: 0 0 15px 20px rgba(241, 196, 15, 0); /* 扩展光晕并淡出 */
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(241, 196, 15, 0);
    }
}

/* 获胜格子的背景高亮和动画 */
.winning-cell {
    background-color: #f1c40f; /* 金黄色背景 */
    color: #2c3e50; /* 深色文字 */
    border-color: #f39c12; /* 橙色边框 */
    animation: winPulse 1.2s infinite ease-in-out;
}

/* 获胜划线的基础样式 */
.winning-cell::after {
    content: '';
    position: absolute;
    background-color: #e74c3c; /* 红色线条 */
    z-index: 1;
    box-shadow: 0 0 5px #c0392b; /* 线条阴影 */
    border-radius: 5px;
}

/* 水平线 */
.winning-cell.win-row::after {
    height: 12px;
    width: 110%; /* 稍微超出格子 */
    top: 50%;
    left: -5%;
    transform: translateY(-50%);
}

/* 垂直线 */
.winning-cell.win-col::after {
    width: 12px;
    height: 110%;
    left: 50%;
    top: -5%;
    transform: translateX(-50%);
}

/* 对角线 (左上到右下) */
.winning-cell.win-diag-1::after {
    width: 12px;
    height: 130%; /* 调整长度以适应倾斜 */
    top: -15%;
    left: 50%;
    transform: translateX(-50%) rotate(-45deg);
    transform-origin: center center;
}

/* 对角线 (右上到左下) */
.winning-cell.win-diag-2::after {
    width: 12px;
    height: 130%;
    top: -15%;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    transform-origin: center center;
}

/* 确保 X 和 O 在线条之上 */
.cell span, .cell::before, .cell::after:not(.winning-cell::after) { /* 排除获胜线条 */
    position: relative;
    z-index: 2;
}
.cell {
    z-index: 2; /* 确保格子内容在背景之上 */
}

/* 状态显示 */
#status {
    font-size: 1.8em;
    margin-bottom: 15px;
    margin-top: 10px;
    font-weight: bold;
    color: #ecf0f1; /* 浅灰色 */
    text-shadow: 1px 1px #34495e; /* 深色阴影 */
}

/* 按钮样式 */
button {
    padding: 12px 25px;
    font-size: 1.1em;
    font-family: 'Press Start 2P', cursive; /* 保持字体一致 */
    cursor: pointer;
    background-color: #e74c3c; /* 红色按钮 */
    color: #ecf0f1; /* 浅色文字 */
    border: none;
    border-radius: 5px;
    margin-top: 20px;
    text-shadow: 1px 1px #c0392b; /* 深红色阴影 */
    box-shadow: 0 3px #c0392b; /* 按钮底部阴影 */
    transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

button:hover {
    background-color: #f1c40f; /* 悬停时变黄 */
    color: #2c3e50; /* 深色文字 */
    text-shadow: 1px 1px #f39c12; /* 橙色阴影 */
    box-shadow: 0 3px #f39c12;
}

button:active {
    background-color: #f39c12; /* 点击时变橙 */
    transform: translateY(2px); /* 向下移动模拟按下效果 */
    box-shadow: 0 1px #f39c12; /* 减少阴影 */
}

/* 确保 #restart ID 也应用按钮样式 (如果 HTML 中是 #restart) */
#restart {
    /* 继承 button 样式 */
}

/* 引入像素字体 (如果需要在线字体) */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');