/* ============================================================
   Mobile H5 Responsive CSS - 武侠江湖
   针对手机竖屏优化：大按钮、大字体、易点击
   ============================================================ */

/* ── 全局触屏优化 ── */
@media (pointer: coarse) {
  /* 所有可点击元素最小48px触控区 */
  .btn, .hud-btn, .bag-tab, .item-equip-btn, .dialogue-option,
  #auto-battle-btn, #exit-battle-btn, #battle-speed-btn,
  .btn-craft, .pill-select-item .ps-set, #invite-btn, #npc-items-btn, #npc-spar-btn, #kick-btn {
    min-height: 48px;
    min-width: 48px;
    font-size: 17px !important;
    padding: 12px 20px;
    -webkit-tap-highlight-color: rgba(240,192,64,0.2);
  }
  .hud-btn { padding: 10px 16px; font-size: 16px !important; }
  .bag-tab { padding: 10px 14px; font-size: 15px !important; min-height: 44px; }
  .dialogue-option { padding: 14px 18px; font-size: 17px !important; line-height: 1.6; }
  .item-card { padding: 14px 16px; gap: 14px; }
  .item-name { font-size: 18px; }
  .item-type { font-size: 16px; }
  .equip-slot { min-height: 76px; }
  .equip-slot .slot-icon { font-size: 32px; }
  .equip-slot .slot-label { font-size: 14px; }
  .equip-slot .slot-item { font-size: 14px; }
  .skill-slot { padding: 14px; }
  .skill-slot-name { font-size: 17px; }
  .skill-slot-label { font-size: 15px; }
  .attr-grid { font-size: 16px; gap: 8px 20px; }
  .wild-card h3 { font-size: 20px; }
  .wild-card p { font-size: 16px; }
  .wild-card .wild-level { font-size: 15px; }
  .log-entry { font-size: 16px; padding: 5px 0; }
  #battle-log { font-size: 16px; }
  .panel-title { font-size: 22px; }
  .pharmacy-recipe h3 { font-size: 18px; }
  .pharmacy-recipe .recipe-desc { font-size: 15px; }
  .recipe-ingredients { font-size: 15px; }
  .herb-card h3 { font-size: 18px; }
  .herb-card p { font-size: 15px; }
  .herb-status { font-size: 15px; }
  .msg-bubble { font-size: 17px; padding: 12px 16px; line-height: 1.7; }
  .dlg-bubble { font-size: 16px; line-height: 1.7; padding: 10px 14px; }
  .detail-name { font-size: 22px; }
  .detail-type { font-size: 16px; }
  .detail-stat { font-size: 16px; }
  .result-title { font-size: 28px; }
  .result-drop-item { font-size: 17px; }
  .member-name { font-size: 16px; }
  .battle-name { font-size: 17px; }
  .battle-num { font-size: 13px; }
  .pill-select-item { padding: 10px 12px; }
  .pill-select-item .ps-name { font-size: 15px; }
  .pill-select-item .ps-count { font-size: 14px; }
  .pill-select-item .ps-set { padding: 6px 14px; font-size: 14px; min-height: 40px; }
  #combat-pill-slot .pill-name { font-size: 15px; }
  #combat-pill-slot .pill-desc { font-size: 13px; }
  #combat-pill-slot .pill-icon { font-size: 26px; }
  .recipe-own { font-size: 14px; }
  .med-inv-item { font-size: 15px; }
  .herb-inv-item { font-size: 15px; }
  .gather-inv-title { font-size: 16px; }
  .tip-affix { font-size: 15px; }
}

/* ============================================================
   手机竖屏 (Portrait)
   ============================================================ */
@media screen and (max-width: 768px) and (orientation: portrait) {
  body {
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    font-size: 16px;
  }

  #game-container {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    transform: none !important;
    margin: 0 !important;
  }

  canvas#game-canvas {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
  }

  #ui-overlay {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
  }

  /* ── 顶部状态栏 HUD（固定在最上方） ── */
  #hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 8px 14px;
    pointer-events: auto;
    z-index: 450;
  }
  #hud-name { font-size: 20px; }
  .hud-bar-label { font-size: 15px; }
  .hud-bar-bg { width: 90px; height: 14px; border-radius: 7px; }
  .hud-bar-num { font-size: 14px; }
  #hud-exp { font-size: 15px !important; }
  #hud-level { font-size: 15px !important; }
  #hud-copper { font-size: 15px !important; }
  #hud-location { font-size: 15px; margin-left: 0; }

  /* ── 底部导航栏 ── */
  #hud-buttons {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-around;
    gap: 0;
    padding: 2px 0;
    padding-bottom: max(2px, env(safe-area-inset-bottom));
    background: linear-gradient(0deg, rgba(12,5,0,0.98) 0%, rgba(20,8,0,0.95) 100%);
    border-top: 1px solid rgba(200,150,12,0.5);
    z-index: 500;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.5);
  }
  #hud-buttons .hud-btn {
    flex: 1;
    text-align: center;
    padding: 12px 2px;
    font-size: 15px !important;
    border-radius: 0;
    border: none;
    border-right: 1px solid rgba(200,150,12,0.2);
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
  }
  #hud-buttons .hud-btn:last-child { border-right: none; }

  /* ── 侧面板全屏覆盖 ── */
  .side-panel {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    border: none !important;
    padding: 64px 16px 40px;
    z-index: 400 !important;
  }

  /* ── 大地图列表面板 ── */
  #worldmap-panel {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    padding: 64px 12px 40px !important;
    border: none !important;
    z-index: 400 !important;
  }
  .map-section-title {
    font-size: 18px !important;
    padding: 14px 0 8px !important;
  }
  .map-loc-card {
    padding: 14px 14px !important;
    margin-bottom: 8px !important;
    gap: 14px !important;
  }
  .map-loc-icon {
    width: 56px !important;
    height: 56px !important;
    font-size: 28px !important;
  }
  .map-loc-name {
    font-size: 17px !important;
  }
  .map-loc-desc {
    font-size: 14px !important;
    white-space: normal !important;
    line-height: 1.4;
  }
  .map-loc-level {
    font-size: 13px !important;
  }

  /* ── 设置按钮 ── */
  #hud-settings-btn {
    font-size: 20px !important;
    padding: 8px 12px !important;
    min-width: 44px;
    min-height: 44px;
  }
  #settings-dropdown {
    min-width: 160px !important;
  }
  #settings-dropdown button {
    padding: 14px 18px !important;
    font-size: 16px !important;
    min-height: 48px;
  }

  /* ── 背包Tab ── */
  #bag-tabs {
    gap: 6px !important;
    margin-bottom: 12px !important;
  }
  #bag-tabs .bag-tab {
    flex: 1 1 auto;
    text-align: center;
    min-width: 0;
    padding: 10px 8px;
    font-size: 14px !important;
  }

  /* ── 装备格子 ── */
  .equip-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
  .equip-slot {
    min-height: 80px;
    padding: 8px;
  }

  /* ── NPC对话面板 ── */
  #dialogue-panel {
    height: 60vh !important;
    max-height: 60vh;
    border-radius: 16px 16px 0 0;
  }
  #dialogue-panel #dialogue-header {
    padding: 14px 18px !important;
  }
  #dialogue-panel #npc-avatar {
    width: 56px !important;
    height: 56px !important;
    font-size: 32px !important;
  }
  #dialogue-panel #npc-name {
    font-size: 20px !important;
  }
  #dialogue-panel #npc-title {
    font-size: 14px !important;
  }
  #dialogue-panel #dialogue-body {
    padding: 12px 18px !important;
  }
  #dialogue-panel #dialogue-footer {
    padding: 10px 16px !important;
    gap: 10px !important;
  }
  #dialogue-panel #dialogue-footer button {
    font-size: 15px !important;
    padding: 10px 16px !important;
    min-height: 44px;
  }
  #dialogue-panel #close-dialogue {
    font-size: 24px !important;
    padding: 8px 12px !important;
    min-width: 44px;
    min-height: 44px;
  }
  #favor-bar {
    height: 8px !important;
  }

  /* ── 战斗面板 ── */
  #battle-panel {
    top: 64px !important;
    padding: 10px 8px 40px;
  }
  #battle-scene {
    flex-direction: column;
    gap: 6px;
    justify-content: space-between;
  }
  .battle-vs {
    font-size: 18px;
    padding: 4px 0;
  }
  .battle-side {
    max-width: 100% !important;
    width: 100% !important;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }
  .battle-entity {
    max-width: 48% !important;
    min-width: 130px;
    flex: 1 1 45%;
  }
  .battle-plate {
    height: 46px;
    border-radius: 4px;
  }
  .battle-name { font-size: 14px; letter-spacing: 2px; }
  .battle-num { font-size: 11px; }
  #battle-log {
    height: 120px;
    font-size: 15px;
    padding: 10px 14px;
  }
  #battle-controls {
    flex-wrap: wrap;
    gap: 10px;
    padding-bottom: 10px;
  }
  #battle-controls button {
    flex: 1;
    min-width: 100px;
    min-height: 52px;
    font-size: 16px !important;
  }
  #battle-loop-info { font-size: 15px; }

  /* ── 野外面板 ── */
  #wilderness-panel {
    top: 64px !important;
    padding: 16px 14px 40px;
  }
  .wild-card {
    padding: 18px;
    margin-bottom: 12px;
  }

  /* ── 采药面板 ── */
  #gather-panel {
    top: 64px !important;
    padding: 16px 14px 40px;
  }

  /* ── 新游戏弹窗 ── */
  #newgame-modal .ng-box {
    min-width: unset !important;
    width: 94vw;
    padding: 28px 18px;
  }
  #newgame-modal .ng-title {
    font-size: 24px;
    letter-spacing: 4px;
  }
  #newgame-modal .ng-subtitle { font-size: 14px; }
  .ng-gender-option { width: 120px; }
  .ng-gender-img { width: 90px; height: 90px; }
  .ng-gender-label { font-size: 16px; }
  #hero-name-input {
    font-size: 20px;
    padding: 16px 18px;
  }
  .ng-btns .btn {
    font-size: 18px !important;
    padding: 14px 24px;
    min-height: 52px;
  }

  /* ── 弹窗适配 ── */
  .item-detail-box, .result-box {
    width: 94vw !important;
    max-width: 94vw !important;
    min-width: unset !important;
  }
  .result-box { padding: 28px 20px; }
  .result-title { font-size: 26px; margin-bottom: 18px; }
  .result-drop-item { font-size: 16px; padding: 6px 0; }
  .detail-btns { gap: 10px; }
  .detail-btns .btn {
    font-size: 16px !important;
    padding: 12px 16px;
    min-height: 48px;
    flex: 1;
  }

  #item-tooltip { display: none !important; }

  #sell-modal > div {
    width: 94vw !important;
    max-width: 94vw !important;
    min-width: unset !important;
    padding: 24px 18px;
  }
  #sell-modal > div button {
    min-height: 48px;
    font-size: 16px !important;
  }
  #sell-quality-checks, #sell-tier-checks { gap: 8px; }
  #sell-preview { font-size: 15px; }

  #npc-items-modal > div {
    width: 94vw !important;
    max-width: 94vw !important;
    min-width: unset !important;
    padding: 22px 16px;
  }
  #npc-items-modal > div button {
    min-height: 48px;
    font-size: 16px !important;
    padding: 12px 24px;
  }

  /* ── 生活技能面板 ── */
  #lifeskill-panel {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    border: none !important;
  }
  .btn-craft {
    font-size: 16px;
    padding: 10px 20px;
    min-height: 48px;
  }

  /* ── 背包一键售出按钮 ── */
  .panel-title button {
    font-size: 14px !important;
    padding: 8px 14px !important;
    min-height: 40px;
  }

  /* ── 装备卡片图片大一点 ── */
  .item-img {
    width: 76px;
    height: 76px;
  }
  .item-card-large { min-height: 90px; }

  /* ── 武功进度条 ── */
  .skill-slot-progress { height: 6px; }
}

/* ============================================================
   手机横屏 (Landscape)
   ============================================================ */
@media screen and (max-height: 500px) and (orientation: landscape) {
  body { display: block; overflow: hidden; }
  #game-container {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    transform: none !important;
    margin: 0 !important;
  }
  canvas#game-canvas {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
  }
  #ui-overlay {
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
  }
  #hud {
    height: 44px;
    padding: 0 12px;
    gap: 12px;
    pointer-events: auto;
  }
  #hud-name { font-size: 16px; }
  .hud-bar-label { font-size: 13px; }
  .hud-bar-bg { width: 80px; }
  #hud-buttons {
    top: 4px;
    right: 4px;
    gap: 4px;
  }
  #hud-buttons .hud-btn {
    padding: 8px 12px;
    font-size: 14px !important;
  }
  .side-panel {
    top: 44px !important;
    width: 50vw !important;
    max-width: 440px;
    height: calc(100vh - 44px) !important;
    height: calc(100dvh - 44px) !important;
  }
  #dialogue-panel { height: 220px !important; }
  #battle-panel { top: 44px !important; }
  #battle-log { height: 100px; }
  #wilderness-panel, #gather-panel { top: 44px !important; }
  #item-tooltip { display: none !important; }
}

/* ============================================================
   平板 (Tablet)
   ============================================================ */
@media screen and (min-width: 769px) and (max-width: 1200px) {
  .btn { font-size: 17px; padding: 12px 28px; }
  .hud-btn { font-size: 16px !important; padding: 10px 16px; }
  .bag-tab { font-size: 14px; padding: 8px 14px; }
  .panel-title { font-size: 20px; }
  .item-name { font-size: 17px; }
  .attr-grid { font-size: 15px; }
  .side-panel { width: 420px; }
  .dialogue-option { font-size: 16px; padding: 12px 16px; }
  .msg-bubble { font-size: 16px; }
  .dlg-bubble { font-size: 15px; }
}

/* ============================================================
   iPhone 刘海 / 安全区
   ============================================================ */
@supports (padding: env(safe-area-inset-top)) {
  #hud {
    padding-top: max(10px, env(safe-area-inset-top));
  }
  #dialogue-panel {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  @media screen and (max-width: 768px) and (orientation: portrait) {
    .side-panel {
      padding-top: max(64px, calc(env(safe-area-inset-top) + 56px));
      padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 40px));
    }
    #battle-panel {
      top: max(64px, calc(env(safe-area-inset-top) + 56px)) !important;
    }
    #wilderness-panel, #gather-panel {
      top: max(64px, calc(env(safe-area-inset-top) + 56px)) !important;
    }
  }
}

/* ============================================================
   小屏手机额外优化 (< 375px width)
   ============================================================ */
@media screen and (max-width: 374px) and (orientation: portrait) {
  #hud-name { font-size: 17px; }
  #hud-exp, #hud-level, #hud-copper { font-size: 13px !important; }
  #hud-buttons .hud-btn { font-size: 13px !important; padding: 10px 1px; }
  .equip-grid { grid-template-columns: repeat(3, 1fr); }
  .ng-gender-option { width: 100px; }
  .ng-gender-img { width: 72px; height: 72px; }
  #bag-tabs .bag-tab { font-size: 12px !important; padding: 8px 6px; }
}

/* ============================================================
   大屏手机优化 (> 414px portrait)
   ============================================================ */
@media screen and (min-width: 415px) and (max-width: 768px) and (orientation: portrait) {
  .equip-grid { grid-template-columns: repeat(5, 1fr); }
  .battle-entity { max-width: 45% !important; }
  #dialogue-panel { height: 55vh !important; }
}
