/* =============================================
   PROJECT MODAL
   Glassmorphism modal with comparison sliders
   ============================================= */

.project-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  padding: 34px;
  align-items: center;
  justify-content: center;
}

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

/* Backdrop */
.project-modal .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,15,18,.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  touch-action: none;
  overscroll-behavior: contain;
}

/* Content panel */
.project-modal .modal-content {
  position: relative;
  width: min(1040px, calc(100% - 28px));
  z-index: 10001;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.10);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 30px 120px rgba(0,0,0,.40);
  overflow: hidden;
  max-height: 90vh;
  color: #fff;
  display: flex;
  flex-direction: column;
  will-change: transform;
}

/* Header */
.project-modal .modal-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 36px 82px 18px 36px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  background: inherit;
  backdrop-filter: inherit;
  -webkit-backdrop-filter: inherit;
}

.project-modal .modal-title {
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
  font-size: 26px;
  font-weight: 950;
  letter-spacing: -0.02em;
  color: #fff;
  margin: 0;
}

.project-modal .modal-meta {
  font-size: 13px;
  color: rgba(255,255,255,.76);
}

.project-modal .modal-meta .products-used {
  color: #fff;
  font-weight: 900;
}

/* Close button */
.project-modal .modal-close {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.10);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  z-index: 101;
  transition: transform .18s var(--ease), border-color .18s var(--ease), background .18s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.project-modal .modal-close:hover {
  transform: translateY(-1px);
  border-color: rgba(209,15,27,.35);
  background: rgba(209,15,27,.10);
}

/* Scrollable body */
.project-modal .modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 22px 22px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.25) transparent;
}

.project-modal .modal-body::-webkit-scrollbar { width: 6px; }
.project-modal .modal-body::-webkit-scrollbar-track { background: transparent; }
.project-modal .modal-body::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.20);
  border-radius: 10px;
}
.project-modal .modal-body::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.35); }
.project-modal .modal-body::-webkit-scrollbar-thumb:active { background: rgba(209,15,27,.65); }

/* Slider section */
.project-modal .slider-section { margin: 18px 14px; }

.project-modal .slider-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: rgba(255,255,255,.70);
  font-weight: 950;
  margin-bottom: 12px;
}

/* ── Before/After comparison slider ────────── */
.project-modal .comparison-slider {
  position: relative;
  width: 100%;
  margin: 0 auto;
  border-radius: 18px;
  overflow: hidden;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.10);
  box-shadow: 0 18px 60px rgba(0,0,0,.25);
  user-select: none;
  -webkit-user-select: none;
}

.project-modal .comparison-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
}

.project-modal .comparison-image.after  { z-index: 1; }
.project-modal .comparison-image.before {
  z-index: 2;
  clip-path: inset(0 50% 0 0);
  -webkit-clip-path: inset(0 50% 0 0);
}

.project-modal .slider-handle {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 3px;
  background: rgba(255,255,255,.9);
  transform: translateX(-50%);
  cursor: ew-resize;
  z-index: 10;
  box-shadow: 0 0 30px rgba(0,0,0,.35);
}

.project-modal .slider-handle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.project-modal .before-label,
.project-modal .after-label {
  position: absolute;
  top: 16px;
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: .12em;
  background: rgba(15,15,18,.55);
  color: #fff;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 12;
  pointer-events: none;
}

.project-modal .before-label { left: 16px; }
.project-modal .after-label  { right: 16px; }

/* ── Gallery grid ────────────────────────────── */
.project-modal .project-gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.project-modal .project-gallery-item {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(255,255,255,.06);
  cursor: pointer;
  transition: transform .18s var(--ease), border-color .18s var(--ease), background .18s var(--ease);
  padding: 0;
}

.project-modal .project-gallery-item:hover {
  transform: translateY(-2px);
  border-color: rgba(209,15,27,.35);
  background: rgba(209,15,27,.08);
}

.project-modal .project-gallery-item img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
}

/* ── Gallery lightbox ────────────────────────── */
.project-modal .gallery-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10050;
}

.project-modal .gallery-lightbox.active { display: block; }

.project-modal .gallery-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.project-modal .gallery-lightbox-body {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.project-modal .gallery-lightbox-img {
  max-width: min(1100px, 92vw);
  max-height: 84vh;
  border-radius: 18px;
  box-shadow: 0 30px 120px rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.14);
  background: #111;
}

/* Lightbox close & nav buttons — shared styles */
.project-modal .gallery-lightbox-close,
.project-modal .gallery-lightbox-nav {
  position: absolute;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.20);
  background: rgba(255,255,255,.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  -webkit-tap-highlight-color: transparent;
}

.project-modal .gallery-lightbox-close {
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  font-size: 20px;
  line-height: 1;
  transition: all 0.25s var(--ease);
}

.project-modal .gallery-lightbox-close:hover {
  background: rgba(209,15,27,.85);
  border-color: rgba(209,15,27,.95);
  transform: scale(1.12);
  box-shadow: 0 12px 32px rgba(209,15,27,.45);
}

.project-modal .gallery-lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  font-size: 26px;
  transition: all 0.25s var(--ease);
}

.project-modal .gallery-lightbox-nav.prev { left: 32px; }
.project-modal .gallery-lightbox-nav.next { right: 32px; }

.project-modal .gallery-lightbox-nav:hover {
  background: rgba(209,15,27,.85);
  border-color: rgba(209,15,27,.95);
  transform: translateY(-50%) scale(1.12);
  box-shadow: 0 12px 32px rgba(209,15,27,.45);
}

@media (min-width: 1400px) {
  .project-modal .gallery-lightbox-nav.prev { left: 60px; }
  .project-modal .gallery-lightbox-nav.next { right: 60px; }
}

@media (min-width: 1600px) {
  .project-modal .gallery-lightbox-nav.prev { left: 100px; }
  .project-modal .gallery-lightbox-nav.next { right: 100px; }
}

/* ── Outside navigation arrows ───────────────── */
.modal-nav-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.20);
  background: rgba(255,255,255,.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10002;
  transition: all 0.25s var(--ease);
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  -webkit-tap-highlight-color: transparent;
}

.modal-nav-left  { left: calc(50% - 600px); }
.modal-nav-right { right: calc(50% - 600px); }

.modal-nav-arrow:hover {
  background: rgba(209,15,27,.85);
  border-color: rgba(209,15,27,.95);
  transform: translateY(-50%) scale(1.1);
  box-shadow: 0 12px 32px rgba(209,15,27,.45);
}

/* Fix arrow overlap at narrower screens */
@media (max-width: 1200px) {
  .modal-nav-left  { left: 20px !important; right: auto !important; }
  .modal-nav-right { right: 20px !important; left: auto !important; }
}

/* ── Mobile modal — fixed centered box ───────── */
@media (max-width: 820px) {
  .project-modal {
    padding: 0;
    align-items: center;
    justify-content: center;
  }

  .project-modal .modal-content {
    /* Fixed size — doesn't grow or shrink with content */
    width: calc(100vw - 40px) !important;
    max-width: 420px !important;
    height: 72vh !important;
    max-height: 72vh !important;
    min-height: 72vh !important;
    margin: 0 auto !important;
    border-radius: 20px !important;
    padding: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: 0 24px 80px rgba(0,0,0,.50);
  }

  /* Sticky compact header */
  .project-modal .modal-header {
    padding: 18px 20px 12px !important;
    padding-right: 60px !important;
    border-radius: 20px 20px 0 0 !important;
    border-bottom: 1px solid rgba(255,255,255,.12);
    flex-shrink: 0 !important;
  }

  .project-modal .modal-title { font-size: 18px !important; line-height: 1.2 !important; }
  .project-modal .modal-meta  { font-size: 11px !important; margin-top: 4px !important; opacity: .78 !important; }

  .project-modal .modal-close {
    top: 12px !important;
    right: 12px !important;
    width: 38px !important;
    height: 38px !important;
    font-size: 20px !important;
    touch-action: manipulation;
  }

  /* Scrollable body fills remaining space */
  .project-modal .modal-body {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 16px !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .project-modal .slider-section { margin: 12px 0 !important; }

  .project-modal .comparison-slider {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 14px;
    touch-action: pan-y;
  }

  /* Nav arrows — sit outside the fixed box */
  .modal-nav-arrow {
    display: flex !important;
    width: 44px !important;
    height: 44px !important;
    font-size: 20px !important;
    touch-action: manipulation;
  }

  .modal-nav-left  { left: 6px !important; right: auto !important; }
  .modal-nav-right { right: 6px !important; left: auto !important; }

  /* Gallery - 2 columns on mobile */
  .project-modal .project-gallery-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  .project-modal .project-gallery-item img { height: 120px; }

  /* Lightbox */
  .project-modal .gallery-lightbox-img { max-width: 94vw; max-height: 80vh; border-radius: 12px; }

  .project-modal .gallery-lightbox-close { top: 12px; right: 12px; width: 38px; height: 38px; font-size: 18px; }

  .project-modal .gallery-lightbox-nav  { width: 42px; height: 42px; font-size: 22px; }
  .project-modal .gallery-lightbox-nav.prev { left: 12px; }
  .project-modal .gallery-lightbox-nav.next { right: 12px; }

  /* Touch: allow pan-x on tiles */
  #projects .projects-wheel .gallery .tile { touch-action: pan-x pan-y !important; }
}

@media (max-width: 480px) {
  .project-modal .project-gallery-grid { grid-template-columns: 1fr; }

  .project-modal .modal-content {
    width: calc(100vw - 32px) !important;
    max-width: calc(100vw - 32px) !important;
    /* Keep the same fixed height — centered box feel */
    height: 70vh !important;
    max-height: 70vh !important;
    min-height: 70vh !important;
    border-radius: 18px !important;
  }

  .project-modal .modal-title { font-size: 16px !important; }
  .project-modal .modal-meta  { font-size: 10px !important; }

  .project-modal .project-gallery-item img { height: 180px; }
}

@media (max-width: 820px) and (orientation: landscape) {
  .project-modal .comparison-slider { max-height: 70vh; }
}