/* =================================================================
 * Dynamic Vision Test Styles (Final Polish & Dark Mode Fix)
 * =================================================================
 */

/* --- コントローラー (十字キー) --- */
.d-pad-grid {
    display: grid;
    /* サイズ縮小: 64px -> 52px */
    grid-template-columns: 52px 52px 52px;
    grid-template-rows: 52px 52px 52px;
    gap: 6px;
}

.dir-btn {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    /* アイコンも少し小さく */
    border-radius: 50% !important;
    transition: all 0.1s;
}

.dir-btn:active {
    transform: scale(0.95);
}

/* --- ゲームステージ --- */
#game-card {
    border: none;
}

#dynamic-stage {
    background-color: #212529;
    overflow: hidden;
    cursor: crosshair;
    transition: background-color 0.5s;
}

/* 移動ターゲット */
#moving-target {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    border-radius: 50%;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
    will-change: transform, top, left;
    z-index: 2;
}

#moving-target svg {
    width: 60%;
    height: 60%;
    fill: #000;
}

/* --- 悪天候モード (Bad Weather) --- */
#dynamic-stage.weather-bad {
    background-color: #343a40;
    background-image:
        repeating-linear-gradient(45deg,
            rgba(255, 255, 255, 0.03),
            rgba(255, 255, 255, 0.03) 1px,
            transparent 1px,
            transparent 10px);
}

/* 悪天候時のターゲット */
#dynamic-stage.weather-bad #moving-target {
    background-color: #6c757d;
    /* 背景をグレーに */
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.1);
    filter: blur(1px);
    /* ぼかし */
    opacity: 0.8;
}

#dynamic-stage.weather-bad #moving-target svg path {
    fill: #212529;
    /* Cの黒い部分を薄く */
}

/* 切れ目を隠すための矩形(rect)の色も背景に合わせる */
#dynamic-stage.weather-bad #moving-target svg rect {
    fill: #6c757d;
}

/* ユーティリティ */
.drop-shadow {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* =================================================================
 * ダークモード対応 & 視認性修正
 * =================================================================
 */

/* --- 背景色の調整 --- */

/* ライトモード (デフォルト) の明示 */
.bg-light,
.card.bg-light {
    background-color: #f8f9fa;
    color: #212529;
}

.bg-white {
    background-color: #ffffff;
    color: #212529;
}

/* ダークモード時の上書き (強制的に暗くする) */
[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .card.bg-light {
    background-color: #212529 !important;
    /* Dark Gray */
    border-color: #495057 !important;
    color: #e0e0e0 !important;
}

[data-bs-theme="dark"] .bg-white {
    background-color: #343a40 !important;
    /* Slightly lighter Dark Gray */
    border-color: #495057 !important;
    color: #e0e0e0 !important;
}

/* --- テキスト色の調整 --- */
/* ダークモード時、明るい背景用クラスの中にある文字を白くする */
[data-bs-theme="dark"] .bg-light h3,
[data-bs-theme="dark"] .bg-light h5,
[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-white .text-muted {
    color: #adb5bd !important;
}

/* --- テーブルの調整 --- */
[data-bs-theme="dark"] .table {
    --bs-table-color: #e0e0e0;
    --bs-table-bg: transparent;
    border-color: #444;
}

[data-bs-theme="dark"] .table thead th {
    background-color: #333;
    color: #fff;
}

/* --- ボタンの調整 --- */
[data-bs-theme="dark"] .dir-btn.btn-outline-dark {
    color: #e0e0e0;
    border-color: #6c757d;
}

[data-bs-theme="dark"] .dir-btn.btn-outline-dark:hover,
[data-bs-theme="dark"] .dir-btn.btn-outline-dark:active {
    background-color: #495057;
    color: #fff;
    border-color: #f8f9fa;
}

/* --- その他 --- */
[data-bs-theme="dark"] #speed-display {
    color: #ffc107 !important;
}

/* ダークモードのprimary(#9d83d9)は白テキストとのコントラストが2.9:1でWCAG不合格のため
   ライトモードのprimaryに近い暗めのバイオレットを使用 → 白テキストとのコントラスト約7:1 */
[data-bs-theme="dark"] #game-card .card-header.bg-primary {
    background-color: #5a3fa8 !important;
}

/* .vision-tool-card は /common/style-components.css に共通化済み */

/* レスポンシブ調整 */
@media (max-width: 576px) {
    .d-pad-grid {
        grid-template-columns: 46px 46px 46px;
        grid-template-rows: 46px 46px 46px;
        gap: 6px;
    }

    .dir-btn {
        font-size: 1.1rem;
    }

    #game-card .card-body {
        height: 300px !important;
    }

    #moving-target {
        width: 60px !important;
        height: 60px !important;
    }
}

/* =================================================================
 * カウントダウンアニメーション
 * =================================================================
 */
#countdown-overlay div {
    animation: countdownPop 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes countdownPop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }

    100% {
        transform: scale(1.0);
        opacity: 0;
        /* 数字が消えていくフェードアウト */
    }
}