/* ── Core App Structure ── */
#app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    background: var(--bg-void);
    overflow: hidden; /* App 전체는 고정 */
}

/* ── Top View (Boss & Status Area) ── */
#top-view {
    flex: 0 0 var(--top-view-ratio);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    background: radial-gradient(circle at center, #1a1a2e 0%, var(--bg-void) 100%);
    /* 은은한 글로우 경계선 리뉴얼 */
    border-bottom: 1px solid var(--accent-gold);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.2), 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 2;
    overflow: visible; /* 🚨 경계선 버튼이 잘리지 않도록 함 */
}

/* ── Bottom View (Sacred Ebony & Inlaid Gold Tray) ── */
#bottom-view { 
    flex: 0 0 var(--bottom-view-ratio, 55%);
    width: 100%;
    position: relative; 
    background: radial-gradient(circle at center, #181822 0%, #0a0a0f 100%) !important;
    box-shadow: 
        inset 0 15px 40px rgba(0,0,0,0.9), 
        inset 0 -15px 40px rgba(0,0,0,0.9) !important;
    border-top: 2px solid rgba(212, 175, 55, 0.4) !important;
    border-left: 8px solid #070709 !important;
    border-right: 8px solid #070709 !important;
    border-bottom: 8px solid #070709 !important;
    overflow: visible; /* 🚨 버튼 잘림 방지 */
    z-index: 1;
}

#bottom-view canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    touch-action: none;
    border-radius: 4px;
}

/* ── UI Layout Wrappers ── */
#dice-bag-wrapper {
    position: absolute;
    bottom: 0px; /* 더 아래로 배치 */
    left: 10px;
    z-index: 200;
}

/* ── UI Layout Wrappers (🚨 Layering & Positioning Fixes) ── */
#relic-inventory {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 320px;
    z-index: 100;
}

#btn-help {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 9999 !important; /* 항상 최상위 보장 */
}

#recipe-board {
    position: absolute;
    top: 70px;
    right: 20px;
    width: 260px;
    z-index: 9999 !important; /* 트레이에 가려지지 않도록 최상위 부여 */
}

#player-container {
    position: absolute;
    bottom: 24px;
    left: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    z-index: 10;
}

#tray-ui {
    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999 !important; /* 액션 버튼 최상위 보장 */
    pointer-events: none;
}

.controls {
    display: flex;
    gap: 15px;
    pointer-events: auto;
}

#monster-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 5;
}

/* ── Responsive Layout Adjustment ── */
@media (max-width: 768px) {
    :root {
        --top-view-ratio: 55%;
        --bottom-view-ratio: 45%;
    }
    
    #relic-inventory { width: 180px; top: 10px; left: 10px; }
    #btn-help { top: 10px; right: 10px; }
    #recipe-board { width: 220px; top: 55px; right: 10px; }
    #player-container { bottom: 12px; left: 12px; }
    
    /* 굴리기 버튼 위치 및 크기 최적화 (트레이 내부 상단으로 안정화) */
    #tray-ui { 
        top: 5px !important; 
        transform: none !important;
        z-index: 1000; 
    }
    #btn-action { 
        padding: 10px 24px !important; 
        font-size: 15px !important; 
        min-width: 130px !important;
        box-shadow: 0 0 25px rgba(0, 255, 255, 0.4);
    }
    
    /* 가방 버튼 위치 최적화 (하단 구석 밀착) */
    #dice-bag-wrapper {
        bottom: 10px !important;
        left: 10px !important;
    }
    
    /* 모바일 환경에서는 보더 두께 조절 */
    #bottom-view {
        border-width: 4px;
        outline-offset: -2px;
    }
}
/* ── Wide Screen / PC Layout Optimization ── */
@media (min-width: 1024px) {
    #dice-bag-wrapper {
        left: 40px !important;
        bottom: 40px !important;
        transform: scale(1.2); /* PC에서는 조금 더 크게 */
    }

    #tray-ui {
        top: 50% !important;
        left: auto !important;
        right: 40px !important;
        width: auto !important;
        transform: translateY(-50%) !important;
        justify-content: flex-end !important;
    }

    .controls {
        flex-direction: column; /* 가로 화면에서는 세로로 배치 가능 */
        gap: 20px;
    }

    #player-container {
        left: 40px;
        bottom: 120px; /* 가방 버튼 위에 배치 */
    }
}
