/**
 * Sprint 7 — Performance + a11y motion helpers (safe, no visual redesign).
 * Keep tiny. Loaded after trail bundle on all exchange pages.
 */

/* Large schedule boards: skip offscreen paint work without removing nodes.
   Desktop only — on mobile content-visibility:auto causes scroll stutter
   as groups enter/leave the viewport (layout/paint thrash). */
@media (min-width: 992px) {
  .exchange-app .ex-inplay-group {
    content-visibility: auto;
    contain-intrinsic-size: auto 220px;
  }

  .exchange-app .ex-personalization-strip,
  .exchange-app .ex-smart-hub__section {
    content-visibility: auto;
    contain-intrinsic-size: auto 96px;
  }
}

@media (max-width: 991.98px) {
  /* Theme sets scroll-behavior:smooth on html.theme-* — beats plain `html`
     in exchange-perf and makes finger-scroll feel laggy / sticky. */
  html,
  html.theme-light,
  html.theme-dark {
    scroll-behavior: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Kill every content-visibility lazy paint on phones — any leftover rule
     (trading lazy bodies, groups, workspace sections) thrashes on scroll. */
  .exchange-app .ex-inplay-group,
  .exchange-app .ex-personalization-strip,
  .exchange-app .ex-smart-hub__section,
  .exchange-app .ex-trading-section,
  .exchange-app .ex-workspace-page [data-ex-trading-section],
  .exchange-app [data-ex-trading-body],
  .exchange-app .ex-trading-lazy:not(.is-paint-ready) {
    content-visibility: visible !important;
    contain-intrinsic-size: none !important;
    contain: none !important;
  }

  /* Sticky chrome blur repaints every frame while the page moves. */
  .exchange-app .ex-market-jump,
  .exchange-app .ex-workspace-sticky-head,
  .exchange-app .ex-trading-section__head,
  .exchange-app .ex-workspace-nav,
  .exchange-app .ex-betslip-account-summary,
  .exchange-app .ex-match-detail-board__rail,
  .exchange-app .ex-schedule-subnav,
  .exchange-app .ex-premium-score--sticky,
  .exchange-app .ex-header-bar,
  .exchange-app .ex-inplay-group__head {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  /* contain:layout on sticky rows forces extra layout passes on iOS. */
  .exchange-app .ex-market-jump,
  .exchange-app .ex-workspace-sticky-head,
  .exchange-app .ex-trading-section__head {
    contain: none !important;
  }

  /* Dozens of infinite LIVE / countdown animations repaint during scroll. */
  .exchange-app .ex-indibet-list__live-badge::after,
  .exchange-app .ex-indibet-list__live-badge .ex-live-dot,
  .exchange-app .ex-indibet-list__live-dot,
  .exchange-app .ex-list-match-table__live-dot,
  .exchange-app .ex-list-match-table__countdown--lt5m::before,
  .exchange-app .ex-list-match-table__countdown--lt5m::after,
  .exchange-app .ex-list-match-table__countdown--lt5m .ex-list-match-table__countdown-hand {
    animation: none !important;
  }

  .exchange-app {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
  }

  /* Sticky rows re-layout every frame while the page moves — disable on phones. */
  body.ex-home-dense .ex-live-cat-strip,
  .exchange-app .ex-inplay-group__list--indibet .ex-indibet-list__columns,
  .exchange-app .ex-home-ia__subnav,
  .exchange-app .ex-schedule-subnav {
    position: relative !important;
    top: auto !important;
  }
}

/* Sticky chrome: isolate paints from odds flash below (desktop). */
@media (min-width: 992px) {
  .exchange-app .ex-market-jump,
  .exchange-app .ex-workspace-sticky-head,
  .exchange-app .ex-trading-section__head {
    contain: layout style;
  }
}

/* Touch targets — enforce minimum hit area without changing visible chrome size. */
.exchange-app .ex-market-jump__chip,
.exchange-app .ex-mybets-chip,
.exchange-app .ex-workspace-actions__btn,
.exchange-app .ex-smart-hub__chip,
.exchange-app .ex-workspace-nav__chip {
  min-height: 2.25rem;
}

.exchange-app .ex-mobile-nav__item {
  min-height: 2.75rem;
}

/* Focus visibility for keyboard traders */
.exchange-app .ex-price:focus-visible,
.exchange-app a.ex-price[role="button"]:focus-visible,
.exchange-app .ex-market-jump__chip:focus-visible,
.exchange-app .ex-trading-section__toggle:focus-visible,
.exchange-app .ex-workspace-actions__btn:focus-visible,
.exchange-app .ex-smart-hub__layout-btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--theme-accent, #38bdf8) 80%, transparent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .exchange-app *,
  .exchange-app *::before,
  .exchange-app *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .exchange-app .ex-market-jump,
  .exchange-app .ex-workspace-sticky-head,
  .exchange-app .ex-trading-section__head,
  .exchange-app .ex-workspace-float-jump {
    backdrop-filter: none !important;
  }
}
