/* NatureDex Android safe-area patch (Capacitor 8 / Android 15+).
 * Applied LAST to override legacy full-screen profile rules; CSS-only, no gameplay changes.
 * Capacitor SystemBars provides --safe-area-inset-* for WebViews where env() is unreliable.
 */
:root{
  --ndx-inset-top:max(env(safe-area-inset-top, 0px),var(--safe-area-inset-top, 0px));
  --ndx-inset-bottom:max(env(safe-area-inset-bottom, 0px),var(--safe-area-inset-bottom, 0px));
}
/* Reserve a minimum native top clearance even when an older Android WebView reports zero insets.
 * A little extra breathing room on older devices is preferable to an inaccessible close button. */
body.ndx-native-app{
  --ndx-profile-top:max(28px,var(--ndx-inset-top));
  --ndx-profile-bottom:var(--ndx-inset-bottom);
}
body:not(.ndx-native-app){
  --ndx-profile-top:var(--ndx-inset-top);
  --ndx-profile-bottom:var(--ndx-inset-bottom);
}
@media(max-width:680px){
  /* All species profiles (old and new) must live BETWEEN, not behind, the system bars. */
  #animalModal:not(.hidden){
    box-sizing:border-box!important;
    position:fixed!important;
    inset:0!important;
    display:flex!important;
    flex-direction:column!important;
    align-items:stretch!important;
    justify-content:flex-start!important;
    padding:var(--ndx-profile-top) 0 var(--ndx-profile-bottom)!important;
    width:100%!important;
    height:100dvh!important;
    max-height:100dvh!important;
    overflow:hidden!important;
    background:#071e14;
  }
  #animalModal:not(.hidden) > .modal-card{
    box-sizing:border-box!important;
    flex:1 1 auto!important;
    display:block!important;
    width:100%!important;
    max-width:100%!important;
    height:100%!important;
    max-height:100%!important;
    min-height:0!important;
    margin:0!important;
    padding:0!important;
    border-radius:0!important;
    border:0!important;
    overflow-x:hidden!important;
    overflow-y:auto!important;
    overscroll-behavior:contain!important;
    -webkit-overflow-scrolling:touch;
    scrollbar-gutter:auto;
  }
  /* Override V85/V88/V89's stacked position styles, including :has() variants.
     Both X and Founder pencil remain sticky and in separate corners. */
  #animalModal:not(.hidden) > .modal-card > .modal-close,
  #animalModal:has(.nd88-profile):not(.hidden) .n42-modal-card > .modal-close{
    box-sizing:border-box!important;
    position:sticky!important;
    display:grid!important;
    place-items:center!important;
    float:right!important;
    top:9px!important;
    left:auto!important;
    right:10px!important;
    width:44px!important;
    height:44px!important;
    min-width:44px!important;
    min-height:44px!important;
    margin:8px 10px -52px 0!important;
    padding:0!important;
    z-index:100!important;
    border-radius:50%!important;
    border:1px solid #aec39e!important;
    background:#f5f1df!important;
    color:#143f2a!important;
    box-shadow:0 3px 14px #061a1275!important;
    font-size:28px!important;
    line-height:1!important;
    touch-action:manipulation;
  }
  #animalModal:has(.nd88-profile):not(.hidden) .n42-modal-card > .nd88-founder-pencil{
    position:sticky!important;
    float:left!important;
    top:9px!important;
    left:10px!important;
    right:auto!important;
    margin:8px 0 -52px 10px!important;
    width:44px!important;
    height:44px!important;
    z-index:95!important;
  }
  /* The newer comparison overlay must also keep its title and Close above the OS bars. */
  body.ndx-native-app .ndxv2-sheet:not([hidden]){
    padding-top:var(--ndx-profile-top)!important;
  }
  .ndxv2-sheet:not([hidden]) .ndxv2-foot{
    padding-bottom:calc(10px + var(--ndx-profile-bottom))!important;
  }
  /* Safeguard the mobile app header if WebView's env() inset is zero. */
  body.ndx-native-app .topbar{
    padding-top:var(--ndx-profile-top)!important;
  }
  #animalModal .modal-card > .modal-close:focus-visible,
  #animalModal .modal-card > .nd88-founder-pencil:focus-visible{
    outline:3px solid #e8ca65!important;
    outline-offset:2px!important;
  }
}
/* Landscape: protect the two top actions from the OS bar/notch, without imposing
   a portrait-only minimum when the real safe-area measurements are available. */
@media(max-width:900px) and (orientation:landscape){
  body.ndx-native-app #animalModal:not(.hidden){
    padding-top:var(--ndx-profile-top)!important;
    padding-left:var(--safe-area-inset-left, env(safe-area-inset-left,0px))!important;
    padding-right:var(--safe-area-inset-right, env(safe-area-inset-right,0px))!important;
  }
}
