/* ============================================================================
 * BlockMonster — 작은 화면 / safe-area / 디바이스 대응 보정
 * (이 파일은 가장 마지막에 로드되어 모든 인라인 스타일을 덮어씀)
 * ============================================================================ */

/* ── 동적 viewport (dvh) + 가로 스크롤 차단 ──────────────────────────────
 * 시스템바 / IME 영역은 네이티브 MainActivity 의 ViewCompat insets 로 처리됨
 * (WeekCash 방식 — Android root content 에 직접 padding 적용)
 * CSS 는 그 외 보정만:
 *   - height 100dvh 로 가용 영역 동적 추적
 *   - 가로 스크롤 차단
 * ────────────────────────────────────────────────────────────────────────── */
html, body {
    background: #0f0c29;
    height: 100vh;
    height: 100dvh;
    overscroll-behavior: none;
}

#loadingScreen,
#homeScreen,
#gameContainer,
#shopScreen,
#gachaScreen,
#dexScreen,
#rankScreen,
#collectionScreen,
#creatorScreen,
#stageSelectModal {
    box-sizing: border-box !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
}

#gameContainer canvas {
    max-width: 100% !important;
    max-height: 100% !important;
    display: block;
    margin: 0 auto;
}

/* 모달은 safe area 영역을 침범하지 않도록 */
.modal {
    padding: max(12px, env(safe-area-inset-top, 12px)) max(12px, env(safe-area-inset-right, 12px))
             max(12px, env(safe-area-inset-bottom, 12px)) max(12px, env(safe-area-inset-left, 12px)) !important;
    box-sizing: border-box !important;
}

/* 모달 콘텐츠가 화면 폭/높이를 절대 넘지 않게 */
.modal-content {
    max-width: min(92vw, 420px) !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* 인게임 정보 모달도 동일 */
#infoModal .modal-content,
#startModal .modal-content,
#helpModal .modal-content,
#tutorialModal .modal-content,
#gameOverModal .modal-content,
#monsterClearModal .modal-content,
#monsterDiffModal .modal-content,
#shopModal .modal-content,
#attendanceModal .modal-content {
    max-width: min(92vw, 420px) !important;
}

/* 풀스크린 화면들도 가로 스크롤 막기 */
#creatorScreen,
#dexScreen,
#rankScreen,
#shopScreen,
#collectionScreen,
#stageSelectModal,
#gachaScreen {
    overflow-x: hidden !important;
    max-width: 100vw !important;
}
#creatorScreen > div,
#dexScreen > div,
#rankScreen > div,
#shopScreen > div,
#stageSelectModal > div {
    max-width: min(100vw, 480px) !important;
    box-sizing: border-box;
}

/* ──────────────────────────────────────────────────────────────────────────
 * 타이틀 위아래 잘림 방지 — line-height + padding 보강 (전 화면 공통)
 * ────────────────────────────────────────────────────────────────────────── */
#loadingScreen .loading-title {
    line-height: 1.4 !important;
    padding: 8px 16px !important;
    /* text-shadow 가 위아래로 길어 잘려보이는 현상 완화 */
    text-shadow: 0 2px 8px rgba(0,0,0,0.7), 0 0 20px rgba(255,214,10,0.3) !important;
    /* 부모 폭에 맞춰 줄어들도록 */
    max-width: calc(100vw - 32px) !important;
    box-sizing: border-box !important;
}
#homeScreen .home-title {
    line-height: 1.4 !important;
    padding: 6px 14px !important;
    text-shadow: 0 1px 10px rgba(99,102,241,0.5), 0 0 24px rgba(0,0,0,0.7) !important;
    max-width: calc(100vw - 24px) !important;
    box-sizing: border-box !important;
    margin-bottom: 8px !important;
}
#homeTitleText {
    line-height: 1.4 !important;
    padding: 6px 14px !important;
    box-sizing: border-box !important;
}

/* ──────────────────────────────────────────────────────────────────────────
 * 작은 화면 (~ 380px : iPhone SE, Galaxy A 일부)
 * ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 380px) {

    /* 홈 타이틀 */
    #homeScreen .home-title { font-size: 26px !important; line-height: 1.45 !important; padding: 6px 12px !important; }
    #loadingScreen .loading-title { font-size: 28px !important; letter-spacing: 2px !important; line-height: 1.45 !important; padding: 6px 14px !important; }
    #loadingTagline { font-size: 14px !important; }

    /* 홈 상단 정보바 (열쇠/수정) */
    #homeScreen .home-top { padding: 12px 14px !important; }
    #homeScreen .home-stat { font-size: 11.5px !important; padding: 5px 9px !important; }

    /* 4개 유틸 버튼 (상점/사격/등급/보상) */
    #homeScreen .home-buttons,
    #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr 1fr"],
    #homeScreen > div[style*="grid-template-columns: 1fr 1fr 1fr 1fr"] {
        padding: 0 12px !important;
        gap: 6px !important;
    }
    #homeShopBtn,
    #homeGradeBtn,
    #homeRewardsBtn,
    #homeScreen button.home-btn.btn-shop,
    #homeScreen button.home-btn.btn-gacha,
    #homeScreen button.home-btn.btn-rank,
    #homeScreen button.home-btn.btn-badge {
        padding: 9px 0 !important;
        font-size: 13px !important;
    }

    /* 모드 버튼 3개 (몬스터/무한/STAGE) — 가장 깨지기 쉬운 부분 */
    #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr"],
    #homeScreen > div[style*="grid-template-columns: 1fr 1fr 1fr"] {
        padding: 0 12px !important;
        gap: 6px !important;
    }
    #homeScreen button.home-btn.btn-survival,
    #homeScreen button.home-btn.btn-endless,
    #homeSurvivalLabel,
    #homeEndlessLabel,
    #homeStageLabel {
        font-size: clamp(11px, 3.6vw, 16px) !important;
        white-space: nowrap !important;
        letter-spacing: -0.3px !important;
        display: block !important;
        overflow: hidden !important;
        text-overflow: clip !important;
    }
    /* 모드 버튼 본체 — 좌우 패딩 압축 (글자 영역 최대 확보) */
    #homeScreen button.home-btn.btn-survival,
    #homeScreen button.home-btn.btn-endless,
    #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr"] > button:last-child {
        padding-left: 2px !important;
        padding-right: 2px !important;
    }
    #monsterDailyLabel,
    #endlessDailyLabel,
    #stageModeLabel {
        font-size: clamp(9px, 2.8vw, 12px) !important;
        white-space: nowrap !important;
        letter-spacing: -0.3px !important;
        overflow: hidden !important;
        text-overflow: clip !important;
    }

    /* BGM 컨트롤 */
    #homeBgmBtn { font-size: 13px !important; padding: 7px 14px !important; min-width: 130px !important; }
    #homeBgmPrev, #homeBgmNext { font-size: 14px !important; padding: 7px 11px !important; }
    #homeBgmTitle { font-size: 14px !important; }

    /* 홈 하단 링크 (랭킹/도움말/제작/약관/언어) */
    #homeScreen .home-bottom { padding: 10px 8px 24px !important; }
    #homeScreen .home-bottom > div { gap: 6px !important; flex-wrap: wrap !important; justify-content: center !important; }
    #homeScreen .home-bottom-btn { padding: 6px 8px !important; font-size: 11px !important; }

    /* 모달 헤더 */
    .modal h2 { font-size: 20px !important; }
    .modal p { font-size: 13px !important; }
    .modal button { padding: 11px 24px !important; font-size: 14px !important; }

    /* 사격 (가챠) 화면 - 하단 버튼 */
    #gachaBottomBar { padding: 6px 8px !important; padding-bottom: max(6px, env(safe-area-inset-bottom)) !important; }
    #gachaHomeBtn, #gachaExchangeBtn { font-size: 12px !important; padding: 10px 28px !important; max-width: none !important; }

    /* 상점 화면 */
    #shopScreen > div > h1,
    #shopTitle { font-size: 22px !important; }
    #shopScreen button { font-size: 13px !important; }

    /* 등급/랭킹 화면 */
    #rankScreenTitle,
    #dexTitle,
    #shopTitle { font-size: 22px !important; }
    #rankContent table,
    #dexGrid { font-size: 11.5px !important; }

    /* 스테이지 선택 그리드 — 5칸이 너무 많은 경우 4칸으로 */
    #stageSelectList { grid-template-columns: repeat(4, 1fr) !important; }
}

/* ──────────────────────────────────────────────────────────────────────────
 * 매우 작은 화면 (~ 340px : iPhone 5/SE 1세대)
 * ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 340px) {
    #homeScreen .home-title { font-size: 22px !important; line-height: 1.5 !important; }
    #loadingScreen .loading-title { font-size: 24px !important; letter-spacing: 1.5px !important; }
    #homeScreen .home-top { padding: 10px 10px !important; }
    #homeScreen .home-stat { font-size: 10.5px !important; padding: 4px 7px !important; }

    #homeShopBtn, #homeGradeBtn, #homeRewardsBtn,
    #homeScreen button.home-btn.btn-shop,
    #homeScreen button.home-btn.btn-gacha,
    #homeScreen button.home-btn.btn-rank,
    #homeScreen button.home-btn.btn-badge {
        font-size: 11.5px !important; padding: 7px 0 !important;
    }
    #homeSurvivalLabel, #homeEndlessLabel, #homeStageLabel {
        font-size: clamp(10px, 3.4vw, 13px) !important;
        white-space: nowrap !important;
        letter-spacing: -0.5px !important;
        display: block !important;
        overflow: hidden !important;
    }
    #monsterDailyLabel, #endlessDailyLabel, #stageModeLabel {
        font-size: clamp(8.5px, 2.6vw, 10.5px) !important;
        white-space: nowrap !important;
        letter-spacing: -0.5px !important;
        overflow: hidden !important;
    }
    /* 모드 버튼 본체 패딩 더 축소 (320~340px) */
    #homeScreen button.home-btn.btn-survival,
    #homeScreen button.home-btn.btn-endless,
    #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr"] > button:last-child {
        padding-left: 1px !important;
        padding-right: 1px !important;
        padding-top: 10px !important;
        padding-bottom: 10px !important;
    }
    #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr"] {
        padding: 0 8px !important;
        gap: 4px !important;
    }

    #homeScreen .home-bottom-btn { font-size: 10px !important; padding: 5px 6px !important; }

    #stageSelectList { grid-template-columns: repeat(3, 1fr) !important; }
}

/* ──────────────────────────────────────────────────────────────────────────
 * 짧은 화면 (저높이 — 가로 모드 또는 작은 폰 height < 640)
 * ────────────────────────────────────────────────────────────────────────── */
@media (max-height: 640px) {
    #homeScreen .home-buttons { margin-top: 6vh !important; }
    #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr 1fr"] { margin-top: 6px !important; }
    #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr"] { margin-top: 8px !important; }
    .modal-content { padding: 18px 16px !important; }
    .modal h2 { margin-bottom: 10px !important; font-size: 18px !important; }
    #loadingScreen .loading-title { top: calc(100% * 2 / 7 - 10px) !important; }
}

/* ──────────────────────────────────────────────────────────────────────────
 * 입력 필드 — iOS 자동 줌 방지 (font-size 16px 이상)
 * ────────────────────────────────────────────────────────────────────────── */
input[type=text],
input[type=email],
input[type=password],
input[type=number],
select,
textarea {
    font-size: 16px !important;
}

/* ──────────────────────────────────────────────────────────────────────────
 * 게임 진행 중 우발적 터치 동작 방지
 * ────────────────────────────────────────────────────────────────────────── */
* {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
button, [onclick] {
    -webkit-user-select: none;
    user-select: none;
}

/* 가로 스크롤 자체를 차단 */
html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
}

/* ────────────────────────────────────────────────────────────────────
 * 🚫 상단 안테나/상태바 영역 제거 (사용자 요청)
 *   - WebView 가 화면 끝(top:0)까지 확장
 *   - safe-area-inset-top 0 으로 강제 (안전 영역 공간 미사용)
 *   - 단, 동적 오버레이 (백키 다이얼로그 등) 는 inset 유지 (가독성)
 * ──────────────────────────────────────────────────────────────────── */
html, body {
    padding-top: 0 !important;
    margin-top: 0 !important;
}
#loadingScreen,
#homeScreen,
#gameContainer {
    padding-top: 0 !important;
    top: 0 !important;
}
/* iOS 노치 / Android 카메라 컷아웃 영역은 그대로 유지 (게임 영역 침범 방지) */
@supports (padding: env(safe-area-inset-top)) {
    #homeScreen .home-top,
    #gameContainer { padding-top: env(safe-area-inset-top, 0) !important; }
}

/* ════════════════════════════════════════════════════════════════════
 * 📱 태블릿 — 600px 이상 / 900px 이상 (가로/세로 큰 기기)
 *   홈 화면 + 모달 + 게임 캔버스를 더 넓게 사용
 * ═══════════════════════════════════════════════════════════════════ */
@media (min-width: 600px), (min-height: 900px) {
  /* 홈 화면 — 컨테이너를 넓게 확장 */
  #homeScreen .home-buttons,
  #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr 1fr"],
  #homeScreen > div[style*="grid-template-columns: 1fr 1fr 1fr 1fr"],
  #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr"],
  #homeScreen > div[style*="grid-template-columns: 1fr 1fr 1fr"] {
    max-width: 560px !important;
    padding-left: 20px !important;
    padding-right: 20px !important;
    gap: 14px !important;
  }
  /* 홈 타이틀 키우기 */
  #homeScreen .home-title,
  #homeTitleText {
    font-size: 44px !important;
    padding: 10px 20px !important;
  }
  /* 홈 상단 정보 (등급/열쇠/수정) — 더 크게 */
  #homeScreen .home-stat {
    font-size: 17px !important;
    padding: 9px 18px !important;
    gap: 6px !important;
  }
  /* 홈 모드 버튼 더 크게 */
  #homeScreen button.home-btn {
    font-size: 21px !important;
  }
  #homeSurvivalLabel, #homeEndlessLabel, #homeStageLabel {
    font-size: 22px !important;
  }
  #monsterDailyLabel, #endlessDailyLabel, #stageModeLabel {
    font-size: 16px !important;
  }
  /* 모달 — 태블릿에선 넉넉히 */
  .modal-content {
    max-width: 540px !important;
    padding: 28px 32px !important;
  }
  .modal h2 { font-size: 26px !important; }
  .modal p  { font-size: 16px !important; }
  .modal button { font-size: 17px !important; padding: 14px 32px !important; }

  /* 게임 캔버스 컨테이너 — 가운데 정렬 + 자연스럽게 (cellSize 가 알아서 키움) */
  #gameContainer {
    margin: 0 auto !important;
    max-width: none !important;
  }
  #gameContainer canvas {
    display: block;
    margin: 0 auto;
  }
  /* BGM 컨트롤 — 태블릿에서 더 크게 */
  #homeBgmBtn { font-size: 18px !important; padding: 12px 28px !important; min-width: 220px !important; }
  #homeBgmPrev, #homeBgmNext { font-size: 20px !important; padding: 11px 18px !important; }
  #homeBgmTitle { font-size: 20px !important; }
  /* 하단 버튼 (랭킹/도움말/제작/약관/언어) */
  #homeScreen .home-bottom-btn {
    font-size: 14px !important;
    padding: 10px 18px !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * 🏹 가챠/사격 화면 — 좁은 폰 (폴드 등) 가로폭 깨짐 방지
 * ═══════════════════════════════════════════════════════════════════ */

/* 🌐 가챠 상단 — 모든 화면에서 카운터 nowrap + 라벨 한 줄 강제 (글로벌) */
#gachaCurrencyLabel, #gachaItemsLabel {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: clip !important;
}
#gachaScreen span[style*="background:rgba(255,255,255,0.08)"],
#gachaScreen span[style*="background:rgba(255,200,50,0.15)"],
#gachaScreen span[style*="background:rgba(100,200,255,0.15)"],
#gachaScreen span[style*="background:rgba(255,120,50,0.15)"],
#gachaScreen span[style*="background:rgba(80,200,120,0.15)"] {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: clip !important;
  min-width: 0 !important;
}
/* 🌐 가챠 상단 — clamp() 로 자동 스케일 (좁을수록 작게, 부드럽게) */
@media (max-width: 420px) {
  #gachaCurrencyLabel, #gachaItemsLabel {
    font-size: clamp(9px, 3.2vw, 14px) !important;
    letter-spacing: -0.2px !important;
    padding: 2px 4px !important;
  }
  #gachaKeys, #gachaGems, #gachaLightnings, #gachaMissiles, #gachaFlames, #gachaBoomerangs {
    font-size: clamp(9px, 3vw, 13px) !important;
  }
}

@media (max-width: 380px) {
  /* 상단 정보바 — 글자 + 패딩 압축 */
  #gachaCurrencyLabel, #gachaItemsLabel {
    font-size: 11px !important;
    padding: 2px 4px !important;
    letter-spacing: -0.3px !important;
  }
  /* 재화/아이템 카운터 — 한 줄에 다 들어가게 */
  #gachaKeys, #gachaGems, #gachaLightnings, #gachaMissiles, #gachaFlames, #gachaBoomerangs {
    font-size: 11px !important;
  }
  #gachaScreen .gachaCounter,
  #gachaScreen [id^="gacha"][id$="s"] {
    font-size: 11px !important;
  }
  /* 상단 컨테이너 자체 압축 */
  #gachaScreen > div > div[style*="background:rgba(60,35,10"] {
    padding: 5px 4px 4px !important;
  }
  #gachaScreen > div > div[style*="background:rgba(60,35,10"] > div {
    gap: 3px !important;
  }
  /* 카운터 박스 패딩 */
  #gachaScreen span[style*="background:rgba(255,255,255,0.08)"],
  #gachaScreen span[style*="background:rgba(255,200,50,0.15)"],
  #gachaScreen span[style*="background:rgba(100,200,255,0.15)"],
  #gachaScreen span[style*="background:rgba(255,120,50,0.15)"],
  #gachaScreen span[style*="background:rgba(80,200,120,0.15)"] {
    padding: 3px 1px !important;
    font-size: 11px !important;
  }
  /* 하단 바람 안내 */
  #gachaWindHint { font-size: 10.5px !important; margin-bottom: 4px !important; letter-spacing: -0.3px !important; }
  /* 하단 버튼 (홈/교환/TIP) — 한 줄 강제, 가로 압축 */
  #gachaScreen #gachaBottomBar { padding: 6px 6px !important; }
  #gachaScreen #gachaBottomBar > div { gap: 4px !important; flex-wrap: nowrap !important; }
  #gachaScreen #gachaBottomBar button {
    font-size: 11.5px !important;
    padding: 9px 2px !important;
    letter-spacing: -0.3px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: clip !important;
    min-width: 0 !important;
  }
  /* TIP(❗) 버튼 */
  #gachaScreen #gachaBottomBar button[style*="width:44px"] {
    width: 34px !important; font-size: 14px !important; flex-shrink: 0 !important;
  }
  /* 홈이동 버튼 — 글자 폭에 맞춤 */
  #gachaHomeBtn {
    width: auto !important;
    flex-shrink: 0 !important;
    font-size: 12px !important;
    padding: 9px 34px !important;
    white-space: nowrap !important;
  }
  #gachaExchangeBtn {
    flex: 1 !important;
    max-width: none !important;
    font-size: 12px !important;
    padding: 9px 4px !important;
  }
}

/* 📱 폴드 (~320px) — 극단적 압축 */
@media (max-width: 320px) {
  #gachaCurrencyLabel, #gachaItemsLabel { font-size: 9.5px !important; letter-spacing: -0.5px !important; }
  #gachaKeys, #gachaGems, #gachaLightnings, #gachaMissiles, #gachaFlames, #gachaBoomerangs {
    font-size: 9.5px !important;
    letter-spacing: -0.3px !important;
  }
  #gachaScreen > div > div[style*="background:rgba(60,35,10"] > div {
    gap: 2px !important;
  }
  #gachaScreen > div > div[style*="background:rgba(60,35,10"] {
    padding: 5px 3px 4px !important;
  }
  #gachaScreen span[style*="background:rgba(255,255,255,0.08)"],
  #gachaScreen span[style*="background:rgba(255,200,50,0.15)"],
  #gachaScreen span[style*="background:rgba(100,200,255,0.15)"],
  #gachaScreen span[style*="background:rgba(255,120,50,0.15)"],
  #gachaScreen span[style*="background:rgba(80,200,120,0.15)"] {
    padding: 2px 1px !important;
    font-size: 9.5px !important;
    border-width: 0.5px !important;
    border-radius: 6px !important;
  }
  /* 하단 바 320px */
  #gachaScreen #gachaBottomBar { padding: 5px 4px !important; }
  #gachaScreen #gachaBottomBar > div { gap: 3px !important; }
  #gachaScreen #gachaBottomBar button {
    font-size: 10.5px !important;
    padding: 8px 1px !important;
    letter-spacing: -0.5px !important;
  }
  #gachaScreen #gachaBottomBar button[style*="width:44px"] {
    width: 28px !important; font-size: 12px !important; padding: 8px 0 !important;
  }
  #gachaHomeBtn {
    width: auto !important;
    font-size: 11px !important;
    padding: 8px 28px !important;
    white-space: nowrap !important;
  }
  #gachaExchangeBtn {
    font-size: 10.5px !important;
    padding: 8px 2px !important;
  }
}

/* 📱 폴드 접힘 (~280px) — Galaxy Z Fold 외부 화면 가장 좁은 상태 */
@media (max-width: 280px) {
  #gachaCurrencyLabel, #gachaItemsLabel {
    font-size: 8.5px !important;
    letter-spacing: -0.6px !important;
    padding: 1px 2px !important;
  }
  /* "🎒 아이템 (최대 99)" 가 안 들어가면 줄임 */
  #gachaCurrencyLabel { padding-right: 3px !important; }
  #gachaItemsLabel { padding: 1px 0 !important; }
  #gachaKeys, #gachaGems, #gachaLightnings, #gachaMissiles, #gachaFlames, #gachaBoomerangs {
    font-size: 8.5px !important;
    letter-spacing: -0.4px !important;
  }
  #gachaScreen > div > div[style*="background:rgba(60,35,10"] {
    padding: 3px 2px 2px !important;
  }
  #gachaScreen > div > div[style*="background:rgba(60,35,10"] > div {
    gap: 1px !important;
  }
  #gachaScreen span[style*="background:rgba(255,255,255,0.08)"],
  #gachaScreen span[style*="background:rgba(255,200,50,0.15)"],
  #gachaScreen span[style*="background:rgba(100,200,255,0.15)"],
  #gachaScreen span[style*="background:rgba(255,120,50,0.15)"],
  #gachaScreen span[style*="background:rgba(80,200,120,0.15)"] {
    padding: 1px 0 !important;
    font-size: 8.5px !important;
    border-radius: 4px !important;
    border-width: 0 !important;
  }
  /* 하단 안내문 */
  #gachaWindHint { font-size: 9px !important; letter-spacing: -0.6px !important; margin-bottom: 3px !important; }
  /* 하단 버튼 — 한 줄 강제 */
  #gachaScreen #gachaBottomBar { padding: 4px 3px !important; }
  #gachaScreen #gachaBottomBar > div { gap: 2px !important; }
  #gachaScreen #gachaBottomBar button {
    font-size: 9px !important;
    padding: 6px 1px !important;
    letter-spacing: -0.6px !important;
  }
  #gachaScreen #gachaBottomBar button[style*="width:44px"] {
    width: 24px !important; font-size: 11px !important; padding: 6px 0 !important;
  }
  #gachaHomeBtn {
    width: auto !important;
    font-size: 10px !important;
    padding: 6px 24px !important;
    white-space: nowrap !important;
  }
  #gachaExchangeBtn {
    font-size: 9px !important;
    padding: 6px 1px !important;
  }
}

/* 📱 큰 태블릿 (810px+, iPad Pro) — 더 크게 */
@media (min-width: 810px) {
  #homeScreen .home-title, #homeTitleText { font-size: 52px !important; }
  #homeScreen .home-stat { font-size: 19px !important; padding: 11px 22px !important; }
  #homeScreen button.home-btn { font-size: 24px !important; }
  #homeSurvivalLabel, #homeEndlessLabel, #homeStageLabel { font-size: 26px !important; }
  #monsterDailyLabel, #endlessDailyLabel, #stageModeLabel { font-size: 18px !important; }
}

/* ════════════════════════════════════════════════════════════════════
 * 🔧 폴드/소형 단말 종합 보강 (2026-05-24)
 *   Galaxy Z Fold 접힘 (~280px), Z Flip 접힘, 초소형 단말 대응
 *   - 가로 패딩 압축 (좌우 X자가 좁아도 컨텐츠 영역 최대 확보)
 *   - 폰트 클램프 (vw 기반 자동 스케일)
 *   - 동적 오버레이 (#bmAuthOverlay / #bmInGameQuit / #bmExitConfirm / #bmBackToast) 대응
 * ═══════════════════════════════════════════════════════════════════ */

/* 🌐 글로벌 — clamp() 로 큰 폰트 자동 축소 (모든 화면) */
@media (max-width: 420px) {
  /* 큰 헤더/타이틀: 28px → 22px ~ 28px 사이 자동 (좁을수록 작게) */
  h1, .home-title, .loading-title {
    font-size: clamp(20px, 6vw, 30px) !important;
  }
  /* 모달 헤더: 22px → 17px ~ 22px */
  .modal h2 {
    font-size: clamp(16px, 5vw, 22px) !important;
  }
  /* 모달 본문: 14~15px → 12~15px */
  .modal p, .modal-content p {
    font-size: clamp(12px, 3.6vw, 15px) !important;
    line-height: 1.55 !important;
  }
  /* 모달 컨테이너 패딩 — 좌우 절반으로 */
  .modal-content {
    padding: 18px 14px !important;
    max-width: 92vw !important;
  }
  /* 동적 오버레이 (Capacitor 백키 다이얼로그, 로그인, 점검 등) */
  [id^="bm"][id$="Confirm"] > div,
  #bmInGameQuit > div,
  #bmAuthOverlay > div,
  #bmExitConfirm > div,
  #bmBackToast {
    max-width: 90vw !important;
    padding: 20px 16px !important;
  }
  #bmBackToast {
    padding: 12px 16px !important;
    font-size: 13px !important;
  }
}

/* 📱 작은 화면 강화 (~ 360px) — 추가 패딩 압축 */
@media (max-width: 360px) {
  body, html { padding: 0 !important; margin: 0 !important; }

  /* 홈 좌우 패딩 모두 8px 로 통일 */
  #homeScreen > div[style*="padding"] {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
  #homeScreen .home-top { padding: 10px 10px !important; }
  #homeScreen .home-stat { font-size: 11px !important; padding: 4px 8px !important; gap: 3px !important; }
  #homeScreen .home-buttons,
  #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr 1fr"],
  #homeScreen > div[style*="grid-template-columns: 1fr 1fr 1fr 1fr"],
  #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr"],
  #homeScreen > div[style*="grid-template-columns: 1fr 1fr 1fr"] {
    padding-left: 8px !important;
    padding-right: 8px !important;
    gap: 5px !important;
  }
  /* 홈 하단 버튼들 (랭킹/도움말/제작/약관/언어) — 1줄로 압축 */
  #homeScreen .home-bottom {
    padding: 8px 6px 18px !important;
  }
  #homeScreen .home-bottom > div {
    gap: 4px !important;
  }
  #homeScreen .home-bottom-btn {
    padding: 5px 6px !important;
    font-size: 10.5px !important;
    letter-spacing: -0.3px !important;
  }
  /* 모달 패딩 더 압축 */
  .modal-content {
    padding: 16px 12px !important;
  }
  /* 게임오버/시작전 등 일반 모달 버튼 */
  .modal button {
    padding: 10px 18px !important;
    font-size: 13px !important;
    margin: 4px !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * 🔧 홈 상단 영역 — 모든 화면 통합 보강 (2026-05-27)
 *   닉네임 / 등급 / 열쇠 / 수정 카운터 — 좁은 폰에서 깨짐 방지
 *   clamp() 로 자동 스케일링 + 좌우 wrap 허용
 * ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  /* 홈 상단 컨테이너 — wrap 허용 + gap 압축 */
  #homeScreen .home-top {
    flex-wrap: wrap !important;
    gap: 6px !important;
    padding: 10px 12px !important;
    row-gap: 6px !important;
  }
  /* 상단 좌/우 그룹 — wrap 가능 */
  #homeScreen .home-top > div {
    flex-wrap: wrap !important;
    gap: 4px !important;
    min-width: 0 !important;
  }
  /* 등급 / 열쇠 / 수정 카운터 — clamp 자동 축소 */
  #homeScreen .home-stat {
    font-size: clamp(10px, 3vw, 13px) !important;
    padding: clamp(3px, 1vw, 6px) clamp(6px, 2vw, 12px) !important;
    gap: 3px !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  /* 등급 이름 / 닉네임 — 너무 길면 자르기 */
  #homeRankName, #homeNickname, #homeKeys, #homeGems {
    max-width: 30vw !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    display: inline-block !important;
    vertical-align: middle !important;
  }
  /* 프로필 버튼 — 좁은 화면에서 작게 */
  #homeProfileBtn {
    width: clamp(28px, 8vw, 38px) !important;
    height: clamp(28px, 8vw, 38px) !important;
  }
  #homeProfileBtn svg {
    width: clamp(16px, 5vw, 22px) !important;
    height: clamp(16px, 5vw, 22px) !important;
  }
  /* 광고PASS / 관리자 라벨 — 폴드에서 짧게 */
  #homeAdPassLabel, #homeAdminLabel {
    font-size: clamp(9px, 2.6vw, 13px) !important;
    padding: 2px 6px !important;
    border-radius: 6px !important;
    background: rgba(0,0,0,0.45);
    color: #d8b4fe;
  }
}

/* 📱 폴드 화면 (~ 320px) — Galaxy Z Fold 접힘 / Z Flip 접힘 */
@media (max-width: 320px) {
  /* 홈 상단 — 한 줄에 다 들어가도록 극단적 압축 */
  #homeScreen .home-top {
    padding: 7px 8px !important;
    gap: 4px !important;
  }
  #homeScreen .home-top > div {
    gap: 3px !important;
  }
  #homeScreen .home-stat {
    font-size: 9.5px !important;
    padding: 3px 5px !important;
    gap: 2px !important;
    letter-spacing: -0.3px !important;
  }
  /* 닉네임/등급 이름 — 폴드 폭의 22%까지만 */
  #homeRankName, #homeNickname {
    max-width: 22vw !important;
    font-size: 9.5px !important;
  }
  /* 카운터 (열쇠/수정) — 숫자만 압축 */
  #homeKeys, #homeGems {
    max-width: 18vw !important;
    font-size: 9.5px !important;
  }
  #homeProfileBtn {
    width: 28px !important;
    height: 28px !important;
  }
  #homeProfileBtn svg {
    width: 15px !important;
    height: 15px !important;
  }
}

/* 📱 폴드 화면 (~ 320px) — Galaxy Z Fold 접힘 / Z Flip 접힘 */
@media (max-width: 320px) {
  #homeScreen .home-title { font-size: 20px !important; padding: 4px 8px !important; }
  #loadingScreen .loading-title { font-size: 20px !important; letter-spacing: 1px !important; }
  #homeScreen .home-top { padding: 8px 8px !important; }
  #homeScreen .home-stat { font-size: 10px !important; padding: 3px 6px !important; }

  /* 그리드 갭/패딩 더 좁힘 */
  #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr 1fr"],
  #homeScreen > div[style*="grid-template-columns: 1fr 1fr 1fr 1fr"],
  #homeScreen > div[style*="grid-template-columns:1fr 1fr 1fr"],
  #homeScreen > div[style*="grid-template-columns: 1fr 1fr 1fr"] {
    padding-left: 6px !important;
    padding-right: 6px !important;
    gap: 4px !important;
  }

  #homeShopBtn, #homeGradeBtn, #homeRewardsBtn,
  #homeScreen button.home-btn.btn-shop,
  #homeScreen button.home-btn.btn-gacha,
  #homeScreen button.home-btn.btn-rank,
  #homeScreen button.home-btn.btn-badge {
    font-size: 10.5px !important;
    padding: 6px 0 !important;
  }
  #homeSurvivalLabel, #homeEndlessLabel, #homeStageLabel {
    font-size: 11.5px !important;
    letter-spacing: -0.5px !important;
  }
  #monsterDailyLabel, #endlessDailyLabel, #stageModeLabel {
    font-size: 9.5px !important;
  }

  #homeScreen .home-bottom-btn {
    padding: 4px 5px !important;
    font-size: 9.5px !important;
    letter-spacing: -0.5px !important;
  }
  /* 하단 5개 버튼이 안 들어가면 wrap (다음 줄로) */
  #homeScreen .home-bottom > div {
    flex-wrap: wrap !important;
  }

  /* BGM 컨트롤 */
  #homeBgmBtn {
    font-size: 11px !important;
    padding: 6px 10px !important;
    min-width: 110px !important;
  }
  #homeBgmPrev, #homeBgmNext {
    font-size: 12px !important;
    padding: 5px 8px !important;
  }
  #homeBgmTitle { font-size: 12px !important; }

  /* 모달 — 화면 90% 사용, 패딩 최소 */
  .modal-content {
    padding: 14px 10px !important;
    max-width: 94vw !important;
    border-radius: 14px !important;
  }
  .modal h2 { font-size: 17px !important; margin-bottom: 10px !important; }
  .modal p { font-size: 12px !important; line-height: 1.5 !important; }
  .modal button {
    padding: 9px 14px !important;
    font-size: 12.5px !important;
    margin: 3px !important;
    border-radius: 10px !important;
  }

  /* 동적 오버레이 (백키 / 로그인 / 종료확인) */
  #bmInGameQuit > div,
  #bmAuthOverlay > div,
  #bmExitConfirm > div {
    padding: 16px 12px !important;
    max-width: 94vw !important;
    border-radius: 14px !important;
  }
  #bmBackToast {
    padding: 10px 14px !important;
    font-size: 12px !important;
    max-width: 90vw !important;
  }

  /* 가챠/상점/약관 화면 */
  #shopScreen > div > h1,
  #shopTitle,
  #rankScreenTitle,
  #dexTitle { font-size: 18px !important; padding: 6px 10px !important; }
  #shopScreen button { font-size: 11px !important; padding: 7px 6px !important; }

  /* 도움말 모달 탭 */
  #helpTabs button {
    font-size: 10.5px !important;
    padding: 5px 4px !important;
    letter-spacing: -0.7px !important;
  }

  /* 스테이지 선택 그리드 — 3칸으로 */
  #stageSelectList { grid-template-columns: repeat(3, 1fr) !important; gap: 6px !important; }
  #stageSelectList > * { font-size: 11px !important; }
}

/* 📱 초소형 (~ 280px) — Galaxy Z Fold 가장 좁은 상태 */
@media (max-width: 280px) {
  #homeScreen .home-title { font-size: 17px !important; }
  #loadingScreen .loading-title { font-size: 17px !important; }
  .modal-content { padding: 12px 8px !important; }
  .modal h2 { font-size: 15px !important; }
  .modal p { font-size: 11px !important; }
  .modal button { font-size: 11.5px !important; padding: 7px 12px !important; }
}

/* ──────────────────────────────────────────────────────────────────────────
 * 글자 위/아래가 짤려 보이는 일반 케이스 방지
 * (한글 자모 받침의 baseline descender / 폰트 line-box 누락 보정)
 * ────────────────────────────────────────────────────────────────────────── */
h1, h2, h3, .home-title, .loading-title,
[class*="title"], [id*="title"], [id*="Title"] {
    line-height: 1.4 !important;
    /* 글자 위/아래 충분한 여백 */
    padding-top: 0.15em;
    padding-bottom: 0.15em;
}
