/* Global Styles */
:root {
    --bg-color: #2c3e50;
    --board-color: #e6b36f;
    --line-color: #3b3024;
    --stone-black: #1a1a1a;
    --stone-white: #f0f0f0;
    --accent-color: #e74c3c;
    --text-color: #ecf0f1;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Noto Sans TC', sans-serif;
    /* User can replace 'background.jpg' with their own image path */
    background: linear-gradient(rgba(30, 42, 54, 0.8), rgba(52, 73, 94, 0.8)), url('background.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-color);
}

.game-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    max-width: 95vw;
}

header {
    margin-bottom: 1.5rem;
}

h1 {
    font-size: 2.5rem;
    margin: 0 0 1rem 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 2px;
}

/* Turn Indicator */
.turn-indicator {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px 20px;
    border-radius: 50px;
    margin: 0 auto;
    width: fit-content;
}

#turn-text {
    font-size: 1.2rem;
    font-weight: bold;
}

.current-stone {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.current-stone.black {
    background: radial-gradient(circle at 30% 30%, #555, #000);
}

.current-stone.white {
    background: radial-gradient(circle at 30% 30%, #fff, #bbb);
}

/* Game Board */
.board-wrapper {
    background: #5d4037;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: inline-block;
}

.gomoku-board {
    display: grid;
    grid-template-columns: repeat(15, 40px);
    grid-template-rows: repeat(15, 40px);
    background-color: var(--board-color);
    border: 2px solid var(--line-color);
    position: relative;
    cursor: pointer;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
}

/* Grid Lines */
.cell {
    position: relative;
    width: 40px;
    height: 40px;
    box-sizing: border-box;
}

.cell::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--line-color);
    transform: translateY(-50%);
    z-index: 0;
    /* Lines at bottom */
}

.cell::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    height: 100%;
    width: 2px;
    background-color: var(--line-color);
    transform: translateX(-50%);
    z-index: 0;
}

/* Star Points (Dots) */
.star-point::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--line-color);
    transform: translate(-50%, -50%);
    z-index: 0;
    /* On top of lines */
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

/* Stones */
.stone {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    z-index: 1;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
}

.stone.placed {
    transform: translate(-50%, -50%) scale(1);
}

.stone.black {
    background: radial-gradient(circle at 35% 35%, #666, #000);
}

.stone.white {
    background: radial-gradient(circle at 35% 35%, #fff, #ccc);
}

/* Last Move Marker */
.stone.last-move::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: rgba(255, 0, 0, 0.6);
    transform: translate(-50%, -50%);
    box-shadow: 0 0 5px rgba(255, 0, 0, 0.8);
}

/* Hover Effect handled by ghost-stone below */

.cell:hover .ghost-stone {
    opacity: 0.5;
}

/* Ghost Stone - Controlled by Board State */
.ghost-stone {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    /* Above lines */
    opacity: 0;
    pointer-events: none;
    transition: background 0.2s, opacity 0.2s;
}

.gomoku-board.black-turn .cell:not(.occupied):hover .ghost-stone {
    opacity: 0.5;
    background: radial-gradient(circle at 35% 35%, #666, #000);
}

.gomoku-board.white-turn .cell:not(.occupied):hover .ghost-stone {
    opacity: 0.5;
    background: radial-gradient(circle at 35% 35%, #fff, #ccc);
}


/* Controls */
.controls {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.mode-selection {
    display: flex;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 5px;
    border-radius: 50px;
}

.btn {
    background: transparent;
    color: var(--text-color);
    border: 2px solid rgba(255, 255, 255, 0.1);
    padding: 10px 25px;
    font-size: 1rem;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.btn.active {
    background: linear-gradient(to bottom, #3498db, #2980b9);
    border-color: transparent;
    box-shadow: 0 4px 10px rgba(52, 152, 219, 0.4);
}

.btn.restart {
    background: linear-gradient(to bottom, #e74c3c, #c0392b);
    border: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    padding: 12px 40px;
    font-size: 1.1rem;
}

.btn.restart:hover {
    background: linear-gradient(to bottom, #ec7063, #e74c3c);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #2c3e50;
    padding: 3rem;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
    color: #f1c40f;
}

/* Responsive */
@media (max-width: 700px) {
    .gomoku-board {
        grid-template-columns: repeat(15, 22px);
        grid-template-rows: repeat(15, 22px);
    }

    .cell {
        width: 22px;
        height: 22px;
    }

    .stone,
    .ghost-stone {
        width: 18px;
        height: 18px;
    }
}