/**
 * 모바일 전용 세로형(Portrait) UI - Flexbox 구조
 * body.mobile-ui 클래스가 적용될 때만 활성화 (uiRenderer.js)
 * PC UI는 수정하지 않음
 */

/* ========== CSS 변수: 모바일용 크기 ========== */
body.mobile-ui {
    --mobile-touch-min: 44px;
    --mobile-header-height: 40px;
    --mobile-status-height: 100px;
    --mobile-quickbar-height: 56px;
}

/* ========== Flexbox 구조: 위→아래 흐름 강제 ========== */
body.mobile-ui {
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    height: 100vh;
}

/* ========== 모바일: 레터박스/스케일 비활성화 ========== */
body.mobile-ui .letterbox {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    height: 100vh;
    overflow: hidden;
}

body.mobile-ui .scale-wrapper {
    width: 100% !important;
    height: 100% !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.mobile-ui .container {
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ========== 게임 화면: Flexbox 세로 배치 ========== */
body.mobile-ui .game-screen {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* 모바일 레이아웃 순서: [헤더]-[메인이미지]-[채팅]-[상태바] */
body.mobile-ui .game-screen .game-ui-overlay {
    order: 0;
}
body.mobile-ui .game-screen .map-background {
    order: 1;
}
body.mobile-ui .game-screen .map-navigation {
    order: 2;
}
body.mobile-ui .game-screen .battle-chat-row {
    order: 3;
}
body.mobile-ui .game-screen #statusBar,
body.mobile-ui .game-screen .bottom-bar {
    order: 4;
}
/* battleMonsterView는 map-background 위에 absolute 오버레이 */

/* ========== 1. 상단 헤더: 40px 고정 ========== */
body.mobile-ui .game-ui-overlay {
    position: relative;
    flex: 0 0 var(--mobile-header-height);
    min-height: var(--mobile-header-height);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    background: linear-gradient(to bottom, rgba(15, 12, 8, 0.98) 0%, rgba(35, 28, 18, 0.9) 100%);
    border-bottom: 2px solid #ffd700;
}

body.mobile-ui .game-ui-overlay .game-header h2 {
    display: none;
}

body.mobile-ui .game-ui-overlay .character-info {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 13px;
}

/* ========== 2. 메인 이미지/전투: flex 1.5 ========== */
body.mobile-ui .map-background {
    position: relative;
    flex: 1.5;
    min-height: 180px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

/* 전투 시 몬스터: 위에서 22% 위치 (아래로 조정), HP바는 이미지 바로 하단 */
body.mobile-ui .battle-monster-view {
    top: 22% !important;
    left: 50%;
    transform: translateX(-50%) !important;
    justify-content: flex-start;
    padding-top: 2%;
}

body.mobile-ui .battle-monster-list:not(.battle-monster-list-horizontal) .monster-slot-inner {
    padding-top: 0 !important;
}

body.mobile-ui .battle-monster-list:not(.battle-monster-list-horizontal) .monster-hp-bar {
    margin-top: 8px !important; /* 몬스터 이미지 바로 하단에 */
}

body.mobile-ui .battle-monster-list .monster-slot {
    max-width: 400px;
    width: 90vw;
    height: auto;
    min-height: 0;
}

body.mobile-ui .battle-monster-list .monster-slot img.monster-img {
    min-width: 200px !important;
    min-height: 240px !important;
    max-width: 360px !important;
    max-height: 400px !important;
    width: auto !important;
    height: auto !important;
}

/* ========== 3. 이동/NPC 버튼 (비전투 시) ========== */
body.mobile-ui .map-navigation {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    padding: 12px;
    border-bottom: 2px solid #ffd700;
    pointer-events: auto;
}

body.mobile-ui .map-navigation * {
    pointer-events: auto;
}

/* 이동가능한 장소: 한 줄에 3개 이상, 버튼 클릭 가능 */
body.mobile-ui .location-buttons {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

body.mobile-ui .location-buttons button,
body.mobile-ui .map-navigation button {
    min-height: var(--mobile-touch-min);
    width: 100%;
    padding: 12px 16px;
    font-size: 14px;
    pointer-events: auto !important;
    z-index: 10;
}

/* 전투 시 맵 네비게이션 숨김 (battle-mode에서 처리) */
body.mobile-ui.battle-mode .map-navigation {
    display: none !important;
}

/* ========== 4. 전투 버튼 영역: [파티|공격+퀵슬롯] 좌측 | [채팅] 우측(내정보 위) ========== */
body.mobile-ui .battle-chat-row {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
    position: relative;
    padding: 0;
    overflow: hidden;
}

/* 모바일 전투 시: Grid로 파티 위, 공격 아래, 채팅 우측 */
body.mobile-ui.battle-mode .battle-chat-row {
    display: grid !important;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "party chat"
        "attack chat";
    gap: 8px;
    padding: 8px;
}

body.mobile-ui.battle-mode .battle-chat-row .left-panel {
    display: flex !important;
    grid-area: party;
    flex-direction: column;
    min-width: 150px; /* 100 * 1.5 (파티창 1.5배에 맞춤) */
}

body.mobile-ui.battle-mode .left-panel .party-hud-container {
    flex: 0 0 auto;
}

/* 공격버튼 + 퀵슬롯: 채팅창 왼편, 파티 아래 */
body.mobile-ui.battle-mode .right-panel {
    display: flex !important;
    grid-area: attack;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    justify-content: flex-start;
    align-items: stretch;
    padding: 0;
}

/* 공격/스킬/마법/아이템/도망 버튼 (2배 크기) */
body.mobile-ui .battle-control-panel {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: auto;
    flex: 0 0 auto;
    min-width: 280px;
    padding: 12px;
}

/* 퀵슬롯: 공격버튼 바로 오른편 */
body.mobile-ui .battle-quickslots {
    display: flex !important;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    flex: 0 0 auto;
    min-width: 100px;
}

body.mobile-ui .battle-quickslots .quickslot-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

body.mobile-ui .battle-quickslots .quickslot-row {
    display: flex;
    gap: 6px;
}

/* 채팅창: 우측, 내정보 버튼 바로 위에 딱 붙음 */
body.mobile-ui.battle-mode .chat-window {
    grid-area: chat;
    min-width: 0;
}

body.mobile-ui .battle-control-panel .battle-action-btn {
    min-height: calc(var(--mobile-touch-min) * 1.5);
    width: 100%;
    font-size: 22px;
}

/* 퀵슬롯 X 버튼: 모바일에서 제거 */
body.mobile-ui .quickslot-unregister {
    display: none !important;
}

/* 전투 UI 드래그 핸들: 터치 영역 확대 */
body.mobile-ui.battle-mode .battle-action-drag-handle {
    min-height: var(--mobile-touch-min);
}
body.mobile-ui.battle-mode .battle-quickslots-drag-handle {
    min-height: var(--mobile-touch-min);
}

/* ========== 5. 채팅 영역: flex 1, 내부만 스크롤 ========== */
body.mobile-ui .battle-chat-row .chat-window,
body.mobile-ui #chatWindow {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.mobile-ui .chat-messages {
    flex: 1;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.4;
}

body.mobile-ui .chat-input {
    min-height: var(--mobile-touch-min);
    font-size: 16px;
    flex-shrink: 0;
}

body.mobile-ui .chat-send-btn {
    min-height: var(--mobile-touch-min);
    min-width: 60px;
}

body.mobile-ui .left-panel {
    display: none;
}

/* 비전투 시 right-panel 숨김 */
body.mobile-ui:not(.battle-mode) .right-panel {
    display: none !important;
}

/* ========== 6. 하단 상태바: flex 0, 내용만큼 ========== */
body.mobile-ui #statusBar,
body.mobile-ui .bottom-bar {
    position: relative !important; /* fixed → relative, flex 흐름에 포함 */
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    margin-top: 0;
    height: auto !important;
    min-height: auto;
}

body.mobile-ui .bottom-bar-buttons {
    display: none;
}

/* LV, AC, 성향, 무게, 배고픔 모두 모바일에서 표시 */
body.mobile-ui .status-icons {
    display: flex !important;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

body.mobile-ui .status-icons .status-icon {
    display: flex !important;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #ffd700;
}

body.mobile-ui #statusLevel .status-icon-label {
    font-weight: bold;
}

body.mobile-ui .status-icons .status-gauge-inline {
    min-width: 40px;
}

/* 파티/채팅 하단: 내정보, 인벤토리, LV, HP/MP 항상 표시 */
body.mobile-ui .mobile-quickbar-wrap {
    display: block !important;
    margin-bottom: 10px;
}

body.mobile-ui .bottom-bar {
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
}

body.mobile-ui .hpmp-magic-wrap {
    width: calc(100% - 20px);
    max-width: none;
    margin: 0 10px;
    flex-direction: column;
    gap: 8px;
}

body.mobile-ui .hpmp-magic-wrap .hpmp-bars {
    width: 100%;
    max-width: none;
}

body.mobile-ui .hp-bar-container,
body.mobile-ui .mp-bar-container {
    width: 100%;
}

body.mobile-ui .hp-bar,
body.mobile-ui .mp-bar {
    width: calc(100% - 20px);
    max-width: 100%;
}

body.mobile-ui .bottom-bar-right-group .magic-btn-wrap {
    display: none;
}

/* ========== 퀵바 버튼 ========== */
body.mobile-ui .mobile-quickbar {
    display: flex;
    justify-content: center;
    gap: 12px;
}

body.mobile-ui .mobile-quickbar .mobile-quick-btn {
    min-width: var(--mobile-touch-min);
    min-height: var(--mobile-touch-min);
    padding: 10px;
    font-size: 12px;
    border: 1px solid #ffd700;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: #ffd700;
    flex: 1;
    max-width: 80px;
}

/* ========== 버튼 터치 최소 크기 ========== */
body.mobile-ui button,
body.mobile-ui .menu-btn {
    min-height: var(--mobile-touch-min);
}

/* ========== 장비창/인벤토리 모바일 ========== */
body.mobile-ui .equipment_window,
body.mobile-ui .inventory-window-lineage {
    max-height: 80vh;
    overflow-y: auto;
}

/* ========== 모바일 로그인 화면 최적화 ========== */
body.mobile-ui #loginScreen {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

body.mobile-ui .login-container {
    padding: 16px;
}

body.mobile-ui .login-box {
    padding: 24px 20px;
}

body.mobile-ui .login-input {
    font-size: 16px;
    padding: 12px 16px;
}

body.mobile-ui .login-btn {
    min-width: 90px;
    min-height: 48px;
    padding: 12px 24px;
}

body.mobile-ui .login-copyright {
    margin-top: 24px;
    font-size: 11px;
}

body.mobile-ui .signup-button {
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
}
