        body {
            margin: 0;
            padding: 0;
            background-color: #222;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: white;
            font-family: sans-serif;
            overflow: hidden;
        }
        canvas {
            background-color: #000;
            border: 2px solid #444;
            box-shadow: 0 0 20px rgba(0,0,0,0.5);
            /* CSSスケーリング */
            width: 100%;
            height: 100%;
            object-fit: contain;
            /* タッチドラッグ中にブラウザ側のスクロール/ズーム/長押しメニューを抑止 */
            touch-action: none;
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            user-select: none;
        }
        #ui {
            position: absolute;
            top: 20px;
            left: 20px;
            font-size: 24px;
            pointer-events: none; /* UIがクリックを邪魔しないように */
            text-shadow: 2px 2px 0 #000;
            font-weight: bold;
        }
        .bar-container {
            width: 300px;
            height: 30px;
            background-color: #555;
            margin-bottom: 10px;
            border: 2px solid #fff;
            box-shadow: 0 0 5px rgba(0,0,0,0.8);
        }
        #hp-bar {
            width: 100%;
            height: 100%;
            background-color: #32C832; /* Green */
            transition: width 0.2s;
        }
        #mp-bar {
            width: 100%;
            height: 100%;
            background-color: #1E90FF; /* DodgerBlue */
            transition: width 0.2s;
        }
        #xp-bar {
            width: 0%;
            height: 100%;
            background-color: #00FFFF; /* Cyan */
            transition: width 0.2s;
        }
        #levelup-screen {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.85);
            display: none;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 100;
        }
        #npc-select-screen {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.9);
            display: none;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 105;
        }
        .powerup-card {
            background: #333;
            border: 2px solid #fff;
            color: white;
            padding: 20px;
            margin: 10px;
            width: 300px;
            cursor: pointer;
            text-align: center;
        }
        .powerup-card:hover, .powerup-card.selected {
            background: #555;
            border-color: #FFD700;
        }
        .powerup-title {
            font-size: 24px;
            font-weight: bold;
            color: #FFD700;
            margin-bottom: 5px;
        }
        #chest-screen {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.9);
            display: none;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 110;
            color: #FFD700;
        }
        .chest-content {
            display: flex;
            gap: 20px;
            margin: 30px;
            flex-wrap: wrap;
            justify-content: center;
        }
        .chest-item {
            background: #444;
            border: 2px solid #FFD700;
            padding: 20px;
            width: 150px;
            text-align: center;
            color: white;
            animation: popIn 0.5s ease-out forwards;
            opacity: 0;
        }
        @keyframes popIn {
            0% { transform: scale(0); opacity: 0; }
            80% { transform: scale(1.1); opacity: 1; }
            100% { transform: scale(1); opacity: 1; }
        }
        .chest-btn {
            padding: 15px 40px;
            font-size: 24px;
            background: #FFD700;
            color: #000;
            border: none;
            cursor: pointer;
            font-weight: bold;
            margin-top: 20px;
            border-radius: 5px;
        }
        .chest-btn:hover {
            background: #FFF;
        }
        .start-menu-btn.selected, .ending-menu-btn.selected {
            outline: 3px solid #FF00FF;
            outline-offset: 2px;
            box-shadow: 0 0 12px #FF00FF;
        }
        #ending-screen {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.9);
            display: none;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 120;
        }
        #start-screen {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.6);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 200;
        }
        #stats-container {
            color: #ddd;
            font-size: 16px;
            margin-bottom: 20px;
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 10px 30px;
        }
        #inventory {
            position: absolute;
            top: 20px;
            right: 20px;
            width: 300px;
            display: flex;
            flex-wrap: wrap;
            justify-content: flex-end;
            gap: 4px;
            pointer-events: auto;
        }
        .inv-slot {
            width: 32px;
            height: 32px;
            background-color: rgba(0,0,0,0.5);
            border: 1px solid #888;
            position: relative;
        }
        .inv-slot:hover::after {
            content: attr(data-tooltip);
            position: absolute;
            top: 100%;
            right: 0;
            background: rgba(0, 0, 0, 0.9);
            color: #fff;
            padding: 8px;
            border: 1px solid #fff;
            width: 200px;
            z-index: 1000;
            font-size: 12px;
            white-space: pre-wrap;
            pointer-events: none;
        }
        .inv-slot img {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
        .inv-level {
            position: absolute;
            bottom: 0;
            right: 0;
            font-size: 10px;
            color: white;
            background-color: rgba(0,0,0,0.8);
            padding: 0 2px;
        }
        #dialog-box {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            width: 80%;
            background: rgba(0, 0, 0, 0.9);
            border: 2px solid #FFF;
            padding: 20px;
            color: #FFF;
            font-size: 20px;
            display: none;
            z-index: 300;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0,0,0,0.8);
        }
        #chat-box {
            position: absolute;
            bottom: 120px;
            left: 50%;
            transform: translateX(-50%);
            background-color: rgba(255, 255, 255, 0.9);
            border: 3px solid #333;
            border-radius: 15px;
            padding: 15px 30px;
            color: #333;
            font-weight: bold;
            font-size: 18px;
            display: none;
            pointer-events: none;
            z-index: 250;
            text-align: center;
            box-shadow: 0 4px 10px rgba(0,0,0,0.3);
            min-width: 300px;
        }
        #ranking-screen {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.95); display: none; flex-direction: column; justify-content: center; align-items: center; z-index: 250; color: white;
        }
        .rank-row { display: flex; justify-content: space-between; width: 400px; font-size: 20px; margin: 5px 0; border-bottom: 1px solid #444; padding: 5px; }

        #settings-btn {
            position: absolute;
            top: 20px;
            right: 340px;
            width: 40px;
            height: 40px;
            background: rgba(0,0,0,0.6);
            border: 2px solid #888;
            border-radius: 50%;
            color: #fff;
            font-size: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            pointer-events: auto;
            z-index: 90;
        }
        #settings-btn:hover { border-color: #FFD700; }
        #settings-screen {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            background-color: rgba(0, 0, 0, 0.95);
            display: none;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 260;
            color: white;
        }
        #settings-body {
            max-height: 70vh;
            overflow-y: auto;
            overflow-x: hidden;
            width: 500px;
            max-width: 90vw;
            box-sizing: border-box;
            padding: 0 10px;
        }
        .settings-section { margin-bottom: 15px; min-width: 0; }
        .settings-section h4 { color: #FFD700; margin: 10px 0 5px; border-bottom: 1px solid #555; padding-bottom: 4px; }
        .setting-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            padding: 4px 0;
            font-size: 14px;
            min-width: 0;
        }
        .setting-label { flex: 1; min-width: 0; }
        .setting-value { width: 45px; flex-shrink: 0; text-align: right; color: #FFD700; }
        #volume-slider { flex: 2; min-width: 0; }
        .keybind-list { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
        .keybind-btn {
            background: #333; color: #fff; border: 1px solid #777;
            padding: 6px 10px; cursor: pointer; font-size: 12px;
            min-width: 90px; max-width: 100%; box-sizing: border-box;
            text-align: left; display: flex; justify-content: space-between; gap: 8px;
        }
        .keybind-btn span { color: #FFD700; font-weight: bold; }
        .keybind-btn:hover { background: #555; border-color: #fff; }
        .keybind-btn.rebinding { border-color: #FF4500; color: #FF4500; animation: blink 1s infinite; }

        #start-shard-display { pointer-events: none; }
        #meta-store-screen {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            background-color: rgba(0, 0, 0, 0.95);
            display: none;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 260;
            color: white;
            text-align: center;
        }
        #meta-store-balance {
            font-size: 20px;
            color: #00FFFF;
            margin-bottom: 15px;
            font-weight: bold;
        }
        #meta-store-list {
            width: 550px;
            max-width: 90vw;
            max-height: 60vh;
            overflow-y: auto;
            box-sizing: border-box;
            padding: 0 10px;
        }
        .meta-store-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 15px;
            background: #222;
            border: 2px solid #444;
            border-radius: 6px;
            padding: 10px 15px;
            margin-bottom: 8px;
            text-align: left;
            min-width: 0;
        }
        .meta-store-info { flex: 1; min-width: 0; }
        .meta-store-title { font-weight: bold; color: #00FFFF; }
        .meta-store-level { color: #FFD700; font-size: 13px; margin-left: 6px; }
        .meta-store-desc { font-size: 12px; color: #ccc; margin-top: 2px; }
        .meta-buy-btn {
            flex-shrink: 0;
            padding: 8px 16px;
            font-size: 14px;
            min-width: 70px;
        }
        .meta-buy-btn:disabled {
            background-color: #555 !important;
            color: #999 !important;
            cursor: not-allowed;
        }

        @keyframes titleFloat {
            0% { transform: translateY(0px); text-shadow: 0 0 10px red; }
            50% { transform: translateY(-10px); text-shadow: 0 0 20px red, 0 0 40px orange; }
            100% { transform: translateY(0px); text-shadow: 0 0 10px red; }
        }
        @keyframes blink {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.3; }
        }
        
        #spells-container {
            position: absolute;
            bottom: 20px;
            left: 20px;
            display: flex;
            gap: 10px;
            pointer-events: none;
        }
        .spell-slot {
            width: 50px;
            height: 50px;
            background: rgba(0,0,0,0.7);
            border: 2px solid #888;
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
            color: white;
            font-weight: bold;
            font-size: 12px;
            flex-direction: column;
        }
        .spell-cooldown {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            background: rgba(0, 0, 0, 0.8);
            height: 0%;
            transition: height 0.1s linear;
        }
        .spell-slot.cooldown {
            opacity: 0.5;
        }
        .spell-key {
            position: absolute;
            top: -10px;
            left: -5px;
            background: #FFD700;
            color: #000;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            text-align: center;
            line-height: 20px;
            font-size: 12px;
            font-weight: bold;
        }
        .spell-slot:hover {
            border-color: #FFD700;
            cursor: pointer;
        }
        .spell-slot:hover::after {
            content: attr(data-tooltip);
            position: absolute;
            bottom: 100%;
            left: 0;
            background: rgba(0, 0, 0, 0.9);
            color: #fff;
            padding: 8px;
            border: 1px solid #fff;
            width: 250px;
            z-index: 1000;
            font-size: 14px;
            white-space: pre-wrap;
            pointer-events: none;
            margin-bottom: 5px;
        }

        #debug-menu {
            position: absolute;
            top: 60px;
            right: 20px;
            width: 300px;
            max-height: 80vh;
            background: rgba(0, 0, 0, 0.9);
            border: 2px solid #f0f;
            color: #fff;
            padding: 10px;
            overflow-y: auto;
            display: none;
            z-index: 1000;
            font-family: monospace;
            pointer-events: auto;
        }
        .debug-section { margin-bottom: 10px; border-bottom: 1px solid #555; padding-bottom: 5px; }
        .debug-section h4 { margin: 5px 0; color: #f0f; }
        .debug-btn {
            background: #333; color: #fff; border: 1px solid #777;
            margin: 2px; padding: 4px 8px; cursor: pointer; font-size: 12px;
            display: inline-block;
        }
        .debug-btn:hover { background: #555; border-color: #fff; }

        /* --- モバイル/狭幅・低高さ画面向けレイアウト（縦持ち・横持ちの両方をカバー） --- */
        @media (max-width: 600px), (max-height: 500px) {
            #ui {
                top: 8px;
                left: 8px;
                font-size: 13px;
            }
            .bar-container {
                width: 140px;
                height: 16px;
                margin-bottom: 4px;
            }
            #inventory {
                top: 8px;
                right: 8px;
                width: 40vw;
            }
            .inv-slot {
                width: 24px;
                height: 24px;
            }
            #spells-container {
                bottom: 8px;
                left: 8px;
                flex-wrap: wrap;
                max-width: 60vw;
                gap: 4px;
            }
            .spell-slot {
                width: 36px;
                height: 36px;
                font-size: 9px;
            }
            #debug-menu {
                width: 85vw;
                right: 7.5vw;
            }
            .powerup-card {
                width: 80vw;
                max-width: 300px;
                padding: 12px;
            }
            .powerup-title {
                font-size: 18px;
            }
            #chat-box {
                min-width: 0;
                width: 85vw;
                font-size: 14px;
                padding: 10px 15px;
                bottom: 90px;
            }
            #dialog-box {
                font-size: 15px;
                padding: 12px;
            }
            #start-screen h1, #ending-screen h1, #chest-screen h1 {
                font-size: 22px !important;
                max-width: 90vw;
                text-align: center;
            }
            #start-screen p, #ending-screen p {
                font-size: 16px !important;
            }
            .rank-row {
                width: 90vw;
                font-size: 14px;
            }
            #settings-btn {
                top: auto;
                bottom: 8px;
                right: 8px;
                width: 32px;
                height: 32px;
                font-size: 16px;
            }
            #settings-body {
                width: 90vw;
            }
            .keybind-btn {
                min-width: 0;
                font-size: 11px;
                padding: 5px 8px;
            }
            .setting-value {
                width: 38px;
                font-size: 12px;
            }
            #meta-store-list {
                width: 90vw;
            }
            .meta-store-row {
                flex-direction: column;
                align-items: stretch;
                gap: 8px;
            }
            .meta-buy-btn {
                width: 100%;
            }
        }
