:root {
    --board-bg: #E6BF83; /* 木のような薄茶色 */
    --board-border: #382E2C;
    --piece-bg: #F3D9A5; /* 駒の背景色 */
    --piece-color: #000000;
    --highlight-color: rgba(255, 223, 0, 0.7); /* 選択中の駒のハイライト */
    --possible-move-bg: rgba(76, 175, 80, 0.5); /* 移動可能な場所の背景 */
    --captured-bg: #F5E8D3;
    --main-font: 'Hiragino Kaku Gothic ProN', 'メイリオ', Meiryo, sans-serif;
}

body {
    font-family: var(--main-font);
    background-color: #F0F0F0;
    color: var(--board-border);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    box-sizing: border-box;
}

.screen {
    display: none;
    width: 100%;
    max-width: 600px;
    text-align: center;
}

.screen.active {
    display: block;
}

#start-screen h1 {
    font-size: 2.5rem;
}

.setting {
    margin-bottom: 20px;
}

.options {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
}

button {
    font-family: var(--main-font);
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
    border: 2px solid var(--board-border);
    background-color: #fff;
    color: var(--board-border);
    border-radius: 5px;
    transition: all 0.2s ease;
}

button:hover {
    background-color: var(--board-border);
    color: #fff;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

button.selected {
    background-color: var(--board-border);
    color: #fff;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#board-container {
    width: 100%;
    max-width: 540px; /* 60px * 9 */
    aspect-ratio: 1 / 1;
    position: relative;
}

#board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 100%;
    height: 100%;
    background-color: var(--board-bg);
    border: 2px solid var(--board-border);
    box-shadow: 5px 5px 15px rgba(0,0,0,0.2);
}

.square {
    position: relative;
    width: 100%;
    height: 100%;
    border: 1px solid var(--board-border);
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
}

.piece {
    position: absolute;
    width: 90%;
    height: 90%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(12px, 2.5vw, 18px);
    font-weight: bold;
    color: var(--piece-color);
    cursor: pointer;
    transition: transform 0.3s ease-in-out, background-color 0.2s;
    user-select: none;
    background-color: var(--piece-bg);
    border: 1px solid var(--board-border);
    box-sizing: border-box;
    clip-path: polygon(50% 0%, 100% 30%, 90% 100%, 10% 100%, 0% 30%);
}

.piece.opponent {
    transform: rotate(180deg);
}
.piece.promoted {
    color: red;
}
.piece.selected {
    background-color: var(--highlight-color);
}

.possible-move::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30%;
    height: 30%;
    background-color: var(--possible-move-bg);
    border-radius: 50%;
}

.square.in-check {
    background-color: rgba(255, 0, 0, 0.15);
}

.captured-area {
    width: 100%;
    max-width: 540px;
    min-height: 40px;
    background-color: var(--captured-bg);
    border: 1px solid var(--board-border);
    border-radius: 5px;
    padding: 5px;
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
}

.captured-wrap {
    width: 100%;
    max-width: 540px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.captured-label {
    text-align: left;
    font-size: 0.9rem;
    color: var(--board-border);
}

.captured-area .piece {
    position: static;
    transform: none !important;
    width: 30px;
    height: 30px;
    font-size: 14px;
    border: 1px solid var(--board-border);
}

#info-panel {
    margin-top: 15px;
}

#game-screen.your-turn {
    box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.35);
    border-radius: 8px;
}

#game-screen.opponent-turn {
    box-shadow: 0 0 0 4px rgba(120, 120, 120, 0.25);
    border-radius: 8px;
}

#turn-display.your-turn {
    color: #2e7d32;
    font-weight: bold;
}

#turn-display.opponent-turn {
    color: #666;
    font-weight: bold;
}

.turn-flash {
    animation: turnFlash 0.4s ease-in-out;
}

@keyframes turnFlash {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

#game-screen.opponent-turn #board {
    cursor: not-allowed;
    opacity: 0.95;
}

#board-container::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.03);
    opacity: 0;
    pointer-events: none;
}

#game-screen.opponent-turn #board-container::after {
    opacity: 1;
}

/* Win Overlay */
#win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none; /* Hidden by default */
    pointer-events: none; /* Allow clicks to pass through */
    z-index: 100;
}

#win-message {
    position: absolute;
    top: 5%;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 10px 25px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    text-shadow: 1px 1px 3px #000;
}

#reset-game-btn {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: auto; /* Make the button clickable */
    z-index: 101; /* Ensure it's above the canvas */
}

#fireworks-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Responsive Design */
@media (max-width: 640px) {
    body {
        padding: 10px;
    }

    #game-container {
      flex-direction: column;
    }

    .captured-area {
        min-height: 35px;
    }
}
