/* ================================================================
   v181 — 요청사항 1~5: 전투열 간격, 본진 전투열, 책사 스킬,
   본진 버프 대상, 모바일 하단 배치 보정
   ================================================================ */

/* 1) 고정 그리드 행 수와 실제 DOM 행 수가 달라 생기던 무점령지/아군 2열 겹침 제거.
   전투 보드는 실제 자식 높이대로 흐르는 세로 flex로 배치한다. */
body:not(.prebattle) .boardwrap{
  overflow-x:hidden!important;
  overflow-y:auto!important;
}
body:not(.prebattle) .battlefield-layout>.board{
  display:flex!important;
  flex-direction:column!important;
  justify-content:flex-start!important;
  align-content:initial!important;
  height:auto!important;
  min-height:100%!important;
  gap:5px!important;
}
body:not(.prebattle) .battlefield-layout>.board>.lane,
body:not(.prebattle) .battlefield-layout>.board>.hq-battle-row{
  position:relative!important;
  flex:0 0 auto!important;
}
body:not(.prebattle) .battlefield-layout>.board>.neutral-lane{
  position:relative!important;
  z-index:1!important;
  margin:5px 0!important;
  clear:both!important;
}
body:not(.prebattle) .battlefield-layout>.board>.lane[data-row="a2"]{
  position:relative!important;
  z-index:1!important;
}

/* PC에서는 모든 일반 전투열이 카드 한 장을 완전히 감싸도록 고정한다. */
@media (min-width:851px){
  body:not(.prebattle) .battlefield-layout>.board>.lane:not(.hq-defense-lane){
    box-sizing:border-box!important;
    height:calc(var(--hand-card-height,138px) + 10px)!important;
    min-height:calc(var(--hand-card-height,138px) + 10px)!important;
    max-height:none!important;
    overflow:hidden!important;
  }
  body:not(.prebattle) .battlefield-layout>.board>.lane:not(.hq-defense-lane)>.slots{
    height:var(--hand-card-height,138px)!important;
    min-height:var(--hand-card-height,138px)!important;
    max-height:var(--hand-card-height,138px)!important;
  }
  body:not(.prebattle) .battlefield-layout>.board>.lane:not(.hq-defense-lane)>.slots>.slot,
  body:not(.prebattle) .battlefield-layout>.board>.lane:not(.hq-defense-lane)>.slots>.slot>.unit{
    height:var(--hand-card-height,138px)!important;
    min-height:var(--hand-card-height,138px)!important;
    max-height:var(--hand-card-height,138px)!important;
  }
}

/* 2) 본진 전투열도 일반 전투열과 같은 카드 크기/실선 슬롯을 사용한다. */
body:not(.prebattle) .hq-defense-lane.active{
  box-sizing:border-box!important;
  display:block!important;
  height:calc(var(--hand-card-height,138px) + 10px)!important;
  min-height:calc(var(--hand-card-height,138px) + 10px)!important;
  max-height:none!important;
  padding:4px 6px!important;
  overflow:hidden!important;
}
body:not(.prebattle) .hq-defense-lane .hq-battlefield-grid{
  box-sizing:border-box!important;
  display:grid!important;
  grid-template-columns:repeat(5,var(--hand-card-width,106px))!important;
  grid-template-rows:var(--hand-card-height,138px)!important;
  grid-auto-rows:var(--hand-card-height,138px)!important;
  width:max-content!important;
  max-width:100%!important;
  height:var(--hand-card-height,138px)!important;
  min-height:var(--hand-card-height,138px)!important;
  max-height:var(--hand-card-height,138px)!important;
  gap:7px!important;
  margin:0 auto!important;
  padding:0 3px 2px!important;
  align-items:stretch!important;
  justify-content:start!important;
  overflow-x:auto!important;
  overflow-y:hidden!important;
  scrollbar-width:thin;
}
body:not(.prebattle) .hq-defense-lane .hq-field-slot{
  box-sizing:border-box!important;
  width:var(--hand-card-width,106px)!important;
  min-width:var(--hand-card-width,106px)!important;
  max-width:var(--hand-card-width,106px)!important;
  height:var(--hand-card-height,138px)!important;
  min-height:var(--hand-card-height,138px)!important;
  max-height:var(--hand-card-height,138px)!important;
  padding:0!important;
  border:1px solid #765b36!important;
  border-style:solid!important;
  border-radius:7px!important;
  background:linear-gradient(180deg,#17120de6,#0d0a08e8)!important;
  overflow:hidden!important;
}
body:not(.prebattle) .hq-defense-lane .hq-field-slot.empty::after{
  content:none!important;
}
body:not(.prebattle) .hq-defense-lane .hq-field-slot.empty>span{
  color:#bda57b80!important;
  font-size:10px!important;
  font-weight:800!important;
}
body:not(.prebattle) .hq-defense-lane .hq-field-slot>.unit{
  width:100%!important;
  min-width:100%!important;
  max-width:100%!important;
  height:100%!important;
  min-height:100%!important;
  max-height:100%!important;
  border-radius:6px!important;
}

/* 책사 칸은 크기만 동일하게 유지하고 보라/청색 계열로 구분한다. */
body:not(.prebattle) .hq-defense-lane .hq-advisor-field-slot{
  border-color:#a899ff!important;
  background:linear-gradient(180deg,#292242f0,#12182ce8)!important;
  box-shadow:inset 0 0 0 1px #c4baff44,0 0 10px #7767d933!important;
}
body:not(.prebattle) .hq-advisor-field-slot .hq-advisor-slot,
body:not(.prebattle) .hq-advisor-field-slot .advisor{
  box-sizing:border-box!important;
  position:static!important;
  inset:auto!important;
  display:flex!important;
  width:100%!important;
  min-width:100%!important;
  max-width:100%!important;
  height:100%!important;
  min-height:100%!important;
  max-height:100%!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  border-radius:6px!important;
  background:transparent!important;
  box-shadow:none!important;
  overflow:hidden!important;
}
body:not(.prebattle) .hq-advisor-field-slot .advisor-card,
body:not(.prebattle) .hq-advisor-field-slot .advisor-image-only,
body:not(.prebattle) .hq-advisor-field-slot .advisor-portrait{
  box-sizing:border-box!important;
  width:100%!important;
  min-width:100%!important;
  max-width:100%!important;
  height:100%!important;
  min-height:100%!important;
  max-height:100%!important;
}
body:not(.prebattle) .hq-advisor-field-slot .advisor-empty{
  width:100%!important;
  height:100%!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  color:#e4ddff!important;
  font-weight:900!important;
  letter-spacing:.04em!important;
}

/* 본진 카드도 버프 대상 강조를 일반 필드와 동일하게 보이게 한다. */
body:not(.prebattle) .hq-field-slot.supportable{
  outline:3px solid #58e2d0!important;
  box-shadow:0 0 0 5px #58e2d02e,0 0 20px #58e2d033!important;
}
body:not(.prebattle) .hq-field-slot.buff-cancel-source,
body:not(.prebattle) .hq-field-slot .support-buff-caster{
  outline:3px solid #ffd867!important;
  box-shadow:0 0 0 4px #ffd86730,0 0 18px #ffd86744!important;
}

/* 5) 모바일: 하단 아군 본진 이미지 박스는 제거하고, 핸드는 화면 맨 아래에 고정한다. */
body.ui-mode-mobile:not(.prebattle) .mobile-ally-hq-mount,
body.ui-mode-mobile-preview:not(.prebattle) .mobile-ally-hq-mount{
  display:none!important;
  visibility:hidden!important;
  position:static!important;
  width:0!important;
  min-width:0!important;
  max-width:0!important;
  height:0!important;
  min-height:0!important;
  max-height:0!important;
  margin:0!important;
  padding:0!important;
  overflow:hidden!important;
}

@media (max-width:850px){
  body.ui-mode-mobile:not(.prebattle) .mobile-hand-mount{
    display:block!important;
    position:fixed!important;
    left:0!important;
    right:0!important;
    bottom:0!important;
    transform:none!important;
    width:100%!important;
    max-width:none!important;
    z-index:96!important;
  }
  body.ui-mode-mobile:not(.prebattle) .bottom-hud{
    display:block!important;
    position:fixed!important;
    left:0!important;
    right:0!important;
    bottom:var(--v120-hand-height,var(--mobile-hand-float-height,174px))!important;
    width:100%!important;
    height:46px!important;
    min-height:46px!important;
    max-height:46px!important;
    padding:4px 6px!important;
    z-index:95!important;
  }
  body.ui-mode-mobile:not(.prebattle) .bottom-hud .hud-status{
    display:block!important;
    height:100%!important;
    padding:0!important;
    background:transparent!important;
  }
  body.ui-mode-mobile:not(.prebattle) .bottom-hud .hud-status>:not(.hud-actions){display:none!important;}
  body.ui-mode-mobile:not(.prebattle) .bottom-hud .hud-actions{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:5px!important;
    width:100%!important;
    height:100%!important;
    min-width:0!important;
  }
  body.ui-mode-mobile:not(.prebattle) .bottom-hud .hud-actions .btn{
    min-height:36px!important;
    height:36px!important;
    padding:3px 5px!important;
    font-size:10px!important;
  }
  body.ui-mode-mobile:not(.prebattle),
  body.ui-mode-mobile:not(.prebattle) .app{
    padding-bottom:calc(var(--v120-hand-height,var(--mobile-hand-float-height,174px)) + 54px + env(safe-area-inset-bottom,0px))!important;
  }
}

/* 데스크톱에서 보는 모바일 미리보기에도 같은 하단 도킹 규칙 적용. */
body.ui-mode-mobile-preview:not(.prebattle) .mobile-hand-mount{
  display:block!important;
  position:fixed!important;
  left:50%!important;
  right:auto!important;
  bottom:0!important;
  transform:translateX(-50%)!important;
  width:var(--mobile-play-width,430px)!important;
  max-width:var(--mobile-play-width,430px)!important;
  z-index:96!important;
}
body.ui-mode-mobile-preview:not(.prebattle) .bottom-hud{
  display:block!important;
  position:fixed!important;
  left:50%!important;
  right:auto!important;
  bottom:var(--v120-hand-height,var(--mobile-hand-float-height,174px))!important;
  transform:translateX(-50%)!important;
  width:var(--mobile-play-width,430px)!important;
  height:46px!important;
  min-height:46px!important;
  max-height:46px!important;
  padding:4px 6px!important;
  z-index:95!important;
}
body.ui-mode-mobile-preview:not(.prebattle) .bottom-hud .hud-status{
  display:block!important;
  height:100%!important;
  padding:0!important;
  background:transparent!important;
}
body.ui-mode-mobile-preview:not(.prebattle) .bottom-hud .hud-status>:not(.hud-actions){display:none!important;}
body.ui-mode-mobile-preview:not(.prebattle) .bottom-hud .hud-actions{
  display:grid!important;
  grid-template-columns:repeat(3,minmax(0,1fr))!important;
  gap:5px!important;
  width:100%!important;
  height:100%!important;
  min-width:0!important;
}
body.ui-mode-mobile-preview:not(.prebattle) .bottom-hud .hud-actions .btn{
  min-height:36px!important;
  height:36px!important;
  padding:3px 5px!important;
  font-size:10px!important;
}
body.ui-mode-mobile-preview:not(.prebattle),
body.ui-mode-mobile-preview:not(.prebattle) .app{
  padding-bottom:calc(var(--v120-hand-height,var(--mobile-hand-float-height,174px)) + 54px)!important;
}
