/* Telegram's in-app browser can leave substantially less height than the phone's screen. */
@media (max-width: 680px) {
  html:has(body.intro-active) {
    overflow: hidden !important;
    background: #fff !important;
  }

  body.intro-active {
    background: #fff !important;
  }
  body.intro-active > :not(.site-intro):not(script) {
    visibility: hidden !important;
  }

  html {
    scroll-padding-top: calc(84px + env(safe-area-inset-top, 0px));
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overscroll-behavior-y: none;
  }

  body {
    min-width: 0 !important;
    overflow-x: clip;
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
  }

  input, select, textarea { font-size: 16px !important; }

  /* Keep the header in the root scroll flow: iOS WebViews can offset fixed
     elements from the visible viewport as Telegram's chrome collapses. */
  .site-header {
    position: sticky !important;
    top: 0 !important;
    width: 100% !important;
    height: calc(68px + env(safe-area-inset-top, 0px)) !important;
    min-height: calc(68px + env(safe-area-inset-top, 0px)) !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
  }
  body.menu-open::before {
    top: calc(68px + env(safe-area-inset-top, 0px)) !important;
  }
  .main-nav,
  .main-nav.open {
    position: absolute !important;
    top: calc(80px + env(safe-area-inset-top, 0px)) !important;
    max-height: calc(var(--iapd-visible-height, 100dvh) - 92px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .mobile-nav-tools button {
    width: 40px !important;
    height: 40px !important;
    flex: none;
  }
  #registryResults,
  #russiaSubregionPicker,
  #registry .registry-region-picker {
    scroll-margin-top: calc(84px + env(safe-area-inset-top, 0px)) !important;
  }

  /* A browser toolbar or keyboard must not hide close buttons and dialog actions. */
  .member-profile-modal,
  .article-reader,
  .contact-modal,
  .lightbox-modal {
    max-height: calc(var(--iapd-visible-height, 100dvh) - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .member-profile,
  .article-reader__body,
  .modal-card {
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .article-reader__close {
    top: calc(8px + env(safe-area-inset-top, 0px)) !important;
    right: calc(12px + env(safe-area-inset-right, 0px)) !important;
    margin: 0 !important;
  }
  .site-footer { padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)) !important; }
  .site-intro {
    top: 0 !important;
    bottom: auto !important;
    height: calc(max(100dvh, var(--iapd-visible-bottom, 100dvh)) + 160px) !important;
    touch-action: none;
  }
  .site-intro__lockup { top: calc(var(--iapd-visible-height, 100dvh) / 2) !important; }

  /* Editor: one swipeable row keeps the form visible on short phone screens. */
  .login-panel {
    min-height: var(--iapd-visible-height, 100dvh) !important;
    padding-top: calc(22px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .sidebar {
    padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
  }
  .sidebar nav {
    display: flex !important;
    flex-wrap: nowrap !important;
    gap: 7px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    padding-bottom: 7px !important;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav button,
  .sidebar nav a {
    flex: none !important;
    min-height: 44px !important;
    white-space: nowrap !important;
    scroll-snap-align: start;
  }
  .workspace-main {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
  }
}
