/* 全体のリセットとスマホアプリ風の設定 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    background-color: #121212;
    color: #ffffff;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: relative; /* ★追加: 絶対配置の基準にするため */
}

/* ヘッダー（上部枠） */
#top-header {
    order: 1;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px;
    background-color: #1e1e1e;
    border-bottom: 2px solid #333;
    flex-wrap: nowrap;
    gap: 10px;
    flex-shrink: 0;
}

#header-left {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
    min-width: 0;
}

#header-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

#header-right button {
    width: 100%;
    text-align: center;
}

button {
    background-color: #3a3a3c;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
}

#retry-button {
    background-color: #c0392b;
}
#retry-button:active {
    background-color: #e74c3c;
}

/* メインエリア（盤面を中央に配置） */
main {
    order: 2;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    min-height: 0;
}

/* 7x7の盤面グリッド */
#board {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(7, 1fr);
    gap: 2px;
    background-color: #555;
    border: 2px solid #555;
    aspect-ratio: 1 / 1;
    width: 400px;
    max-width: 100%;
    max-height: 100%;
}

/* 「一手戻す」ボタンの格納エリア（縦画面の時） */
#undo-container {
    order: 3;
    background-color: #1e1e1e;
    border-top: 2px solid #333;
    padding: 10px 10px 5px 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    width: 100%;
}

#undo-button {
    width: 100%;
    max-width: 300px;
    padding: 12px;
    font-size: 16px;
    background-color: #2980b9;
    white-space: nowrap;
}

/* フッター（広告専用エリア） */
#bottom-footer {
    order: 4;
    padding: 5px 10px 10px 10px;
    background-color: #1e1e1e;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
}


/* 💡 ここが魔法の設定！横画面になった時だけの「絶対配置（ワープ）」ルール */
@media (orientation: landscape) {
    #top-header {
        border-bottom: none; /* 盤面との境界線を消す */
    }

    /* ★ココが完全修正版！ボタンを指定の座標に強制ワープさせる */
    #undo-container {
        position: absolute; /* 通常の並び順から切り離す */
        top: 42px; /* ★難易度バーと「やり直す」ボタンの高さにピタリと合わせる数値！ */
        left: 50%; /* 画面のド真ん中 */
        transform: translateX(-50%); /* ズレを補正して完全に中央配置 */

        /* 不要な背景や枠線をすべて消す */
        border: none;
        background: transparent;
        padding: 0;
        width: auto;
        z-index: 100; /* 他の要素より手前に表示 */
    }

    #undo-button {
        padding: 8px 24px; /* 横画面用に少しスリムにする */
        font-size: 14px;
        margin: 0;
        box-shadow: 0 4px 8px rgba(0,0,0,0.5); /* 浮いているように少し影をつける */
    }

    main {
        order: 3;
        padding-top: 5px; /* ボタンが抜けた分、盤面をさらに上に詰める！ */
    }
    #bottom-footer {
        order: 4;
        border-top: 2px solid #333;
    }
}


/* 1つのマス */
.cell {
    background-color: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* 中央マス(3,3)の目印（赤いドット） */
.cell.center-mark::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20%;
    height: 20%;
    background-color: #e74c3c;
    border-radius: 50%;
    opacity: 0.5;
    z-index: 20;
}

/* 将来バナー広告が入るスペース */
#banner-ad-space {
    width: 320px;
    height: 50px;
    background-color: #000;
    color: #888;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px dashed #555;
}

/* --- コマのデザイン --- */
.piece {
    width: 80%;
    height: 80%;
    border-radius: 50%;
    box-shadow: 0 4px 6px rgba(0,0,0,0.6);
    transition: all 0.3s ease;
    z-index: 10;
}

.piece.black { background-color: #1a1a1a; border: 2px solid #555; }
.piece.white { background-color: #f5f5f5; border: 2px solid #ccc; }

.piece.core {
    border-radius: 25%;
    box-shadow: 0 0 10px currentColor;
}

.piece.core.black { color: #8a2be2; border-color: #8a2be2; }
.piece.core.white { color: #00ffff; border-color: #00ffff; }

.piece.selected {
    box-shadow: 0 0 15px 5px #f1c40f;
    transform: scale(1.1);
}

.cell.highlight-slide {
    background-color: rgba(46, 204, 113, 0.4);
    cursor: pointer;
}

/* --- ポップアップ画面のデザイン --- */
#rule-modal {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex; justify-content: center; align-items: center;
    z-index: 100;
}

#rule-modal.hidden {
    display: none;
}

.modal-content {
    background-color: #2c3e50;
    padding: 20px;
    border-radius: 10px;
    width: 90%; max-width: 350px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    line-height: 1.6;
}

#close-modal {
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #e74c3c;
}

#rule-modal .modal-content {
    max-height: 80vh;
    overflow-y: auto;
    text-align: left;
}

#rule-modal h2 { font-size: 20px; text-align: center; color: #ffffff; margin-bottom: 10px; border-bottom: 2px solid #34495e; padding-bottom: 5px;}
#rule-modal h3 { margin-top: 25px; margin-bottom: 10px; font-size: 16px; border-bottom: 1px solid #555; padding-bottom: 5px; color: #f1c40f; }
#rule-modal h4 { margin-top: 20px; margin-bottom: 5px; font-size: 15px; color: #3498db; }
#rule-modal p { font-size: 14px; margin-bottom: 10px; line-height: 1.6; }
#rule-modal ol { padding-left: 20px; font-size: 14px; margin-bottom: 15px; line-height: 1.6; }
#rule-modal ul { padding-left: 20px; font-size: 14px; }
#rule-modal li { margin-bottom: 8px; }

.hint {
    background-color: rgba(241, 196, 15, 0.1);
    border-left: 4px solid #f1c40f;
    padding: 10px;
    border-radius: 4px;
    font-size: 13px;
    color: #f39c12;
    margin: 15px 0;
}

.rule-outro {
    margin-top: 30px;
    font-weight: bold;
    text-align: center;
    color: #2ecc71;
    font-size: 15px !important;
}

/* --- CPUレベル調整UI --- */
.level-slider-container {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #f1c40f;
}

#cpu-level {
    width: 100px;
}

.level-btn {
    background-color: transparent;
    color: #f1c40f;
    border: none;
    font-size: 18px;
    padding: 0 5px;
    cursor: pointer;
    transition: transform 0.1s;
}

.level-btn:active {
    transform: scale(0.7);
    color: #f39c12;
}

#cpu-level:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.level-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
    color: #7f8c8d;
}

/* --- 対戦モード選択UI --- */
.mode-select {
    background-color: #2c3e50;
    color: #ffffff;
    border: 1px solid #34495e;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    width: 100%;
    margin-bottom: 5px;
}

.mode-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#player-info {
    margin-top: 5px;
    font-size: 14px;
}

/* --- リザルト画面UI --- */
#result-modal {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex; justify-content: center; align-items: center;
    z-index: 200;
}

#result-modal.hidden {
    display: none;
}

#result-title {
    text-shadow: 0 0 10px currentColor;
}

#restart-button:active {
    background-color: #2ecc71;
    transform: scale(0.95);
}

/* --- 広告モーダル用デザイン --- */
#ad-modal {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    display: flex; justify-content: center; align-items: center;
    z-index: 300;
}

#ad-modal.hidden {
    display: none;
}