/* ------------------------------------------------------------------ *
 * Safari / iPadOS performance guards.
 *
 * Loaded by every page. Desktop Chrome and Android are unaffected —
 * everything here is behind a touch-device or Safari-only query.
 * ------------------------------------------------------------------ */

/* 1. The single biggest cause of the iPad stutter.
 *
 * A backdrop-filter element re-blurs everything behind it on EVERY frame.
 * Put that on a position:sticky bar and Safari re-renders the blur through
 * the whole scroll, pinning the main thread — the page "hangs" while the
 * finger is down. The bars are already 78-88% opaque, so dropping the blur
 * on touch devices costs almost nothing visually and removes the work
 * entirely. Desktop keeps the blur (hover:hover). */
@media (hover: none) {
  .topbar, .chips, .backdrop, .sheet-scrim, .modal-scrim, .drawer-scrim,
  .gate-scrim, .lock-scrim, .ask-panel, .acct-menu {
    -webkit-backdrop-filter: none !important;
            backdrop-filter: none !important;
  }
}

/* 2. iOS reports 100vh as the height WITHOUT the address bar, so full-height
 * panes overflow, the page rubber-bands, and every scroll re-lays-out.
 * dvh is the viewport as it actually is. Browsers that do not know dvh keep
 * the vh rule above it. */
@supports (height: 100dvh) {
  .sidebar   { height: calc(100dvh - 138px) !important; }
  .drawer    { height: 100dvh !important; }
  .tool-main { min-height: calc(100dvh - var(--topbar-h)) !important; }
}

/* 3. Stop the whole page bouncing when an inner list hits its end — on iOS
 * that bounce forces a repaint of the sticky bars behind it. */
html, body { overscroll-behavior: none; }

/* 4. iOS keeps a 300ms grey flash on every tap; it makes a fast app feel slow. */
* { -webkit-tap-highlight-color: rgba(0,0,0,0); }

/* 5. Momentum scrolling for any inner scroller, and keep those scrollers on
 * their own layer so they do not repaint their ancestors. */
.sidebar, .sidenav, .drawer, .tool-main, .chips {
  -webkit-overflow-scrolling: touch;
}

/* 6. Respect the accessibility setting; also a cheap win on old iPads. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
