body { 
    margin: 0; padding: 0; 
    width: 100vw; height: 100vh; height: 100dvh; 
    background-color: #000; 
    display: flex; justify-content: center; align-items: center; 
    touch-action: none; overflow: hidden; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#game-container { 
    width: 418px; height: 740px; 
    background: #111; 
    display: flex; flex-direction: column; 
    box-shadow: 0 0 30px rgba(255,255,255,0.1); 
    position: relative; overflow: hidden;
    transform-origin: center center;
}

#game-view { flex: 1 1 auto; min-height: 0; position: relative; background-color: #1a253a; }

#ui-layer { display: none; position: absolute; top: 15px; left: 0; width: 100%; text-align: center; color: white; font-weight: bold; font-size: 24px; text-shadow: 2px 2px 2px #000; z-index: 5; pointer-events: none;}
#lava-warning { color: #ff3300; font-size: 20px; margin-top: 5px; text-shadow: 1px 1px 2px #000; display: none; animation: blink 1s infinite;}
@keyframes blink { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; } }

#countdown-layer {
    display: none; position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);
    font-size: 120px; font-weight: 900; color: #FFD700; text-shadow: 6px 6px 0 #b23c17, 0 0 30px rgba(0,0,0,0.8); 
    z-index: 25; pointer-events: none; animation: popIn 1s infinite;
}
#game-over-effect {
    display: none; position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);
    font-size: 60px; font-weight: 900; color: #ff0000; text-shadow: 5px 5px 0 #fff, 0 0 30px rgba(0,0,0,0.8); 
    z-index: 25; pointer-events: none; text-align: center; width: 100%;
}
@keyframes popIn {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    30% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

#menu-screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(135deg, rgba(44,62,80,0.95) 0%, rgba(0,0,0,0.98) 100%); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 30; }
.menu-step { display: none; flex-direction: column; align-items: center; width: 100%; }
.menu-step.active { display: flex; }

.title-text { font-size: 52px; font-weight: 900; color: #ff5722; text-shadow: 4px 4px 0 #b23c17, 8px 8px 15px rgba(0,0,0,1); margin-bottom: 30px; text-align: center; line-height: 1.1; letter-spacing: 2px;}
.step-title { font-size: 28px; font-weight: 900; color: #fff; margin-bottom: 20px; text-shadow: 2px 2px 0 #000; }

.btn-group { display: flex; flex-direction: column; gap: 15px; width: 70%; }

.char-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 90%; }
.char-btn { padding: 12px 8px; border: 2px solid #444; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; background: rgba(0,0,0,0.6); transition: 0.1s;}
.char-btn:active { transform: scale(0.95); }
.char-btn.selected { border-color: white; box-shadow: 0 0 15px rgba(255,255,255,0.5); }
.char-name { font-size: 18px; font-weight: bold; color: white; margin-bottom: 4px;}
.char-tag { font-size: 11px; color: #aaa; }

.stat-box { width: 90%; background: #222; padding: 15px; border-radius: 10px; margin-top: 20px; box-sizing: border-box; box-shadow: inset 0 0 10px #000;}
.stat-row { display: flex; align-items: center; margin-bottom: 10px; font-size: 13px; color: #ddd; font-weight: bold;}
.stat-label { width: 60px; }
.stat-bar { flex: 1; background: #000; height: 14px; border-radius: 7px; overflow: hidden; margin-left: 10px; position: relative;}
.stat-fill { height: 100%; width: 0%; transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.4s; }

.stage-btn { width: 85%; padding: 20px; background: #333; border: 2px solid #555; border-radius: 12px; margin-bottom: 15px; display: flex; flex-direction: column; align-items: center; color: white; cursor: pointer; transition: 0.1s; box-sizing: border-box;}
.stage-btn.selected { border-color: #ff5722; background: rgba(255,87,34,0.3); }
.stage-btn.locked { opacity: 0.5; cursor: not-allowed; border-color: #222; background: #111;}
.stage-name { font-size: 22px; font-weight: bold; margin-bottom: 5px; }
.stage-desc { font-size: 14px; color: #ccc; }

.nav-btn-box { margin-top: 25px; width: 80%; display: flex; gap: 10px; }

.ui-btn { padding: 14px 20px; font-size: 18px; font-weight: bold; color: white; border: none; border-radius: 10px; cursor: pointer; transition: transform 0.1s, box-shadow 0.1s; flex: 1; text-align: center;}
.ui-btn.orange { background-color: #ff5722; box-shadow: 0 6px 0 #b23c17; }
.ui-btn.blue { background-color: #2196F3; box-shadow: 0 6px 0 #1976D2; }
.ui-btn.gray { background-color: #666; box-shadow: 0 6px 0 #444; }
.ui-btn.gray.disabled { opacity: 0.5; pointer-events: none; }
.ui-btn:active { transform: translateY(6px); box-shadow: none; }

#game-over { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); flex-direction: column; justify-content: center; align-items: center; z-index: 20; }
.result-box { background: #222; padding: 25px; border-radius: 15px; text-align: center; font-weight: bold; box-shadow: 0 0 20px rgba(255,87,34,0.5); border: 2px solid #ff5722; width: 80%; max-width: 320px;}
#ranking-board { margin: 15px 0; text-align: left; font-size: 16px; display: flex; flex-direction: column; gap: 6px; }
.rank-item { display: flex; justify-content: space-between; align-items: center; padding: 10px; background: rgba(0,0,0,0.6); border-radius: 8px; }

#loading-screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #000; color: white; display: flex; justify-content: center; align-items: center; font-size: 20px; z-index: 40; }

#controls { display: none; flex: 0 0 40%; min-height: 220px; width: 100%; box-sizing: border-box; background-color: #111; flex-direction: column; border-top: 4px solid #000; }
#status-board { display: flex; gap: 4px; padding: 6px; background-color: #000; border-bottom: 2px solid #222; box-sizing: border-box; }
.status-card { flex: 1; background: #1a1a1a; color: white; padding: 8px 2px; border-radius: 6px; border-left: 5px solid; display: flex; flex-direction: column; text-align: center; }
.status-name { font-weight: 900; margin-bottom: 6px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.status-state { font-size: 12px; color: #eee; font-weight: bold; }

#input-zone { flex: 1; display: flex; width: 100%; }
#joystick-zone { flex: 1; display: flex; justify-content: center; align-items: center; position: relative; }
#joystick-bg { width: 110px; height: 110px; background-color: rgba(255, 255, 255, 0.08); border: 3px solid rgba(255,255,255,0.15); border-radius: 50%; position: relative; touch-action: none; margin-bottom: 30px;}
#joystick-knob { width: 46px; height: 46px; background-color: rgba(255, 255, 255, 0.95); border-radius: 50%; position: absolute; top: 32px; left: 32px; pointer-events: none; box-shadow: 0 5px 15px rgba(0,0,0,0.7);}
#button-zone { flex: 1; display: flex; justify-content: space-evenly; align-items: center; padding: 0 10px; margin-bottom: 30px;}

.action-btn { width: 60px; height: 60px; border-radius: 50%; border: none; color: white; font-size: 15px; font-weight: bold; user-select: none; touch-action: none; transition: transform 0.05s, box-shadow 0.05s, filter 0.2s;}
.action-btn:active, .action-btn.active-key { transform: translateY(6px); box-shadow: none !important; }
#btn-a { background-color: #4CAF50; box-shadow: 0 6px 0 #388E3C; }
#btn-b { background-color: #2196F3; box-shadow: 0 6px 0 #1976D2; }
.cooldown { filter: grayscale(100%); pointer-events: none; }

canvas { display: block; width: 100%; height: 100%; }
