:root {
    --board-bg: #1b5e20;
    --board-border: #33691e;
    --bg-dark: #1a1a2e;
    --bg-panel: #16213e;
    --bg-input: #0f3460;
    --text-primary: #e0e0e0;
    --text-muted: #a0a0a0;
    --accent: #e94560;
    --highlight: #ffd54f;
    --shadow: rgba(0, 0, 0, 0.4);
    --cell-size: min(60px, calc((100vw - 160px) / 8));
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    background: linear-gradient(135deg, var(--bg-dark), #0f3460);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.game-container {
    display: flex;
    flex-direction: row;
    gap: 24px;
    max-width: 100%;
}

/* 將標題與棋盤放在同個主區塊，桌面版會顯示在棋盤上方 */
.main-area {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
}

/* ===== 標題與分數 ===== */
.game-header {
    text-align: center;
    margin-bottom: 16px;
    width: 100%;
}

.game-header h1 {
    font-size: 2rem;
    font-weight: 300;
    letter-spacing: 0.15em;
    margin-bottom: 12px;
    background: linear-gradient(90deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.score-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 1.1rem;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 8px;
    background: var(--bg-panel);
    transition: transform 0.2s;
}

.score-item:hover {
    transform: translateY(-2px);
}

.score-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-block;
}

.black-dot {
    background: radial-gradient(circle at 30% 30%, #666, #000);
    box-shadow: inset -1px -1px 3px rgba(255, 255, 255, 0.3), inset 1px 1px 3px rgba(0, 0, 0, 0.7);
}

.white-dot {
    background: radial-gradient(circle at 30% 30%, #fff, #ccc);
    box-shadow: inset -1px -1px 3px rgba(0, 0, 0, 0.5), inset 1px 1px 3px rgba(255, 255, 255, 0.5);
}

.score-num {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--highlight);
}

.score-vs {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.result-text {
    margin-top: 8px;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent);
    min-height: 2rem;
}

.ai-text {
    margin-top: 4px;
    font-size: 1rem;
    color: var(--highlight);
    min-height: 1.5rem;
}

/* ===== 棋盤 ===== */
.board-wrapper {
    flex-shrink: 0;
}

#reversi_board {
    display: grid;
    grid-template-columns: repeat(8, var(--cell-size));
    grid-template-rows: repeat(8, var(--cell-size));
    border: 2px solid var(--board-border);
    background-color: var(--board-bg);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--shadow);
    overflow: hidden;
}

.cells {
    display: contents;
}

.cell {
    aspect-ratio: 1;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: background-color 0.2s;
    cursor: default;
    position: relative;
}

.cell.empty {
    cursor: default;
}

.cell.step {
    cursor: pointer;
}

.cell.step::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 35%;
    height: 35%;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.25);
    pointer-events: none;
    animation: pulse 1.5s infinite;
}

.cell.step:hover::after {
    background-color: rgba(255, 255, 255, 0.45);
    transform: translate(-50%, -50%) scale(1.2);
}

.cell.black {
    background: radial-gradient(circle at 30% 30%, #666, #000);
    border-radius: 50%;
    box-shadow: inset -2px -2px 5px rgba(255, 255, 255, 0.3), inset 2px 2px 5px rgba(0, 0, 0, 0.7);
    animation: placePiece 0.3s ease-out;
}

.cell.white {
    background: radial-gradient(circle at 30% 30%, #fff, #ccc);
    border-radius: 50%;
    box-shadow: inset -2px -2px 5px rgba(0, 0, 0, 0.5), inset 2px 2px 5px rgba(255, 255, 255, 0.5);
    animation: placePiece 0.3s ease-out;
}

.cell.computer_board {
    box-shadow: 0 0 0 3px var(--highlight), inset 0 0 0 2px var(--accent);
    animation: highlightMove 0.5s ease-out;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 0.8; transform: translate(-50%, -50%) scale(1.1); }
}

@keyframes placePiece {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes highlightMove {
    from { box-shadow: 0 0 0 6px var(--highlight); }
    to { box-shadow: 0 0 0 3px var(--highlight), inset 0 0 0 2px var(--accent); }
}

/* ===== 控制面板 ===== */
.controls {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 220px;
    padding: 20px;
    background: var(--bg-panel);
    border-radius: 12px;
    box-shadow: 0 4px 16px var(--shadow);
    align-self: flex-start;
}

/* 置中顯示結果與 AI 計算文字（header 內） */
.game-header .result-text,
.game-header .ai-text,
.result-text,
.ai-text {
    text-align: center;
    width: 100%;
}

/* controls 內的結果列：整列置中顯示 */
.controls .result-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
}

/* 上一步按鈕樣式 */
.btn-undo {
    margin-top: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #4a90e2, #377dd9);
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    letter-spacing: 0.03em;
}

.btn-undo:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(55, 125, 217, 0.35);
}

.control-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-row label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.control-row select {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.control-row select:hover {
    border-color: var(--accent);
}

.depth-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.depth-input button {
    width: 32px;
    height: 36px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

.depth-input button:hover {
    border-color: var(--accent);
}

.depth-input button:active {
    transform: scale(0.95);
}

.depth-input input {
    width: 80px;
    text-align: center;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.btn-restart {
    margin-top: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #c62828);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    letter-spacing: 0.05em;
}

.btn-restart:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
}

/* ===== RWD ===== */
@media (max-width: 900px) {
    .game-container {
        flex-direction: column;
        align-items: center;
    }

    .controls {
        width: 100%;
        max-width: 400px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        padding: 16px;
        gap: 12px;
        margin: 0 auto;
    }

    .control-row {
        flex: 1;
        min-width: 140px;
    }

    .depth-input {
        width: 100%;
    }

    .btn-restart {
        width: 100%;
        margin-top: 0;
    }
}

@media (max-width: 600px) {
    :root {
        --cell-size: calc((100vw - 64px) / 8);
    }

    body {
        padding: 12px;
    }

    .game-header h1 {
        font-size: 1.5rem;
    }

    .score-bar {
        font-size: 0.95rem;
        gap: 8px;
    }

    .score-item {
        padding: 6px 10px;
    }

    .score-num {
        font-size: 1.2rem;
    }

    .controls {
        width: 100%;
        max-width: 400px;
        padding: 12px;
        gap: 10px;
        margin: 0 auto;
    }

    .control-row label {
        font-size: 0.75rem;
    }

    .control-row select,
    .depth-input input {
        padding: 6px 8px;
        font-size: 0.85rem;
    }
}

@media (max-width: 380px) {
    :root {
        --cell-size: calc((100vw - 48px) / 8);
    }

    .game-header h1 {
        font-size: 1.2rem;
    }

    .score-bar {
        font-size: 0.85rem;
    }
}
