/* 画面全体を1画面（100vh）に固定し、外側のスクロールを禁止する */
body { 
    background-color: #1a1a1a; 
    color: #fff; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    height: 100vh; 
    max-height: 100vh;
    overflow: hidden; 
    padding: 10px; 
    box-sizing: border-box; 
}

header { 
    background: #2a2a2a; 
    width: 100%; 
    max-width: 1350px; 
    padding: 4px 15px; /* 上下パディングをグッと縮小 */
    border-radius: 6px; 
    margin-bottom: 8px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    border: 1px solid #444; 
    flex-shrink: 0; 
}
header h2 {
    font-size: 1.2rem; /* タイトルの文字サイズも少しスリムに調整 */
    margin: 0;
}

/* ヘッダーの左側（タイトルと【招集】ボタンを横に並べる） */
.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 【招集】ボタンと、その下に開く招集できるコマの一覧 */
.summon-wrap {
    position: relative;
}
.summon-open-btn {
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: bold;
    padding: 4px 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: 0.2s;
}
.summon-open-btn:hover:not(:disabled) {
    background: #2563eb;
}
.summon-open-btn.active {
    background: #1d4ed8;
    box-shadow: 0 0 0 2px #fbbf24; /* 一覧を開いているあいだは、金色の枠を付ける */
}
.summon-open-btn:disabled {
    background: #4b5563;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ヘッダーの【ターン終了】【降伏する】 */
.header-action-btn {
    color: #fff;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: bold;
    padding: 4px 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: 0.2s;
}
.header-action-btn:disabled {
    cursor: not-allowed;
}
.header-end-btn {
    background: #ef4444;
    border: 1px solid #ef4444;
}
.header-end-btn:hover:not(:disabled) {
    background: #dc2626;
}
.header-end-btn:disabled {
    background: #4b5563;
    border-color: #4b5563;
    opacity: 0.6;
}
/* 降伏：押し間違えないよう、ほかのボタンと違う「枠線だけ」の形にする。押せないときは薄くする */
.header-surrender-btn {
    background: transparent;
    color: #e5e5e5;
    border: 1px solid #9ca3af;
    font-weight: normal;
}
.header-surrender-btn:hover:not(:disabled) {
    background: #374151;
}
.header-surrender-btn:disabled {
    opacity: 0.3;
}

.summon-menu {
    position: absolute;
    left: 0;
    top: calc(100% + 6px);
    z-index: 900; /* 設定の窓と同じ。ゲーム画面より上、タイトル画面・ルール画面・戦闘終了の画面（1000〜）より下 */
    min-width: 220px;
    max-height: 70vh;
    overflow-y: auto; /* コマが増えて長くなったら、一覧の中でスクロールする */
    background: #2a2a2a;
    border: 2px solid #fbbf24;
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
    box-sizing: border-box;
}
/* 一覧の1行（左からアイコン・名前・コスト） */
.summon-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 6px 10px;
    margin: 3px 0;
    font-size: 0.95rem;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
}
.summon-item:hover:not(:disabled) {
    background: #2563eb;
}
.summon-item:disabled {
    background: #4b5563;
    cursor: not-allowed;
    opacity: 0.6;
}
.summon-item-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    object-fit: contain;
    background: #1f1f1f;
    border-radius: 4px;
    image-rendering: pixelated;
}
.summon-item-name {
    flex: 1;
    text-align: left;
    white-space: nowrap;
}
.summon-item-cost {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ヘッダーの右側（ターンの表示と ⚙ ボタンを横に並べる） */
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 設定：⚙ ボタンと、その下に開く窓 */
.settings-wrap {
    position: relative;
}
.settings-btn {
    background: #3a3a3a;
    color: #fff;
    border: 1px solid #555;
    border-radius: 6px;
    font-size: 1.2rem;
    line-height: 1;
    padding: 4px 8px;
    cursor: pointer;
}
.settings-btn:hover {
    background: #4a4a4a;
}

/* ヘッダーの【全体を見る】ボタン（全体を見ているあいだは【元に戻す】になり、オレンジにする） */
.overview-btn {
    background: #3b82f6;
    color: #fff;
    border: 1px solid #3b82f6;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: bold;
    padding: 4px 10px;
    cursor: pointer;
    white-space: nowrap;
}
.overview-btn:hover {
    background: #2563eb;
}
.overview-btn.active {
    background: #b45309;
    border-color: #f59e0b;
}
.settings-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 900; /* タイトル画面・ルール画面・戦闘終了の画面（1000〜）より下、ゲーム画面より上 */
    background: #2a2a2a;
    border: 2px solid #fbbf24;
    border-radius: 8px;
    padding: 12px 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
    white-space: nowrap;
}
.settings-title {
    color: #fbbf24;
    font-weight: bold;
    margin-bottom: 8px;
}
.settings-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
}
.settings-label {
    width: 7em;
    color: #e5e5e5;
}
.toggle-group {
    display: flex;
}
.toggle-btn {
    background: #3a3a3a;
    color: #aaa;
    border: 1px solid #555;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.85rem;
}
.toggle-btn:first-child {
    border-radius: 4px 0 0 4px;
}
.toggle-btn:last-child {
    border-radius: 0 4px 4px 0;
}
.toggle-btn.active {
    background: #3b82f6;
    color: #fff;
    font-weight: bold;
}
.volume-slider {
    width: 120px;
}
.volume-slider:disabled {
    opacity: 0.35; /* オフのあいだは薄くして、動かせなくする（音量の値は覚えておく） */
}
.volume-text {
    width: 2.5em;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.volume-text.off {
    color: #666;
}
.player-info { display: flex; gap: 20px; font-weight: bold; }

/* ゲームコンテナの高さを「画面残り全部」に固定し、下部を綺麗に収める */
.game-container {
    display: flex;
    flex-direction: row;
    gap: 15px;
    justify-content: center;
    width: 100%;
    max-width: 1400px;
    height: calc(100vh - 75px); /* ヘッダーと余白を除いた残りの高さを正確に割り当て */
    min-height: 0; /* flexbox内で子要素がはみ出るのを防ぐ必須設定 */
}

/* 下部左側MAP：高さは親（game-container）に追従し、中身が1280pxのため枠内で独立スクロール */
#canvas-wrapper {
    flex: 7;
    position: relative;
    background: #000;
    border: 2px solid #555;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    height: 100%;
    overflow: auto; /* マップの縦横スクロール */
    touch-action: pan-x pan-y; /* スマホ：1本指のスクロールはそのまま。2本指の拡大はブラウザにさせず、全体を見る操作（game.js）に使う */
}

canvas {
    width: 1280px;  /* 64px × 20マス分の実サイズを固定 */
    height: 1280px; /* 縦横を完全に固定し、縮小・変形を防ぐ */
    display: block;
}

/* 下部右側サイドパネル：高さは親に追従し、情報量が多い場合はこの枠内だけで独立して縦スクロール */
.side-panel {
    flex: 3;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    overflow-y: auto; /* 右側パネル全体の縦スクロール */
    padding-right: 4px; /* スクロールバーとの重なり防止 */
}
.panel-box { background: #2a2a2a; border: 1px solid #444; border-radius: 8px; padding: 12px; }
.panel-title { font-size: 1.1rem; font-weight: bold; margin-bottom: 8px; color: #fbbf24; border-bottom: 1px solid #444; padding-bottom: 4px; }

.action-btn { width: 100%; padding: 10px; font-size: 1rem; font-weight: bold; border-radius: 6px; border: none; cursor: pointer; transition: 0.2s; margin-top: 5px; }
.btn-end { background: #ef4444; color: white; }
.btn-end:hover:not(:disabled) { background: #dc2626; }
.btn-end:disabled { background: #4b5563; cursor: not-allowed; opacity: 0.6; }
.btn-wait { background: #f59e0b; color: white; }
.btn-wait:hover { background: #d97706; }
#log-box { height: 140px; overflow-y: auto; font-size: 0.85rem; background: #111; padding: 8px; border-radius: 4px; border: 1px solid #333; line-height: 1.4; }
.log-entry { margin-bottom: 4px; border-bottom: 1px dotted #333; padding-bottom: 2px; }

/* 戦況パネル（固定グリッドレイアウト） */
.status-grid {
    display: grid;
    grid-template-columns: auto 1fr 1fr; /* 左の列（ラベル）は、一番長いラベル（未行動コマ数 / コマ数：）に合わせて広がる */
    gap: 6px 8px;
    font-size: 0.9rem;
    align-items: center;
    padding: 4px;
}
.status-cell {
    white-space: nowrap;
}
.header-cell {
    font-weight: bold;
    text-align: center;
    border-bottom: 1px solid #444;
    padding-bottom: 4px;
    white-space: normal; /* 「プレイヤー1（CPU）」のような長い呼び名は折り返す（右側の枠からはみ出ないように） */
}
.label-cell {
    color: #ccc;
}
.value-cell {
    text-align: right;
    font-variant-numeric: tabular-nums; /* 数字の幅を固定してガタつきを防止 */
}
.info-content {
    font-size: 0.9rem;
    color: #e5e5e5; /* 背景(#2a2a2a)に対して読みやすい明るい文字色に変更 */
    line-height: 1.5;
    min-height: 6rem; /* 地形情報は最大4行（1.5rem × 4行 = 6rem）のため、高さが変動しないよう最小の高さを固定 */
}

/* 戦況メーター */
.battle-meter {
    margin-top: 10px;
    padding: 4px;
}
.battle-meter-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: bold;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums; /* 数字の幅を固定してガタつきを防止 */
}
.meter-p1 { color: #60a5fa; } /* 自軍の文字色（青） */
.meter-p2 { color: #f87171; } /* CPUの文字色（赤） */
.battle-meter-bar {
    position: relative;
    height: 12px;
    background: #ef4444; /* バー全体の色＝CPU側（右）の色 */
    border: 1px solid #444;
    border-radius: 6px;
    overflow: hidden;
}
.battle-meter-fill {
    height: 100%;
    background: #3b82f6; /* 自軍側（左）の色 */
    transition: width 0.4s ease; /* 割合が変わったときに滑らかに伸び縮みさせる */
}
/* 中央（50%）の目印の線 */
.battle-meter-bar::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(255, 255, 255, 0.7);
    transform: translateX(-50%);
}

/* タイトル画面・ルール画面（ゲーム画面全体の上に重ねて表示） */
.overlay-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
#title-screen {
    background: #000;
    z-index: 1000;
    cursor: pointer;
}
.title-image {
    width: 100%;
    height: 100%;
    object-fit: contain; /* 縦横の比率を保ったまま、画面に収まる一番大きい大きさにする（ロゴ全体が見える。形が違えば上下か左右に黒い余白） */
}
/* タイトル画面の下の「CLICK TO START」（スマホは「TAP TO START」） */
.title-start {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 8%;
    text-align: center;
    color: #fff;
    font-size: 2rem;
    font-weight: bold;
    letter-spacing: 0.15em;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.9), 0 2px 0 #000;
    pointer-events: none; /* 文字の上を押しても、タイトル画面を押したことにする */
}
/* パソコンは「CLICK TO START」、指で操作する画面（スマホ・タブレット）は「TAP TO START」 */
.title-start-touch {
    display: none;
}
@media (hover: none) and (pointer: coarse) {
    .title-start-click {
        display: none;
    }
    .title-start-touch {
        display: inline;
    }
}
/* 押したあと：速く点滅させる（title.js が title-start-flash を付け、1秒後にステージ選択へ進む） */
.title-start-flash {
    animation: title-start-flash 0.16s steps(1, end) infinite;
}
@keyframes title-start-flash {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
}
#rules-screen {
    background: rgba(0, 0, 0, 0.75); /* タイトル画像の上に、暗い半透明の幕を重ねる */
    z-index: 1001;
}
/* チュートリアルの説明の窓（ゲーム画面の上に、うすい幕と一緒に出す。後ろの盤面が見えるように、幕は薄め） */
#tutorial-screen {
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
}
.rules-box {
    width: min(600px, 90vw);
    background: #2a2a2a;
    border: 2px solid #fbbf24;
    border-radius: 10px;
    padding: 24px 28px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
    box-sizing: border-box;
}
.rules-text {
    font-size: 1.05rem;
    line-height: 1.8;
    color: #e5e5e5;
    min-height: 11rem; /* ページごとに文章の量が違っても、ボタンの位置が動かないよう高さを固定 */
}
.rules-heading {
    color: #fbbf24;
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 8px;
}
.rules-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}
.rules-btn {
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: bold;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
}
.rules-btn-start { background: #ef4444; }
.rules-btn-start:hover { background: #dc2626; }
.rules-btn-next { background: #3b82f6; }
.rules-btn-next:hover { background: #2563eb; }

/* 戦闘終了の画面（ゲーム画面の上に、暗い半透明の幕と一緒に重ねて表示） */
#result-screen {
    background: rgba(0, 0, 0, 0.75);
    z-index: 1002;
}
.result-box {
    width: min(520px, 90vw);
    background: #2a2a2a;
    border: 2px solid #fbbf24;
    border-radius: 10px;
    padding: 28px 32px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
    box-sizing: border-box;
    text-align: center;
}

/* 1つずつ順に出す項目：最初は隠しておき、shown が付いたら浮き上がるように出る */
.result-item {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none; /* 隠れているあいだは押せない（見えないボタンを押して、次の対戦が始まらないように） */
}
.result-item.shown {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

/* VICTORY／DEFEAT：大きい文字が、縮みながらドンと出る */
.result-title {
    font-size: 4rem;
    font-weight: bold;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
    transform: scale(1.8);
    transition: opacity 0.25s ease, transform 0.25s ease-out;
}
.result-title.shown {
    transform: scale(1);
}
.result-win {
    color: #fde047;
    text-shadow: 0 0 12px rgba(250, 204, 21, 0.8), 0 3px 0 #92400e;
}
.result-lose {
    color: #93c5fd;
    text-shadow: 0 0 12px rgba(59, 130, 246, 0.6), 0 3px 0 #1e3a8a;
}
/* 人間同士・CPU同士の対戦の「○○の勝利」：文字が長いので小さめにし、勝ったプレイヤーの色にする */
.result-title.result-named {
    font-size: 2.2rem;
    letter-spacing: 0.05em;
}
.result-p1 {
    color: #93c5fd;
    text-shadow: 0 0 12px rgba(59, 130, 246, 0.8), 0 3px 0 #1e3a8a;
}
.result-p2 {
    color: #fca5a5;
    text-shadow: 0 0 12px rgba(239, 68, 68, 0.8), 0 3px 0 #7f1d1d;
}

/* デバッグモードのボタン（CPUの一時停止・1手進める。ヘッダーの右側、ターンの表示の隣） */
.debug-controls {
    display: flex;
    gap: 6px;
}
.debug-ctrl-btn {
    background: #3a3a3a;
    color: #fff;
    border: 1px solid #555;
    border-radius: 6px;
    font-size: 0.85rem;
    padding: 4px 10px;
    cursor: pointer;
}
.debug-ctrl-btn:hover:not(:disabled) {
    background: #4a4a4a;
}
.debug-ctrl-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.debug-ctrl-btn.active {
    background: #b45309; /* 一時停止中は、ボタンをオレンジにして目立たせる */
    border-color: #f59e0b;
}

/* 降伏ボタン（操作パネルの【ターン終了】の下）
   押し間違えないよう、ほかのボタンと違う「枠線だけ」の形にする。押せないときは薄くする */
.btn-surrender { background: transparent; color: #e5e5e5; border: 1px solid #9ca3af; font-size: 0.9rem; padding: 6px; }
.btn-surrender:hover:not(:disabled) { background: #374151; }
.btn-surrender:disabled { cursor: not-allowed; opacity: 0.3; }

/* 降伏（中断）の確認の画面（ゲーム画面の上に、暗い半透明の幕と一緒に重ねて表示） */
#surrender-screen {
    background: rgba(0, 0, 0, 0.6);
    z-index: 1003;
}
.surrender-text {
    font-size: 1.3rem;
    font-weight: bold;
    color: #fbbf24;
    margin-bottom: 8px;
}

/* CPU対CPUの「中断」 */
.result-abort {
    color: #d1d5db;
    text-shadow: 0 0 10px rgba(156, 163, 175, 0.6), 0 3px 0 #374151;
}

/* スマホのときだけ改行する印（mobile-break）と、パソコンのときだけ出す文字（pc-only）
   パソコンでは mobile-break は何もしない。スマホの指定（@media (max-height: 500px)）で、改行と入れ替える */
.mobile-break {
    display: none;
}

/* ==========================================
   スマホを横向きにしたとき（画面の高さが500px以下）
   パソコンの画面と同じ並び（左にMAP、右に情報パネル）のまま、文字や余白を小さくして画面に収める
   ========================================== */
@media (max-height: 500px) {
    body {
        /* iPhone の画面の端（左右のカメラの切り欠き・下のアプリを切り替える場所）にかからないよう、その分の余白を取る
           env(safe-area-inset-○○) は iPhone が教えてくれる、かかってはいけない幅（ほかのスマホやパソコンでは0） */
        /* 下の余白に戦況バー（高さ16px）を置くので、下の余白は22px以上にする */
        padding: 4px max(4px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));        
        height: 100dvh;      /* スマホのアドレスバーの分を除いた、実際に見えている高さ */
        max-height: 100dvh;
    }
    header {
        padding: 2px 8px;
        margin-bottom: 4px;
    }
    header h2 {
        font-size: 0.95rem;
    }
    #turn-indicator {
        font-size: 0.8rem;
    }
    .header-right {
        gap: 6px;
    }
    .settings-btn {
        font-size: 1rem;
        padding: 2px 6px;
    }
    .settings-panel {
        max-height: 80dvh;
        overflow-y: auto;
        padding: 8px 10px;
        font-size: 0.85rem;
    }
    .debug-ctrl-btn {
        font-size: 0.75rem;
        padding: 2px 6px;
    }
    .overview-btn {
        font-size: 0.75rem;
        padding: 2px 6px;
    }

    .game-container {
        gap: 6px;
        height: auto;        /* 下の余白の大きさが機種で変わるので、決まった高さではなく、残りの高さいっぱいにする */
        flex: 1 1 auto;
        min-height: 0;
    }

    /* 右側の情報パネル：幅を詰め、文字と余白を小さくする */
    .side-panel {
        flex: 0 0 200px;
        min-width: 0;
        gap: 6px;
    }
    /* 長い見出しや情報を2行に分けて、パネルの幅を詰める（mobile-break で改行し、pc-only の「 / 」「 | 」は消す） */
    .mobile-break {
        display: block;
    }
    .pc-only {
        display: none;
    }
    .panel-box {
        padding: 6px 8px;
    }
    .panel-title {
        font-size: 0.85rem;
        margin-bottom: 4px;
        padding-bottom: 2px;
    }
    .status-grid {
        font-size: 0.72rem;
        gap: 2px 4px;
        padding: 2px;
    }
    .label-cell {
        white-space: normal; /* 「未行動コマ数 / コマ数：」を折り返して、列の幅を詰める */
    }
    /* 戦況メーター：右のパネルから外し、画面の下の余白に、横幅いっぱいの1行で出す
       （右のパネルを短くするため。見るだけでタップしないので、iPhone のホームバーの場所に置いても困らない）
       並び：「自軍 55%」【バー】「CPU 45%」 */
    .battle-meter {
        position: fixed;
        left: max(4px, env(safe-area-inset-left));
        right: max(4px, env(safe-area-inset-right));
        bottom: 3px;
        height: 16px;
        margin: 0;
        padding: 0 8px;
        display: flex;
        align-items: center;
        gap: 8px;
        background: #2a2a2a;
        border: 1px solid #444;
        border-radius: 8px;
        box-sizing: border-box;
        z-index: 10;
    }
    /* 文字の入れ物をなくして、「自軍 ○%」と「CPU ○%」をバーの左右に並べる */
    .battle-meter-labels {
        display: contents;
        font-size: 0.72rem;
    }
    .meter-p1 {
        order: 1;
        white-space: nowrap;
    }
    .battle-meter-bar {
        order: 2;
        flex: 1 1 auto;
        height: 8px;
    }
    .meter-p2 {
        order: 3;
        white-space: nowrap;
    }
    .info-content {
        font-size: 0.72rem;
        line-height: 1.35;
        min-height: 0;
    }


    .header-left {
        gap: 6px;
    }
    .summon-open-btn {
        font-size: 0.75rem;
        padding: 2px 8px;
    }
    .header-action-btn {
        font-size: 0.75rem;
        padding: 2px 8px;
    }
    .summon-menu {
        min-width: 180px;
        max-height: 80dvh;
        padding: 4px;
    }
    .summon-item {
        padding: 4px 8px;
        margin: 2px 0;
        font-size: 0.8rem;
    }
    .summon-item-icon {
        width: 24px;
        height: 24px;
    }
    .action-btn {
        padding: 6px;
        font-size: 0.85rem;
        margin-top: 3px;
    }
    .btn-surrender {
        padding: 4px;
        font-size: 0.75rem;
    }
    #log-box {
        height: 90px;
        font-size: 0.72rem;
        padding: 4px;
    }

    /* ルール画面・戦闘終了の画面・降伏の確認の画面：画面に収まるように詰める（入りきらなければ枠の中でスクロール） */
    .rules-box,
    .result-box {
        padding: 12px 16px;
        max-height: 94dvh;
        overflow-y: auto;
    }
    .rules-text {
        font-size: 0.9rem;
        line-height: 1.6;
        min-height: 0;
    }
    .rules-heading {
        font-size: 1rem;
        margin-bottom: 4px;
    }
    .rules-buttons {
        margin-top: 10px;
    }
    .rules-btn {
        padding: 8px 14px;
        font-size: 0.9rem;
    }
    .result-title {
        font-size: 2.4rem;
        margin-bottom: 2px;
    }
    .result-title.result-named {
        font-size: 1.5rem;
    }
    .result-reason {
        font-size: 0.9rem;
        margin-bottom: 8px;
    }
    .result-stats {
        gap: 4px;
    }
    .result-row {
        font-size: 1rem;
        padding: 3px 10px;
    }
    .result-value {
        font-size: 1.2rem;
    }
    .surrender-text {
        font-size: 1.1rem;
    }
    /* タイトル画面の「TAP TO START」：画面が低いので、文字を小さくする */
    .title-start {
        font-size: 1.3rem;
        bottom: 6%;
    }

    /* モード選択・ステージ選択・デバッグモードの画面 */
    .menu-box {
        padding: 12px 16px;
        max-height: 94dvh;
    }
    .menu-title {
        font-size: 1.15rem;
        margin-bottom: 10px;
    }
    .menu-header {
        gap: 8px;
        margin-bottom: 8px;
    }
    .menu-small-btn {
        padding: 4px 10px;
        font-size: 0.8rem;
    }
    .menu-buttons {
        gap: 8px;
    }
    .menu-btn {
        padding: 10px 16px;
        font-size: 1rem;
    }
    .stage-card {
        padding: 8px;
        gap: 10px;
        font-size: 0.8rem;
    }
    .stage-map {
        max-width: 140px;  /* 小さなMAPの絵を、縦横の比率を保ったまま小さく表示する */
        max-height: 140px;
    }
    .unit-icon {
        width: 22px;
        height: 22px;
    }
    .stage-select-row {
        margin-top: 4px;
    }
    .stage-name {
        font-size: 1rem;
        margin-bottom: 4px;
    }
    .stage-row {
        margin: 2px 0;
        line-height: 1.35;
    }
    .debug-players {
        gap: 6px;
    }
    .debug-player {
        padding: 6px 8px;
    }
    .debug-row {
        margin: 3px 0;
        font-size: 0.8rem;
    }
}

.result-reason {
    font-size: 1.1rem;
    color: #e5e5e5;
    margin-bottom: 20px;
}

.result-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 8px;
}
.result-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 1.3rem;
    padding: 6px 12px;
    background: #1f1f1f;
    border: 1px solid #444;
    border-radius: 6px;
}
.result-label {
    color: #ccc;
}
.result-value {
    color: #fbbf24;
    font-weight: bold;
    font-size: 1.6rem;
    font-variant-numeric: tabular-nums; /* くるくる回っているあいだ、数字の幅が変わってガタつかないように */
    min-width: 3em;
    text-align: right;
}
.result-buttons {
    justify-content: center;
}

/* モード選択・ステージ選択・デバッグモードの画面（タイトル画像の上に、暗い半透明の幕と一緒に重ねて表示） */
.menu-screen {
    background: rgba(0, 0, 0, 0.75);
    z-index: 1001;
}
.menu-box {
    width: min(420px, 90vw);
    max-height: 90vh;
    overflow-y: auto; /* 中身が多いときは、この枠の中だけでスクロールする */
    background: #2a2a2a;
    border: 2px solid #fbbf24;
    border-radius: 10px;
    padding: 24px 28px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
    box-sizing: border-box;
}
.menu-box-wide {
    width: min(760px, 94vw);
}
.menu-title {
    color: #fbbf24;
    font-size: 1.5rem;
    font-weight: bold;
    text-align: center;
    margin-bottom: 18px;
}
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.menu-btn {
    padding: 14px 20px;
    font-size: 1.15rem;
    font-weight: bold;
    color: #fff;
    background: #3b82f6;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
}
.menu-btn:hover {
    background: #2563eb;
}
.menu-btn-debug {
    background: #4b5563;
}
.menu-btn-debug:hover {
    background: #374151;
}

/* ステージ選択：ステージのカード（左に小さなMAPの絵、右にステージの情報） */
.stage-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.stage-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
    padding: 12px;
    background: #1f1f1f;
    border: 2px solid #444;
    border-radius: 8px;



    color: #e5e5e5;
    font-size: 0.95rem;
    text-align: left;
    cursor: pointer;
}
/* カードの枠の点滅：灰色 → 金色（少し光る）→ 灰色 */
@keyframes stage-card-blink {
    0%, 100% {
        border-color: #444;
        box-shadow: none;
    }
    50% {
        border-color: #fbbf24;
        box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
    }
}
/* マウスを合わせたカード（スマホでは1回タップしたカード）：枠を点滅させる（menu.js が stage-card-active を付ける） */
.stage-card.stage-card-active {
    background: #2f2a1a;
    animation: stage-card-blink 1.6s ease-in-out infinite;
}
/* 押したカード：点滅を速くする（menu.js が stage-card-chosen を付ける。少しあとにゲームが始まる） */
.stage-card.stage-card-chosen {
    animation: stage-card-blink 0.3s ease-in-out infinite;
}



/* 【選択】ボタン（カードの情報の下、右寄せ） */
.stage-select-row {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}
/* 招集できるコマのアイコン */
.unit-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    background: #333;
    border: 1px solid #555;
    border-radius: 4px;
    margin-right: 4px;
    vertical-align: middle;
}
/* （マウスを合わせたときの見た目は、menu.js が付ける stage-card-active で出す。スマホでタップの後に色が残らないよう :hover は使わない） */
.stage-map {
    flex-shrink: 0;
    width: auto;  /* ゲームのMAP用の canvas の大きさ（1280px）の指定を打ち消し、描いた大きさのまま表示する */
    height: auto;
    border: 1px solid #555;
    image-rendering: pixelated; /* 縮小したMAPの絵をくっきり見せる */
}
.stage-info {
    flex: 1;
    min-width: 0;
}
.stage-name {
    color: #fbbf24;
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 8px;
}
.stage-row {
    display: flex;
    gap: 8px;
    margin: 4px 0;
    line-height: 1.5;
}
.stage-label {
    flex-shrink: 0;
    width: 8em;
    color: #aaa;
}
.stage-record {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dotted #555;
}

/* デバッグモードの設定の画面 */
.debug-top {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 12px;
}
.debug-top-settings {
    flex: 1;
}
.debug-players {
    display: flex;
    gap: 12px;
}
.debug-player {
    flex: 1;
    background: #1f1f1f;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px 12px;
}
.debug-player-title {
    font-weight: bold;
    margin-bottom: 6px;
}
.debug-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 6px 0;
    color: #e5e5e5;
}
.debug-label {
    flex-shrink: 0;
    width: 7em;
    color: #aaa;
    padding-top: 3px;
}
.debug-row select,
.debug-row input {
    background: #111;
    color: #eee;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 3px 6px;
}
.debug-gold {
    width: 80px;
    text-align: right;
}
.debug-checks label {
    display: inline-block;
    margin: 2px 10px 2px 0;
    cursor: pointer;
}
.debug-message {
    color: #f87171;
    font-size: 0.9rem;
    margin-top: 8px;
    min-height: 1.2em;
}
/* デバッグモードの画面の【ツール】（音のツール・コマのエディター・MAPツールを新しいタブで開く） */
.debug-tools {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dotted #555;
}
.debug-tool-btn {
    background: #374151;
    color: #e5e5e5;
    border: 1px solid #6b7280;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 0.9rem;
    cursor: pointer;
}
.debug-tool-btn:hover {
    background: #4b5563;
    border-color: #fbbf24;
}
.rules-btn:disabled {
    background: #4b5563;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ステージ選択の画面：見出し「ステージ選択」と【遊び方】【デバッグモード】は動かさず、カードの一覧だけをスクロールする */
.menu-box-list {
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 枠全体はスクロールしない（中の stage-list だけがスクロールする） */
}
.menu-box-list .stage-list {
    flex: 1 1 auto;
    min-height: 0;     /* 枠の高さに収まるよう、カードの一覧を縮められるようにする */
    overflow-y: auto;
    padding: 4px;      /* 点滅するカードの枠の光が、スクロールする枠で切れないように */
}
/* 見出しの行：「ステージ選択」の横に【遊び方】【デバッグモード】を並べる */
.menu-header {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
    flex-shrink: 0;
}
.menu-header .menu-title {
    margin-bottom: 0;
}
.menu-header-buttons {
    display: flex;
    gap: 8px;
}
.menu-small-btn {
    padding: 6px 14px;
    font-size: 0.9rem;
    font-weight: bold;
    color: #fff;
    background: #3b82f6;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
}
.menu-small-btn:hover {
    background: #2563eb;
}
.menu-small-btn-debug {
    background: #4b5563;
}
.menu-small-btn-debug:hover {
    background: #374151;
}
/* 難易度の星（塗った星は金色、残りは灰色） */
.stage-stars {
    color: #fbbf24;
    letter-spacing: 2px;
}
.stage-stars-empty {
    color: #666;
}

/* ターンの切り替えの表示：MAPの枠と同じ位置・大きさの箱（game.js が位置を合わせる）。はみ出した画像は見せない */
.turn-banner {
    position: fixed;
    display: none;
    overflow: hidden;
    pointer-events: none; /* 表示中も、下の画面を押した扱いにはしない（操作は game.js で止める） */
    z-index: 800;         /* ゲーム画面より上、設定の窓（900）より下 */
}
/* 画像：箱の真ん中に置く（横の動きは game.js がつける）。箱より大きい画像は縮める */
.turn-banner-img {
    position: absolute;
    left: 50%;
    top: 50%;
    max-width: 90%;
    max-height: 80%;
    transform: translate(-50%, -50%);
}