/* ===== MODAL FIX - Prevent Page Jumping & Layout Shift ===== */

/* Prevent body scroll when modal is open - NO JUMP */
body.modal-open {
  overflow: hidden !important;
  padding-right: var(--scrollbar-width, 0px) !important;
  position: relative;
}

/* Calculate scrollbar width dynamically */
html {
  --scrollbar-width: 0px;
}

/* Modal smooth transitions */
.modal {
  transition: opacity 0.3s ease, visibility 0.3s ease;
  opacity: 0;
  visibility: hidden;
}

.modal.show {
  opacity: 1;
  visibility: visible;
}

/* Prevent content shift during modal animations */
.modal-content {
  will-change: transform, opacity;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Smooth modal backdrop */
.modal::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: -1;
}

/* Prevent layout shift on page transitions */
.page-container {
  min-height: 100vh;
  position: relative;
}

/* Smooth page transitions - No shake */
.page-transition-enter {
  opacity: 0;
  transform: translateY(10px);
}

.page-transition-enter-active {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.page-transition-exit {
  opacity: 1;
  transform: translateY(0);
}

.page-transition-exit-active {
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Fix for iOS Safari bounce */
html, body {
  position: relative;
  overflow-x: hidden;
}

body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Prevent background scroll on mobile when modal is open */
@media (max-width: 768px) {
  body.modal-open {
    position: fixed;
    width: 100%;
    top: calc(var(--scroll-position, 0) * -1px);
  }
}

/* Prevent flash of unstyled content (FOUC) */
.modal-content > * {
  animation-fill-mode: both;
}

/* Smooth modal close */
.modal.closing {
  animation: fadeOut 0.3s ease forwards;
}

.modal.closing .modal-content {
  animation: slideDown 0.3s ease forwards;
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes slideDown {
  from {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  to {
    transform: translateY(20px) scale(0.95);
    opacity: 0;
  }
}

/* Prevent CLS (Cumulative Layout Shift) */
.link-card,
.bg-card,
.modal-content {
  contain: layout;
}

/* GPU acceleration for smoother animations */
.modal,
.modal-content,
.bg-fixed-container,
.bg-grid-overlay,
.bg-blur-effect {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Prevent text selection during transitions */
.modal-content {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.modal.show .modal-content {
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
}

/* Fix for Chrome jitter */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent layout shift from images */
img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Prevent reflow during animations */
.fade-in {
  animation-fill-mode: both;
  will-change: opacity, transform;
}

/* Stable footer positioning */
footer {
  flex-shrink: 0;
}
