/* =================================================================
 * Peripheral Vision Training Styles (Fixed: Dark Mode Visibility & Gap)
 * =================================================================
 */

/* ゲームエリア */
#play-screen {
    transition: background-color 0.3s ease;
}

/* 数字ボタン共通 */
.num-btn {
    border: 2px solid #dee2e6;
    background-color: #ffffff;
    color: #333;
    font-weight: bold;
    font-family: 'Roboto', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: all 0.1s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.num-btn:active {
    transform: scale(0.95);
    background-color: #e9ecef;
}

/* 正解した時のアニメーション */
.num-btn.correct {
    background-color: #a5d6a7 !important;
    /* Green */
    border-color: #81c784 !important;
    color: #1b5e20 !important;
    opacity: 0;
    transform: scale(1.2);
    pointer-events: none;
}

/* --- モード別レイアウト --- */

/* シュルテ・テーブル (5x5 固定グリッド) */
#numbers-container.mode-schulte {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 12px;
    padding: 10px;
    aspect-ratio: 1 / 1;
    max-width: 500px;
    margin: 0 auto;
}

/* グリッドサイズ別調整 */
#numbers-container.grid-3 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

#numbers-container.grid-5 {
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
}

#numbers-container.grid-6 {
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
}

#numbers-container.grid-7 {
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(7, 1fr);
    gap: 5px !important;
}

#numbers-container.grid-3 .num-btn {
    font-size: 2rem;
    border-radius: 12px;
}

#numbers-container.grid-5 .num-btn {
    font-size: 1.5rem;
    border-radius: 8px;
}

#numbers-container.grid-6 .num-btn {
    font-size: 1.3rem;
    border-radius: 6px;
}

#numbers-container.grid-7 .num-btn {
    font-size: 1.1rem;
    border-radius: 4px;
}

/* ワイド探索 (レスポンシブ拡散) */
#numbers-container.mode-wide {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 15px;
    padding: 15px;
    align-content: center;
    justify-content: center;
    height: 100%;
}

#numbers-container.mode-wide.grid-7 {
    grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
    gap: 10px;
}

#numbers-container.mode-wide .num-btn {
    font-size: 1.2rem;
    border-radius: 50%;
    aspect-ratio: 1 / 1;
}

/* =================================================================
 * ダークモード対応 & 視認性修正 (強力上書き)
 * =================================================================
 */

/* 背景色の調整: bg-light を暗くする */
[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .card.bg-light {
    background-color: #212529 !important;
    /* Dark Gray */
    border-color: #495057 !important;
}

/* ★追加修正: bg-white も暗くする（詳しい使い方のカード等） */
[data-bs-theme="dark"] .bg-white {
    background-color: #343a40 !important;
    /* Slightly lighter Dark Gray */
    color: #e0e0e0 !important;
    border-color: #495057 !important;
}

[data-bs-theme="dark"] .num-btn {
    background-color: #343a40;
    border-color: #495057;
    color: #e0e0e0;
}

[data-bs-theme="dark"] .num-btn:active {
    background-color: #495057;
}

/* ゲーム画面自体は暗く */
#play-screen.bg-light {
    background-color: #f8f9fa;
}

[data-bs-theme="dark"] #play-screen.bg-light {
    background-color: #121212 !important;
}

/* ★テキスト視認性修正 (最重要)★ */
/* bg-light, bg-white 内のテキストを、ダークモード時は白く、ライトモード時は黒くする */

/* ライトモード (デフォルト) */
.bg-light h3,
.bg-light h6,
.bg-light p,
.bg-light .text-dark,
.bg-light strong,
.bg-white h3,
.bg-white h6,
.bg-white p,
.bg-white .text-dark,
.bg-white strong {
    color: #212529 !important;
    /* 黒文字 */
}

.bg-light .text-muted,
.bg-white .text-muted {
    color: #6c757d !important;
    /* グレー */
}

/* ダークモード (反転) */
/* 親要素が bg-light または bg-white の場合、中のテキストを白にする */
[data-bs-theme="dark"] .bg-light h3,
[data-bs-theme="dark"] .bg-light h6,
[data-bs-theme="dark"] .bg-light p,
[data-bs-theme="dark"] .bg-light .text-dark,
[data-bs-theme="dark"] .bg-light strong,
[data-bs-theme="dark"] .bg-white h3,
[data-bs-theme="dark"] .bg-white h6,
[data-bs-theme="dark"] .bg-white p,
[data-bs-theme="dark"] .bg-white .text-dark,
[data-bs-theme="dark"] .bg-white strong {
    color: #e0e0e0 !important;
    /* 白文字 */
}

[data-bs-theme="dark"] .bg-light .text-muted,
[data-bs-theme="dark"] .bg-light .small.text-muted,
[data-bs-theme="dark"] .bg-white .text-muted,
[data-bs-theme="dark"] .bg-white .small.text-muted {
    color: #adb5bd !important;
    /* 明るいグレー */
}

/* ★モード選択ボタン内の文字色修正★ */
[data-bs-theme="dark"] #game-card #setup-screen .btn {
    color: #e0e0e0 !important;
}

[data-bs-theme="dark"] #game-card #setup-screen .btn span.fw-bold {
    color: #ffffff !important;
}

[data-bs-theme="dark"] #game-card #setup-screen .btn span.text-muted {
    color: #adb5bd !important;
    opacity: 1 !important;
}

[data-bs-theme="dark"] #game-card #setup-screen .btn i {
    color: #e0e0e0 !important;
}

/* ホバー時・選択時の視認性向上 */
[data-bs-theme="dark"] #game-card #setup-screen .btn:hover,
[data-bs-theme="dark"] #game-card #setup-screen .btn-check:checked+.btn {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: #f8f9fa !important;
}

[data-bs-theme="dark"] #game-card #setup-screen .btn:hover span,
[data-bs-theme="dark"] #game-card #setup-screen .btn-check:checked+.btn span {
    color: #ffffff !important;
}

/* レスポンシブ調整 */
@media (max-width: 576px) {
    #setup-screen {
        padding: 1.5rem !important;
    }

    #numbers-container.mode-schulte {
        gap: 8px;
        padding: 5px;
    }

    #numbers-container.mode-schulte .num-btn {
        border-width: 1px;
    }

    /* スマホで7x7は見づらいのでフォント調整 */
    #numbers-container.grid-7 .num-btn {
        font-size: 0.9rem;
    }
}