 :root {
            --theme-color: #0984e3; --bg-color: #0b1f15; 
            --text-main: #2d3436; --success: #00b894; --warning: #e74c3c;
        }

        body, html {
            margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; 
            background-color: var(--bg-color); font-family: 'Nanum Gothic', sans-serif; 
            user-select: none; touch-action: none; -webkit-touch-callout: none;
        }

        /* 게임 화면 컨테이너 (전체화면 꽉 차게) */
        #game-view-wrapper {
            position: absolute; top: 0; left: 0; width: 100vw; height: 100vh;
            display: flex; justify-content: center; align-items: center; 
            background: radial-gradient(circle at center, #1e3a29 0%, #0b1f15 100%);
            padding: 10vh 2vw 12vh 2vw; /* 좌우 여백을 주어 테두리가 화면 끝에 붙지 않게 함 */
            box-sizing: border-box;
        }
        canvas { 
            display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; aspect-ratio: 3 / 2; object-fit: contain;
            image-rendering: pixelated; 
            border: 3px solid #34495e; border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.6);
            background: #000; box-sizing: border-box;
        }

        /* 무적 상태 시 형광 반짝임 효과 */
        @keyframes invincibleBlink {
            0%, 100% { opacity: 1; filter: drop-shadow(0 0 15px #00ff00) brightness(1.5); }
            50% { opacity: 0.3; filter: drop-shadow(0 0 5px #00ff00) brightness(1); }
        }
        .blinking { animation: invincibleBlink 0.3s infinite; }

        /* --- 상단 UI (얇은 에너지바, 아이템 배치) --- */
        #ui-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; z-index: 10;}
        
        .bottom-bar { display: flex; flex-direction: column; gap: 15px; padding: 15px 3vw; background: linear-gradient(0deg, rgba(0,0,0,0.9) 0%, transparent 100%); pointer-events: auto; width: 100%; box-sizing: border-box; position: absolute; bottom: 0; }

        /* 상단 UI (레벨, 에너지, 버튼) */
        .top-bar { display: flex; flex-direction: column; gap: 10px; padding: 15px 3vw; background: linear-gradient(180deg, rgba(0,0,0,0.9) 0%, transparent 100%); pointer-events: auto; width: 100%; box-sizing: border-box; }
        .status-row-1 { display: flex; justify-content: space-between; align-items: center; width: 100%; flex-wrap: nowrap; gap: 10px; }
        .status-row-2 { display: flex; justify-content: center; align-items: center; width: 100%; position: relative; margin-top: 5px; }
        .status-left, .status-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
        .status-text-group { display: flex; gap: 20px; align-items: center; justify-content: center; width: 100%; }
        
        .level-badge { background: #6c5ce7; color: white; padding: 4px 15px; border-radius: 12px; font-weight: 900; font-size: 1.2rem; box-shadow: 0 2px 4px rgba(0,0,0,0.5);}
        .timer-box { font-weight: 900; font-size: 1.4rem; color: #fff; text-shadow: 1px 1px 2px #000; }
        .lives-wrapper { display: flex; gap: 5px; color: #ff7675; font-size: 1.2rem; text-shadow: 1px 1px 2px #000; }
        .info-text { font-weight: 900; color: #fff; font-size: 1.1rem; text-shadow: 1px 1px 2px #000; }
        .score-text { font-weight: 900; color: #f1c40f; font-size: 1.1rem; text-shadow: 1px 1px 2px #000; }
        .icon-btn-top { background: rgba(255,255,255,0.2); border: 2px solid rgba(255,255,255,0.4); color: white; border-radius: 10px; padding: 6px 12px; cursor: pointer; font-size: 1.2rem; transition: 0.2s; backdrop-filter: blur(5px); }
        .icon-btn-top:active { transform: scale(0.9); background: rgba(255,255,255,0.4); }
        
        .energy-wrapper { min-width: 150px; flex: 1; max-width: 400px; display: flex; align-items: center; gap: 8px; margin: 0 10px; }
        .energy-bar-bg { flex: 1; height: 12px; background: rgba(255,255,255,0.3); border-radius: 6px; overflow: hidden; border: 1px solid #fff;}
        .energy-bar-fill { height: 100%; background: linear-gradient(90deg, #ff7675, #d63031); width: 100%; transition: 0.2s linear; }
        
        .items-row { display: flex; justify-content: center; gap: 15px; margin-top: 0;}
        .item-slot { width: 50px; height: 50px; background: rgba(0,0,0,0.6); border: 2px solid #555; border-radius: 12px; position: relative; display: flex; align-items: center; justify-content: center; transition: 0.2s;}
        .item-slot.selected { border-color: #f1c40f; background: rgba(241, 196, 15, 0.4); box-shadow: 0 0 12px #f1c40f;}
        .item-badge { position: absolute; top: -8px; right: -8px; background: #e74c3c; color: white; border-radius: 50%; width: 22px; height: 22px; font-size: 0.9rem; font-weight: bold; display: flex; justify-content: center; align-items: center; border: 1px solid #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.5); z-index: 5;}
        .item-icon { font-size: 1.4rem; }

        /* --- 하단 컨트롤러 (투명 패드) --- */
        .bottom-controls { position: absolute; bottom: 80px; left: 0; width: 100%; display: none; justify-content: space-between; align-items: flex-end; padding: 10px 4vw; box-sizing: border-box; pointer-events: none; z-index: 20;} /* 하단 아이템바와 겹치지 않게 위로 올림 */
        .bottom-controls.show { display: flex; }
        
        .dpad { display: block; position: relative; width: 160px; height: 160px; background: rgba(255, 255, 255, 0.15); border: 2px solid rgba(255,255,255,0.4); border-radius: 50%; pointer-events: auto; backdrop-filter: blur(5px); }
        .dbtn { position: absolute; width: 50px; height: 50px; background: rgba(255, 255, 255, 0.2); color: white; border-radius: 50%; font-size: 2rem; display: flex; align-items: center; justify-content: center; transition: 0.1s; touch-action: manipulation;}
        .dbtn:active { background: rgba(255,255,255,0.6); transform: scale(0.9); }
        .up { top: 5px; left: 55px; } .left { top: 55px; left: 5px; } .right { top: 55px; right: 5px; } .down { bottom: 5px; left: 55px; }

        .action-pad { display: flex; align-items: flex-end; gap: 20px; pointer-events: auto; margin-bottom: 10px; }
        .btn-action { width: 70px; height: 70px; display: flex; justify-content: center; align-items: center; border-radius: 50%; color: white; font-size: 2rem; font-weight: 900; background: rgba(255, 255, 255, 0.2); border: 2px solid rgba(255,255,255,0.5); backdrop-filter: blur(5px); transition: 0.1s; touch-action: manipulation; box-shadow: 0 4px 15px rgba(0,0,0,0.3);}
        .btn-action:active { transform: scale(0.9); background: rgba(255,255,255,0.6); color: #333; }

        @media (max-width: 768px) {
            .status-text-group { gap: 10px; }
            .status-row-2 { flex-direction: column; align-items: center; }
            .level-badge { font-size: 1rem; padding: 3px 10px; }
            .timer-box { font-size: 1.2rem; }
        }

        /* --- 스플래시 & 스토리 --- */
        #splash-screen { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: linear-gradient(135deg, #0b1f15, #1e3a29); color: white; z-index: 99999; display: flex; flex-direction: column; justify-content: center; align-items: center; transition: opacity 0.8s;}
        .splash-logo { font-size: 2.5rem; font-weight: 900; margin-bottom: 15px; color: #f1c40f; letter-spacing: 5px; }
        .splash-title { font-size: 4rem; font-weight: 900; text-shadow: 0 8px 15px rgba(0,0,0,0.8); margin-bottom: 40px; }

        .intro-btns-wrap { display:flex; gap:15px; margin-top: 25px; position:relative; z-index: 10; }
        .start-action-btn { padding:10px 20px; font-size:1.1rem; border-radius:12px; background:rgba(255,255,255,0.2); border:2px solid #fff; color:#fff; font-weight:bold; cursor:pointer; backdrop-filter:blur(5px); transition: 0.2s;}
        .start-action-btn:hover { background:rgba(255,255,255,0.4); }

        .story-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 10000; padding: 30px; box-sizing: border-box; overflow-y: auto; }
        .story-content { font-size: 1.6rem; color: #fff; line-height: 1.8; max-width: 800px; text-align: left; white-space: pre-wrap; font-weight: bold;}
        .skip-btn { margin-top: 20px; padding: 15px 40px; font-size: 1.4rem; font-weight: bold; background: #27ae60; color: white; border: none; border-radius: 20px; cursor: pointer;}

        /* --- 방탈출 UI (돌벽 배경 및 크기 확대) --- */
        #room-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(10px); z-index: 9000; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; box-sizing: border-box;}
        
        .stone-room {
            background: #2d4031 url('data:image/svg+xml;utf8,<svg width="60" height="40" xmlns="http://www.w3.org/2000/svg"><rect width="60" height="40" fill="%232d4031"/><path d="M0 20h60M30 0v40" stroke="%231a2b22" stroke-width="3"/></svg>');
            padding: 25px;
            border-radius: 16px;
            border: 6px solid #1a2b22;
            box-shadow: inset 0 0 40px rgba(0,0,0,0.8), 0 20px 50px rgba(0,0,0,0.8);
            width: 95vw;
            max-width: 1000px;
            height: auto;
            min-height: 60vh;
            max-height: 95vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            overflow-y: auto;
            box-sizing: border-box;
            gap: 15px;
        }
        .stone-room::-webkit-scrollbar { width: 10px; }
        .stone-room::-webkit-scrollbar-thumb { background: #1a2b22; border-radius: 5px; }

        .glass-panel { background: rgba(255, 255, 255, 0.95); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); padding: 20px; box-sizing: border-box; width: 100%;}
        
        .header-btn-wrap { width: 100%; display: flex; justify-content: flex-end; margin-bottom: 0; }
        .escape-btn { background: #ff7675; color: white; border: none; padding: 8px 15px; border-radius: 10px; font-weight: bold; font-size: 1.1rem;}
        
        .mission-area { display: flex; flex-direction: column; gap: 15px; width: 100%; margin-bottom: 5px;}
        @media (min-width: 768px) { .mission-area { flex-direction: row; align-items: stretch; } } /* 넓은 화면일 때 가로 배치 */
        
        .story-box { flex: 1; display: flex; flex-direction: column; align-items: center; text-align: center; justify-content: center;}
        .stage-badge { background: var(--theme-color); color: white; padding: 4px 15px; border-radius: 15px; font-weight: 900; margin-bottom: 5px; font-size: 1.1rem;}
        .story-text { font-size: 1.2rem; font-weight: 800; color: var(--text-main); word-break: keep-all; line-height: 1.3;}
        
        .table-box { flex: 1; overflow: hidden; padding: 0; display: flex; flex-direction: column;}
        .data-table { width: 100%; height: 100%; min-height: 150px; border-collapse: collapse; text-align: center; font-size: 1.4rem; font-weight: bold;}
        .data-table th { background: var(--theme-color); color: white; border: 2px solid #dfe6e9; padding: 10px;}
        .data-table td { border: 2px solid #dfe6e9; padding: 10px;}

        #phase-1 { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 15px; }
        .slots-container { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 5px 0;}
        .slot-eq { width: 45px; height: 50px; background: #f1f2f6; border: 3px dashed #b2bec3; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; font-weight: 900; color: var(--theme-color);}
        .slot-eq.filled { background: white; border: 2px solid var(--theme-color); border-bottom: 4px solid var(--theme-color); }
        .keypad-box { width: 100%; max-width: 600px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin: 0 auto; }
        .key-btn { background: white; border: 1px solid #ccc; border-radius: 12px; font-size: 1.8rem; font-weight: 900; padding: 12px 0; box-shadow: 0 4px 0 #ccc; font-family: 'Nanum Gothic', sans-serif; transition: background 0.1s, transform 0.1s; cursor: pointer; touch-action: manipulation; }
        .key-btn:active { background: #dfe6e9 !important; transform: translateY(4px); box-shadow: none; }
        .key-btn.action { background: #ff7675; color: white; border-color: #e55039; }

        #phase-2 { width: 100%; display: none; flex-direction: column; align-items: center; gap: 15px;}
        .predict-q { font-size: 1.5rem; font-weight: 900; color: #e84393; text-align: center; margin: 0;}
        .calc-btn { background: #f1f2f6; border: 2px solid #dfe6e9; border-radius: 12px; font-size: 2rem; font-weight: 900; color: var(--theme-color); font-family: 'Nanum Gothic', sans-serif; transition: background 0.1s, transform 0.1s; padding: 15px 0; cursor: pointer; touch-action: manipulation; box-shadow: 0 4px 0 #bdc3c7;}
        .calc-btn:active { background: #dcdde1 !important; transform: translateY(4px); box-shadow: none; }
        .calc-action { background: #ff7675; color: white; border-color: #e55039; }
        .calc-submit { background: #27ae60; color: white; border-color: #219c54; font-size: 1.6rem; }
        .calc-display { background: #fff; border: 3px solid #dfe6e9; border-radius: 12px; height: 60px; display: flex; align-items: center; justify-content: flex-end; padding: 0 15px; font-size: 2.5rem; font-weight: 900; color: var(--theme-color); margin-bottom: 10px; letter-spacing: 2px;}

        .toast-msg { position: fixed; top: 10%; left: 50%; transform: translate(-50%, -50%); background: rgba(0, 0, 0, 0.85); color: white; padding: 15px 30px; border-radius: 30px; font-size: 1.3rem; font-weight: 900; z-index: 10000; opacity: 0; pointer-events: none; transition: 0.4s; text-align: center;}
        .toast-msg.show { opacity: 1; }
        .hidden-screen { display: none !important; }

        .intro-character {
            width: 120px; height: 120px;
            background-image: url('images/sprite.png');
            background-size: 400% 400%; /* 스프라이트 시트 분할용 */
            background-position: 0 0;
            image-rendering: pixelated;
            margin-bottom: 20px;
        }