/* ==========================================================================
   Comprehensive Mobile-First Responsiveness & Ergonomics
   Ensures perfect viewing on iPhone, Android, and tablets (320px - 768px+)
   ========================================================================== */

/* 1. Global Viewport & Box Integrity */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  max-width: 100vw;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
  overscroll-behavior-y: none;
}

body {
  min-width: 320px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Canonical site header typography.
   Keep this here because every page loads this stylesheet, including the
   standalone Gallery and Shakunavali layouts. */
#header {
  font-family: Manrope, Arial, sans-serif;
}

#header nav {
  min-height: 80px;
}

#header nav > div:nth-child(2) {
  gap: 1.25rem !important;
  font-family: Manrope, Arial, sans-serif !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1.5;
}

#header nav > div:nth-child(2) > button,
#header nav > div:nth-child(2) > a {
  font-family: Manrope, Arial, sans-serif !important;
  font-size: 14px !important;
  font-weight: 600 !important;
}

#header nav > div:nth-child(2) [class*="absolute"] a {
  font-family: Manrope, Arial, sans-serif !important;
  font-size: 12px !important;
  font-weight: 600 !important;
}

#header nav > a strong {
  font-family: "Cormorant Garamond", Georgia, serif !important;
  font-size: 20px !important;
  font-weight: 600 !important;
}

#header nav > div:last-child > a {
  font-family: Manrope, Arial, sans-serif !important;
  font-size: 12px !important;
  font-weight: 700 !important;
}

#header #mobileMenu,
#header #mm {
  font-family: Manrope, Arial, sans-serif;
}

#header #mobileMenu a,
#header #mm a {
  font-size: 14px;
  font-weight: 500;
}

/* Prevent unwanted horizontal overflow from any long words or URLs */
h1, h2, h3, h4, h5, h6, p, blockquote, figcaption, a, span, li, dt, dd {
  overflow-wrap: break-word;
  word-wrap: break-word;
  hyphens: auto;
}

/* Responsive Images & Media */
img, svg, video, canvas, audio, iframe, embed, object {
  max-width: 100%;
  height: auto;
}

img {
  image-rendering: auto;
}

/* Render long pages progressively while reserving stable space. */
main > section:not(:first-child),
main > article > section,
.story-body > section,
.mogar-story > section {
  content-visibility: auto;
  contain-intrinsic-size: auto 720px;
}

:where(section, article, div)[id] {
  scroll-margin-top: 104px;
}

/* Smooth Touch Ergonomics */
button, a, input, select, textarea {
  touch-action: manipulation;
}

/* Form Controls: prevent iOS Safari automatic zoom on focus by enforcing >= 16px */
input, select, textarea {
  font-size: 16px !important;
}

/* 2. Global Mobile Header & Navigation */
@media (max-width: 1024px) {
  html { scroll-padding-top: 76px; }
  header nav {
    min-height: 72px !important;
    height: auto !important;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
  #mobileMenu, #mm {
    max-height: calc(100dvh - 72px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
  #mobileMenu a, #mm a {
    min-height: 46px;
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-radius: 0.6rem;
    transition: background-color 0.2s ease;
  }
  #mobileMenu a:active, #mm a:active {
    background-color: rgba(231, 214, 186, 0.5);
  }
}

/* 3. Hero & Headline Adaptations for Small & Medium Screens */
@media (max-width: 640px) {
  body { font-size: 16px; }

  .home-hero {
    min-height: 720px !important;
  }
  .home-hero > div.relative {
    min-height: 720px !important;
    padding-top: 7rem !important;
    padding-bottom: 4rem !important;
  }
  .home-hero h1 {
    font-size: clamp(2.45rem, 11vw, 3.15rem) !important;
    line-height: 1.02 !important;
  }
  .home-hero p {
    max-width: 34rem;
  }

  main > section,
  .section,
  .vm-section,
  .mogar-life,
  .mogar-rituals {
    scroll-margin-top: 78px;
  }

  p, li {
    line-height: 1.75;
  }
  /* Fluid and comfortable headlines on small screens */
  h1 {
    font-size: clamp(2.2rem, 8.5vw, 3.2rem) !important;
    line-height: 1.05 !important;
    letter-spacing: -0.02em !important;
  }
  h2 {
    font-size: clamp(1.8rem, 7vw, 2.5rem) !important;
    line-height: 1.15 !important;
  }
  h3 {
    font-size: clamp(1.35rem, 5.5vw, 1.85rem) !important;
    line-height: 1.25 !important;
  }

  /* Spiritual Hero Banner */
  .spiritual-hero {
    min-height: 480px !important;
    padding-top: 6.5rem !important;
    padding-bottom: 3.5rem !important;
    padding-left: 1.25rem !important;
    padding-right: 1.25rem !important;
  }
  .spiritual-hero h1 {
    font-size: clamp(2.25rem, 8.5vw, 3.2rem) !important;
    line-height: 1.08 !important;
  }
  .spiritual-hero p.mt-8,
  .spiritual-hero p {
    font-size: 0.95rem !important;
    line-height: 1.75 !important;
  }

  /* Quotes on Mobile */
  .sacred-quote {
    padding: 2.5rem 1.25rem !important;
  }
  .sacred-quote blockquote {
    font-size: clamp(1.4rem, 6vw, 2.1rem) !important;
    line-height: 1.3 !important;
  }

  /* Content Padding on Mobile */
  .sacred-content {
    padding: 2.75rem 1.25rem !important;
  }

  /* Actions & Button Stacking on Mobile */
  .actions,
  .home-hero .mt-9,
  .shakun-hero .mt-9,
  .visma-actions {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 0.75rem;
  }
  .actions a,
  .home-hero .mt-9 a,
  .shakun-hero .mt-9 a,
  .visma-actions a {
    width: 100%;
    text-align: center;
    justify-content: center;
    min-height: 46px;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
  }

  /* Side border decorative images shouldn't overflow or crowd mobile content */
  .ashram-edge,
  .story-edge,
  .story-body:before,
  .story-body:after,
  .mogar-story:before,
  .mogar-story:after,
  .nc-topic:before,
  .nc-topic:after {
    max-width: 36px !important;
    opacity: 0.06 !important;
  }

  /* Gallery Grid on Mobile */
  #gallery-grid {
    grid-auto-rows: 250px !important;
    gap: 1rem !important;
  }
  .gallery-card.row-span-2 {
    grid-row: span 1 !important;
  }

  /* Single Column Cards */
  .mogar-learning-inner,
  .mogar-intro,
  .mogar-visit,
  .mogar-life-grid,
  .visma-care,
  .contact-hero-inner,
  .contact-enquiry,
  .vm-split {
    grid-template-columns: 1fr !important;
    gap: 1.75rem !important;
  }

  /* Home Seva Track on Mobile */
  .home-seva-track {
    grid-template-columns: 1fr !important;
    grid-auto-rows: 240px !important;
    gap: 1rem !important;
  }
  .home-seva-card:nth-child(n) {
    grid-column: auto !important;
    grid-row: auto !important;
    min-height: 220px !important;
  }
  .home-seva-card span {
    font-size: 1.25rem !important;
    padding: 2.5rem 1rem 1rem !important;
  }

  /* Mobile Touch Targets in Footer */
  footer a:not(.h-9):not([aria-label]),
  footer span:not(.h-9) {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
  }

  /* Forms on Mobile */
  form input, form textarea, form select {
    width: 100% !important;
    border-radius: 0.75rem !important;
    padding: 0.75rem 1rem !important;
  }
}

/* Tablet: retain breathing room without desktop-sized gaps. */
@media (min-width: 641px) and (max-width: 1024px) {
  .mogar-wrap,
  .vm-inner,
  .story-chapter-inner {
    width: min(100% - 3rem, 900px) !important;
  }
  .mogar-intro,
  .mogar-learning-inner,
  .mogar-visit {
    gap: clamp(2rem, 5vw, 3.5rem) !important;
  }
}

/* Desktop: prevent stretched copy and keep images crisp and balanced. */
@media (min-width: 1025px) {
  main { width: 100%; }
  p { text-wrap: pretty; }
  h1, h2, h3 { text-wrap: balance; }
  .mogar-wrap,
  .vm-inner,
  .story-chapter-inner { margin-inline: auto; }
}

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

/* 4. Ultra-compact screens (iPhone SE, Galaxy Fold, 320px - 380px) */
@media (max-width: 380px) {
  header nav {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }
  header nav a strong {
    font-size: 1rem !important;
  }
  header nav a small {
    font-size: 7px !important;
    letter-spacing: 0.12em !important;
  }
  .home-hero h1,
  .story-hero h1 {
    font-size: 2rem !important;
    line-height: 1.1 !important;
  }
  .button, a.rounded-full:not(.h-9):not([aria-label]) {
    padding-left: 1.25rem !important;
    padding-right: 1.25rem !important;
    font-size: 0.85rem !important;
  }
}


/* Footer Social Media Icons: ensure perfect circular dimensions & centered SVG on mobile */
footer a.h-9,
footer a[aria-label="LinkedIn"],
footer a[aria-label="YouTube"],
footer a[aria-label="Instagram"],
footer a[aria-label="Facebook"] {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  max-width: 36px !important;
  max-height: 36px !important;
  padding: 0 !important;
  border-radius: 9999px !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
  color: rgba(255, 255, 255, 0.7) !important;
}

footer a.h-9:hover,
footer a[aria-label="LinkedIn"]:hover,
footer a[aria-label="YouTube"]:hover,
footer a[aria-label="Instagram"]:hover,
footer a[aria-label="Facebook"]:hover {
  border-color: #C69A42 !important;
  color: #C69A42 !important;
}

footer a.h-9 svg,
footer a[aria-label="LinkedIn"] svg,
footer a[aria-label="YouTube"] svg,
footer a[aria-label="Instagram"] svg,
footer a[aria-label="Facebook"] svg {
  display: block !important;
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  min-height: 18px !important;
  max-width: 18px !important;
  max-height: 18px !important;
  margin: auto !important;
  flex-shrink: 0 !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: none;
}
