/**
 * Page Transitions — iOS-safe, flicker-free animations.
 *
 * Rules followed to avoid WKWebView flickering:
 *  - Only animate `opacity` (no transform on body/main)
 *  - Short durations (200-300ms)
 *  - No `will-change`, `backface-visibility`, or `backdrop-filter`
 *  - No `backwards` fill mode (elements must never start invisible)
 *  - No bounce / overshoot easing
 *  - No staggered nth-child animations on broad selectors
 */

/* Prevent layout shift from scrollbar */
html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
}

/* Gentle fade-in for page content on load */
@keyframes safeFadeIn {
  from { opacity: 0.7; }
  to   { opacity: 1; }
}

/* Page content fades in quickly — starting at 0.7 avoids the
   "flash of invisible content" that causes flicker on iOS. */
.page-content,
[role="main"],
main {
  animation: safeFadeIn 0.25s ease forwards;
}

/* Modal / dialog fade-in */
.modal,
[role="dialog"],
.overlay {
  animation: safeFadeIn 0.2s ease forwards;
}

/* Smooth transitions for interactive elements */
button,
a,
.btn,
[role="button"] {
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

button:active,
a:active,
.btn:active,
[role="button"]:active {
  opacity: 0.75;
}

/* Navigation tab transitions */
.nav-tab {
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-tab:active {
  opacity: 0.75;
}

nav {
  transition: background-color 0.2s ease;
}

/* Form input focus transitions */
input,
textarea,
select {
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Image lazy-load fade */
img {
  transition: opacity 0.2s ease;
}

/* Body background transition (theme switching) */
body {
  transition: background-color 0.2s ease;
}

/* Font smoothing */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent interaction during navigation */
html[data-transitioning] {
  pointer-events: none;
}

/* Utility classes — opt-in only */
.fade-in {
  animation: safeFadeIn 0.25s ease forwards;
}

/* Reduce motion support */
@media (prefers-reduced-motion: reduce) {
  .page-content,
  [role="main"],
  main,
  .modal,
  [role="dialog"],
  .overlay,
  .fade-in {
    animation: none !important;
  }

  button, a, .btn, [role="button"],
  .nav-tab, nav, input, textarea, select, img, body {
    transition: none !important;
  }

  html {
    scroll-behavior: auto;
  }
}
