/* Mipez.app V5.1.7.3.2.2.4.3.5
 * Mobile Toast Safe Area & Responsive Final Polish
 * Incremental over V5.1.7.3.2.2.4.3.4.
 * UI-only: no camera, player physics, collisions, Bubble Arsenal,
 * World Director event logic or Octopus combat behavior changed.
 */

:root{
  --mipez-v435-safe-left:env(safe-area-inset-left,0px);
  --mipez-v435-safe-right:env(safe-area-inset-right,0px);
  --mipez-v435-safe-bottom:env(safe-area-inset-bottom,0px);
  --mipez-v435-toast-width:270px;
  --mipez-v435-toast-bottom:170px;
}

/* ------------------------------------------------------------
   MOBILE TOAST AUTHORITY
   Keep Sonner useful during play, but prevent old notifications from
   stacking into the playfield. The most recent/front toast is the only
   one visible on compact game layouts.
   ------------------------------------------------------------ */
@media (pointer:coarse), (max-width:700px), (max-height:560px){
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toaster]{
    --width:var(--mipez-v435-toast-width)!important;
    --gap:4px!important;
    width:var(--mipez-v435-toast-width)!important;
    max-width:var(--mipez-v435-toast-width)!important;
    z-index:2147483643!important;
    pointer-events:none!important;
  }

  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast][data-front="false"],
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast][data-mipez-v435-current="false"]{
    opacity:0!important;
    visibility:hidden!important;
    pointer-events:none!important;
  }

  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast][data-styled="true"]{
    min-height:0!important;
    max-height:31px!important;
    padding:6px 9px!important;
    gap:5px!important;
    border-radius:999px!important;
    border:1px solid rgba(139,228,255,.34)!important;
    background:linear-gradient(180deg,rgba(2,38,76,.93),rgba(2,27,61,.91))!important;
    color:#f4fdff!important;
    box-shadow:0 7px 20px rgba(0,15,45,.23)!important;
    backdrop-filter:blur(9px)!important;
    -webkit-backdrop-filter:blur(9px)!important;
    font-size:9.5px!important;
    line-height:1.05!important;
    overflow:hidden!important;
    pointer-events:none!important;
  }

  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast] [data-content]{
    display:flex!important;
    align-items:center!important;
    gap:4px!important;
    min-width:0!important;
    max-width:100%!important;
    overflow:hidden!important;
  }

  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast] [data-title],
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast] [data-description]{
    min-width:0!important;
    max-width:100%!important;
    margin:0!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
    font-size:9.5px!important;
    line-height:1.05!important;
  }

  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast] [data-title]{
    font-weight:750!important;
  }

  /* Message already lives in data-title for normal Mipez notifications.
     A secondary description is redundant on a phone-sized playfield. */
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast] [data-title]:not(:empty) ~ [data-description]{
    display:none!important;
  }

  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast] [data-icon]{
    width:13px!important;
    height:13px!important;
    min-width:13px!important;
    margin:0!important;
  }
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast] [data-icon] svg{
    width:13px!important;
    height:13px!important;
  }

  /* Gameplay alerts are transient information, not dialogs. */
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toast] [data-close-button]{
    display:none!important;
  }
}

/* ------------------------------------------------------------
   PORTRAIT SAFE AREA
   The JS patch measures the actual highest touch control and places the
   toast above that control deck. This adapts to 360x740, larger phones,
   browser UI changes and safe-area insets without hard-coding one device.
   ------------------------------------------------------------ */
@media (orientation:portrait) and (max-width:620px){
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toaster][data-x-position="right"],
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toaster][data-x-position="left"],
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toaster][data-x-position="center"]{
    left:50%!important;
    right:auto!important;
    transform:translateX(-50%)!important;
  }

  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toaster][data-y-position="bottom"]{
    bottom:calc(var(--mipez-v435-toast-bottom) + var(--mipez-v435-safe-bottom))!important;
    top:auto!important;
  }
}

/* ------------------------------------------------------------
   SHORT LANDSCAPE SAFE CORRIDOR
   Joystick lives on the left; Turbo/Bubble live on the right. Center the
   toast in the free corridor instead of lifting it over the fish.
   ------------------------------------------------------------ */
@media (orientation:landscape) and (max-height:560px){
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toaster][data-x-position="right"],
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toaster][data-x-position="left"],
  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toaster][data-x-position="center"]{
    left:50%!important;
    right:auto!important;
    transform:translateX(-50%)!important;
  }

  body[data-mipez-game-phase="playing"].mipez-v435-toast-safe [data-sonner-toaster][data-y-position="bottom"]{
    bottom:calc(10px + var(--mipez-v435-safe-bottom))!important;
    top:auto!important;
  }
}

/* ------------------------------------------------------------
   RESULT-SCREEN GUARANTEE
   Previous patches already retire the gameplay HUD. This final guard also
   eliminates a one-frame Sonner flash during the playing -> gameover swap.
   ------------------------------------------------------------ */
body[data-mipez-game-phase="gameover"] [data-sonner-toaster]{
  display:none!important;
  visibility:hidden!important;
  opacity:0!important;
  pointer-events:none!important;
}
