/* ==========================================================================
   Keyboard — dialogs and sheets sit right on top of the on-screen keyboard,
   the way they do in a native app.

   On phones the keyboard slides over the page without resizing it (iPhone:
   every browser; Android: Chrome, Samsung Internet and others). A sheet pinned to
   the bottom of the page would end up behind the keyboard, or float with page
   showing between them. While a modal or a bottom-sheet list is open and you type,
   moey.js measures the part of the screen you can still see and sets, on <html>:
     .mo-keyboard     the keyboard is up
     --mo-kb          how much of the bottom it covers
     --mo-vv-top      how far the browser has panned the page (iPhone does this)
     --mo-vv-h        the height you can still see
   Everything here only applies while .mo-keyboard is on.
   ========================================================================== */

/* Dialogs and sheets: the box they sit in becomes the visible area above the keyboard */
html.mo-keyboard :is(.dialog, .sheet):modal {
  inset-block: var(--mo-vv-top) var(--mo-kb);
}
html.mo-keyboard .sheet:modal {
  max-height: calc(var(--mo-vv-h) - var(--_top-gap));
  padding-bottom: 0;                             /* the home bar is under the keyboard now */
}
html.mo-keyboard .sheet-full:modal { max-height: var(--mo-vv-h); }
html.mo-keyboard .sheet-inset:modal { max-height: calc(var(--mo-vv-h) - var(--_top-gap) - .5rem); margin-bottom: .5rem; }
html.mo-keyboard .dialog:modal:not(.sheet) { max-height: calc(var(--mo-vv-h) - 1rem); }
html.mo-keyboard .dialog-fullscreen:modal { height: var(--mo-vv-h); max-height: var(--mo-vv-h); padding-bottom: 0; }
@media (width < 576px) {
  html.mo-keyboard .dialog:modal:not(.dialog-center, .dialog-fullscreen) { max-height: calc(var(--mo-vv-h) - 2.5rem); padding-bottom: 0; }
}

/* Drawers: as tall as what's visible */
html.mo-keyboard .drawer:modal { inset-block: var(--mo-vv-top) auto; height: var(--mo-vv-h); }
html.mo-keyboard .drawer-bottom:modal { inset-block: auto var(--mo-kb); height: var(--mo-drawer-size, auto); max-height: calc(var(--mo-vv-h) - 2.5rem); }
html.mo-keyboard .drawer-top:modal { height: var(--mo-drawer-size, auto); max-height: calc(var(--mo-vv-h) - 2.5rem); }

/* Bottom-sheet lists (adapt): docked on the keyboard. A list you're searching opens
   to its full height, so it doesn't jump around as the results change. */
html.mo-keyboard .is-sheet[popover]:popover-open {
  --mo-menu-max-height: calc(var(--mo-vv-h) - 2.5rem);
  bottom: var(--mo-kb) !important;
  padding-bottom: .75rem;
}
html.mo-keyboard .is-sheet[popover]:popover-open:focus-within:has(:is(input, textarea):focus) {
  height: var(--mo-menu-max-height);
}

/* The move itself: eased like the keyboard, only while it's moving (so dragging and
   the open / close animations are untouched) */
@media (prefers-reduced-motion: no-preference) {
  html.mo-keyboard-moving :is(.dialog, .sheet, .drawer):modal:not(.is-dragging) {
    transition: inset-block .3s cubic-bezier(.32, .72, 0, 1), max-height .3s cubic-bezier(.32, .72, 0, 1), height .3s cubic-bezier(.32, .72, 0, 1);
  }
  html.mo-keyboard-moving .is-sheet[popover]:popover-open:not(.is-dragging) {
    transition: bottom .3s cubic-bezier(.32, .72, 0, 1), max-height .3s cubic-bezier(.32, .72, 0, 1), height .3s cubic-bezier(.32, .72, 0, 1);
  }
}
