/* SUNDEX p245 — stable iOS input and virtual-keyboard geometry. */

@media (max-width: 820px), (pointer: coarse) {
  /* iOS zooms the visual viewport when a focused field renders below 16px.
   * Keeping form controls at the platform threshold prevents that zoom and
   * the matching horizontal/vertical jump. */
  :where(
    input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    textarea,
    select,
    [contenteditable="true"]
  ) {
    font-size: max(16px, 1em) !important;
  }

  html.sx-mobile-input-active,
  html.sx-mobile-input-active body {
    scroll-behavior: auto !important;
    overflow-anchor: none !important;
    touch-action: auto !important;
  }

  html.sx-mobile-input-active :where(
    .platform-shell,
    .platform-main,
    .stx-shell,
    .stx-head,
    .stx-stage,
    [role="dialog"]
  ) {
    animation: none !important;
    transition: none !important;
  }

  html.sx-mobile-keyboard-open :where(
    .support-launcher,
    .support-chat-launcher,
    [data-support-launcher],
    .sundex-support-button
  ) {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  /* iOS uses the document as the only scroll owner on processing routes.
   * Keeping a nested fixed-height stage here traps the touch gesture as soon
   * as the virtual keyboard changes the visual viewport. */
  html:has(body.sundex-transaction-system),
  body.sundex-transaction-system {
    width: 100% !important;
    height: auto !important;
    min-height: 100% !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: auto !important;
  }

  body.sundex-transaction-system #root {
    height: auto !important;
    min-height: calc(100svh - var(--sx127-header-h, var(--sx96-header-h, 70px))) !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.sundex-transaction-system #root > .platform-shell,
  body.sundex-transaction-system .platform-main,
  body.sundex-transaction-system main.platform-main,
  body.sundex-transaction-system :is(.stx-funding-shell, .stx-shell) {
    height: auto !important;
    min-height: calc(100svh - var(--sx127-header-h, var(--sx96-header-h, 70px))) !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.sundex-transaction-system :is(.stx-stage, .stx-vf-stage) {
    height: auto !important;
    min-height: max-content !important;
    max-height: none !important;
    overflow: visible !important;
    overscroll-behavior: auto !important;
    scroll-behavior: auto !important;
    contain: none !important;
    touch-action: auto !important;
  }

  /* Route-specific layers used pan-y to stabilise old nested scrollers. That
   * also disables Safari pinch zoom. Restore native panning and zooming over
   * every interactive processing surface. */
  body.sundex-transaction-system :is(
    .platform-shell,
    .platform-main,
    .stx-shell,
    .stx-stage,
    .stx-vf-stage,
    .sx110-coin-scroll,
    .sx156-coin-scroll,
    .sx134-step1-list,
    form,
    input,
    textarea,
    select,
    button
  ) {
    touch-action: auto !important;
  }

  body.sundex-flow-withdraw input,
  body.sundex-flow-withdraw textarea,
  body.sundex-flow-withdraw select {
    transform: none !important;
    zoom: 1 !important;
  }

  /* Safari keeps the root viewport separate from the visual viewport. Let
   * html own scrolling and keep body visible; two overflow scrollers can leave
   * Safari with no draggable surface after an address field receives focus. */
  html.sx-ios-safari:has(body.sundex-transaction-system) {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    min-height: 100% !important;
    overflow-x: hidden !important;
    overflow-y: scroll !important;
    overscroll-behavior-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: manipulation !important;
  }

  html.sx-ios-safari body.sundex-transaction-system {
    position: static !important;
    inset: auto !important;
    height: auto !important;
    min-height: 100svh !important;
    max-height: none !important;
    overflow: visible !important;
    overscroll-behavior-y: auto !important;
    touch-action: manipulation !important;
  }

  html.sx-ios-safari body.sundex-transaction-system :is(
    #root,
    #root > .platform-shell,
    .platform-main,
    main.platform-main,
    .stx-shell,
    .stx-stage,
    .stx-vf-stage
  ) {
    position: relative !important;
    inset: auto !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    overscroll-behavior-y: auto !important;
    touch-action: manipulation !important;
  }

  html.sx-ios-safari body.sundex-transaction-system .stx-shell,
  html.sx-ios-safari body.sundex-transaction-system .stx-shell * {
    touch-action: manipulation !important;
  }
}

@media (max-width: 820px) and (prefers-reduced-motion: no-preference) {
  html.sx-mobile-input-active :where(.animate-pulse, .animate-spin, [class*="animate-"]) {
    animation-play-state: paused !important;
  }
}
