/*
 * K-BOOKS MOBILE STABILITY v3.2
 * Layered after kbooks-mobile-v3.1.css
 * PC layout untouched: <=900px only unless display-mode standalone.
 */
@media (max-width:900px){

  /* Fixed-width Gnuboard shells: remove remaining 1200px inheritance. */
  html body #hd,
  html body #hd_wrapper,
  html body #wrapper,
  html body #container_wr,
  html body #container,
  html body #ft,
  html body #ft_wr,
  html body #tnb .inner,
  html body #gnb .gnb_wrap,
  html body .icd-shell{
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
  }

  html body #container{
    float:none!important;
  }

  /* Prevent media and long content from silently extending past viewport. */
  html body img,
  html body svg,
  html body video,
  html body canvas,
  html body iframe,
  html body object,
  html body embed{
    max-width:100%!important;
  }

  html body pre{
    max-width:100%!important;
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
    white-space:pre;
  }

  html body code,
  html body .url,
  html body .link,
  html body a[href^="http"]{
    overflow-wrap:anywhere;
    word-break:break-word;
  }

  html body input,
  html body select,
  html body textarea,
  html body button{
    max-width:100%;
  }

  /* Common table wrappers: scroll the table, not the whole page. */
  html body .tbl_wrap,
  html body .tbl_head01,
  html body .tbl_head02,
  html body .tbl_frm01,
  html body .table-responsive,
  html body .icd-table-wrap,
  html body .ksp-table-wrap,
  html body .kba-table-wrap,
  html body .kbop-table-wrap{
    max-width:100%!important;
    overflow-x:auto!important;
    -webkit-overflow-scrolling:touch;
  }

  /*
   * Top utility account row is horizontally scrollable on mobile.
   * An absolute dropdown inside that scroll container can be clipped.
   * Promote the opened "내 학습" menu to viewport-fixed positioning.
   */
  html body #icd-header .icd-account-learning.open .icd-account-learning-menu{
    position:fixed!important;
    z-index:2147483000!important;
    left:12px!important;
    right:12px!important;
    width:auto!important;
    min-width:0!important;
    max-width:none!important;
    max-height:min(70vh,520px)!important;
    overflow-y:auto!important;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
    box-shadow:0 14px 34px rgba(12,43,55,.18)!important;
  }

  html body #icd-header .icd-account-learning-menu a{
    min-height:42px;
    display:flex!important;
    align-items:center;
    white-space:normal!important;
    word-break:keep-all!important;
  }

  /* Keep floating top button clear of modern phone bottom safe area. */
  html body #top_btn{
    right:max(14px,env(safe-area-inset-right))!important;
    bottom:max(14px,calc(env(safe-area-inset-bottom) + 14px))!important;
  }
}

/* iOS Safari zooms focused form controls smaller than 16px. */
@media (max-width:640px){
  html body input[type="text"],
  html body input[type="search"],
  html body input[type="email"],
  html body input[type="password"],
  html body input[type="tel"],
  html body input[type="url"],
  html body input[type="number"],
  html body textarea,
  html body select{
    font-size:16px!important;
  }
}

/* Installed PWA: respect device cut-outs without changing normal browser layout. */
@media (display-mode:standalone){
  html body #top_btn{
    bottom:max(16px,calc(env(safe-area-inset-bottom) + 16px))!important;
  }
  html body .icd-footer-bottom{
    padding-bottom:env(safe-area-inset-bottom);
  }
}

/* Audit mode only: JS adds this class to actual viewport offenders. */
.kbooks-mobile-overflow-offender{
  outline:3px solid #d9463e!important;
  outline-offset:-3px!important;
}

/* K-BOOKS MOBILE HEADER CLEANUP v1 */
@media (max-width:900px){
  /* 첫 화면 상단의 긴 회원/관리 유틸 바는 모바일에서 제거 */
  html body #icd-header .icd-util{
    display:none!important;
  }

  html body #icd-header .icd-brand-row{
    border-top:0!important;
  }

  /* 햄버거 안 모바일 전용 계정/학습 도구 */
  html body #icd-header .kb-mobile-tools{
    display:block!important;
    width:100%!important;
    margin:0 0 10px!important;
    padding:12px 0 13px!important;
    border-bottom:1px solid #e4eaeb!important;
  }

  html body #icd-header .kb-mobile-tools-group + .kb-mobile-tools-group{
    margin-top:12px!important;
  }

  html body #icd-header .kb-mobile-tools-title{
    display:block!important;
    margin:0 0 7px!important;
    color:#60747b!important;
    font-size:9px!important;
    font-weight:800!important;
    letter-spacing:.08em!important;
  }

  html body #icd-header .kb-mobile-tools-links{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:6px!important;
  }

  html body #icd-header .kb-mobile-tools-links>a{
    display:flex!important;
    min-width:0!important;
    min-height:40px!important;
    padding:8px 10px!important;
    align-items:center!important;
    justify-content:center!important;
    border:1px solid #dfe6e8!important;
    border-radius:8px!important;
    background:#f8fafb!important;
    color:#173849!important;
    font-size:11px!important;
    font-weight:700!important;
    line-height:1.35!important;
    text-align:center!important;
    text-decoration:none!important;
    white-space:normal!important;
    word-break:keep-all!important;
  }

  html body #icd-header .kb-mobile-tools-links>a:active{
    background:#edf4f4!important;
  }

  html body #icd-header .kb-mobile-tools-links>a.kb-mobile-admin{
    border-color:#cfdde0!important;
    background:#eef5f5!important;
  }

  /* 상단 바 제거 후 브랜드/검색 사이 간격을 조금 압축 */
  html body #icd-header .icd-brand-inner{
    padding-top:10px!important;
    padding-bottom:10px!important;
  }

  html body #icd-header .icd-mobile-search{
    padding-top:8px!important;
    padding-bottom:10px!important;
  }
}

@media (max-width:430px){
  html body #icd-header .kb-mobile-tools-links{
    grid-template-columns:1fr 1fr!important;
  }
}
/* /K-BOOKS MOBILE HEADER CLEANUP v1 */

/* K-BOOKS MOBILE HEADER PC HOTFIX v1
 * Mobile-only cloned tools must never appear in desktop GNB.
 */
@media (min-width:901px){
  html body #icd-header .kb-mobile-tools{
    display:none!important;
  }
}
/* /K-BOOKS MOBILE HEADER PC HOTFIX v1 */
