/* ==========================================
 * TOUCH INTERFACE (タッチ操作・仮想パッド)
 * ========================================== */

/* タッチ操作レイヤー全体 */
#touch-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;         /* 最前面 */
    pointer-events: none; /* デフォルトでは下のレイヤー（Canvas等）を操作可能に */
    overflow: hidden;
}

/* 左半分：移動操作ゾーン */
#joystick-zone {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%; /* 画面の左半分 */
    height: 100%;
    pointer-events: auto; /* ここだけタッチを受け付ける */
    /* background: rgba(255, 0, 0, 0.1); デバッグ時はコメントアウト解除 */
}

/* ジョイスティックの土台（指を置いたときに出現） */
#joystick-visual {
    position: absolute;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: none;        /* JSで表示制御 */
    pointer-events: none; /* 見た目だけ */
    transform: translate(-50%, -50%); /* 中心基準 */
}

/* ジョイスティックのグリグリ部分 */
#joystick-head {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

/* 右下：アクションボタン */
#action-button {
    position: absolute;
    bottom: 60px;
    right: 40px;
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    pointer-events: auto; /* タッチを受け付ける */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    user-select: none;
}
#action-button:active {
    background: rgba(255, 255, 255, 0.6);
}

/* バーチャルパッド：PCでは非表示のまま（HTMLで hidden 付いてる想定） */
#virtual-pad {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px 12px 16px;
    z-index: 20;
}

/* パッド配置 */
.pad-grid {
    width: min(420px, 96vw);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    align-items: center;
    justify-items: center;
}

/* パッドボタンは .btn を継承してサイズだけ変更 */
.pad-btn {
    width: 100%;
    min-height: 56px;
    font-size: 18px;
}

/* 十字＋中央配置 */
#btn-up     { grid-column: 2; grid-row: 1; }
#btn-left   { grid-column: 1; grid-row: 2; }
#btn-action { grid-column: 2; grid-row: 2; }
#btn-right  { grid-column: 3; grid-row: 2; }
#btn-down   { grid-column: 2; grid-row: 3; }


/* ==========================================
 * RESPONSIVE & DEVICE WARNINGS (端末・レスポンシブ対応)
 * ========================================== */

/* スマホ（タッチ）環境のUI切り替え */
@media (hover: none) and (pointer: coarse) {
    /* バーチャルパッドを表示 */
    #virtual-pad.hidden {
        display: block !important;
    }

    /* スマホだとbodyのflex中央寄せが窮屈なので、縦詰まりを緩和 */
    body {
        align-items: flex-start;
        padding-top: 10px;
    }

    /* 💡 ここが魔法のCSS：タッチパネルの端末（スマホやタブレット）ではPC操作説明を隠す */
    #pc-instruction {
        display: none;
    }

    /* マップボタンを強制的に表示する（JSによる非表示状態が残るのを防ぐ） */
    #btn-toggle-map {
        display: block !important;
    }
}

/* PC（マウス操作ができる環境）のUI切り替え */
@media (hover: hover) and (pointer: fine) {
    /* PCではマップ切り替えボタンを隠す（Shiftキーで操作するため） */
    #btn-toggle-map {
        display: none;
    }
}

/* スマホなど、画面の高さが低い時のメニュー調整 */
@media (max-height: 600px) {
    .menu-buttons {
        margin-top: 15px; /* 画面が狭いときは、重ならないように少し詰める */
        margin-bottom: 20px; 
    }

    /* 横画面（ランドスケープ）対応 */
    .overlay {
        justify-content: flex-end;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-bottom: 8%;
        overflow-y: auto;
    }

    /* ロゴを小さくする */
    .menu-oni {
        width: 60px; /* 通常は80-140pxなので小さく */
        margin: 5px auto;
    }

    /* タイトル文字を小さくする */
    .overlay h1 {
        font-size: 1.8rem; /* 3remから縮小 */
        margin-bottom: 5px;
    }

    /* 名前入力エリアの隙間を詰める */
    #name-input-area {
        margin-top: 5px;
        gap: 5px;
    }
    
    /* 入力欄自体も少し細く */
    #player-name {
        padding: 5px;
        font-size: 16px;
    }

    /* メニューボタン周りの余白調整 */
    .menu-buttons {
        gap: 10px;
        margin-bottom: 20px; /* スクロール時の下余白確保 */
    }
}

/* さらに画面の高さが低い時（横向きスマホ等）のレイアウト調整 */
@media (max-height: 500px) {
    .overlay {
        /* 背景画像の見え方を調整 */
        /* 中央ではなく「上」を基準に表示する */
        background-position: center 15%;
        background-size: 100% auto;
        justify-content: flex-end;
        padding-bottom: 8%;
    }

    /* 横画面だと背景画像とボタンが被って見にくい場合があるため */
    .menu-buttons, #name-input-area {
        background: rgba(0, 0, 0, 0.5); /* ボタンの背景を少し暗くして読みやすく */
        padding: 0px;
        border-radius: 10px;
        margin-bottom: 0px !important; /* 下の隙間を消す */
        gap: 5px !important;           /* ボタン同士の間隔も最小限に */
    }
}

/* デフォルトでは警告を隠す */
#orientation-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #333;
    color: white;
    z-index: 10000;
    text-align: center;
    padding-top: 20%;
}

/* 画面が「縦長（portrait）」の時だけ警告を表示する */
@media screen and (orientation: portrait) {
    #orientation-warning {
        display: block;
    }
}