/* ============================================
   Projects Page CSS - Modern Grid with Modal
   ============================================ */

/* ========== PROJECTS HERO SECTION ========== */
.projects-hero-section {
  background-image: url('../images/site/projects-background.webp') !important;
  background-size: cover !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
}

.projects-hero-section::before {
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.4) 0%,
    rgba(0, 0, 0, 0.3) 50%,
    rgba(0, 0, 0, 0.5) 100%
  ) !important;
}

/* Mobile Background Image */
@media (max-width: 768px) {
  .projects-hero-section {
    background-image: url('../images/site/projects-background-mobile.webp') !important;
    background-attachment: scroll; /* Disable fixed attachment on mobile for better performance */
  }
}

/* ========== PROJECTS PAGE SECTION ========== */
.projects-page-section {
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
  background-color: var(--color-bg-light, #f6f8fd);
  padding: 80px 30px;
  scroll-margin-top: 100px; /* Account for sticky navbar */
  scroll-padding-top: 100px; /* Account for sticky navbar */
}

.projects-page-container {
  max-width: 1400px;
  margin: 0 auto;
}

/* ========== PROJECTS GRID ========== */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 200px;
  gap: 25px;
  padding: 0;
}

/* ========== PROJECT CARD ========== */
.project-grid-card {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 0;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(0, 99, 173, 0.1);
}

/* Masonry grid patterns - different sizes for visual interest */
.project-grid-card:nth-child(1) {
  grid-column: span 2;
  grid-row: span 2;
}

.project-grid-card:nth-child(2) {
  grid-column: span 2;
  grid-row: span 1;
}

.project-grid-card:nth-child(3) {
  grid-column: span 2;
  grid-row: span 3;
}

.project-grid-card:nth-child(4) {
  grid-column: span 2;
  grid-row: span 2;
}

.project-grid-card:nth-child(5) {
  grid-column: span 2;
  grid-row: span 2;
}

.project-grid-card:nth-child(6) {
  grid-column: span 2;
  grid-row: span 2;
}

.project-grid-card:nth-child(7) {
  grid-column: span 2;
  grid-row: span 2  ;
}

.project-grid-card:nth-child(8) {
  grid-column: span 2;
  grid-row: span 3;
}

.project-grid-card:nth-child(9) {
  grid-column: span 2;
  grid-row: span 2;
}

.project-grid-card:nth-child(10) {
  grid-column: span 2;
  grid-row: span 2;
}

.project-grid-card:nth-child(11) {
  grid-column: span 2;
  grid-row: span 2;
}

/* Continue pattern for remaining items */
.project-grid-card:nth-child(n+12) {
  grid-column: span 2;
  grid-row: span 2;
}

.project-grid-card:hover {
  transform: translateY(-10px) scale(1.02);
  box-shadow: 0 16px 32px rgba(0, 99, 173, 0.25);
  border-color: rgba(0, 99, 173, 0.3);
}

.project-grid-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.3) 60%,
    rgba(0, 0, 0, 0.8) 100%
  );
  z-index: 1;
  transition: opacity 0.3s ease;
}

.project-grid-card:hover::before {
  opacity: 0.9;
}

.project-grid-card-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 25px;
  z-index: 2;
  color: white;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.5) 50%, rgba(0, 0, 0, 0.2) 80%, transparent 100%);
  min-height: 100px;
}

.project-grid-card-title {
  font-family: "Noto Sans Hebrew", "Open Sans", sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 8px 0;
  color: white;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
  letter-spacing: 0.5px;
}

.project-grid-card-subtitle {
  font-family: "Noto Sans Hebrew", "Open Sans", sans-serif;
  font-size: 0.85rem;
  opacity: 0.95;
  margin: 0;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
  font-weight: 400;
}

/* Liquid glass hover panel */
.project-grid-card-hover {
  position: absolute;
  top: -100%;
  left: 0;
  right: 0;
  margin-left: auto;
  margin-right: auto;
  width: calc(100% - 24px);
  height: auto;
  min-height: 120px;
  max-height: 50%;
  border-bottom-left-radius: 50px;
  border-bottom-right-radius: 50px;
  border-width: 0 1px 1px;
  border-style: solid;
  border-color: rgba(255, 255, 255, 1);
  background-color: rgba(69, 74, 63, 0.2);
  padding: 24px;
  color: rgb(255, 255, 255);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 3;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.project-grid-card:hover .project-grid-card-hover {
  top: 0;
}

.project-grid-card-summary {
  font-family: "Noto Sans Hebrew", "Open Sans", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  margin: 0;
  color: rgb(255, 255, 255);
  text-align: center;
  font-weight: 400;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* RTL support for hover panel */
html[dir="rtl"] .project-grid-card-summary,
body[dir="rtl"] .project-grid-card-summary {
  text-align: center;
  direction: rtl;
}

/* ========== MODAL ========== */
.project-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.project-modal.active {
  display: flex;
  opacity: 1;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: 24px;
  max-width: 1600px;
  width: 95%;
  height: 90vh;
  max-height: 90vh;
  /* Use dynamic viewport height where supported to avoid iOS address-bar issues */
  height: 90dvh;
  max-height: 90dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 1;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.project-modal.active .modal-content {
  transform: scale(1);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px; /* Default: right side for LTR (English) */
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 0;
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1a1a1a;
  transition: color 0.2s ease, transform 0.2s ease;
  box-shadow: none;
  font-weight: 300;
  -webkit-tap-highlight-color: transparent;
}

/* RTL support - X button on left for Hebrew */
html[dir="rtl"] .modal-close,
body[dir="rtl"] .modal-close,
.modal-content[dir="rtl"] .modal-close {
  right: auto !important;
  left: 12px !important;
}

/* LTR support - X button on right for English (explicit) */
html[dir="ltr"] .modal-close,
body[dir="ltr"] .modal-close,
.modal-content[dir="ltr"] .modal-close {
  left: auto !important;
  right: 12px !important;
}

.modal-close:hover {
  background: transparent;
  color: #0063AD;
  transform: rotate(90deg) scale(1.06);
}

.modal-close:active {
  color: #004a7a;
}

.modal-header {
  padding: 30px 50px 20px;
  border-bottom: 2px solid #e2e8f0;
  flex-shrink: 0;
  background: linear-gradient(to bottom, rgba(246, 248, 253, 0.5), transparent);
}

.modal-project-title {
  font-family: "Noto Sans Hebrew", "Open Sans", sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: #0063AD;
  margin: 0;
  letter-spacing: 0.5px;
}

/* Optima font for English modal project titles */
[lang="en"] .modal-project-title,
[dir="ltr"] .modal-project-title,
.ltr .modal-project-title {
  font-family: "Optima LT W02 Roman", "Optima", sans-serif;
  text-transform: uppercase;
}

.modal-body {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 0;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

/* ========== GALLERY ========== */
.modal-gallery {
  position: relative;
  width: 100%;
  height: 100%;
  background: #0a0a0a;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid #e2e8f0;
  min-height: 0;
}

.gallery-container {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* Allow horizontal touch swipes for image navigation without scrolling the page */
  touch-action: pan-y;
}

.gallery-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.gallery-image.loaded {
  opacity: 1;
}

.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 50px;
  height: 50px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.gallery-nav:hover {
  background: #0063AD;
  color: white;
  transform: translateY(-50%) scale(1.1);
}

/* Default LTR: prev on left, next on right */
.gallery-prev {
  left: 20px;
  right: auto;
}

.gallery-next {
  right: 20px;
  left: auto;
}

/* RTL: prev on right, next on left */
html[dir="rtl"] .gallery-prev,
body[dir="rtl"] .gallery-prev,
.modal-content[dir="rtl"] .gallery-prev {
  right: 20px !important;
  left: auto !important;
}

html[dir="rtl"] .gallery-next,
body[dir="rtl"] .gallery-next,
.modal-content[dir="rtl"] .gallery-next {
  left: 20px !important;
  right: auto !important;
}

/* LTR: prev on left, next on right (explicit) */
html[dir="ltr"] .gallery-prev,
body[dir="ltr"] .gallery-prev,
.modal-content[dir="ltr"] .gallery-prev {
  left: 20px !important;
  right: auto !important;
}

html[dir="ltr"] .gallery-next,
body[dir="ltr"] .gallery-next,
.modal-content[dir="ltr"] .gallery-next {
  right: 20px !important;
  left: auto !important;
}

.gallery-nav:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.gallery-counter {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.65);
  color: white;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.3px;
  font-family: "Open Sans", sans-serif;
  z-index: 5;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}

/* Loader shown while gallery image is loading */
.gallery-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 3;
}

.gallery-loader.visible {
  opacity: 1;
}

.gallery-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  animation: gallery-spin 0.9s linear infinite;
}

@keyframes gallery-spin {
  to { transform: rotate(360deg); }
}

/* One-time swipe hint on touch devices */
.gallery-swipe-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.4s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.gallery-swipe-hint.visible { opacity: 1; }

/* ========== THUMBNAILS STRIP ========== */
.gallery-thumbnails {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  overflow-x: auto;
  overflow-y: hidden;
  background: rgba(0, 0, 0, 0.55);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.35) transparent;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  overscroll-behavior-inline: contain;
}

.gallery-thumbnails:empty {
  display: none;
}

.gallery-thumbnails::-webkit-scrollbar {
  height: 6px;
}

.gallery-thumbnails::-webkit-scrollbar-track {
  background: transparent;
}

.gallery-thumbnails::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
}

.gallery-thumb {
  flex: 0 0 auto;
  width: 80px;
  height: 54px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  overflow: hidden;
  background: #1a1a1a;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s ease, transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-thumb:hover {
  opacity: 0.9;
}

.gallery-thumb.active {
  opacity: 1;
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(0, 99, 173, 0.75);
  transform: scale(1.04);
}

.gallery-thumb:focus-visible {
  outline: 2px solid #0063AD;
  outline-offset: 2px;
  opacity: 1;
}

/* ========== MODAL DETAILS ========== */
.modal-details {
  padding: 30px 40px;
  font-family: "Noto Sans Hebrew", "Open Sans", sans-serif;
  overflow-y: auto;
  height: 100%;
  box-sizing: border-box;
  background: rgba(246, 248, 253, 0.3);
}

/* Lato font for English modal details */
[lang="en"] .modal-details,
[dir="ltr"] .modal-details,
.ltr .modal-details {
  font-family: 'Lato', 'Open Sans', sans-serif;
}

.modal-details::-webkit-scrollbar {
  width: 8px;
}

.modal-details::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.modal-details::-webkit-scrollbar-thumb {
  background: #0063AD;
  border-radius: 4px;
}

.modal-details::-webkit-scrollbar-thumb:hover {
  background: #004a7a;
}

.modal-details h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: #0063AD;
  margin: 0 0 12px 0;
}

.modal-details p {
  font-size: 0.95rem;
  line-height: 1.7;
  color: #666;
  margin: 0 0 15px 0;
}

.modal-details ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.modal-details li {
  padding: 12px 0;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.9rem;
  color: #666;
  line-height: 1.6;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.modal-details li:last-child {
  border-bottom: none;
}

.modal-details li .detail-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  color: #0063AD;
}

.modal-details li .detail-content {
  flex: 1;
}

.modal-details li strong {
  color: #0063AD;
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1200px) {
  .projects-grid {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 180px;
    gap: 20px;
  }
  
  .project-grid-card:nth-child(1),
  .project-grid-card:nth-child(5),
  .project-grid-card:nth-child(8) {
    grid-column: span 2;
    grid-row: span 2;
  }
  
  .project-grid-card:nth-child(2),
  .project-grid-card:nth-child(9) {
    grid-column: span 1;
    grid-row: span 3;
  }
  
  .project-grid-card:nth-child(3),
  .project-grid-card:nth-child(4),
  .project-grid-card:nth-child(6),
  .project-grid-card:nth-child(10),
  .project-grid-card:nth-child(11) {
    grid-column: span 1;
    grid-row: span 1;
  }
  
  .project-grid-card:nth-child(7) {
    grid-column: span 3;
    grid-row: span 1;
  }
  
  .project-grid-card:nth-child(n+12) {
    grid-column: span 1;
    grid-row: span 2;
  }
}

@media (max-width: 1024px) {
  .projects-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 200px;
    gap: 20px;
  }
  
  .project-grid-card:nth-child(1),
  .project-grid-card:nth-child(2),
  .project-grid-card:nth-child(5),
  .project-grid-card:nth-child(8),
  .project-grid-card:nth-child(9) {
    grid-column: span 1;
    grid-row: span 2;
  }
  
  .project-grid-card:nth-child(3),
  .project-grid-card:nth-child(4),
  .project-grid-card:nth-child(6),
  .project-grid-card:nth-child(10),
  .project-grid-card:nth-child(11) {
    grid-column: span 1;
    grid-row: span 1;
  }
  
  .project-grid-card:nth-child(7) {
    grid-column: span 2;
    grid-row: span 1;
  }
  
  .project-grid-card:nth-child(n+12) {
    grid-column: span 1;
    grid-row: span 2;
  }
  
  .modal-content {
    max-width: 95%;
  }
}

@media (max-width: 768px) {
  .projects-page-section {
    padding: 100px 15px 40px;
    background-attachment: scroll;
  }
  
  .projects-page-header {
    margin-bottom: 40px;
  }
  
  .projects-page-title {
    font-size: 2.5rem;
    margin-bottom: 15px;
  }
  
  .projects-page-motto {
    font-size: 1.1rem;
  }
  
  .projects-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: 300px;
    gap: 20px;
  }
  
  .project-grid-card {
    grid-column: span 1 !important;
    grid-row: span 1 !important;
  }
  
  .project-grid-card-content {
    padding: 20px;
  }
  
  .project-grid-card-title {
    font-size: 1.3rem;
  }
  
  /* Centered card “popup” — not full-screen */
  .project-modal {
    padding: max(10px, env(safe-area-inset-top, 0px)) 14px max(14px, env(safe-area-inset-bottom, 0px));
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .modal-content {
    width: calc(100% - 8px);
    max-width: min(520px, 100vw - 28px);
    max-height: min(88dvh, 720px);
    min-height: 0;
    overflow: hidden;
    border-radius: 20px;
    transform: translateY(12px) scale(0.98);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.25s ease;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  }

  .project-modal.active .modal-content {
    transform: translateY(0) scale(1);
    opacity: 1;
  }

  /* Sticky header so the title remains visible while scrolling details */
  .modal-header {
    padding: 12px 48px 10px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 20px 20px 0 0;
  }

  html[dir="rtl"] .modal-header,
  body[dir="rtl"] .modal-header,
  .modal-content[dir="rtl"] .modal-header {
    padding-right: 16px;
    padding-left: 48px;
  }

  .modal-project-title {
    font-size: 1.25rem;
    line-height: 1.3;
  }

  /* Single unified scroll so thumb + details feel like one sheet */
  .modal-body {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    grid-template-rows: none;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .modal-gallery {
    flex: 0 0 auto;
    height: 42vh;
    height: min(42dvh, 360px);
    min-height: 200px;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid #1a1a1a;
  }

  .gallery-nav {
    width: 42px;
    height: 42px;
    font-size: 26px;
    background: rgba(255, 255, 255, 0.94);
  }

  .gallery-prev { left: 10px; right: auto; }
  .gallery-next { right: 10px; left: auto; }

  html[dir="rtl"] .gallery-prev,
  body[dir="rtl"] .gallery-prev,
  .modal-content[dir="rtl"] .gallery-prev {
    right: 10px !important;
    left: auto !important;
  }

  html[dir="rtl"] .gallery-next,
  body[dir="rtl"] .gallery-next,
  .modal-content[dir="rtl"] .gallery-next {
    left: 10px !important;
    right: auto !important;
  }

  html[dir="ltr"] .gallery-prev,
  body[dir="ltr"] .gallery-prev,
  .modal-content[dir="ltr"] .gallery-prev {
    left: 10px !important;
    right: auto !important;
  }

  html[dir="ltr"] .gallery-next,
  body[dir="ltr"] .gallery-next,
  .modal-content[dir="ltr"] .gallery-next {
    right: 10px !important;
    left: auto !important;
  }

  .gallery-counter {
    top: 12px;
    font-size: 12px;
    padding: 5px 12px;
  }

  .gallery-thumbnails {
    padding: 8px 10px;
    gap: 6px;
  }

  .gallery-thumb {
    width: 64px;
    height: 44px;
  }

  .modal-details {
    flex: 1 1 auto;
    padding: 20px 18px calc(28px + env(safe-area-inset-bottom, 0px));
    max-height: none;
    overflow: visible;
    font-size: 0.95rem;
  }

  .modal-details li {
    padding: 14px 0;
    font-size: 0.95rem;
  }

  /* Close: no circle, sits high in the card corner */
  .modal-close {
    position: absolute;
    top: 4px;
    right: 6px;
    width: 44px;
    height: 44px;
    font-size: 30px;
    background: transparent;
    box-shadow: none;
    color: #1a1a1a;
  }

  html[dir="rtl"] .modal-close,
  body[dir="rtl"] .modal-close,
  .modal-content[dir="rtl"] .modal-close {
    right: auto !important;
    left: 6px !important;
  }
  
  /* Adjust hover panel for mobile */
  .project-grid-card-hover {
    height: auto;
    min-height: 100px;
    max-height: 50%;
    padding: 20px;
    width: calc(100% - 16px);
    border-bottom-left-radius: 30px;
    border-bottom-right-radius: 30px;
  }
  
  .project-grid-card-summary {
    font-size: 0.9rem;
    line-height: 1.4;
  }
}

@media (max-width: 480px) {
  .projects-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .projects-page-title {
    font-size: 1.8rem;
  }

  .modal-project-title {
    font-size: 1.15rem;
  }

  .modal-header {
    padding-right: 54px;
    padding-left: 16px;
  }

  html[dir="rtl"] .modal-header,
  body[dir="rtl"] .modal-header,
  .modal-content[dir="rtl"] .modal-header {
    padding-right: 16px;
    padding-left: 54px;
  }

  .modal-gallery {
    height: 48vh;
    height: min(48dvh, 380px);
    min-height: 220px;
  }

  .gallery-thumb {
    width: 58px;
    height: 40px;
  }

  .modal-details {
    padding: 16px 14px calc(24px + env(safe-area-inset-bottom, 0px));
  }
}

/* Landscape phones: smaller gallery inside popup */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  .modal-content {
    max-height: min(92dvh, 560px);
  }

  .modal-gallery {
    height: min(38dvh, 240px);
    min-height: 160px;
    max-height: 45vh;
  }

  .gallery-thumbnails {
    padding: 6px 10px;
  }

  .gallery-thumb {
    width: 54px;
    height: 38px;
  }
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .project-modal,
  .project-modal .modal-content,
  .gallery-image,
  .gallery-thumb,
  .gallery-nav,
  .modal-close {
    transition: none !important;
    animation: none !important;
  }
}

