/* ==========================================================================
   SAJ Dental Clinic — "Our Gallery" section
   Scope: every selector is prefixed saj-gallery-. Visual values are CSS
   custom properties so they can map to future CMS / widget controls.
   ========================================================================== */

/* Standalone preview page only (gallery.html): extra room so the scroll
   parallax can be previewed. */
.saj-gallery-preview {
  margin: 0;
  /* padding-bottom: 50vh; */
  background: #FFFFFF;
}

.saj-gallery-section,
.saj-gallery-lightbox {
  /* ---- Brand ---- */
  --g-navy: #0B2340;
  --g-navy-deep: #0D2C6B;          /* active filter pill */
  --g-navy-soft: #1A3557;
  --g-blue: #1269A8;
  --g-orange: #F4511E;
  --g-text: #4A5770;
  --g-line: rgba(18, 105, 168, 0.18);

  /* ---- Type ---- */
  --g-font-display: "Playfair Display", Georgia, "Times New Roman", serif;
  --g-font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  --g-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

.saj-gallery-section {
  --g-title-size: clamp(2.1rem, 3.3vw, 4rem);
  --g-cols: 5;
  --g-gap: clamp(12px, 1vw, 18px);
  --g-card-radius: 18px;
  --g-max: 1640px;

  box-sizing: border-box;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  overflow: clip;
  padding: clamp(64px, 5.6vw, 110px) 0 clamp(96px, 9vw, 170px);
  background:
    radial-gradient(60% 45% at 50% 22%, #FFFFFF 0%, rgba(255, 255, 255, 0) 70%),
    linear-gradient(180deg, #F3F8FE 0%, #EDF4FC 55%, #E9F2FB 100%);
  font-family: var(--g-font-body);
  color: var(--g-text);
  -webkit-font-smoothing: antialiased;
}

.saj-gallery-section *,
.saj-gallery-section *::before,
.saj-gallery-section *::after,
.saj-gallery-lightbox,
.saj-gallery-lightbox * {
  box-sizing: border-box;
}

/* --------------------------------------------------------------------------
   1. Background
   Outer element = scroll parallax; inner .saj-gallery-bg-layer = mouse
   parallax + idle drift (so transforms never fight).
   -------------------------------------------------------------------------- */
.saj-gallery-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.saj-gallery-bg-orb,
.saj-gallery-bg-shape,
.saj-gallery-bg-tooth {
  position: absolute;
}

.saj-gallery-bg-layer {
  display: block;
  width: 100%;
  height: 100%;
}

.saj-gallery-bg-orb .saj-gallery-bg-layer {
  border-radius: 50%;
}

.saj-gallery-bg-orb--one {
  left: -10%;
  top: 20%;
  width: 40vw;
  height: 40vw;
}

.saj-gallery-bg-orb--one .saj-gallery-bg-layer {
  background: radial-gradient(closest-side, rgba(190, 216, 244, 0.6), rgba(190, 216, 244, 0));
}

.saj-gallery-bg-orb--two {
  right: -8%;
  top: -12%;
  width: 44vw;
  height: 44vw;
}

.saj-gallery-bg-orb--two .saj-gallery-bg-layer {
  background: radial-gradient(closest-side, rgba(200, 224, 248, 0.65), rgba(200, 224, 248, 0));
}

.saj-gallery-bg-shape--top {
  left: -4%;
  top: -4%;
  width: 108%;
  height: 46%;
}

.saj-gallery-bg-shape--bottom {
  left: -6%;
  bottom: -4%;
  width: 112%;
  height: 34%;
}

/* Soft organic form on the right */
.saj-gallery-bg-shape--side {
  right: -14%;
  top: 30%;
  width: 34vw;
  height: 30vw;
}

.saj-gallery-bg-shape--side .saj-gallery-bg-layer {
  border-radius: 62% 38% 55% 45% / 45% 55% 45% 55%;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0));
  border: 1.5px solid rgba(255, 255, 255, 0.8);
}

.saj-gallery-bg-tooth {
  left: clamp(-40px, 1.5vw, 40px);
  top: clamp(20px, 4vw, 70px);
  width: clamp(140px, 14vw, 270px);
  aspect-ratio: 100 / 110;
  opacity: 0.85;
  filter: drop-shadow(0 20px 30px rgba(18, 105, 168, 0.1));
}

/* --------------------------------------------------------------------------
   Container + header
   -------------------------------------------------------------------------- */
.saj-gallery-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: calc(var(--g-max) + 2 * clamp(20px, 5.4vw, 100px));
  margin: 0 auto;
  padding: 0 clamp(20px, 5.4vw, 100px);
}

.saj-gallery-header {
  max-width: 900px;
  margin: 0 auto clamp(28px, 2.6vw, 44px);
  text-align: center;
}

.saj-gallery-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 20px;
  margin: 0 0 clamp(18px, 2vw, 32px);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--g-navy-deep);
}

.saj-gallery-eyebrow-line {
  display: block;
  width: 44px;
  height: 2px;
  border-radius: 2px;
  background: var(--g-orange);
  transform-origin: right center;
}

.saj-gallery-title {
  margin: 0 0 clamp(16px, 1.6vw, 26px);
  font-family: var(--g-font-display);
  font-size: var(--g-title-size);
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.015em;
  color: var(--g-navy-deep);
}

/* Line masks — padding leaves room for italic overhang + descenders */
.saj-gallery-title-line {
  display: block;
  overflow: hidden;
  padding: 0 0.1em 0.1em;
  margin-bottom: -0.1em;
}

.saj-gallery-title-text,
.saj-gallery-title-highlight {
  display: inline-block;
  text-wrap: balance;            /* no orphaned last word on narrow screens */
}

.saj-gallery-title-highlight {
  font-style: italic;
  font-weight: 600;
  color: var(--g-orange);
}

.saj-gallery-description {
  max-width: 38em;
  margin: 0 auto;
  font-size: clamp(1rem, 1.05vw, 1.125rem);
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   3. Filters
   -------------------------------------------------------------------------- */
.saj-gallery-filters-wrap {
  position: relative;
  margin: 0 auto clamp(22px, 1.6vw, 30px);
}

.saj-gallery-filters {
  display: flex;
  justify-content: center;
  gap: clamp(10px, 0.9vw, 16px);
  padding: 4px 4px 10px;
}

.saj-gallery-filter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex: none;
  min-width: clamp(120px, 8.4vw, 146px);
  min-height: clamp(48px, 3.2vw, 56px);
  padding: 0 clamp(20px, 1.8vw, 32px);
  border: 1.5px solid var(--g-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--g-navy-deep);
  font: 500 clamp(0.9375rem, 0.92vw, 1.0625rem)/1 var(--g-font-body);
  cursor: pointer;
  box-shadow: 0 6px 18px -14px rgba(11, 35, 64, 0.35);
  transition:
    transform 0.4s var(--g-ease),
    border-color 0.35s ease,
    box-shadow 0.35s ease,
    background-color 0.35s ease,
    color 0.35s ease;
}

.saj-gallery-filter svg {
  flex: none;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--g-blue);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.4s var(--g-ease), stroke 0.35s ease;
}

.saj-gallery-filter:hover {
  transform: translateY(-2px);
  border-color: rgba(18, 105, 168, 0.4);
  box-shadow: 0 12px 24px -14px rgba(11, 35, 64, 0.35);
}

.saj-gallery-filter:hover svg {
  transform: translateY(-1px) scale(1.06);
}

.saj-gallery-filter:focus-visible {
  outline: 2px solid var(--g-orange);
  outline-offset: 3px;
}

.saj-gallery-filter.active {
  border-color: var(--g-navy-deep);
  background: var(--g-navy-deep);
  color: #FFFFFF;
  box-shadow: 0 14px 28px -14px rgba(13, 44, 107, 0.65);
}

.saj-gallery-filter.active svg {
  stroke: #FFFFFF;
}

.saj-gallery-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   4–5. Grid + cards
   Flex (not grid) so a partial last row — e.g. after filtering — stays
   centred instead of hugging the left.
   -------------------------------------------------------------------------- */
.saj-gallery-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--g-gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

.saj-gallery-card {
  flex: 0 0 calc((100% - (var(--g-cols) - 1) * var(--g-gap)) / var(--g-cols));
  min-width: 0;
}

.saj-gallery-card.is-hidden {
  display: none;
}

.saj-gallery-card-link {
  position: relative;
  display: block;
  padding: 5px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--g-card-radius);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 16px 34px -24px rgba(11, 35, 64, 0.35);
  color: inherit;
  text-decoration: none;
  transition:
    transform 0.6s var(--g-ease),
    box-shadow 0.6s ease,
    border-color 0.5s ease,
    background-color 0.5s ease;
}

.saj-gallery-card-link:focus-visible {
  outline: 2px solid var(--g-orange);
  outline-offset: 3px;
}

.saj-gallery-image-wrap {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: calc(var(--g-card-radius) - 5px);
  background: #DCE8F5;
  isolation: isolate;
}

/* Slightly taller than the frame so the scroll parallax never shows an edge */
.saj-gallery-image {
  position: absolute;
  left: 0;
  top: -5%;
  display: block;
  width: 100%;
  height: 110%;
  object-fit: cover;
  will-change: transform;
}

/* Soft light that follows the cursor (positioned by JS) */
.saj-gallery-glow {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  width: 70%;
  aspect-ratio: 1;
  margin: -35% 0 0 -35%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.saj-gallery-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(180deg, rgba(13, 44, 107, 0.08), rgba(13, 44, 107, 0.42));
  opacity: 0;
  transition: opacity 0.6s ease;
}

.saj-gallery-view {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transform: scale(0.6);
  opacity: 0;
  transition: transform 0.6s var(--g-ease), opacity 0.5s ease;
}

.saj-gallery-view svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: #FFFFFF;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.saj-gallery-caption {
  max-width: 90%;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
  color: #FFFFFF;
  text-shadow: 0 1px 8px rgba(11, 35, 64, 0.4);
  transform: translateY(8px);
  opacity: 0;
  transition: transform 0.6s var(--g-ease), opacity 0.5s ease;
}

/* Hover + keyboard focus share the same treatment */
.saj-gallery-card-link:hover,
.saj-gallery-card-link:focus-visible {
  transform: translateY(-6px);
  border-color: #FFFFFF;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 26px 40px -24px rgba(11, 35, 64, 0.45);
}

.saj-gallery-card-link:hover .saj-gallery-overlay,
.saj-gallery-card-link:focus-visible .saj-gallery-overlay,
.saj-gallery-card-link:hover .saj-gallery-glow {
  opacity: 1;
}

.saj-gallery-card-link:hover .saj-gallery-view,
.saj-gallery-card-link:focus-visible .saj-gallery-view {
  transform: scale(1);
  opacity: 1;
}

.saj-gallery-card-link:hover .saj-gallery-caption,
.saj-gallery-card-link:focus-visible .saj-gallery-caption {
  transform: translateY(0);
  opacity: 1;
}

/* Without GSAP (no hover engine, no image parallax) CSS zooms the image */
.saj-gallery-section:not(.is-animated) .saj-gallery-image {
  transition: transform 0.8s var(--g-ease);
}

.saj-gallery-section:not(.is-animated) .saj-gallery-card-link:hover .saj-gallery-image {
  transform: scale(1.05);
}

/* --------------------------------------------------------------------------
   12. Lightbox
   -------------------------------------------------------------------------- */
.saj-gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 64px);
  font-family: var(--g-font-body);
}

.saj-gallery-lightbox[hidden] {
  display: none;
}

.saj-gallery-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 22, 46, 0.82);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.saj-gallery-lightbox-figure {
  position: relative;
  margin: 0;
  max-width: min(1100px, 100%);
  text-align: center;
}

.saj-gallery-lightbox-image {
  display: block;
  width: min(1100px, 100%);
  max-height: calc(100vh - 160px);
  object-fit: contain;
  border: 6px solid rgba(255, 255, 255, 0.92);
  border-radius: 20px;
  background: #FFFFFF;
  box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.6);
}

.saj-gallery-lightbox-caption {
  margin-top: 16px;
  font-size: 1rem;
  font-weight: 500;
  color: #FFFFFF;
}

.saj-gallery-lightbox-close {
  position: absolute;
  top: clamp(14px, 2.4vw, 32px);
  right: clamp(14px, 2.4vw, 32px);
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.4s var(--g-ease);
}

.saj-gallery-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.24);
  transform: rotate(90deg);
}

.saj-gallery-lightbox-close:focus-visible {
  outline: 2px solid var(--g-orange);
  outline-offset: 3px;
}

.saj-gallery-lightbox-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* --------------------------------------------------------------------------
   Reveal pre-state + fail-safe
   -------------------------------------------------------------------------- */
.saj-gallery-section:not(.is-animated) [data-saj-gallery-reveal] {
  opacity: 0;
  animation: saj-gallery-failsafe 0.8s ease 1.8s forwards;
}

@keyframes saj-gallery-failsafe {
  to { opacity: 1; }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* Large laptop: still 5 columns, tighter */
@media (max-width: 1439px) {
  .saj-gallery-section {
    --g-gap: 12px;
    --g-card-radius: 16px;
  }

  .saj-gallery-filter {
    min-width: 0;
    padding: 0 22px;
  }
}

/* iPad landscape: 4 columns (last row centres), filters may wrap */
@media (max-width: 1199px) {
  .saj-gallery-section {
    --g-cols: 4;
    --g-title-size: clamp(2rem, 3.9vw, 2.75rem);
  }

  .saj-gallery-filters {
    flex-wrap: wrap;
  }

  .saj-gallery-bg-tooth {
    width: 130px;
    left: -20px;
  }
}

/* iPad portrait + mobile: 2 columns, filters scroll sideways */
@media (max-width: 1023px) {
  .saj-gallery-section {
    --g-cols: 2;
    --g-gap: 14px;
    --g-title-size: clamp(1.9rem, 5.4vw, 2.6rem);
  }

  /* Bleed the scroller to the screen edges; fade the ends */
  .saj-gallery-filters-wrap {
    margin-left: calc(clamp(20px, 5.4vw, 100px) * -1);
    margin-right: calc(clamp(20px, 5.4vw, 100px) * -1);
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 22px, #000 calc(100% - 22px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 22px, #000 calc(100% - 22px), transparent 100%);
  }

  .saj-gallery-filters {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding: 6px clamp(20px, 5.4vw, 100px) 12px;
    scroll-padding-inline: clamp(20px, 5.4vw, 100px);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .saj-gallery-filters::-webkit-scrollbar {
    display: none;
  }

  .saj-gallery-bg-tooth {
    opacity: 0.55;
  }
}

/* Mobile */
@media (max-width: 767px) {
  .saj-gallery-section {
    --g-gap: 10px;
    --g-card-radius: 14px;
    --g-title-size: clamp(1.65rem, 7vw, 2.2rem);
    padding-top: 56px;
  }

  .saj-gallery-eyebrow {
    gap: 14px;
    font-size: 0.75rem;
  }

  .saj-gallery-eyebrow-line {
    width: 32px;
  }

  .saj-gallery-description {
    font-size: 0.9375rem;
  }

  .saj-gallery-filter {
    min-height: 44px;
    padding: 0 18px;
    gap: 9px;
    font-size: 0.875rem;
  }

  .saj-gallery-filter svg {
    width: 20px;
    height: 20px;
  }

  .saj-gallery-card-link {
    padding: 4px;
  }

  .saj-gallery-view {
    width: 40px;
    height: 40px;
  }

  .saj-gallery-caption {
    display: none;
  }

  .saj-gallery-bg-tooth {
    width: 96px;
    top: 8px;
    left: -24px;
    opacity: 0.4;
  }

  .saj-gallery-bg-shape--side {
    display: none;
  }
}

/* Very narrow phones: one column */
@media (max-width: 359px) {
  .saj-gallery-section {
    --g-cols: 1;
  }
}

/* Reduced motion: nothing hidden for long, no hover motion */
@media (prefers-reduced-motion: reduce) {
  .saj-gallery-section:not(.is-animated) [data-saj-gallery-reveal] {
    animation-delay: 0.6s;
  }

  .saj-gallery-filter,
  .saj-gallery-filter svg,
  .saj-gallery-card-link,
  .saj-gallery-view,
  .saj-gallery-caption,
  .saj-gallery-section .saj-gallery-image {
    transition: none !important;
  }

  .saj-gallery-filter:hover,
  .saj-gallery-filter:hover svg,
  .saj-gallery-card-link:hover,
  .saj-gallery-card-link:focus-visible,
  .saj-gallery-section .saj-gallery-card-link:hover .saj-gallery-image {
    transform: none;
  }
}
