/* ==========================================
 * LAYOUT & CONTAINERS (レイアウト・コンテナ)
 * ========================================== */

/* ゲームコンテナを相対配置の基準にする */
/* #: 固有のidを持つ部品に対する設定 */
#game-container {
    position: relative;
    
    /* 中身を上から下へ順番に並べる、すべてを中央に寄せる */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    
    text-align: center;
    
    /* サイズ設定 */
    width: 100%;         /* 基本は横幅いっぱい */
    height: 100%;        /* 基本は高さもいっぱい */
    width: min(100vw, 800px); /* canvasサイズが固定でも、スマホで溢れないようにする */
    max-width: 800px;    /* ただし、最大でも800pxまで */
    max-height: 800px;   /* 高さも広がりすぎないようにする */

    /* 横長画面で縦幅がキツキツの場合、少し余白を持たせる（任意） */
    max-height: 100svh;
}

/* Canvas自体の設定（もし変な余白があればリセット） */
#gameCanvas {
    display: block;
    margin: 0 auto;           /* Canvas自身も中央へ */
}

/* 操作説明を包んでいる箱 */
#game-screen {
    width: 100%;
    display: flex;            /* これ自体も中身を制御する箱にする */
    flex-direction: column;
    align-items: center;
    margin-top: 10px;         /* Canvasとの隙間 */
}


/* ==========================================
 * MENU SCREEN (メニュー画面)
 * ========================================== */

/* オーバーレイ（メニュー画面）のデザイン  */
/* 「.（ドット）名前」で始まるコードは，HTMLの class="(名前)" と書かれた部品に適用される */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%; /* 親のwidthに合わせる = canvasと同じ幅 */
    height: 100%; /* 親のheightに合わせる = canvasと同じ高さ */
    /* 背景色を黒から画像に変更 */
    background-image: url('../img/menu-lobby/menu.png'); /* ここに使用したい画像パスを記述 */
    background-size: cover;      /* 画面いっぱいに広げる */
    background-position: center; /* 画像の中央を表示 */
    background-repeat: no-repeat;
    background-color: rgb(0, 0, 0); /* 不透明度100%の黒 */
    opacity: 1;                     /* 親で透明度が設定されている場合の保険 */
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;

    padding-top: env(safe-area-inset-top);
    padding-bottom: 8%;

    z-index: 10;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    box-sizing: border-box; /* 忘れずに追加（余白を計算に含める） */
}

.menu-oni{
    width: clamp(80px, 25vw, 140px);
    height: auto;
    display: block;
    margin: 12px auto;
}

.menu-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;

    /* --- 追加：ボタンエリアを下に押し下げる --- */
    margin-top: 40px; /* PCなど余裕があるときの間隔 */
}

/* --- 名前入力エリア --- */
#name-input-area {
    margin-top: 20px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

/* 「名前を入力してください」のテキスト */
#name-input-area p {
    color: #fb0202; /* 血のような暗い赤 */
    font-size: 1.2rem;
    font-family: 'Yu Mincho', serif;
    font-weight: bold;
    text-shadow: 0 0 8px rgba(255, 0, 0, 0.6); /* 赤いぼんやりした光 */
    margin: 0;
    /* タイトルと同じように少しだけ明滅させる */
    animation: text-flicker 4s infinite;
}

/* 名前入力欄（inputタグ） */
#player-name {
    font-size: 18px;
    padding: 12px;
    width: 240px;
    text-align: center;
    border-radius: 5px;
    /* 枠線を暗い赤、背景を半透明の黒に */
    border: 1px solid #4a0000;
    background-color: rgba(0, 0, 0, 0.7);
    color: #ffffff; /* 入力する文字は白 */
    font-family: 'Yu Mincho', serif;
    box-shadow: inset 0 0 10px rgba(74, 0, 0, 0.5);
    transition: all 0.3s;
}

/* 入力欄を選択したとき（フォーカス時） */
#player-name:focus {
    outline: none;
    border-color: #ff0000;
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.4), inset 0 0 10px rgba(74, 0, 0, 0.5);
}

@keyframes text-flicker {
    0%, 100% { opacity: 1; text-shadow: 0 0 8px rgba(255, 0, 0, 0.6); }
    50% { opacity: 0.7; text-shadow: 0 0 3px rgba(255, 0, 0, 0.2); }
}


/* ==========================================
 * LOBBY SCREEN (ロビー画面)
 * ========================================== */

/* ロビー画面（#lobby-screen）は .overlay を継承するので差分だけ */
#lobby-screen {
    text-align: left;
    
    /* ロビー専用の画像を指定（例: lobby_bg.png） */
    background-image: url('../img/menu-lobby/background.png') !important; 
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: rgb(0, 0, 0); /* 不透明度100%の黒 */
    opacity: 1;                     /* 親で透明度が設定されている場合の保険 */

    /* 下寄せになってしまっている場合は上寄せに戻す */
    justify-content: flex-start;
    
    /* iPhoneの横持ち対策（ノッチ）を維持しつつ、左右の余白を確保 */
    padding-top: max(40px, env(safe-area-inset-top));
    padding-bottom: 20px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    
    box-sizing: border-box; /* ★超重要：これがないと padding の分だけ画面右側に飛び出します！ */
}

/* ルール説明ボタン（メニューに戻るボタンの左隣に絶対配置） */
#btn-show-rules {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    right: calc(max(20px, env(safe-area-inset-right)) + 170px);
    z-index: 20;
}

/* ホスト設定エリア */
#host-settings {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
}

/* 入力欄 */
#input-oni-count {
    width: 120px;
    font-size: 16px;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.25);
    background: rgba(0,0,0,0.35);
    color: #fff;
}

/* 参加者リストを囲むボックス */
.lobby-players-box {
    margin: 15px auto; /* これで左右中央寄せになります（autoが重要） */
    background-color: rgba(0, 0, 0, 1); /* 黒背景でゲームっぽく */
    border: 2px solid #555;
    border-radius: 8px;
    
    /* ここから大きさの改善！ */
    width: 90%;          /* スマホでも画面の横幅を広く（90%）使う */
    max-width: 800px;    /* パソコンで広がりすぎないように制限（300pxから500pxに拡大！） */
    
    height: 50vh;        /* 画面の高さの40%を贅沢に使う（スマホでもPCでもいい感じの高さに） */
    min-height: 200px;   /* 最低でもこれくらいの高さは確保する */
    max-height: 400px;   /* パソコンで縦に伸びすぎないように制限 */
    
    overflow-y: auto;    /* 縦方向にはみ出た場合のみスクロールバーを出す */
    padding: 10px;
    box-sizing: border-box; /* ★ここにも追加！枠線や余白を90%の中に収める */
}

/* リスト(<ul>)本体の設定 */
#lobby-player-list {
    list-style-type: none; /* 先頭の「・」を消す */
    padding: 0;
    margin: 0;
    text-align: left;
}

/* リストの各項目(<li>)の設定 */
#lobby-player-list li {
    padding: 5px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2); /* 区切り線 */
    color: white;
    font-size: 16px;
}

/* 最後の要素の区切り線は消す */
#lobby-player-list li:last-child {
    border-bottom: none;
}


/* ==========================================
 * RESULT SCREEN (リザルト画面)
 * ========================================== */

/* --- リザルト画面 --- */
#result-screen {
    /* 背景画像を消して、真っ黒にする */
    background-image: none !important;
    background-color: #000000 !important;

    /* リザルト画面は中央に情報を出したいことが多いので、配置を調整 */
    justify-content: center !important;
    padding-bottom: 0 !important;
}

/* リザルト画面のタイトル（「脱出成功」や「ゲームオーバー」など）を怖くする */
#result-screen h1 {
    font-size: 3.5rem;
    color: #ff0000;
    text-shadow: 0 0 20px #8b0000;
    margin-bottom: 20px;
}


/* ==========================================
 * RULES MODAL (ルール説明モーダル)
 * ========================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    position: relative;
    background: #1a0000;
    border: 1px solid #e40909;
    border-radius: 10px;
    padding: 24px;
    width: 90%;
    max-width: 560px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 0 30px rgba(200, 0, 0, 0.4);
    font-family: 'Yu Mincho', serif;
    color: #ddd;
}

.modal-title {
    text-align: center;
    color: #ff4444;
    font-size: 1.4rem;
    margin: 0 0 16px 0;
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: 1px solid #666;
    color: #aaa;
    font-size: 16px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-close:hover {
    border-color: #ff4444;
    color: #ff4444;
}

/* タブボタン */
.modal-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #555;
    border-radius: 6px;
    color: #aaa;
    font-size: 14px;
    cursor: pointer;
    font-family: 'Yu Mincho', serif;
    transition: all 0.2s;
}
.tab-btn.active {
    background: rgba(180, 0, 0, 0.4);
    border-color: #e40909;
    color: #fff;
}
.tab-btn:hover:not(.active) {
    border-color: #999;
    color: #fff;
}

/* タブコンテンツ */
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}

/* ルールリスト */
.rules-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rules-list li {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-left: 3px solid #e40909;
    border-radius: 0 6px 6px 0;
    font-size: 13px;
    line-height: 1.6;
}

.rule-label {
    display: block;
    color: #ff6666;
    font-weight: bold;
    margin-bottom: 4px;
    font-size: 13px;
}