.brl-detail-gallery {
  --brl-gallery-paper: #faf8f4;
  --brl-gallery-ink: #302e29;
  --brl-gallery-accent: #8c7550;
  width: 100%;
  min-width: 0;
  color: var(--brl-gallery-ink);
}

.brl-detail-gallery *,
.brl-gallery-lightbox * {
  box-sizing: border-box;
}

.brl-detail-gallery__stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: min(70vh, 680px);
  overflow: hidden;
  background: var(--brl-gallery-paper);
}

.brl-detail-gallery__open {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
  cursor: zoom-in;
}

.brl-detail-gallery__image {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  object-fit: contain;
}

.brl-detail-gallery__prev,
.brl-detail-gallery__next,
.brl-detail-gallery__thumb,
.brl-gallery-lightbox__button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  font: inherit;
  line-height: 1;
  text-transform: none;
  text-decoration: none;
  box-shadow: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.brl-detail-gallery__prev,
.brl-detail-gallery__next {
  position: absolute;
  z-index: 1;
  top: 50%;
  width: 42px;
  height: 42px;
  border: 1px solid rgb(48 46 41 / 16%);
  border-radius: 50%;
  background: rgb(250 248 244 / 94%);
  color: var(--brl-gallery-ink);
  transform: translateY(-50%);
  transition: background-color 160ms ease, border-color 160ms ease;
}

.brl-detail-gallery__prev { left: 16px; }
.brl-detail-gallery__next { right: 16px; }

.brl-detail-gallery__prev:hover,
.brl-detail-gallery__next:hover {
  border-color: var(--brl-gallery-accent);
  background: #fff;
  color: var(--brl-gallery-ink);
}

.brl-detail-gallery__prev svg,
.brl-detail-gallery__next svg,
.brl-gallery-lightbox__button svg {
  display: block;
  flex: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.brl-detail-gallery__count {
  position: absolute;
  z-index: 1;
  right: 16px;
  bottom: 16px;
  padding: 7px 11px;
  border: 1px solid rgb(48 46 41 / 12%);
  border-radius: 20px;
  background: rgb(250 248 244 / 94%);
  color: var(--brl-gallery-ink);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.brl-detail-gallery__thumbs {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin-top: 14px;
  padding: 3px 2px 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: rgb(140 117 80 / 40%) transparent;
  -webkit-overflow-scrolling: touch;
}

.brl-detail-gallery__caption {
  margin: 12px 0 0;
  color: var(--brl-gallery-accent);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: .015em;
}

.brl-detail-gallery__caption[hidden] { display: none; }

.brl-detail-gallery__thumb {
  flex: 0 0 72px;
  width: 72px;
  height: 76px;
  overflow: hidden;
  border: 1px solid rgb(48 46 41 / 14%);
  border-radius: 0;
  background: var(--brl-gallery-paper);
  opacity: .68;
  transition: opacity 160ms ease, border-color 160ms ease;
}

.brl-detail-gallery__thumb:hover,
.brl-detail-gallery__thumb[aria-pressed="true"] {
  border-color: var(--brl-gallery-accent);
  background: var(--brl-gallery-paper);
  opacity: 1;
}

.brl-detail-gallery__thumb[aria-pressed="true"] {
  box-shadow: inset 0 0 0 1px var(--brl-gallery-accent);
}

.brl-detail-gallery__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 3px;
  object-fit: contain;
  pointer-events: none;
}

.brl-detail-gallery :is(a, button):focus-visible {
  outline: 2px solid var(--brl-gallery-accent);
  outline-offset: 3px;
}

.brl-detail-gallery__open:focus-visible {
  outline-offset: -4px !important;
}

.brl-detail-gallery.is-single :is(.brl-detail-gallery__prev, .brl-detail-gallery__next, .brl-detail-gallery__thumbs) {
  display: none;
}

.brl-detail-gallery--supplement {
  max-width: 640px;
  margin: 36px auto 44px !important;
  padding-top: 24px;
  border-top: 1px solid rgb(48 46 41 / 14%);
}

.brl-detail-gallery__heading {
  margin: 0 0 20px;
  font-size: 24px;
  line-height: 1.3;
  font-weight: 500;
  letter-spacing: normal;
}

.brl-detail-gallery--supplement .brl-detail-gallery__stage {
  max-height: min(56vh, 320px);
}

.brl-detail-gallery--supplement .brl-detail-gallery__thumb {
  flex-basis: 60px;
  width: 60px;
  height: 64px;
}

.brl-gallery-lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  height: 100dvh;
  max-height: none;
  padding: 0;
  margin: 0;
  overflow: hidden;
  border: 0;
  background: rgb(31 29 25 / 97%);
  color: #faf8f4;
  font-family: inherit;
  overscroll-behavior: none;
}

.brl-gallery-lightbox:not([open]) { display: none; }
.brl-gallery-lightbox::backdrop { background: rgb(31 29 25 / 88%); }

.brl-gallery-lightbox__toolbar {
  position: absolute;
  z-index: 3;
  top: max(16px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  left: max(20px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
}

.brl-gallery-lightbox__count {
  font-size: 13px;
  line-height: 1;
  letter-spacing: .06em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.brl-gallery-lightbox__tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brl-gallery-lightbox__button {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border: 1px solid rgb(250 248 244 / 23%);
  border-radius: 50%;
  background: rgb(48 46 41 / 82%);
  color: #faf8f4;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.brl-gallery-lightbox__button:hover {
  border-color: rgb(250 248 244 / 65%);
  background: #4d463b;
  color: #faf8f4;
}

.brl-gallery-lightbox__button:focus-visible {
  outline: 2px solid #faf8f4;
  outline-offset: 4px;
}

.brl-gallery-lightbox__button:disabled {
  opacity: .32;
  cursor: default;
}

.brl-gallery-lightbox__button[hidden] { display: none; }
.brl-gallery-lightbox__close { margin-left: 8px; }

.brl-gallery-lightbox__zoom-value {
  min-width: 42px;
  color: rgb(250 248 244 / 75%);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.brl-gallery-lightbox__viewport {
  position: absolute;
  inset: calc(80px + env(safe-area-inset-top)) max(76px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(76px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  cursor: zoom-out;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.brl-gallery-lightbox__image {
  display: block;
  flex: none;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  object-fit: contain;
  transform-origin: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.brl-gallery-lightbox.is-zoomed .brl-gallery-lightbox__viewport { cursor: grab; }
.brl-gallery-lightbox.is-dragging .brl-gallery-lightbox__viewport { cursor: grabbing; }
.brl-gallery-lightbox.is-loading .brl-gallery-lightbox__image { opacity: 0; }

.brl-gallery-lightbox.is-loading .brl-gallery-lightbox__viewport::after {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 2px solid rgb(250 248 244 / 22%);
  border-top-color: #faf8f4;
  border-radius: 50%;
  content: "";
  animation: brl-gallery-spin 800ms linear infinite;
}

.brl-gallery-lightbox__prev,
.brl-gallery-lightbox__next {
  position: absolute;
  z-index: 2;
  top: 50%;
  transform: translateY(-50%);
}

.brl-gallery-lightbox__prev { left: max(20px, env(safe-area-inset-left)); }
.brl-gallery-lightbox__next { right: max(20px, env(safe-area-inset-right)); }

@keyframes brl-gallery-spin { to { transform: rotate(360deg); } }

@media (max-width: 600px) {
  .brl-detail-gallery__stage { max-height: 62vh; }
  .brl-detail-gallery__prev { left: 10px; }
  .brl-detail-gallery__next { right: 10px; }
  .brl-detail-gallery__count { right: 10px; bottom: 10px; }
  .brl-detail-gallery__thumbs { gap: 8px; margin-top: 10px; }
  .brl-detail-gallery__thumb { flex-basis: 60px; width: 60px; height: 64px; }
  .brl-gallery-lightbox__toolbar { right: 12px; left: 16px; gap: 10px; }
  .brl-gallery-lightbox__tools { gap: 4px; }
  .brl-gallery-lightbox__close { margin-left: 2px; }
  .brl-gallery-lightbox__zoom-value { display: none; }
  .brl-gallery-lightbox__viewport {
    inset: calc(78px + env(safe-area-inset-top)) 12px calc(78px + env(safe-area-inset-bottom));
  }
  .brl-gallery-lightbox__prev,
  .brl-gallery-lightbox__next {
    top: auto;
    bottom: max(18px, env(safe-area-inset-bottom));
    transform: none;
  }
  .brl-gallery-lightbox__prev { left: calc(50% - 56px); }
  .brl-gallery-lightbox__next { right: calc(50% - 56px); }
}

@media (prefers-reduced-motion: reduce) {
  .brl-detail-gallery *,
  .brl-gallery-lightbox * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
