/* General Body Styles */
body {
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* Full viewport height */
    margin: 0;
    background-color: #f0f2f5; /* Light grey background */
    color: #333;
    box-sizing: border-box;
}

/* Game Container */
.game-container {
    background-color: #ffffff;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    text-align: center;
    width: 90%; /* Responsive width */
    max-width: 400px; /* Max width for larger screens */
    box-sizing: border-box;
}

h1 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 2.2em; /* Responsive font size */
}

.status-message {
    font-size: 1.3em;
    font-weight: bold;
    margin-bottom: 25px;
    color: #007bff; /* Blue for active player */
}

/* Tic-Tac-Toe Board */
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 columns, equal width */
    grid-template-rows: repeat(3, 1fr); /* 3 rows, equal height */
    gap: 10px; /* Space between cells */
    width: 100%; /* Make board fill its container */
    max-width: 300px; /* Max width for the board itself */
    aspect-ratio: 1 / 1; /* Keep a 1:1 aspect ratio for the board */
    margin: 0 auto 25px auto; /* Center board horizontally */
    background-color: #e0e0e0; /* Grid line color */
    border-radius: 8px;
    overflow: hidden; /* Ensures rounded corners are applied correctly */
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
}

.cell {
    background-color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3.5em; /* Large font for X/O */
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
    border-radius: 4px; /* Slight rounded corners for cells */
}

.cell:hover {
    background-color: #f8f8f8; /* Hover effect */
}

/* Player X and O styles */
.cell.X {
    color: #dc3545; /* Red for X */
}

.cell.O {
    color: #007bff; /* Blue for O */
}

/* Button Group Styling */
.button-group {
    display: flex; /* 使用 Flexbox 讓按鈕並排 */
    gap: 15px; /* 按鈕間距 */
    justify-content: center; /* 水平置中按鈕 */
    margin-top: 20px; /* 與棋盤上方間距 */
    flex-wrap: wrap; /* 允許按鈕在小螢幕上換行 */
}

/* Common Button Styles */
.button-group button,
.button-group .home-button { /* 同時應用於 button 和 home-button */
    flex: 1; /* 讓按鈕彈性佔據空間 */
    min-width: 120px; /* 最小寬度，避免過小 */
    padding: 12px 25px;
    border: none;
    border-radius: 6px;
    font-size: 1.1em;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, transform 0.1s ease-in-out;
    box-sizing: border-box; /* 確保 padding 不會增加總寬度 */
    text-decoration: none; /* 移除超連結的下劃線 */
    display: inline-flex; /* 確保內聯 Flex 項目也能應用 Flex 屬性 */
    justify-content: center; /* 文本在按鈕中置中 */
    align-items: center; /* 文本在按鈕中垂直置中 */
    color: white; /* 預設文字顏色 */
}

/* Specific Button Colors */
#restartButton {
    background-color: #28a745; /* 綠色 */
}

#restartButton:hover {
    background-color: #218838;
    transform: translateY(-2px);
}

#restartButton:active {
    transform: translateY(0);
}

.home-button {
    background-color: #6c757d; /* 灰色 */
}

.home-button:hover {
    background-color: #5a6268;
    transform: translateY(-2px);
}

.home-button:active {
    transform: translateY(0);
}


/* Media Queries for Responsiveness */

/* Tablets and larger phones */
@media (max-width: 768px) {
    .game-container {
        padding: 25px;
    }

    h1 {
        font-size: 1.8em;
    }

    .status-message {
        font-size: 1.1em;
    }

    .cell {
        font-size: 3em;
    }

    .button-group {
        flex-direction: column; /* 在中等螢幕上，按鈕垂直堆疊 */
        gap: 10px;
    }

    .button-group button,
    .button-group .home-button {
        width: 100%; /* 垂直堆疊時佔滿寬度 */
        padding: 10px 20px;
        font-size: 1em;
    }
}

/* Smaller phones */
@media (max-width: 480px) {
    .game-container {
        padding: 20px;
        border-radius: 10px;
    }

    h1 {
        font-size: 1.6em;
        margin-bottom: 15px;
    }

    .status-message {
        font-size: 1em;
        margin-bottom: 20px;
    }

    .board {
        gap: 8px; /* Slightly smaller gap on small screens */
    }

    .cell {
        font-size: 2.8em;
    }

    .button-group {
        gap: 8px;
    }

    .button-group button,
    .button-group .home-button {
        padding: 8px 18px;
        font-size: 0.95em;
    }
}