/* =========================================================================
   Framer Infinite 3D Carousel Style Specification
   ========================================================================= */
html {
  overflow-x: clip;
}

.carousel-3d-section-wrapper {
  position: relative;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  isolation: isolate;
  /* Reserve the carousel's final footprint before its async data is ready. */
  min-height: calc(clamp(500px, 68vh, 640px) + 40px);
  padding: 10px 0 30px;
  overflow: visible;
}

#home.page-section {
  padding-top: 0;
  padding-bottom: 0;
}

#book.page-section {
  padding-top: 24px;
}

.carousel-3d-wrapper {
  position: relative;
  width: 100%;
  min-height: clamp(500px, 68vh, 640px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

/* Control Dock Toolbar */
.carousel-3d-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: fit-content;
  min-width: 0;
  max-width: calc(100% - 16px);
  gap: 16px;
  align-self: center;
  margin: 12px auto 10px;
  padding: 4px 8px;
  border-radius: 9999px;
  background: rgba(248, 243, 236, 0.88);
  border: 1px solid rgba(141, 105, 89, 0.16);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 8px 24px -4px rgba(141, 105, 89, 0.08), 0 2px 6px rgba(141, 105, 89, 0.03);
  z-index: 20;
}

.carousel-3d-actions {
  display: flex;
  align-items: center;
  gap: 0;
}

.carousel-3d-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(141, 105, 89, 0.16);
  background: #ffffff;
  color: #8d6959;
  cursor: pointer;
  transition: all 180ms cubic-bezier(0.22, 1, 0.36, 1);
  padding: 0;
}
.carousel-3d-btn svg {
  width: 14px;
  height: 14px;
}
.carousel-3d-btn:hover {
  background: #8e9867;
  border-color: #8e9867;
  color: #ffffff;
  transform: scale(1.08);
}
.carousel-3d-btn:active {
  transform: scale(0.94);
}

.carousel-3d-view-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 156px;
  height: 32px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid #1A191B;
  background: #1A191B;
  color: #F1F1EE;
  font-family: 'Inter', var(--font-body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
.carousel-3d-view-toggle span {
  flex: 1;
  min-width: 0;
  text-align: left;
}
.carousel-3d-view-toggle svg {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
}
.carousel-3d-view-toggle[aria-pressed="true"] {
  width: 92px;
}
.carousel-3d-view-toggle[aria-pressed="true"] span {
  font-size: 9px;
  letter-spacing: 0.02em;
  text-align: right;
}
.carousel-3d-view-toggle[aria-pressed="true"] svg {
  order: -1;
  transform: rotate(180deg);
}
.carousel-3d-view-toggle:hover {
  background: #1A191B;
  border-color: #1A191B;
  color: #F1F1EE;
}

/* 3D Perspective Stage Container */
.carousel-3d-stage-container {
  position: relative;
  width: 100%;
  height: clamp(420px, 58vh, 540px);
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1800px;
  -webkit-perspective: 1800px;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

.carousel-3d-stage {
  position: relative;
  width: 100%;
  height: 100%;
  perspective: 1800px;
  -webkit-perspective: 1800px;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  pointer-events: none;
}

/* 3D Cards */
.carousel-3d-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  will-change: transform, opacity;
  border-radius: 22px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.6);
  cursor: grab;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  contain: layout style paint;
  transition: filter 180ms ease, box-shadow 180ms ease;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.carousel-3d-wrapper.is-dragging .carousel-3d-card,
.carousel-3d-card:active {
  cursor: grabbing;
}

.carousel-3d-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 1.5px 1px rgba(255, 255, 255, 0.65), inset 0 -1px 1px rgba(0, 0, 0, 0.05);
  z-index: 5;
}

.carousel-3d-image-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #edebe6;
  border-radius: inherit;
}

.carousel-3d-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
  transition: transform 380ms cubic-bezier(0.22, 1, 0.36, 1), filter 380ms ease;
}

.carousel-3d-card:hover .carousel-3d-img {
  transform: scale(1.035);
  filter: contrast(1.02) saturate(1.03);
}

.carousel-3d-card-badge {
  position: absolute;
  bottom: 14px;
  right: 14px;
  z-index: 6;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(18, 18, 20, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  font-family: 'Inter', var(--font-body);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Masonry Grid collapsible mode */
#gallery:not(.is-visible-grid) {
  display: none !important;
}
#gallery.is-visible-grid {
  display: grid !important;
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
  animation: grid-fade-in 400ms ease;
}
@keyframes grid-fade-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 640px) {
  .carousel-3d-toolbar { min-width: 0; margin: 8px auto 5px; padding: 3px 7px; }
  .carousel-3d-actions { gap: 0; }
  .carousel-3d-view-toggle { width: 140px; height: 28px; gap: 5px; padding: 0 9px; font-size: 9px; }
  .carousel-3d-view-toggle[aria-pressed="true"] { width: 82px; }
  .carousel-3d-view-toggle span { display: inline; }
}


/* Editorial layer and accessible view switching */
.carousel-3d-intro {
  display: none;
}

.carousel-3d-wrapper.is-grid-view {
  min-height: 0;
  justify-content: flex-end;
  padding: 8px 0;
}

.carousel-3d-wrapper.is-grid-view .carousel-3d-stage-container,
.carousel-3d-wrapper.is-grid-view .prev-btn,
.carousel-3d-wrapper.is-grid-view .next-btn,
.carousel-3d-wrapper.is-grid-view .play-btn {
  display: none !important;
}

.carousel-3d-wrapper.is-grid-view .carousel-3d-toolbar {
  justify-content: flex-end;
  align-self: flex-end;
  margin: 0 16px 0 0;
}

#gallery.is-visible-grid {
  scroll-margin-top: 0;
}

/* Collapse the carousel's reserved footprint while Full Grid is visible so
   the masonry items begin directly below the toolbar. */
.carousel-3d-section-wrapper:has(.carousel-3d-wrapper.is-grid-view) {
  min-height: 0;
  padding: 0;
}

.carousel-3d-wrapper.is-grid-view {
  padding: 0;
}

.gallery-container:has(#gallery.is-visible-grid) {
  padding-top: 0;
}

/* Compact desktop viewports need more breathing room around the controls,
   while keeping the carousel cards safely inside the stage. */
@media (min-width: 641px) and (max-height: 760px) {
  .carousel-3d-wrapper {
    min-height: 0;
    padding: 10px 0;
  }

  .carousel-3d-toolbar {
    margin-top: 24px;
    margin-bottom: 0;
  }

  .carousel-3d-stage-container {
    height: clamp(320px, 52vh, 420px);
  }

  .carousel-3d-section-wrapper {
    min-height: calc(clamp(320px, 52vh, 420px) + 151px);
  }

}

@media (max-width: 640px) {
  .carousel-3d-section-wrapper {
    min-height: calc(clamp(240px, 82vw, 340px) + 88px);
    padding: 6px 0 12px;
  }

  .carousel-3d-wrapper {
    min-height: 0;
    padding: 10px 0 5px;
    overflow: visible;
  }

  .carousel-3d-stage-container {
    width: 100%;
    max-width: 100%;
    height: clamp(240px, 82vw, 340px);
    margin: 0 auto;
    flex: 0 0 auto;
  }

  .carousel-3d-stage {
    width: 100%;
    height: 100%;
  }

  body:not(.desktop-gallery-grid) #gallery.is-visible-grid .masonry-item.is-motion-in-view {
    transform: scale(var(--top-scale, 1)) translateY(var(--top-y, 0px)) !important;
    filter: blur(var(--top-blur, 0px)) !important;
  }
}

/* Keep the full masonry grid visually steady on desktop. The carousel and
   the mobile grid retain their existing scroll and pointer motion. */
@media (min-width: 641px) {
  body.desktop-gallery-grid #gallery.is-visible-grid .masonry-item {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
  }

  body.desktop-gallery-grid #gallery.is-visible-grid .gallery-image-stage {
    transform: none !important;
  }

  body.desktop-gallery-grid .is-magnetic {
    transform: none !important;
    transition: none !important;
  }

  body.desktop-gallery-grid.cursor-ready,
  body.desktop-gallery-grid.cursor-ready * {
    cursor: revert !important;
  }

  body.desktop-gallery-grid .motion-cursor {
    display: none !important;
  }
}
