:root {
    /* 갤럭시 내비게이션 바 높이를 고려한 안전 영역 (대략 20px-50px) */
    --safe-bottom-margin: 50px; 
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background-color: #222;
    color: #eee;
    font-family: Arial, sans-serif;
    user-select: none;
    overflow: hidden; 
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5vh;
    /* 하단에 안전 여백 추가 */
    padding-bottom: var(--safe-bottom-margin); 
    background-color: #333;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    width: 98vw;
    max-width: 500px; 
    box-sizing: border-box; 
    height: 100%;
}

/* 상단 상태 패널 (이전과 동일) */
#status-panel {
    text-align: center;
    margin-bottom: 0.5vh; 
    flex-shrink: 0;
    font-size: 0.85em; 
}

#status-panel h1 {
    font-size: 1.5em; 
    margin: 0;
}
#status-panel p {
    margin: 0 0 0.5vh 0; 
}


/* 캔버스 스크롤링을 위한 컨테이너 */
#canvas-wrapper {
    width: 95vw;
    max-width: 400px;
    height: 100%; 
    overflow: hidden; 
    border: 3px solid #00f;
    background-color: #000;
    flex-grow: 1;
    touch-action: none; 
}

#maze-canvas {
    display: block; 
    touch-action: none;
}

/* 스테이지 클리어 메시지 (이전과 동일) */
#message-overlay {
    position: fixed; 
    top: 50%; 
    left: 50%;
    transform: translate(-50%, -50%); 
    width: 80vw;
    max-width: 350px; 
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

/* ====== 반투명 D-Pad 오버레이 스타일 ====== */
#dpad-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    /* D-Pad의 크기와 하단 안전 영역을 포함 */
    height: calc(180px + var(--safe-bottom-margin)); 
    pointer-events: none; /* 기본적으로 터치 이벤트를 통과시킴 */
    z-index: 999;
}

#dpad-visuals {
    pointer-events: auto; /* 시각적 요소 위에서는 터치 이벤트 처리 */
    position: absolute;
    bottom: var(--safe-bottom-margin); /* 안전 영역 위에 배치 */
    left: 50%;
    transform: translateX(-50%);
    width: 160px; /* D-Pad 전체 크기 */
    height: 160px;
    border-radius: 50%;
    background-color: rgba(50, 50, 50, 0.5); /* 반투명 배경 */
    color: white;
    font-size: 1.5em;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

#dpad-visuals div {
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0.6; /* 기본 투명도 */
    transition: background-color 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent; /* 터치 시 하이라이트 제거 */
    cursor: pointer;
}

/* 상하좌우 grid 배치 */
#dpad-up    { grid-area: 1 / 2 / 2 / 3; border-radius: 50% 50% 0 0; }
#dpad-down  { grid-area: 3 / 2 / 4 / 3; border-radius: 0 0 50% 50%; }
#dpad-left  { grid-area: 2 / 1 / 3 / 2; border-radius: 50% 0 0 50%; }
#dpad-right { grid-area: 2 / 3 / 3 / 4; border-radius: 0 50% 50% 0; }
#dpad-center { 
    grid-area: 2 / 2 / 3 / 3; 
    background-color: rgba(0, 0, 0, 0.2); 
    border-radius: 50%;
}

/* 활성화 상태 (밝게 표시) */
#dpad-visuals div.active-touch {
    background-color: rgba(255, 255, 255, 0.2); 
    opacity: 1;
}

/* 미디어 쿼리: 모바일 최적화 */
@media (max-width: 600px) {
    /* 모바일에서는 D-Pad를 더 크게 */
    #dpad-visuals {
        width: 180px;
        height: 180px;
    }
}
