/* 基本スタイル */
body {
    font-family: 'Segoe UI', 'Helvetica Neue', sans-serif;
    text-align: center;
    background: #ffffff;
    margin: 0;
    padding: 20px;
    color: rgb(0, 0, 0);
    min-height: 100vh;
    box-sizing: border-box;
}

* {
    box-sizing: border-box;
}

h1 {
    margin: 20px 0;
    color: white;
    font-size: 2.5em;
    font-weight: 600;
}

/* ボード関連のスタイル */
#board {
    width: min(80vw, 80vh);
    height: min(80vw, 80vh);
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 2px;
    background: #2c1810;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.cell {
    background: #b59270;
    border-radius: 4px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.cell:hover {
    background: #c6a383;
}

.disc {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 90%;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.black {
    background: #333;
    box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.3),
        0 4px 8px rgba(0, 0, 0, 0.5);
}

.white {
    background: #fff;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1),
        0 4px 8px rgba(0, 0, 0, 0.3);
}

.valid-move-black::after,
.valid-move-white::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30%;
    height: 30%;
    border-radius: 50%;
    opacity: 0.3;
    pointer-events: none;
}

.valid-move-black::after {
    background: #333;
}

.valid-move-white::after {
    background: #fff;
}

@keyframes placeDisc {
    0% {
        transform: translate(-50%, -50%) scale(0.3);
        opacity: 0;
    }

    60% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
    }
}

.animate-disc {
    animation: placeDisc 0.3s ease-out forwards;
}

/* ディスク関連のスタイル */
.common-box {
    background: rgba(181, 146, 112, 0.1);
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    color: rgb(0, 0, 0);
    padding: 15px;
}

/* ステータス関連のスタイル */
#status-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 15px auto;
    max-width: min(400px, calc(100vw - 40px));
}

#turnIndicator {
    font-size: 1.2em;
    font-weight: 500;
    width: 100%;
    text-align: center;
}

#status {
    font-size: 1.1em;
    text-align: center;
    min-height: 24px;
    width: 100%;
}

/* コントロール関連のスタイル */
#controls {
    margin-top: 10px;
    margin: 20px auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: min(600px, calc(100vw - 40px));
    padding: 0 10px;
}

button {
    padding: 12px 20px;
    font-size: max(14px, min(1em, calc(var(--cell-size) * 0.32)));
    background: #b59270;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex: 1;
    min-width: max(120px, calc(var(--cell-size) * 2.4));
}

button:hover {
    background: #c6a383;
    transform: translateY(-2px);
}

/* 履歴関連のスタイル */
#historyLog {
    max-width: min(800px, calc(100vw - 40px));
    margin: 20px auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    padding: 20px;
}

.history-item {
    padding: 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.5);
    text-align: center;
    border: 1px solid rgba(181, 146, 112, 0.2);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.history-number {
    font-weight: bold;
    color: #b59270;
}

/* スタート画面のスタイル */
#startScreen {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(80vw, 80vh);
    height: min(80vw, 80vh);
    background: rgba(0 0 0 / 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: all 0.5s ease-in-out;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
    opacity: 1;
    visibility: visible;
    box-sizing: border-box;
    overflow: auto;
}

#startScreen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#gameScreen {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    padding-top: 80px;
    /* 音声コントロール分のスペースを確保 */
    box-sizing: border-box;
}

#gameScreen.active {
    display: block;
    opacity: 1;
}

#gameTitle {
    font-size: clamp(2em, 8vw, 4em);
    margin-bottom: 30px;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    text-align: center;
    width: 100%;
}

.setup-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 400px;
    background: rgba(181, 146, 112, 0.2);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
}

.setup-option {
    width: 100%;
}

.setup-option select {
    width: 100%;
    padding: 12px;
    font-size: clamp(0.9em, 4vw, 1.2em);
    background: #b59270;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    height: auto;
    min-height: 45px;
}

.setup-option select:disabled {
    background: #cccccc;
    cursor: not-allowed;
    opacity: 0.7;
}

.setup-option select option:disabled {
    color: #666666;
    background: #f5f5f5;
}

.setup-option select:hover:not(:disabled) {
    background: #c6a383;
}

/* アニメーション */
@keyframes pulse {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0.3;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 0.6;
    }

    100% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0.3;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* レスポンシブデザイン */
@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 2em;
        margin: 10px 0;
    }

    #controls {
        padding: 10px;
        gap: 8px;
    }

    button {
        padding: 10px 16px;
    }

    #historyLog {
        grid-template-columns: 1fr;
    }

    #startScreen {
        width: 95vw;
        height: auto;
        min-height: auto;
        padding: 15px;
    }

    .setup-container {
        padding: 15px;
        gap: 15px;
        width: 100%;
    }

    .setup-option select {
        padding: 8px;
        min-height: 40px;
    }

    #gameTitle {
        margin-bottom: 20px;
    }

    #startButton {
        padding: 10px;
        font-size: clamp(0.9em, 4vw, 1.1em);
    }

    .sound-controls-start {
        top: 10px;
        right: 10px;
        gap: 10px;
    }

    .sound-control {
        width: 35px;
        height: 35px;
    }

    .sound-icon {
        width: 25px;
        height: 25px;
    }

    #gameScreen {
        padding-top: 60px;
        /* 小さい画面では余白を少し減らす */
    }

    #board {
        width: 95vw;
        height: 95vw;
        padding: 5px;
        gap: 1px;
    }

    .disc {
        width: 85%;
        height: 85%;
    }

    .valid-move-black::after,
    .valid-move-white::after {
        width: 25%;
        height: 25%;
    }
}

/* さらに小さい画面サイズ用の調整 */
@media (max-width: 360px) {
    #startScreen {
        padding: 10px;
    }

    .setup-container {
        padding: 10px;
        gap: 10px;
    }

    .setup-option select {
        padding: 6px;
        min-height: 35px;
        font-size: clamp(0.8em, 3.5vw, 1em);
    }

    #gameTitle {
        font-size: clamp(1.8em, 7vw, 2.5em);
        margin-bottom: 15px;
    }

    #gameScreen {
        padding-top: 50px;
        /* さらに小さい画面では余白をさらに調整 */
    }
}

/* 結果ポップアップのスタイル */
#resultPopup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    text-align: center;
    min-width: min(300px, 90vw);
}

#resultPopup.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

#resultPopup .result-content {
    margin-bottom: 20px;
    font-size: 1.5em;
    font-weight: bold;
    color: rgb(255, 255, 255);
}

#resultPopup.winner-black {
    background: linear-gradient(145deg, #2c3e50, #34495e);
}

#resultPopup.winner-white {
    background: linear-gradient(145deg, #b59270, #c6a383);
}

#resultPopup.winner-draw {
    background: linear-gradient(145deg, #8c816a, #9c917a);
}

#resultPopup button {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 10px 25px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
}

#resultPopup button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.overlay.show {
    opacity: 1;
    visibility: visible;
}

/* 勝者表示スタイル */
.winner-announcement {
    font-size: max(18px, min(1.5em, calc(var(--cell-size) * 0.36)));
    font-weight: bold;
    padding: 20px;
    margin: 20px auto;
    max-width: min(400px, calc(100vw - 40px));
    border-radius: 12px;
    animation: fadeIn 0.5s ease-in;
    background: rgba(181, 146, 112, 0.5);
}

.pass-announcement {
    font-size: max(16px, min(1.2em, calc(var(--cell-size) * 0.32)));
    font-weight: bold;
    padding: 15px;
    margin: 15px auto;
    background: linear-gradient(145deg, #b59270, #c6a383);
    color: white;
    border-radius: 8px;
    animation: fadeIn 0.3s ease-in;
    max-width: min(400px, calc(100vw - 40px));
}

/* サウンドコントロールのスタイル */
.sound-controls-start {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 15px;
    z-index: 1100;
}

.sound-controls-game {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 15px;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: 25px;
    backdrop-filter: blur(5px);
}

.sound-control {
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    padding: 5px;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.sound-control:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.2);
}

.sound-icon {
    width: 30px;
    height: 30px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    transition: transform 0.2s ease;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.bgm-on {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23b59270"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/></svg>');
}

.bgm-off {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23cccccc"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/></svg>');
}

.se-on {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23b59270"><path d="M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z"/></svg>');
}

.se-off {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23cccccc"><path d="M4.27 3L3 4.27l9 9v.28c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4v-1.73L19.73 21 21 19.73 4.27 3zM14 7h4V3h-6v5.18l2 2z"/></svg>');
}