/* --- CSS: ゲームの見た目 --- */

/* ズーム無効化とスマホでの誤操作防止 */
#bfhd-game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: sans-serif;
    max-width: 400px;
    margin: 10px auto;
    padding: 10px;
    border: 3px solid #333;
    border-radius: 8px;
    background-color: #f5f5f5;
    box-sizing: border-box;
    position: relative;
}

/* ズーム抑制（タップ連打での拡大防止） */
#bfhd-game-container,
#bfhd-game-container button {
    touch-action: manipulation;
}


/* 情報パネルのレイアウト */

/* 情報パネルを上下2段にする */
#bfhd-info-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 320px;
    margin-bottom: 8px;
    padding: 5px;
    border: 1px solid #ccc;
    background-color: #fff;
    font-size: 14px;
    box-sizing: border-box;
}

/* 上段：ターン＋行動 */
#bfhd-turn-row {
    margin-bottom: 4px;
    font-weight: bold;
}

/* 下段：HP（左右に配置） */
#bfhd-hp-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ハート共通スタイル */
.bfhd-hp {
    letter-spacing: 1px;      /* ハートが詰まりすぎないように調整 */
}

/* プレイヤー HP（赤） */
.bfhd-hp-player {
    color: #e74c3c;
    font-weight: bold;
}

/* ボス HP（紫） */
.bfhd-hp-boss {
    color: #6f42c1;
    font-weight: bold;
}


#bfhd-map-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    max-width: 320px;
    height: 320px;
    border: 1px solid #000;
    background-color: #eee;
    margin-bottom: 10px;
}

.bfhd-cell {
    position: relative;        /* スプライト＋HPラベルを重ねるために追加 */
    width: 100%;
    height: 100%;
    border: 1px solid #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    font-weight: bold;
    box-sizing: border-box;
    /* ハイライト用アニメーションをスムーズにする */
    transition: background-color 0.1s;
}

/* プレイヤー、敵、ボス、アイテム、空マスのスタイル */
.bfhd-player { background-color: #007bff; color: white; border: 2px solid #0056b3; }
.bfhd-normal-enemy { background-color: #dc3545; color: white; border: 2px solid #a71d2a; }
.bfhd-boss { background-color: #6f42c1; color: white; border: 2px solid #4a2e8c; font-size: 18px; }
.bfhd-item { background-color: #ffc107; color: #333; border: 2px solid #d39e00; }
.bfhd-empty { background-color: #e9e9e9; }

/* 障害物マス */
.bfhd-obstacle {
    background-color: #888;      /* 岩っぽく目立つ色 */
    border: 2px solid #555;
}

/* --- 攻撃/エフェクトのハイライトスタイル --- */

/* 敵の遠距離攻撃範囲のハイライト（本番） */
.bfhd-highlight-attack-range {
    background-color: rgba(255, 0, 0, 0.5) !important;
}

/* プレイヤーがアイテム発射時に選択した範囲のハイライト */
.bfhd-highlight-item-range {
    background-color: rgba(0, 255, 255, 0.4) !important; /* シアン系で視認性を上げる */
}

/* 敵破壊時の瞬間的なフィードバック */
.bfhd-highlight-destruction {
    background-color: #ffcc00 !important; /* 破壊の閃光 */
}

/* プレイヤー近接攻撃のハイライト */
.bfhd-highlight-player-attack {
    background-color: rgba(0, 123, 255, 0.5) !important; /* プレイヤーの色を強調 */
}

/* --- 攻撃予兆表示 --- */

/* 近距離攻撃の予兆（次ターン突進し得る位置） */
.bfhd-forecast-melee {
    box-shadow: inset 0 0 0 2px rgba(255, 165, 0, 0.8);
    background-image: linear-gradient(
        135deg,
        rgba(255, 165, 0, 0.15),
        rgba(255, 215, 0, 0.05)
    );
}

/* 遠距離攻撃の予兆（本番より薄い射線） */
.bfhd-forecast-ranged {
    background-color: rgba(255, 0, 0, 0.18);
}

/* --- ダメージ演出 --- */

@keyframes bfhd-damage-shake {
    0%   { transform: translate(0, 0); }
    25%  { transform: translate(1px, 0); }
    50%  { transform: translate(-1px, 0); }
    75%  { transform: translate(1px, 0); }
    100% { transform: translate(0, 0); }
}

@keyframes bfhd-damage-flash {
    0%   { filter: brightness(1); }
    50%  { filter: brightness(1.6); }
    100% { filter: brightness(1); }
}

.bfhd-damage-hit {
    animation: bfhd-damage-shake 0.12s linear,
               bfhd-damage-flash 0.12s linear;
}

/* --- セル内スプライト＋HPラベル --- */

.bfhd-sprite {
    width: 90%;
    height: 90%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}

/* 右下のHPラベル */
.bfhd-hp-label {
    position: absolute;
    right: 2px;
    bottom: 1px;
    font-size: 10px;
    font-weight: bold;
    text-shadow: 0 0 2px #000;
    color: #fff;
}

/* スプライト用のクラス（実際の画像パス） */
.bfhd-sprite-player   { background-image: url('images/player.jpg'); }
.bfhd-sprite-enemy    { background-image: url('images/enemy.png'); }
.bfhd-sprite-boss     { background-image: url('images/boss.png'); }
.bfhd-sprite-item     { background-image: url('images/item.png'); }
.bfhd-sprite-obstacle { background-image: url('images/obstacle.png'); }

/* --- コントロールとアイテムスロット --- */

/* 1. 方向キーと攻撃ボタンのグリッド */
#bfhd-controls {
    display: grid !important;
    grid-template-areas:
        ". up ."
        "left attack right"
        ". down .";
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
    max-width: 240px;
    margin-top: 10px;
    justify-items: center;    /* 各マスの中でボタンを中央寄せ */
}

/* 2-a. アイテムスロットエリアのスタイリング */
.bfhd-item-button-wrapper {
    display: flex;
    align-items: center;
    gap: 5px;
    width: 100%;
    max-width: 320px;
    margin-top: 10px;
}
#bfhd-item-slot {
    width: 40px;
    height: 40px;
    border: 2px solid #333;
    position: relative;          /* 右下ラベルを重ねるために追加 */
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    overflow: hidden;            /* はみ出し防止（お好み） */
}
/* アイテムスロット内のアイコン */
.bfhd-item-slot-icon {
    width: 100%;
    height: 100%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
}

/* アイテム個数のラベル（右下） */
.bfhd-item-slot-count {
    position: absolute;
    right: 2px;
    bottom: 1px;
    font-size: 10px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 2px #000;
}

#bfhd-item-action-button {
    flex-grow: 1; /* 残りのスペースを埋める */
}

/* 方向選択中のアイテムボタンを目立たせる */
#bfhd-item-action-button.bfhd-item-selecting {
    color: #c00;
    font-weight: bold;
}

/* 2-b. 待機ボタンのスタイリング */
.bfhd-wait-button-wrapper {
    width: 40%;
}
.bfhd-wait-button-wrapper button {
    width: 100%;
    padding: 10px 0;
    font-size: 14px;
    background-color: #f1f1f1; 
    color: #333;
}


/* アイテムスロットが空の場合 */
.bfhd-slot-empty {
    background-color: #ccc;
    color: transparent;
}
/* アイテムスロットにアイテムがある場合 */
.bfhd-slot-filled {
    background-color: #ffc107;
    color: #333;
}

/* コントロールボタンの共通スタイル */
#bfhd-controls button {
    padding: 10px 0;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    border: 1px solid #333;
    border-radius: 4px;
    background-color: #fff;
    box-sizing: border-box;
}

/* この5つのボタンをマスに割り当てる */
#bfhd-controls > button {
    width: 100%;
    box-sizing: border-box;
}

#bfhd-controls > button[data-action="up"]    { grid-area: up; }
#bfhd-controls > button[data-action="down"]  { grid-area: down; }
#bfhd-controls > button[data-action="left"]  { grid-area: left; }
#bfhd-controls > button[data-action="right"] { grid-area: right; }

/* 攻撃ボタンのスタイル */
#bfhd-controls > button[data-action="attack"] {
    grid-area: attack;
    background-color: #dc3545;
    color: #fff;
}

/* アイテム方向選択中の攻撃ボタン（実質アイテムボタン） */
#bfhd-attack-button.bfhd-attack-item-mode {
    background-color: #ffc107;
    color: #333;
}


/* --- メッセージボックスとアイテム方向選択 --- */

#bfhd-message-box {
    position: absolute;
    top: 0; bottom: 0; left: 0; right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    text-align: center;
    border-radius: 8px;
    padding: 20px;
}
#bfhd-message-box p { margin-bottom: 20px; }
#bfhd-message-box button { padding: 10px 20px; font-size: 16px; }

/* ローディング用オーバーレイ */
#bfhd-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10;
}

/* ローディング中の中身（枠＋文字） */
.bfhd-loading-content {
    padding: 16px 24px;
    border-radius: 8px;
    background: #222;
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* ぐるぐる回る丸 */
.bfhd-spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 4px solid #fff;
    border-top-color: transparent;
    animation: bfhd-spin 1s linear infinite;
}

/* ローディング文字 */
.bfhd-loading-text {
    font-size: 14px;
}

/* 回転アニメーション */
@keyframes bfhd-spin {
    to {
        transform: rotate(360deg);
    }
}