        :root { --primary: #4a90e2; --bg: #f8f9fa; }
        body, html { margin: 0; padding: 0; height: 100vh; font-family: "Hiragino Sans", "Meiryo", sans-serif; overflow: hidden; background: var(--bg); }
        #app-container { display: flex; height: 100vh; width: 100vw; }
        #editor-left { flex: 1; border-right: 2px solid #ddd; display: flex; flex-direction: column; }
        #blocklyDiv { flex: 1; width: 100%; }
        /* 素材パレットを50番まで対応・スクロール可能に */
        #asset-palette { width: 120px; background: #eee; border-right: 2px solid #ddd; display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 10px; overflow-y: auto; }
        #editor-right { width: 450px; background: #fff; display: flex; flex-direction: column; padding: 15px; gap: 10px; border-left: 1px solid #ddd; overflow-y: auto; }

        .asset-item { width: 80px; height: 80px; background: #fff; border: 2px solid #ccc; border-radius: 12px; cursor: grab; display: flex; align-items: center; justify-content: center; font-size: 12px; user-select: none; position: relative; overflow: hidden; flex-shrink: 0; }
        .asset-item img { max-width: 90%; max-height: 90%; object-fit: contain; }
        .asset-item.selected { border: 4px solid var(--primary); background: #e3f2fd; transform: scale(1.05); }
        .asset-number { position: absolute; top: 2px; left: 2px; background: rgba(0,0,0,0.5); color: white; padding: 1px 4px; border-radius: 4px; font-size: 10px; }

        #game-message-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.85); z-index: 20000; display: none; align-items: center; justify-content: center; flex-direction: column; }
        #message-box { background: white; padding: 40px; border-radius: 40px; text-align: center; border: 10px solid var(--primary); box-shadow: 0 0 50px rgba(0,0,0,0.5); max-width: 80%; }
        #message-text { font-size: clamp(32px, 8vw, 60px); font-weight: bold; color: #333; display: block; margin-bottom: 20px; }
        #message-score { font-size: clamp(24px, 5vw, 40px); color: #4a90e2; display: block; margin-bottom: 30px; }
        .btn-msg { padding: 15px 40px; font-size: 24px; background: var(--primary); color: white; border: none; border-radius: 100px; cursor: pointer; font-weight: bold; }

        #stage-wrapper.fullscreen { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 9999; background: #000; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
        #btn-exit-fs { 
            display: none; 
            position: absolute; 
            top: 5px; right: 15px; 
            width: 150px; 
            height: 45px; 
            border-radius: 5%; 
            background: rgba(255, 255, 255, 0.05); 
            color: rgba(255, 255, 255, 0.2); 
            border: 1px solid rgba(255, 255, 255, 0.1); 
            font-size: 20px; 
            cursor: pointer; 
            z-index: 10005; 
            align-items: center; 
            justify-content: center; 
        }
        #stage-wrapper.fullscreen #btn-exit-fs { display: flex; }

        /* 「うごピカ」の文字部分のスタイル */
.logo-text {
    font-weight: bold;
    letter-spacing: 0.05em;
    font-family: sans-serif; /* 清潔感のあるフォント */
    opacity: 0.8;
}

/* ホバーした（マウスを乗せた）時だけ少し明るくする */
#btn-exit-fs:hover {
    background: rgba(0, 0, 0, 0.5);
    color: rgba(255, 255, 255, 1);
}



        #fs-header { 
            display: none; 
            width: 100%; 
            height: 50px;
            padding: 5px; 
            color: white; 
            font-size: clamp(24px, 5vw, 40px); 
            font-weight: bold; 
            justify-content: space-around; 
            align-items: center; 
            position: absolute; 
            top: 0; 
            z-index: 10002; 
            background: rgba(0,0,0,0.4); 
            text-shadow: 2px 2px 4px #000; 
        }
        #stage-wrapper.fullscreen #fs-header.active { display: flex; }
        #fs-footer { 
            display: none; 
            width: 100%; 
            padding: 10px; 
            position: absolute; 
            bottom: 0; 
            justify-content: center; 
            gap: 20px; 
            background: rgba(0,0,0,0.4); 
            z-index: 10002; 
        }
        #stage-wrapper.fullscreen #fs-footer.active { display: flex; }

        .btn { padding: 12px; border: none; border-radius: 50px; cursor: pointer; font-weight: bold; font-size: 14px; color: white; text-align: center; }
        .btn-run { background: #ff4757; }
        .btn-fs { padding: 20px 40px; font-size: 24px; border-radius: 60px; box-shadow: 0 4px 15px rgba(0,0,0,0.5); }
        .portrait-mode .btn-fs { padding: 12px 25px !important; font-size: 18px !important; border-radius: 30px !important; }

        #stage-wrapper.fullscreen #stage-container { width: 100vw !important; height: 100vh !important; border: none; border-radius: 0; }
        #game-status-bar { display: flex; justify-content: space-around; align-items: center; background: #222; color: white; padding: 10px; border-radius: 8px; }
        .switch-container { display: flex; align-items: center; gap: 5px; font-size: 12px; color: #aaa; }

        #stage-wrapper { width: 100%; background: #333; padding: 10px; box-sizing: border-box; display: flex; justify-content: center; border-radius: 12px; position: relative; }
        #stage-container { width: 100%; max-height: 100%; aspect-ratio: 16/9; background: linear-gradient(#87CEEB, #E0F7FA); position: relative; overflow: hidden; border: 2px solid #fff; }
        .portrait-mode #stage-container { aspect-ratio: 9/16; width: auto; height: 100%; }

        #main-stage { width: 100%; height: 100%; position: relative; touch-action: none; }
        .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 5px; }
        .ratio-btn { flex: 1; border: none; padding: 8px; border-radius: 6px; cursor: pointer; font-size: 12px; background: #fff; }
        .ratio-btn.active { background: var(--primary); color: white; }
        .obj { 
            touch-action: none; /* 指での操作をブラウザに邪魔させない */
            position: absolute; 
            font-size: 5rem; 
            transform: translate(-50%, -50%); 
            cursor: pointer; 
            user-select: none; 
            z-index: 10; 
            touch-action: none; 
        }
        .obj img { width: 100px; height: 100px; object-fit: contain; pointer-events: none; max-width: none; }
        .hidden { display: none !important; }
        .toggle-switch { position: relative; display: inline-block; width: 34px; height: 18px; }
        .toggle-switch input { opacity: 0; width: 0; height: 0; }
        .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #444; transition: .4s; border-radius: 20px; }
        .slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; }
        input:checked + .slider { background-color: #2ed573; }
        input:checked + .slider:before { transform: translateX(16px); }

        #file-input-label { background: #4a90e2; color: white; padding: 5px 10px; border-radius: 5px; font-size: 12px; cursor: pointer; margin-bottom: 10px; width: 80%; text-align: center; }

/* 削除ボタンのスタイル */
.delete-btn {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(255, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 0 0 0 8px;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}
.asset-item:hover .delete-btn { background: red; }

/* 配置済みオブジェクトのホバー効果 */
.obj:hover {
    filter: brightness(1.2);
    outline: 2px dashed rgba(255, 255, 255, 0.5);
}

#stage-bg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1; /* 一番後ろにする */
}

#main-stage {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2; /* キャラを背景より前に出す */
    background: transparent !important;
}

#stage-container {
    background: #000; /* 背景が塗られるまでの予備色 */
}

/* --- スマホ・はっぴょうモード最適化 --- */
@media (max-height: 700px) {
#stage-wrapper { 
            width: 100%; 
            background: #333; 
            padding: 10px; 
            box-sizing: border-box; 
            display: flex; 
            justify-content: center; 
            border-radius: 12px; 
            position: relative;
            max-height: 100vh; /* ステージの最大高さを画面の55%に制限 */
        }
        #stage-container { 
            width: 100%; 
            max-height: 100%; 
            aspect-ratio: 16/9; 
            background: linear-gradient(#87CEEB, #E0F7FA); 
            position: relative; 
            overflow: hidden; 
            border: 2px solid #fff; 
        }
        /* たて型モードの時の比率調整 */
        .portrait-mode #stage-container {
            aspect-ratio: 9/16;
            width: auto;
            height: 100%;
        }
}

@media (max-height: 400px) {
#stage-wrapper { 
            width: 100%; 
            background: #333; 
            padding: 10px; 
            box-sizing: border-box; 
            display: flex; 
            justify-content: center; 
            border-radius: 12px; 
            position: relative;
            max-height: 55vh; /* ステージの最大高さを画面の55%に制限 */
        }
        #stage-container { 
            width: 100%; 
            max-height: 100%; 
            aspect-ratio: 16/9; 
            background: linear-gradient(#87CEEB, #E0F7FA); 
            position: relative; 
            overflow: hidden; 
            border: 2px solid #fff; 
        }
        /* たて型モードの時の比率調整 */
        .portrait-mode #stage-container {
            aspect-ratio: 9/16;
            width: auto;
            height: 100%;
        }
}

/* --- スマホ向けスクロール解禁設定 --- */
@media (max-width: 900px) {
    /* 1. 縦スクロールを許可し、横揺れのみを禁止する */
    html, body {
        overflow-x: hidden !important;
        overflow-y: auto !important; 
        width: 100vw !important;
        height: auto !important; 
        margin: 0 !important;
        padding: 0 !important;
        position: relative;
        display: flex;
        flex-direction: column;
        min-height: 100vh; /* 画面全体の高さを確保 */
    }

    #app-container {
        flex: 1;
        display: block !important; 
        width: 100% !important;
        display: flex;
        height: calc(100vh - 40px); /* 画面全体からフッター分（40px）を引く */
        overflow: hidden;
        box-sizing: border-box !important;
    }

    /* 2. Blockly（プログラミング）エリア */
    #editor-left {
        width: 100% !important;
        height: 400px !important;
        padding: 0 !important;
    }

    /* 3. 素材パレット：横スクロールバーを可視化 */
    #asset-palette {
        width: 100% !important;
        background: #f0f0f0;
        padding: 0 !important;
        box-sizing: border-box !important;
    display: block !important;
    text-align: left !important;
    }

    #asset-list-container {
        display: flex !important;
        flex-wrap: nowrap !important; 
        overflow-x: auto !important; 
        /* --- 修正箇所：確実に左寄せにする --- */
        justify-content: flex-start !important; 
        /* ---------------------------------- */
        gap: 8px;
        padding: 10px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x;
    }

    /* --- 横スクロールバーを見やすく表示 --- */
    #asset-list-container::-webkit-scrollbar {
        height: 8px !important;
        display: block !important;
    }
    #asset-list-container::-webkit-scrollbar-thumb {
        background: #ccc !important;
        border-radius: 10px;
    }
    #asset-list-container::-webkit-scrollbar-track {
        background: #f0f0f0;
    }

    #asset-list-container div, 
    #asset-list-container .asset-item {
        /* --- 修正箇所：横幅を固定して左に詰める --- */
        flex: 0 0 55px !important; 
        width: 55px !important;
        /* -------------------------------------- */
        height: 55px !important;
        background: white;
        border-radius: 8px;
    }

    /* 4. ステージエリア：横幅ピッタリに */
    #editor-right {
        width: 100% !important;
        padding: 10px !important;
        box-sizing: border-box !important;
        display: block !important;
    }

    #stage-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 5. スタート・リセットボタンの文字を小さく調整 */
    .btn-fs, .btn-run, .controls .btn {
        padding: 5px 10px !important;
        font-size: 13px !important;
        min-width: 70px !important;
        display: flex !important;
    }
    /* 文字とボタンを小さく */
#fs-header, #fs-footer, .btn-fs, .score-display {
    font-size: 12px !important; 
}
.btn-fs {
    height: 32px !important;
    padding: 0 10px !important;
    min-width: 60px !important;
}



/* --- 【完成版】隙間なし・比率維持・ゲーム時のみボタン表示 --- */
@media (max-width: 900px) {

    /* 1. 親要素：100%使用 */
    #stage-wrapper.fullscreen,
    #stage-wrapper:fullscreen {
        display: flex !important;
        flex-direction: column !important;
        width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        padding: 0 !important;
        margin: 0 !important;
        background: #000 !important;
        overflow: hidden !important;
    }

    /* 2. ステージコンテナ */
    #stage-wrapper.fullscreen #stage-container,
    #stage-wrapper:fullscreen #stage-container {
        flex: 1 !important;
        height: 100% !important;
        width: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: transparent !important;
        border: none !important;
    }

    /* 3. ステージ本体：比率を守りつつ最大化 */
    #stage-wrapper.fullscreen #main-stage,
    #stage-wrapper:fullscreen #main-stage {
        max-height: 100% !important; 
        margin: 0 !important;
        padding: 0 !important;
        width: auto !important;
        height: 100% !important;
        aspect-ratio: 16/9 !important;
        object-fit: contain !important;
        position: relative !important;
        top: auto !important;
        left: auto !important;
    }

    /* --- ボタンの表示制御 --- */

    /* デフォルトは非表示 */
    #stage-wrapper.fullscreen #fs-footer,
    #stage-wrapper:fullscreen #fs-footer {
        display: none !important;
    }

    /* スコア(fs-header.active)が出ている時だけ、ボタン(fs-footer)を浮かせて出す */
    #stage-wrapper.fullscreen #fs-header.active ~ #fs-footer,
    #stage-wrapper:fullscreen #fs-header.active ~ #fs-footer {
        display: flex !important;
        position: fixed !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        z-index: 100010 !important;
        /* スコアに近いデザイン（黒半透明） */

        backdrop-filter: blur(5px);
        border: 1px solid rgba(255,255,255,0.2) !important;
        border-radius: 10px !important;
        width: auto !important;

        height: 45px !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 15px !important;
    }

    /* 4. 縦向き（portrait）の位置 */
    @media (orientation: portrait) {
        #stage-wrapper.fullscreen #fs-header.active ~ #fs-footer {
            bottom: 30px !important;
        }
    }

    /* 5. 横向き（landscape）の位置 */
    @media (orientation: landscape) {
        #stage-wrapper.fullscreen #fs-header.active ~ #fs-footer {
            bottom: 10px !important;
        }
    }

    /* ボタン自体のスタイルリセット（PC用の白い背景などを消す） */
    #stage-wrapper.fullscreen #fs-footer .btn,
    #stage-wrapper:fullscreen #fs-footer .btn {
        background: transparent !important;
        border: 1px solid rgba(255,255,255,0.2) !important;
        color: white !important;
        padding: 5px 5px !important;
        border-radius: 0px !important;
        font-size: 13px !important;
    }
}

/* 6. ゲーム終了画面（メッセージオーバーレイ）を最前面に持ってくる */
    #game-message-overlay {
        z-index: 100020 !important; /* スコアやボタン(100100)よりもさらに手前へ */
    }

    /* 終了画面内の文字サイズをスマホ向けに最適化 */
    #message-box {
        width: 85% !important;
        padding: 20px !important;
        border-width: 5px !important;
    }

    #message-text {
        font-size: 28px !important;
    }

    #message-score {
        font-size: 20px !important;
    }

    .btn-msg {
        padding: 10px 30px !important;
        font-size: 18px !important;
    }
}

/* 実行中（running）は、素材の枠や削除ボタンを隠す */
body.running .obj {
    outline: none !important;
    border: none !important;
}

body.running .delete-btn {
    display: none !important;
}

/* フッターのスタイル：潰れを防止 */
.site-footer {
    flex-shrink: 0;   /* ←これが最重要！ 他の要素に押されても縮みません */
    height: 30px;     /* 高さをしっかり確保 */
    background: #fff; /* 背景を白くして文字を見やすく */
    border-top: 1px solid #ddd;
    display: flex;
    align-items: center;    /* 文字を上下中央に */
    justify-content: center; /* 文字を左右中央に */
}

.site-footer p {
    margin: 0;
    font-size: 12px;
    color: #666;
    line-height: 1;   /* 行間を詰めすぎない */
    white-space: nowrap; /* 改行して潰れるのを防ぐ */
}


.obj {
    /* 既存のスタイル */
    touch-action: none;
    user-select: none;
    -webkit-user-drag: none; /* iOS/Safariでの画像ドラッグを禁止 */
    -webkit-tap-highlight-color: transparent; /* タップ時の青い枠を消す */
}

/* ドラッグ中の見た目を変える（お好みで） */
.obj:active {
    cursor: grabbing;
    filter: brightness(1.1);
}