/* Chrysalises — isolated, responsive image gallery. */
body.gallery-body {
  --gallery-bg: #ffffff;
  --gallery-panel: #ffffff;
  --gallery-text: #10100f;
  --gallery-muted: rgba(16, 16, 15, 0.47);
  --gallery-line: rgba(16, 16, 15, 0.2);
  --gallery-ease: cubic-bezier(0.22, 1, 0.36, 1);
  width: 100%;
  height: 100%;
  position: fixed;
  inset: 0;
  overflow: hidden !important;
  overscroll-behavior: none;
  background: var(--gallery-bg);
  color: var(--gallery-text);
}

html.dark body.gallery-body {
  --gallery-bg: #000000;
  --gallery-panel: #000000;
  --gallery-text: #ffffff;
  --gallery-muted: rgba(255, 255, 255, 0.52);
  --gallery-line: rgba(255, 255, 255, 0.22);
}

html:has(body.gallery-body) {
  width: 100%;
  height: 100%;
  overflow: hidden !important;
  overscroll-behavior: none;
  background: var(--gallery-bg, #ffffff);
}

body.gallery-body,
body.gallery-body button {
  font-family: "Unica 77 LL", Arial, sans-serif;
}

body.gallery-body #scroller-wrapper {
  position: fixed !important;
  inset: 0 !important;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden !important;
  color: var(--gallery-text);
  background: var(--gallery-bg);
  overscroll-behavior: none;
}

body.gallery-body #scroller-content,
body.gallery-body .gallery-page {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden !important;
}

body.gallery-body .gallery-page {
  position: relative;
  background: var(--gallery-bg);
}

body.gallery-body .as-route-header {
  color: var(--gallery-text);
  background: color-mix(in srgb, var(--gallery-bg) 90%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

body.gallery-body .gallery-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: clamp(24px, 3vw, 48px);
  width: 100%;
  height: 100%;
  padding: 92px clamp(22px, 3vw, 48px) 22px;
  overscroll-behavior: none;
}

body.gallery-body .gallery-viewer {
  position: relative;
  min-width: 0;
  min-height: 0;
}

body.gallery-body .image-field {
  position: absolute;
  inset: 0 0 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
  user-select: none;
  -webkit-user-select: none;
}

body.gallery-body .image-stack {
  --gallery-drag-x: 0px;
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

body.gallery-body .gallery-main-image,
body.gallery-body .gallery-main-image.is-visible {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  max-width: 1120px;
  max-height: 100%;
  margin: auto;
  object-fit: contain;
  object-position: center;
  opacity: 1 !important;
  transform: none !important;
  transition: none !important;
  animation: none !important;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}

body.gallery-body .image-loader {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  width: 26px;
  height: 1px;
  margin-left: -13px;
  overflow: hidden;
  background: var(--gallery-line);
  opacity: 0;
  pointer-events: none;
}

body.gallery-body .image-loader::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--gallery-text);
  transform: translateX(-100%);
  animation: gallery-load 900ms var(--gallery-ease) infinite;
}

body.gallery-body .image-field.is-loading .image-loader {
  opacity: 0.65;
}

@keyframes gallery-load {
  50%, 100% { transform: translateX(100%); }
}

/* Invisible desktop click zones; no visible arrows or controls cover photos. */
body.gallery-body .gallery-nav-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 4;
  width: 50%;
  padding: 0;
  border: 0;
  color: transparent;
  background: transparent;
  opacity: 0;
}

body.gallery-body .gallery-nav-zone span {
  display: none !important;
}

body.gallery-body .gallery-nav-zone.nav-prev {
  left: 0;
  cursor: w-resize;
}

body.gallery-body .gallery-nav-zone.nav-next {
  right: 0;
  cursor: e-resize;
}

body.gallery-body .gallery-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  min-height: 28px;
  font-size: 11px;
  line-height: 1.2;
  pointer-events: none;
}

body.gallery-body .image-title {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--gallery-muted);
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.gallery-body .thumbnail-rail {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 8%, #000 92%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 8%, #000 92%, transparent 100%);
}

body.gallery-body .thumbnail-rail::-webkit-scrollbar {
  display: none;
}

body.gallery-body .thumbnail-track {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  min-height: max-content;
}

body.gallery-body .thumb {
  position: relative;
  display: block;
  flex: 0 0 52px;
  width: 100%;
  height: 52px;
  min-height: 0;
  padding: 0;
  border: 0;
  color: inherit;
  background: var(--gallery-panel);
  opacity: 0.28;
  overflow: hidden;
  cursor: pointer;
  transform: scale(0.96);
  transition: opacity 200ms ease, transform 240ms var(--gallery-ease);
}

body.gallery-body .thumb:hover,
body.gallery-body .thumb:focus-visible {
  opacity: 0.72;
}

body.gallery-body .thumb:focus-visible {
  outline: 1px solid var(--gallery-text);
  outline-offset: -2px;
}

body.gallery-body .thumb.is-active {
  opacity: 1;
  transform: scale(1);
}

body.gallery-body .thumb.is-active::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--gallery-text);
  box-shadow: inset 0 0 0 1px var(--gallery-bg);
  pointer-events: none;
}

body.gallery-body .thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.78);
  transform: scale(1.001);
  transition: filter 200ms ease;
  -webkit-user-drag: none;
  pointer-events: none;
}

body.gallery-body .thumb:hover img,
body.gallery-body .thumb.is-active img {
  filter: saturate(1);
}

@media (hover: none), (pointer: coarse) {
  body.gallery-body .gallery-nav-zone {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
}

@media (max-width: 767px) {
  body.gallery-body .as-route-header {
    height: calc(64px + env(safe-area-inset-top)) !important;
    padding-top: max(0.8rem, env(safe-area-inset-top)) !important;
    padding-bottom: 0.8rem !important;
  }

  body.gallery-body .gallery-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 62px;
    gap: 12px;
    height: 100%;
    padding: calc(72px + env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
  }

  body.gallery-body .image-field {
    inset: 0 0 36px;
  }

  body.gallery-body .gallery-main-image,
  body.gallery-body .gallery-main-image.is-visible {
    max-width: 100%;
    max-height: 100%;
  }

  body.gallery-body .gallery-nav-zone {
    display: none !important;
  }

  body.gallery-body .gallery-controls {
    min-height: 24px;
    font-size: 10px;
  }

  body.gallery-body .thumbnail-rail {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 8%, #000 92%, transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 8%, #000 92%, transparent 100%);
  }

  body.gallery-body .thumbnail-track {
    flex-direction: row;
    gap: 6px;
    width: max-content;
    height: 100%;
    min-height: 0;
  }

  body.gallery-body .thumb {
    flex: 0 0 72px;
    width: 72px;
    height: 56px;
    scroll-snap-align: center;
  }
}

@media (max-width: 767px) and (orientation: landscape) and (max-height: 520px) {
  body.gallery-body .as-route-header {
    height: calc(48px + env(safe-area-inset-top)) !important;
    padding-top: max(0.45rem, env(safe-area-inset-top)) !important;
    padding-bottom: 0.45rem !important;
  }

  body.gallery-body .gallery-shell {
    grid-template-rows: minmax(0, 1fr) 44px;
    gap: 7px;
    padding: calc(52px + env(safe-area-inset-top)) 10px max(7px, env(safe-area-inset-bottom));
  }

  body.gallery-body .image-field {
    inset: 0 0 22px;
  }

  body.gallery-body .gallery-controls {
    min-height: 15px;
    font-size: 9px;
  }

  body.gallery-body .thumb {
    flex-basis: 58px;
    width: 58px;
    height: 42px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.gallery-body .thumb,
  body.gallery-body .thumb img {
    transition: none;
  }

  body.gallery-body .image-loader::after {
    animation: none;
  }
}
