.gallery-intro {
  padding: 28px 0 8px;
}

.view-toggle {
  display: inline-flex;
  gap: 4px;
  margin-top: 28px;
  padding: 4px;
  border: 1px solid rgba(28, 24, 20, 0.18);
  border-radius: 999px;
  background: var(--white);
}

.view-toggle button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  font-size: 0.94rem;
  font-weight: 500;
}

.view-toggle svg {
  flex: none;
}

.view-toggle button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.gallery-intro h1 {
  max-width: 11ch;
  font-size: clamp(2.7rem, 6vw, 4.6rem);
}

.gallery-row {
  padding: 22px 0 12px;
}

.row-head {
  margin-bottom: 18px;
}

.row-head h2 {
  font-size: clamp(1.9rem, 3vw, 2.7rem);
}

.pager {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.pager button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(28, 24, 20, 0.18);
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 10px 24px rgba(28, 24, 20, 0.18);
  pointer-events: auto;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.pager button[data-dir="-1"] {
  left: calc(var(--gallery-gutter) + 12px);
}

.pager button[data-dir="1"] {
  right: 16px;
}

.pager button:hover:not(:disabled) {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.pager button:disabled {
  opacity: 0.35;
  cursor: default;
}

.carousel {
  position: relative;
  container-type: inline-size;
  --gallery-gutter: max(20px, calc((100% - 1120px) / 2));
}

.track {
  position: relative;
  display: flex;
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: none;
  padding-inline: var(--gallery-gutter);
  padding-bottom: 8px;
  scrollbar-width: none;
}

.track::-webkit-scrollbar {
  display: none;
}

.slide {
  position: relative;
  flex: 0 0 auto;
  height: min(62vh, 440px);
  margin: 0;
  border-radius: 14px;
  overflow: hidden;
  scroll-snap-align: start;
  background: var(--paper-deep);
}

.slide img {
  height: 100%;
  width: auto;
  max-width: none;
}

.slide figcaption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 42px 16px 14px;
  background: linear-gradient(to top, rgba(28, 24, 20, 0.78) 0%, rgba(28, 24, 20, 0.28) 55%, rgba(28, 24, 20, 0) 100%);
  color: #f6f1e8;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.12rem;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.carousel::before {
  content: "";
  position: absolute;
  z-index: 1;
  top: 0;
  bottom: 8px;
  left: 0;
  width: var(--gallery-gutter, 20px);
  background: var(--paper);
  pointer-events: none;
}

html.is-grid .pager,
html.is-grid .carousel::before {
  display: none;
}

html.is-grid .carousel {
  width: min(1120px, calc(100% - 40px));
  margin-inline: auto;
}

html.is-grid .track {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  overflow: visible;
  padding: 0;
  scroll-snap-type: none;
}

html.is-grid .slide {
  width: auto;
  height: auto;
  aspect-ratio: 4 / 3;
  scroll-snap-align: none;
}

html.is-grid .slide img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
}

@media (max-width: 800px) {
  html.is-grid .track {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .carousel {
    --gallery-gutter: 20px;
  }

  .pager button[data-dir="-1"] {
    left: 8px;
  }

  .pager button[data-dir="1"] {
    right: 8px;
  }

  .track {
    align-items: flex-start;
  }

  .slide {
    width: min(calc(100cqi - 40px), calc(300px * var(--ratio, 1)));
    height: auto;
    aspect-ratio: var(--ratio, 1);
  }

  .slide img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    object-fit: cover;
  }

  .slide figcaption {
    font-size: 1rem;
    padding: 36px 12px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .track {
    scroll-behavior: auto;
  }
}
