.gallery-shell,
.gallery-chapter {
  margin-top: 1rem;
}

.gallery-live-preview {
  display: block;
  margin: 1rem 0 1.25rem;
}

.gallery-live-masonry {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 8px;
  grid-auto-flow: row;
  gap: clamp(0.55rem, 1.2vw, 0.95rem);
  align-items: start;
}

.gallery-live-item {
  margin: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
  break-inside: auto;
  margin-bottom: 0;
  contain: layout paint;
}

.gallery-live-cta {
  display: block;
  text-align: center;
  break-inside: avoid;
  padding-top: 0.35rem;
}

.gallery-live-link {
  position: relative;
  display: block;
  cursor: zoom-in;
  aspect-ratio: var(--gallery-item-ratio, auto);
}

.gallery-live-link .gallery-photo {
  cursor: zoom-in;
}

.gallery-live-hover-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.62rem 0.75rem;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.74);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

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

.gallery-live-item .gallery-photo {
  display: block;
  width: 100%;
  height: auto;
}

.gallery-live-masonry.is-scrollfx-ready .gallery-live-item {
  opacity: 1;
  transform: none;
  transition: none;
  will-change: auto;
}

.gallery-live-masonry.is-scrollfx-ready .gallery-live-link {
  opacity: 0;
  transform: translate3d(0, 12px, 0) scale(0.992);
  transition: transform 620ms cubic-bezier(0.16, 1, 0.3, 1), opacity 520ms ease-out;
  transition-delay: var(--gallery-reveal-delay, 0ms);
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.gallery-live-masonry.is-scrollfx-ready .gallery-live-item.is-inview .gallery-live-link {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
}

@media (max-width: 900px) {
  .gallery-live-item {
    content-visibility: visible;
    contain-intrinsic-size: auto;
  }

  .gallery-live-masonry.is-scrollfx-ready .gallery-live-link {
    opacity: 1;
    transform: none;
    transition: none;
    will-change: auto;
  }

  .gallery-live-masonry.is-scrollfx-ready .gallery-live-item.is-inview .gallery-live-link {
    opacity: 1;
    transform: none;
  }
}

.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.gallery-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.gallery-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 13, 0.82);
  backdrop-filter: blur(3px);
}

.gallery-modal-dialog {
  position: relative;
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.75rem;
  padding: clamp(0.7rem, 1.7vw, 1.1rem) clamp(0.6rem, 1.5vw, 1rem) clamp(0.78rem, 1.7vw, 1.15rem);
  border: 0;
  background: linear-gradient(165deg, rgba(18, 22, 28, 0.96) 0%, rgba(13, 15, 19, 0.96) 100%);
  box-shadow: none;
}

.gallery-modal-topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.gallery-modal-action {
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-radius: 999px;
  padding: 0.5rem 0.95rem;
  font: inherit;
  cursor: pointer;
}

.gallery-modal-stage {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  min-height: 0;
  gap: 0.45rem;
}

.gallery-modal-media-wrap {
  min-width: 0;
  text-align: center;
  touch-action: none;
  overscroll-behavior: contain;
}

.gallery-modal-image {
  max-width: 100%;
  max-height: min(75vh, 820px);
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  cursor: grab;
  transition: transform 680ms cubic-bezier(0.18, 0.82, 0.22, 1), opacity 680ms cubic-bezier(0.18, 0.82, 0.22, 1);
  will-change: transform;
  touch-action: none;
}

.gallery-modal-stage.is-dragging .gallery-modal-image {
  cursor: grabbing;
  transition: none;
}

.gallery-modal-nav {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.gallery-modal-caption {
  margin: 1.1rem auto 0;
  max-width: 62ch;
  color: rgba(245, 247, 252, 0.95);
  font-size: clamp(0.96rem, 1.55vw, 1.1rem);
  line-height: 1.35;
}

.gallery-modal.is-captions-hidden .gallery-modal-caption {
  display: none;
}

.gallery-modal-thumbs-wrap {
  position: relative;
  overflow: hidden;
  min-height: 82px;
}

.gallery-modal-thumbs {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.5rem 2.3rem 0.15rem;
  scrollbar-width: thin;
}

.gallery-modal-thumbs-wrap.is-hidden .gallery-modal-thumbs {
  display: none;
}

.gallery-modal-thumb {
  flex: 0 0 auto;
  width: clamp(78px, 7vw, 110px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 0;
  background: transparent;
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
  opacity: 1;
}

.gallery-modal-thumb.is-active {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.86);
}

.gallery-modal-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

body.gallery-modal-open {
  overflow: hidden;
}

.gallery-modal:fullscreen,
.gallery-modal:-webkit-full-screen {
  background: #000;
}

.gallery-modal:fullscreen .gallery-modal-backdrop,
.gallery-modal:-webkit-full-screen .gallery-modal-backdrop {
  background: #000;
  backdrop-filter: none;
}

.gallery-modal:fullscreen .gallery-modal-dialog,
.gallery-modal:-webkit-full-screen .gallery-modal-dialog {
  --gallery-fs-thumbs-bottom: 0.45rem;
  --gallery-fs-thumbs-visual-height: 120px;
  --gallery-fs-caption-gap: 50px;
  padding: 0;
  gap: 0;
  background: #000;
}

.gallery-modal:fullscreen .gallery-modal-topbar,
.gallery-modal:-webkit-full-screen .gallery-modal-topbar {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  left: auto;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
}

.gallery-modal:fullscreen .gallery-modal-stage,
.gallery-modal:-webkit-full-screen .gallery-modal-stage {
  width: 100%;
  height: 100vh;
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.gallery-modal:fullscreen .gallery-modal-image,
.gallery-modal:-webkit-full-screen .gallery-modal-image {
  height: auto;
  max-height: 100vh;
  max-width: 100%;
  width: auto;
}

.gallery-modal:fullscreen .gallery-modal-caption,
.gallery-modal:-webkit-full-screen .gallery-modal-caption {
  position: absolute;
  left: 50%;
  bottom: calc(var(--gallery-fs-thumbs-bottom) + var(--gallery-fs-thumbs-visual-height) + var(--gallery-fs-caption-gap));
  transform: translateX(-50%);
  margin: 0;
  padding: 0.62rem 1.05rem;
  background: rgba(0, 0, 0, 0.48);
  font-size: clamp(1.08rem, 1.9vw, 1.28rem);
  line-height: 1.42;
  z-index: 5;
}

.gallery-modal:fullscreen .gallery-modal-thumbs-wrap,
.gallery-modal:-webkit-full-screen .gallery-modal-thumbs-wrap {
  position: absolute;
  left: 50%;
  bottom: var(--gallery-fs-thumbs-bottom);
  transform: translateX(-50%);
  width: min(92vw, 1120px);
  z-index: 4;
}

.gallery-modal.is-fullscreen-active .gallery-modal-dialog {
  --gallery-fs-thumbs-bottom: 0.45rem;
  --gallery-fs-thumbs-visual-height: 120px;
  --gallery-fs-caption-gap: 50px;
  padding: 0;
  gap: 0;
  background: #000;
}

.gallery-modal.is-fullscreen-active .gallery-modal-topbar {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  left: auto;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
}

.gallery-modal.is-fullscreen-active .gallery-modal-stage {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
}

.gallery-modal.is-fullscreen-active .gallery-modal-media-wrap {
  display: block;
}

.gallery-modal.is-fullscreen-active .gallery-modal-prev {
  grid-area: auto;
  justify-self: auto;
}

.gallery-modal.is-fullscreen-active .gallery-modal-next {
  grid-area: auto;
  justify-self: auto;
}

.gallery-modal.is-fullscreen-active .gallery-modal-image {
  grid-area: auto;
  grid-row: auto;
  grid-column: auto;
  height: auto;
  max-height: 100vh;
  max-width: 100%;
  width: auto;
}

.gallery-modal.is-fullscreen-active .gallery-modal-caption {
  grid-area: auto;
  grid-row: auto;
  grid-column: auto;
  position: absolute;
  left: 50%;
  bottom: calc(var(--gallery-fs-thumbs-bottom) + var(--gallery-fs-thumbs-visual-height) + var(--gallery-fs-caption-gap));
  transform: translateX(-50%);
  width: auto;
  margin: 0;
  padding: 0.62rem 1.05rem;
  font-size: clamp(1.08rem, 1.9vw, 1.28rem);
  line-height: 1.42;
  display: block;
  -webkit-box-orient: initial;
  -webkit-line-clamp: initial;
  overflow: visible;
  justify-self: auto;
  align-self: auto;
  background: rgba(0, 0, 0, 0.48);
  z-index: 5;
}

.gallery-modal.is-fullscreen-active .gallery-modal-thumbs-wrap {
  position: absolute;
  left: 50%;
  bottom: var(--gallery-fs-thumbs-bottom);
  transform: translateX(-50%);
  width: min(92vw, 1120px);
  z-index: 4;
}

.gallery-live-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-width: clamp(8.8rem, 18vw, 10.6rem);
}

.gallery-chapter h2 {
  margin-bottom: 1rem;
}

@media (max-width: 700px) {
  .gallery-live-masonry {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 6px;
    gap: 0.55rem;
  }

  .gallery-live-item {
    margin-bottom: 0;
  }

  .gallery-live-cta {
    margin-bottom: 0.75rem;
    padding-top: 0.35rem;
  }
}

@media (max-width: 700px), (orientation: landscape) and (max-height: 520px) {
  .gallery-modal-dialog {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    padding: 0.55rem 0.48rem 0.72rem;
  }

  .gallery-modal-topbar {
    gap: 0.38rem;
    justify-content: center;
  }

  .gallery-modal-action {
    padding: 0.42rem 0.75rem;
    font-size: 0.9rem;
    background: #000;
    border-color: #fff;
    color: #fff;
  }

  .gallery-modal-action[data-mobile-icon] {
    min-width: 3.15rem;
    min-height: 3.15rem;
    padding: 0;
    font-size: 0;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    text-indent: -9999px;
    white-space: nowrap;
  }

  .gallery-modal-action[data-mobile-icon]::before {
    content: attr(data-mobile-icon);
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 1.42rem;
    line-height: 1;
    text-indent: 0;
  }

  .gallery-modal-action[data-mobile-icon="◻◻◻"]::before {
    content: '◻◻◻';
    font-size: 0.82rem;
    letter-spacing: -0.12em;
    font-weight: 700;
  }

  .gallery-modal-action[data-mobile-icon="[i]"]::before {
    content: '[ ]';
    font-size: 1.12rem;
    letter-spacing: 0.08em;
    font-weight: 700;
  }

  .gallery-modal-action[data-mobile-icon="[i]"]::after {
    content: 'i';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.84rem;
    line-height: 1;
    font-weight: 700;
    text-indent: 0;
  }

  .gallery-modal-action[data-mobile-icon="✕"]::before,
  .gallery-modal-action[data-mobile-icon="⛶"]::before,
  .gallery-modal-action[data-mobile-icon="⤢"]::before {
    font-size: 1.46rem;
    font-weight: 700;
  }

  .gallery-modal-stage {
    min-height: 0;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .gallery-modal-image {
    max-height: 66vh;
  }

  .gallery-modal-nav {
    width: 2.25rem;
    height: 2.25rem;
    background: #000;
    border-color: #fff;
    color: #fff;
  }

  .gallery-modal-caption {
    margin-top: 0.95rem;
    padding-inline: 0.35rem;
    font-size: 0.96rem;
  }

  .gallery-modal-thumbs {
    padding-inline: 2.1rem;
  }

  .gallery-modal-thumb {
    width: clamp(62px, 14vw, 82px);
  }

  .gallery-modal:fullscreen .gallery-modal-stage,
  .gallery-modal:-webkit-full-screen .gallery-modal-stage,
  .gallery-modal.is-fullscreen-active .gallery-modal-stage {
    --gallery-fs-available-height: 100dvh;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: minmax(0, 1fr) !important;
    align-items: center;
    justify-items: center;
    gap: 1rem 0.8rem;
    min-height: 100dvh;
    height: 100dvh;
    box-sizing: border-box;
    padding: 0;
  }

  .gallery-modal:fullscreen .gallery-modal-topbar,
  .gallery-modal:-webkit-full-screen .gallery-modal-topbar,
  .gallery-modal.is-fullscreen-active .gallery-modal-topbar {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.38rem;
    max-width: calc((3.15rem * 2) + 0.38rem);
  }

  .gallery-modal:fullscreen .gallery-modal-topbar .gallery-modal-action,
  .gallery-modal:-webkit-full-screen .gallery-modal-topbar .gallery-modal-action,
  .gallery-modal.is-fullscreen-active .gallery-modal-topbar .gallery-modal-action {
    flex: 0 0 calc(50% - 0.19rem);
  }

  .gallery-modal:fullscreen .gallery-modal-media-wrap,
  .gallery-modal:-webkit-full-screen .gallery-modal-media-wrap,
  .gallery-modal.is-fullscreen-active .gallery-modal-media-wrap {
    grid-area: auto !important;
    grid-row: 1 !important;
    grid-column: 1 !important;
    width: min(100vw, 1120px);
    max-width: min(100vw, 1120px);
    min-height: 0;
    height: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .gallery-modal:fullscreen .gallery-modal-prev,
  .gallery-modal:-webkit-full-screen .gallery-modal-prev,
  .gallery-modal.is-fullscreen-active .gallery-modal-prev {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    grid-area: auto !important;
    grid-row: auto !important;
    grid-column: auto !important;
    justify-self: auto;
    z-index: 5;
  }

  .gallery-modal:fullscreen .gallery-modal-next,
  .gallery-modal:-webkit-full-screen .gallery-modal-next,
  .gallery-modal.is-fullscreen-active .gallery-modal-next {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    grid-area: auto !important;
    grid-row: auto !important;
    grid-column: auto !important;
    justify-self: auto;
    z-index: 5;
  }

  .gallery-modal:fullscreen .gallery-modal-image,
  .gallery-modal:-webkit-full-screen .gallery-modal-image,
  .gallery-modal.is-fullscreen-active .gallery-modal-image {
    grid-area: auto !important;
    grid-row: auto !important;
    grid-column: auto !important;
    display: block;
    width: 100% !important;
    max-width: min(100vw, 1120px) !important;
    height: auto !important;
    max-height: 100dvh !important;
    object-fit: contain;
    object-position: center center;
    justify-self: center;
    align-self: center;
    margin: 0 auto;
  }

  .gallery-modal:fullscreen .gallery-modal-caption,
  .gallery-modal:-webkit-full-screen .gallery-modal-caption,
  .gallery-modal.is-fullscreen-active .gallery-modal-caption {
    position: absolute;
    left: 50%;
    bottom: calc(var(--gallery-fs-thumbs-bottom, 0.35rem) + var(--gallery-fs-thumbs-visual-height, 120px) + 50px);
    transform: translateX(-50%);
    width: min(90vw, 30rem);
    margin: 0;
    padding: 0.5rem 0.78rem;
    font-size: 0.96rem;
    line-height: 1.32;
    display: block;
    overflow: visible;
    justify-self: auto;
    align-self: auto;
  }

  .gallery-modal:fullscreen .gallery-modal-thumbs-wrap,
  .gallery-modal:-webkit-full-screen .gallery-modal-thumbs-wrap,
  .gallery-modal.is-fullscreen-active .gallery-modal-thumbs-wrap {
    width: min(100vw, 1120px);
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    padding-bottom: calc(0.35rem + env(safe-area-inset-bottom));
    box-sizing: border-box;
  }

  .gallery-modal-thumbs {
    gap: 0.34rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-live-masonry.is-scrollfx-ready .gallery-live-item {
    opacity: 1;
    transform: none;
    transition: none;
  }
}
