/**
 * ACF Block: ギャラリー
 * PC: Figma 201:3056 — 4列 / gap 16px / py 42px / 188×141
 * SP: Figma 201:3303 — 3列 / gap 14×9.164 / py 20px / 105.54×79.16
 */

.acf-block-gallery {
	width: 100%;
	margin: 0;
	padding: 42px 0;
	box-sizing: border-box;
}

.wp-block-post-content > .acf-block-gallery,
.wp-block-post-content > .wp-block-acf-gallery,
.entry-content > .acf-block-gallery,
.entry-content > .wp-block-acf-gallery,
.wp-block-acf-gallery {
	margin: 0 !important;
	margin-block-start: 0 !important;
	margin-block-end: 0 !important;
	padding: 42px 0;
	box-sizing: border-box;
}

.wp-block-post-content > .acf-block-gallery + *,
.wp-block-post-content > .wp-block-acf-gallery + *,
.entry-content > .acf-block-gallery + *,
.entry-content > .wp-block-acf-gallery + * {
	margin-block-start: 0 !important;
}

.hds-shell--works .acf-block-gallery,
.hds-shell--works .wp-block-post-content > .acf-block-gallery,
.hds-shell--works .wp-block-post-content > .wp-block-acf-gallery,
.hds-shell--works .entry-content > .acf-block-gallery,
.hds-shell--works .entry-content > .wp-block-acf-gallery,
.hds-shell--works .wp-block-acf-gallery {
	padding: 12px 0;
}

.acf-block-gallery__list {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	grid-auto-flow: dense;
	gap: 16px;
	margin: 0;
	padding: 0;
	list-style: none;
	width: 100%;
	min-width: 0;
}

.acf-block-gallery__item {
	margin: 0;
	min-width: 0;
	max-width: 100%;
	aspect-ratio: 188 / 141;
	overflow: hidden;
	background-color: #c0c0c0;
	border: 0;
	box-sizing: border-box;
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.acf-block-gallery__item:hover,
.acf-block-gallery__item:focus-within {
	border-color: #fff;
	box-shadow: 0 0 0 1px #fff, 0 0 8px rgba(255, 255, 255, 0.75);
}

.acf-block-gallery__item--portrait {
	grid-row: span 2;
	aspect-ratio: 2 / 3;
	height: auto;
	align-self: start;
}

.acf-block-gallery__item img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
}

.acf-block-gallery__trigger {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	cursor: zoom-in;
}

.acf-block-gallery__trigger:focus {
	outline: none;
}

/* Lightbox */
body.hds-gallery-lightbox-open {
	overflow: hidden;
}

.hds-gallery-lightbox {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 48px 24px 72px;
	box-sizing: border-box;
}

.hds-gallery-lightbox[hidden] {
	display: none !important;
}

.hds-gallery-lightbox__overlay {
	position: absolute;
	inset: 0;
	border: 0;
	padding: 0;
	background: rgba(35, 24, 21, 0.82);
	cursor: pointer;
}

.hds-gallery-lightbox__inner {
	position: relative;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 16px;
	width: min(100%, 960px);
	max-height: calc(100vh - 120px);
}

.hds-gallery-lightbox__stage {
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	max-width: min(100%, 800px);
	max-height: calc(100vh - 120px);
	padding: 12px;
	background: #fff;
	box-sizing: border-box;
}

.hds-gallery-lightbox__image {
	display: block;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: calc(100vh - 144px);
	object-fit: contain;
}

.hds-gallery-lightbox__counter {
	position: absolute;
	left: 24px;
	bottom: 24px;
	z-index: 2;
	margin: 0;
	color: #fff;
	font-family: "EB Garamond", "Noto Serif JP", serif;
	font-size: calc(14px * var(--hds-type-scale, 1));
	font-weight: 400;
	line-height: 1;
}

.hds-gallery-lightbox__close {
	position: absolute;
	top: 24px;
	right: 24px;
	bottom: auto;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	cursor: pointer;
}

.hds-gallery-lightbox__close span {
	display: block;
	position: relative;
	width: 24px;
	height: 24px;
}

.hds-gallery-lightbox__close span::before,
.hds-gallery-lightbox__close span::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 24px;
	height: 1px;
	background: #fff;
	transform-origin: center;
}

.hds-gallery-lightbox__close span::before {
	transform: translate(-50%, -50%) rotate(45deg);
}

.hds-gallery-lightbox__close span::after {
	transform: translate(-50%, -50%) rotate(-45deg);
}

.hds-gallery-lightbox__close:hover,
.hds-gallery-lightbox__close:focus {
	opacity: 0.75;
}

.hds-gallery-lightbox__nav {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	cursor: pointer;
}

.hds-gallery-lightbox__nav[hidden] {
	display: none;
}

.hds-gallery-lightbox__nav span {
	display: block;
	width: 12px;
	height: 12px;
	border-top: 1px solid #fff;
	border-right: 1px solid #fff;
}

.hds-gallery-lightbox__nav--prev span {
	transform: rotate(-135deg);
}

.hds-gallery-lightbox__nav--next span {
	transform: rotate(45deg);
}

.hds-gallery-lightbox__nav:hover,
.hds-gallery-lightbox__nav:focus {
	opacity: 0.75;
}

.acf-block-gallery__placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 8rem;
	background-color: var(--wp--preset--color--base-2);
	color: var(--wp--preset--color--contrast-2);
	font-size: calc(var(--wp--preset--font-size--small) * var(--hds-type-scale, 1));
}

/*
 * エディタのキャンバスは狭いことが多く max-width:781px が誤発火する。
 * エディタ内はデザインどおり常に 4 列。
 */
.editor-styles-wrapper .acf-block-gallery__list,
.block-editor-block-list__block .acf-block-gallery__list,
.acf-block-preview .acf-block-gallery__list {
	grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
	grid-auto-flow: dense !important;
	gap: 16px !important;
}

.editor-styles-wrapper .acf-block-gallery,
.block-editor-block-list__block .acf-block-gallery,
.acf-block-preview .acf-block-gallery {
	padding: 42px 0;
}

.editor-styles-wrapper .acf-block-gallery__item,
.block-editor-block-list__block .acf-block-gallery__item,
.acf-block-preview .acf-block-gallery__item {
	min-width: 0;
	max-width: 100%;
	aspect-ratio: 188 / 141;
	overflow: hidden;
	background-color: #c0c0c0;
	border: 0;
}

.editor-styles-wrapper .acf-block-gallery__item--portrait,
.block-editor-block-list__block .acf-block-gallery__item--portrait,
.acf-block-preview .acf-block-gallery__item--portrait {
	grid-row: span 2;
	aspect-ratio: 2 / 3;
	height: auto;
	align-self: start;
}

.editor-styles-wrapper .acf-block-gallery__item img,
.block-editor-block-list__block .acf-block-gallery__item img,
.acf-block-preview .acf-block-gallery__item img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* 実機 SP（エディタ iframe は除外）— Figma Frame 287 (201:3303) */
@media screen and (max-width: 781px) {
	body:not(.editor-styles-wrapper) .acf-block-gallery,
	body:not(.editor-styles-wrapper) .wp-block-post-content > .acf-block-gallery,
	body:not(.editor-styles-wrapper) .wp-block-acf-gallery {
		padding: 20px 0;
	}

	body:not(.editor-styles-wrapper) .acf-block-gallery__list {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		gap: 14px 9.164px;
	}

	body:not(.editor-styles-wrapper) .acf-block-gallery__item {
		aspect-ratio: 105.542 / 79.156;
		border: 0;
		background-color: #c0c0c0;
	}

	body:not(.editor-styles-wrapper) .acf-block-gallery__item--portrait {
		grid-row: span 2;
		aspect-ratio: 2 / 3;
		height: auto;
		align-self: start;
	}

	body:not(.editor-styles-wrapper) .hds-shell--works .acf-block-gallery,
	body:not(.editor-styles-wrapper) .hds-shell--works .wp-block-post-content > .acf-block-gallery,
	body:not(.editor-styles-wrapper) .hds-shell--works .wp-block-acf-gallery {
		padding: 12px 0;
	}
}

.wp-block-acf-gallery {
	width: 100%;
}
