/* iOS Safari fixes — load last */

/* Layout: do not rely on :has() (add .has-nonprofit-bar on body via JS) */
body.has-nonprofit-bar {
  --nonprofit-bar-h: 36px;
}

body.has-nonprofit-bar .site-header {
  top: var(--nonprofit-bar-h);
}

body.has-nonprofit-bar .nav-mobile {
  top: calc(var(--header-h) + var(--nonprofit-bar-h));
  max-height: calc(100vh - var(--header-h) - var(--nonprofit-bar-h));
  max-height: calc(100dvh - var(--header-h) - var(--nonprofit-bar-h));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 1002;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
}

body.has-nonprofit-bar .hero,
body.has-nonprofit-bar .hero--premium {
  padding-top: calc(var(--header-h) + var(--nonprofit-bar-h) + 2rem);
}

body.has-nonprofit-bar .page-hero {
  padding-top: calc(var(--header-h) + var(--nonprofit-bar-h) + 2rem);
}

body.has-nonprofit-bar .mission-statement {
  margin-top: calc(var(--header-h) + var(--nonprofit-bar-h) + 0.5rem);
}

body.site-enhanced.has-nonprofit-bar .mission-statement {
  margin-top: calc(var(--header-h) + var(--nonprofit-bar-h) + 0.5rem);
}

/* background-attachment:fixed breaks painting on iOS */
@supports (-webkit-touch-callout: none) {
  body {
    background-attachment: scroll !important;
  }
}

/* Touch devices: reduce GPU-heavy effects */
@media (hover: none) and (pointer: coarse) {
  body.site-enhanced {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  /* Never hide hero while waiting for JS */
  body.site-enhanced:not(.is-loaded) .hero-content,
  body.site-enhanced:not(.is-loaded) .hero-visual,
  body.site-enhanced:not(.is-loaded) .hero-visual img {
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }

  .site-enhanced .ambient-bg {
    display: none !important;
  }

  .site-enhanced .reveal,
  .site-enhanced .reveal-scale {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  .hero-visual,
  .hero-visual::before {
    transform: none !important;
    -webkit-mask: none !important;
    mask: none !important;
  }

  .hero-visual::before {
    display: none;
  }

  .hero--premium {
    min-height: auto !important;
  }

  .site-enhanced .feature-card,
  .site-enhanced .pillar,
  .site-enhanced .impact-card,
  .site-enhanced .school-card,
  .site-enhanced .testimonial,
  .site-enhanced .step,
  .site-enhanced .contact-card,
  .site-enhanced .stat,
  .site-enhanced .get-involved-card,
  .site-enhanced .work-card,
  .site-enhanced .donate-panel,
  .site-enhanced .newsletter,
  .site-enhanced .leadership,
  .site-enhanced .outcome-item,
  .site-header,
  .btn--outline,
  .hero-badge,
  .nav-mobile.is-open,
  .support-banner,
  .prism-bubble {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(255, 255, 255, 0.97) !important;
  }

  .site-header {
    background: rgba(255, 255, 255, 0.98) !important;
  }

  .section--purple,
  .give-band,
  .nonprofit-bar {
    backdrop-filter: none !important;
  }

  .section--purple .step {
    background: #ffffff !important;
    color: var(--text-dark) !important;
  }

  .section--purple .step h3 {
    color: var(--purple-dark) !important;
  }

  .section--purple .step p {
    color: var(--text-muted) !important;
  }

  .section--purple .step__num {
    color: var(--purple-dark) !important;
    background: var(--purple-lighter) !important;
  }

  .prism-bubbles {
    display: none !important;
  }

  .hero h1 span {
    -webkit-text-fill-color: var(--purple-dark);
    color: var(--purple-dark);
    background: none !important;
  }

  .btn--primary:hover,
  .feature-card:hover,
  .site-enhanced .feature-card:hover {
    transform: none !important;
  }
}

/* Menu open: iOS scroll lock */
html.nav-open,
html.nav-open body {
  overflow: hidden;
  height: 100%;
  touch-action: none;
}

html.nav-open body {
  position: fixed;
  width: 100%;
  left: 0;
  right: 0;
}

/* Safe areas for notched iPhones */
.site-header,
.nonprofit-bar {
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.nonprofit-bar {
  padding-top: env(safe-area-inset-top, 0px);
}

body.has-nonprofit-bar .site-header {
  top: calc(var(--nonprofit-bar-h) + env(safe-area-inset-top, 0px));
}

/* Tap targets */
.menu-toggle {
  min-width: 44px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.nav-mobile a,
.btn {
  -webkit-tap-highlight-color: rgba(190, 73, 223, 0.15);
}

/* Fixed layers stacking */
.scroll-progress {
  z-index: 10003;
}

.nonprofit-bar {
  z-index: 1001;
}

.site-header {
  z-index: 1000;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

/* Prevent 100vh jump when address bar shows/hides */
@supports (min-height: 100dvh) {
  .hero--premium {
    min-height: min(88dvh, 920px) !important;
  }
}

@media (hover: none) and (pointer: coarse) {
  body.site-enhanced::after {
    display: none;
  }

  .hero-visual--animated .hero-visual__img,
  .illus-living .illus-living__img {
    animation: none !important;
  }

  .hero-deco--gear,
  .hero-deco--orb,
  .hero-visual__shine,
  .hero-brand__fx {
    display: none;
  }

  .hero-visual--brand .hero-brand__img {
    animation: none !important;
  }

  .hero-visual--brand .hero-visual__stage {
    animation: none !important;
  }

  .section-banner.prism-animated {
    animation: none !important;
    background-size: cover !important;
  }

  .section-banner.prism-animated::after,
  .section-banner.prism-animated::before {
    animation: none !important;
  }

  .media-flow__img {
    animation: none !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
  }

  .media-flow__layer,
  .media-flow__shine {
    display: none;
  }

  .banner-sphere {
    display: none;
  }
}
