/* v173 요청사항: 핸드/필드 카드 크기 통일, 모바일 본진 압축, 관리자/로그인/드롭 UI */

/* 로그인 전에는 게임 전체 입력을 잠그고 로그인 창만 허용 */
html.login-required,body.login-required{overflow:hidden!important}
body.login-required .app,
body.login-required .mobile-game-header,
body.login-required .bottom-hud,
body.login-required #mobileMenuDrawer{pointer-events:none!important;user-select:none!important;filter:blur(1.5px) brightness(.42)!important}
body.login-required .modal:not(#loginModal){display:none!important}
body.login-required #loginModal{display:flex!important;opacity:1!important;visibility:visible!important;pointer-events:auto!important;z-index:50000!important}
body.login-required #loginModal [data-close-online="loginModal"]{display:none!important}
body.login-required #loginModal .modalbox{pointer-events:auto!important;filter:none!important}

/* 카드 관리자 상단 버튼: 작고 한 줄 유지 */
.card-manager-box .manager-head{gap:8px!important;align-items:flex-start!important}
.card-manager-box .manager-head>div:first-child{min-width:0!important}
.card-manager-box .manager-head h2{font-size:16px!important;line-height:1.2!important;white-space:nowrap!important}
.card-manager-box .manager-head .small{font-size:10px!important;line-height:1.3!important}
.card-manager-box .manager-head-actions{display:flex!important;flex-wrap:nowrap!important;gap:4px!important;align-items:center!important;justify-content:flex-end!important;overflow-x:auto!important;max-width:52%!important}
.card-manager-box .manager-head-actions .btn{min-height:26px!important;height:26px!important;padding:3px 7px!important;font-size:10px!important;line-height:1!important;white-space:nowrap!important;flex:0 0 auto!important;border-radius:6px!important}
.manager-direct-image-drop-zone{width:100%;min-height:92px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:5px;padding:12px;border:1.5px dashed rgba(79,182,255,.8);border-radius:10px;background:rgba(22,56,85,.42);text-align:center;cursor:pointer;transition:.15s ease}
.manager-direct-image-drop-zone:hover,.manager-direct-image-drop-zone:focus,.manager-direct-image-drop-zone.drop-ready{outline:none;border-color:#7ff0bd;background:rgba(23,104,85,.42);transform:translateY(-1px)}
.manager-direct-image-drop-zone strong{font-size:13px;color:#e9fbff}
.manager-direct-image-drop-zone span{font-size:10px;color:#b9d7e8;line-height:1.35}
.manager-direct-image-drop-zone small{font-size:9px;color:#8fa9b8}

/* 능력치 일괄편집 이미지 셀: 클릭/드롭 즉시 업로드 */
.qs-image-thumb{cursor:pointer;position:relative;outline:none;transition:.15s ease}
.qs-image-thumb:hover,.qs-image-thumb:focus,.qs-image-thumb.drop-ready{box-shadow:0 0 0 2px #65e6bd,0 0 14px rgba(101,230,189,.35)!important;transform:scale(1.04)}
.qs-image-thumb.uploading{pointer-events:none;opacity:.55}
.qs-image-thumb.uploading:after{content:'저장 중';position:absolute;inset:0;display:grid;place-items:center;background:rgba(4,15,25,.75);font-size:8px;color:#fff}

/* 데스크톱 핸드카드 높이를 현재 전투필드 카드(160px)와 동일하게 */
@media (min-width:851px){
  #hand.hand{grid-auto-rows:160px!important;grid-template-rows:repeat(2,160px)!important;align-content:start!important}
  #hand.hand .card{height:160px!important;min-height:160px!important;max-height:160px!important;grid-template-rows:24px minmax(0,1fr) 28px!important}
}

/* 모바일: 핸드카드와 필드카드의 폭·높이·내부 행을 완전히 동일하게 */
@media (max-width:850px){
  :root{
    --v173-mobile-hq-height:118px;
    --v173-mobile-hq-content-height:56px;
    --v173-mobile-hand-height:calc(var(--v129-field-card-height, 154px) + 32px);
  }
  body.ui-mode-mobile #hand.hand .card,
  body.ui-mode-mobile .mobile-hand-mount #hand .card{
    width:var(--mobile-card-width)!important;
    min-width:var(--mobile-card-width)!important;
    max-width:var(--mobile-card-width)!important;
    height:var(--v129-field-card-height)!important;
    min-height:var(--v129-field-card-height)!important;
    max-height:var(--v129-field-card-height)!important;
    grid-template-rows:calc(var(--mobile-card-width) * .2684) minmax(0,1fr) calc(var(--mobile-card-width) * .3131)!important;
  }
  body.ui-mode-mobile #hand.hand{
    grid-auto-rows:var(--v129-field-card-height)!important;
    grid-template-rows:var(--v129-field-card-height)!important;
    min-height:var(--v129-field-card-height)!important;
  }
  /* 하단 고정영역 중복 예약을 해제하고 본진·핸드를 실제 흐름에 배치 */
  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount,
  body.ui-mode-mobile:not(.prebattle) .mobile-hand-mount{
    position:relative!important;inset:auto!important;left:auto!important;right:auto!important;top:auto!important;bottom:auto!important;transform:none!important;z-index:auto!important;width:100%!important;margin:4px 0!important;
  }
  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount{height:var(--v173-mobile-hq-height)!important;min-height:var(--v173-mobile-hq-height)!important;max-height:var(--v173-mobile-hq-height)!important;padding:0!important}
  body.ui-mode-mobile:not(.prebattle) .mobile-hand-mount{height:var(--v173-mobile-hand-height)!important;min-height:var(--v173-mobile-hand-height)!important;max-height:var(--v173-mobile-hand-height)!important;padding:0 4px!important;overflow:hidden!important}
  body.ui-mode-mobile:not(.prebattle) .bottom-hud{display:none!important}
  body.ui-mode-mobile:not(.prebattle),body.ui-mode-mobile:not(.prebattle) .app{padding-bottom:max(8px,env(safe-area-inset-bottom))!important}

  /* 적·아군 본진과 책사 슬롯의 높이 통일 */
  body.ui-mode-mobile .enemy-hq-row,
  body.ui-mode-mobile .ally-hq-row,
  body.ui-mode-mobile .battle-hq{
    height:var(--v173-mobile-hq-height)!important;
    min-height:var(--v173-mobile-hq-height)!important;
    max-height:var(--v173-mobile-hq-height)!important;
  }
  body.ui-mode-mobile .battle-hq{padding:0!important;overflow:hidden!important}
  body.ui-mode-mobile .battle-hq .hq-title{height:22px!important;min-height:22px!important;padding:3px 6px!important;font-size:10px!important;line-height:16px!important}
  body.ui-mode-mobile .battle-hq .hq-info-overlay{
    position:absolute!important;left:5px!important;right:calc(var(--mobile-card-width) + 10px)!important;top:25px!important;bottom:auto!important;height:var(--v173-mobile-hq-content-height)!important;min-height:var(--v173-mobile-hq-content-height)!important;display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr))!important;grid-template-rows:repeat(2,minmax(0,1fr))!important;gap:2px!important;padding:2px!important;border-radius:6px!important;
  }
  body.ui-mode-mobile .battle-hq .hq-stat-chip{min-height:0!important;height:auto!important;padding:1px 2px!important;font-size:8px!important;line-height:1!important}
  body.ui-mode-mobile .battle-hq .hq-stat-value{font-size:8px!important;line-height:1!important}
  body.ui-mode-mobile .battle-hq .hq-stat-icon{font-size:8px!important}
  body.ui-mode-mobile .battle-hq .hq-advisor-slot{
    position:absolute!important;right:5px!important;top:25px!important;bottom:auto!important;width:var(--mobile-card-width)!important;height:var(--v173-mobile-hq-content-height)!important;min-height:var(--v173-mobile-hq-content-height)!important;max-height:var(--v173-mobile-hq-content-height)!important;padding:0!important;border-radius:6px!important;overflow:hidden!important;
  }
  body.ui-mode-mobile .hq-advisor-slot .advisor-card,
  body.ui-mode-mobile .hq-advisor-slot .advisor-portrait{position:absolute!important;inset:0!important;width:100%!important;height:100%!important;min-height:0!important;border-radius:5px!important;overflow:hidden!important}
  body.ui-mode-mobile .hq-advisor-slot .advisor-portrait img{width:100%!important;height:100%!important;object-fit:cover!important}
  body.ui-mode-mobile .hq-advisor-slot .advisor-slot-badge{position:absolute!important;left:0!important;right:0!important;bottom:0!important;height:17px!important;min-height:17px!important;padding:2px 3px!important;background:linear-gradient(transparent,rgba(2,8,16,.96))!important;display:flex!important;align-items:flex-end!important;justify-content:center!important;z-index:3!important}
  body.ui-mode-mobile .hq-advisor-slot .advisor-slot-badge b{display:block!important;width:100%!important;overflow:hidden!important;text-overflow:ellipsis!important;white-space:nowrap!important;text-align:center!important;font-size:8px!important;line-height:12px!important}
  body.ui-mode-mobile .hq-advisor-slot .advisor-slot-badge span{display:none!important}
  body.ui-mode-mobile .hq-advisor-slot .advisor-empty{font-size:8px!important;line-height:1.2!important;text-align:center!important;padding:4px!important}
  body.ui-mode-mobile .battle-hq .mobile-hq-actions{position:absolute!important;left:5px!important;right:5px!important;bottom:4px!important;top:auto!important;height:27px!important;min-height:27px!important;display:flex!important;align-items:stretch!important;gap:3px!important;z-index:8!important}
  body.ui-mode-mobile .battle-hq .mobile-hq-actions .btn,
  body.ui-mode-mobile .battle-hq .mobile-hq-actions button{min-height:27px!important;height:27px!important;padding:2px 5px!important;font-size:9px!important;line-height:1!important;white-space:nowrap!important}
  body.ui-mode-mobile .battle-hq .hq-turn-box{display:none!important}
}

/* v173 최종 우선순위 고정: v132/v141의 더 깊은 선택자를 확실히 덮어쓴다. */
@media (max-width:850px){
  :root{
    --v129-hand-card-height:var(--v129-field-card-height)!important;
    --mobile-hand-card-h:var(--v129-field-card-height)!important;
    --v120-hand-height:calc(var(--v129-field-card-height) + 32px)!important;
    --v122-mobile-hq-h:118px!important;
    --v120-hq-height:118px!important;
    --v120-bottom-total:calc(var(--v129-field-card-height) + 150px)!important;
  }

  body.ui-mode-mobile:not(.prebattle) .mobile-hand-mount #hand.hand,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-hand-mount #hand.hand{
    height:var(--v129-field-card-height)!important;
    min-height:var(--v129-field-card-height)!important;
    max-height:var(--v129-field-card-height)!important;
    grid-auto-rows:var(--v129-field-card-height)!important;
    grid-template-rows:var(--v129-field-card-height)!important;
  }
  body.ui-mode-mobile:not(.prebattle) .mobile-hand-mount #hand.hand .card,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-hand-mount #hand.hand .card{
    flex:0 0 var(--mobile-card-width)!important;
    width:var(--mobile-card-width)!important;
    min-width:var(--mobile-card-width)!important;
    max-width:var(--mobile-card-width)!important;
    height:var(--v129-field-card-height)!important;
    min-height:var(--v129-field-card-height)!important;
    max-height:var(--v129-field-card-height)!important;
    display:grid!important;
    grid-template-rows:calc(var(--mobile-card-width) * .2684) minmax(0,1fr) calc(var(--mobile-card-width) * .3131)!important;
    overflow:hidden!important;
  }
  body.ui-mode-mobile:not(.prebattle) .mobile-hand-mount #hand.hand .card .cname,
  body.ui-mode-mobile:not(.prebattle) .mobile-hand-mount #hand.hand .card .card-title-area,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-hand-mount #hand.hand .card .cname,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-hand-mount #hand.hand .card .card-title-area{
    height:100%!important;min-height:0!important;max-height:none!important;
  }
  body.ui-mode-mobile:not(.prebattle) .mobile-hand-mount #hand.hand .card .cstats,
  body.ui-mode-mobile:not(.prebattle) .mobile-hand-mount #hand.hand .card .card-stat-grid,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-hand-mount #hand.hand .card .cstats,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-hand-mount #hand.hand .card .card-stat-grid{
    height:100%!important;min-height:0!important;max-height:none!important;
  }

  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount .ally-hq-row,
  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount .battle-hq,
  body.ui-mode-mobile:not(.prebattle) .enemy-hq-row,
  body.ui-mode-mobile:not(.prebattle) .enemy-hq-row .battle-hq,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-ally-hq-mount .ally-hq-row,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-ally-hq-mount .battle-hq,
  body.ui-mode-mobile-preview:not(.prebattle) .enemy-hq-row,
  body.ui-mode-mobile-preview:not(.prebattle) .enemy-hq-row .battle-hq{
    height:118px!important;min-height:118px!important;max-height:118px!important;overflow:hidden!important;
  }
  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-info-overlay,
  body.ui-mode-mobile:not(.prebattle) .enemy-hq-row .battle-hq .hq-info-overlay,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-info-overlay,
  body.ui-mode-mobile-preview:not(.prebattle) .enemy-hq-row .battle-hq .hq-info-overlay{
    left:5px!important;right:calc(var(--mobile-card-width) + 10px)!important;top:25px!important;bottom:auto!important;
    height:56px!important;min-height:56px!important;max-height:56px!important;
    display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr))!important;grid-template-rows:repeat(2,minmax(0,1fr))!important;
    gap:2px!important;padding:2px!important;align-content:stretch!important;
  }
  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-stat-chip,
  body.ui-mode-mobile:not(.prebattle) .enemy-hq-row .battle-hq .hq-stat-chip,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-stat-chip,
  body.ui-mode-mobile-preview:not(.prebattle) .enemy-hq-row .battle-hq .hq-stat-chip{
    width:auto!important;height:auto!important;min-height:0!important;padding:1px 2px!important;gap:2px!important;font-size:8px!important;border-radius:4px!important;
  }
  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-stat-chip .hq-stat-icon,
  body.ui-mode-mobile:not(.prebattle) .enemy-hq-row .battle-hq .hq-stat-chip .hq-stat-icon,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-stat-chip .hq-stat-icon,
  body.ui-mode-mobile-preview:not(.prebattle) .enemy-hq-row .battle-hq .hq-stat-chip .hq-stat-icon{
    font-size:8px!important;
  }
  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-stat-chip .hq-stat-value,
  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-stat-chip b,
  body.ui-mode-mobile:not(.prebattle) .enemy-hq-row .battle-hq .hq-stat-chip .hq-stat-value,
  body.ui-mode-mobile:not(.prebattle) .enemy-hq-row .battle-hq .hq-stat-chip b,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-stat-chip .hq-stat-value,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-ally-hq-mount .battle-hq .hq-stat-chip b,
  body.ui-mode-mobile-preview:not(.prebattle) .enemy-hq-row .battle-hq .hq-stat-chip .hq-stat-value,
  body.ui-mode-mobile-preview:not(.prebattle) .enemy-hq-row .battle-hq .hq-stat-chip b{
    font-size:8px!important;line-height:1!important;
  }
  body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount .hq-advisor-slot,
  body.ui-mode-mobile:not(.prebattle) .enemy-hq-row .hq-advisor-slot,
  body.ui-mode-mobile-preview:not(.prebattle) .mobile-ally-hq-mount .hq-advisor-slot,
  body.ui-mode-mobile-preview:not(.prebattle) .enemy-hq-row .hq-advisor-slot{
    inset:25px 5px auto auto!important;
    width:var(--mobile-card-width)!important;min-width:var(--mobile-card-width)!important;max-width:var(--mobile-card-width)!important;
    height:56px!important;min-height:56px!important;max-height:56px!important;padding:0!important;overflow:hidden!important;
  }
}
