/* CSTM ポップアップ（テーマの文字サイズ・余白に寄らない独立スタイル） */
.cstm-popup {
	--cstm-popup-btn-bg: #222;
	--cstm-popup-btn-color: #fff;
	/* 閉じるボタンの直径。角に重ねるときは半分はみ出すので、その分を画面の余白に足す */
	--cstm-popup-x: 32px;
	--cstm-popup-gap: 32px;
	box-sizing: border-box;
	width: min(var(--cstm-popup-mw, 600px), calc(100vw - var(--cstm-popup-gap)));
	max-height: none;
	overflow: visible;
	padding: 0;
	margin: 0;
	border: var(--cstm-popup-bdw, 0) solid var(--cstm-popup-bdc, #333);
	border-radius: var(--cstm-popup-rad, 8px);
	/* 背景は内側に持たせる（枠にも置くと、角で切った暗い見出しの縁に白がにじむ） */
	background: transparent;
	color: #222;
	font-size: 16px;
	line-height: 1.6;
	text-align: left;
}
.cstm-popup *, .cstm-popup *::before, .cstm-popup *::after { box-sizing: border-box; }
/* 角に重ねるときは片側の余白を 16px からボタンの半分 + 8px へ（余白をボタン全体ぶん増やすとスマホ幅で本文が折り返す） */
.cstm-popup.is-close-corner { --cstm-popup-gap: calc(16px + var(--cstm-popup-x)); }
/* スクロールは内側だけ（枠は overflow:visible にして、角に重ねた閉じるボタンを切らない）。角丸の内側で中身を切る */
.cstm-popup-inner {
	max-height: calc(100dvh - var(--cstm-popup-gap) - var(--cstm-popup-bdw, 0px) * 2);
	overflow: auto;
	overscroll-behavior: contain;
	background: var(--cstm-popup-bg, #fff);
	/* border-radius で切ると背景と中身を別々にぼかし、角の暗い見出しの縁に背景色がにじむ。filter でひとまとめに描かせ、clip-path で一度だけ切る
	   （will-change: transform は overscroll-behavior: contain と重なると効かなかった。2026-11-02 に Chrome で実測） */
	clip-path: inset(0 round max(0px, calc(var(--cstm-popup-rad, 8px) - var(--cstm-popup-bdw, 0px))));
	filter: opacity(1);
}
.cstm-popup-inner:focus { outline: none; }

/* モーダル: dialog の display は開いているときだけ（閉じた状態の display:none を上書きしない）。UA の dialog:modal の overflow:auto・max-height も外す */
dialog.cstm-popup-modal { position: fixed; inset: 0; margin: auto; }
dialog.cstm-popup-modal:modal { max-height: none; overflow: visible; }
dialog.cstm-popup-modal::backdrop { background: rgb(0 0 0 / .6); overflow: hidden; overscroll-behavior: contain; }

/* 追従バナー: ページの操作は妨げない */
.cstm-popup-banner { --cstm-popup-x: 28px; position: fixed; z-index: 99990; width: min(var(--cstm-popup-mw, 320px), calc(100vw - var(--cstm-popup-gap))); box-shadow: 0 8px 24px rgb(0 0 0 / .2); }
.cstm-popup-banner[hidden] { display: none; }
/* タッチ端末は指を離しても :hover が残り薄いままになるので、ホバーできる端末だけ */
@media (hover: hover) {
	.cstm-popup-banner { transition: opacity .2s; }
	.cstm-popup-banner:hover { opacity: .8; }
}
/* 影（既定はクラスなし: モーダルは影なし・追従バナーは上の値）。box-shadow は枠の角丸に沿い、枠は overflow:visible なので切れない */
.cstm-popup.is-shadow-none { box-shadow: none; }
.cstm-popup.is-shadow-sm { box-shadow: 0 2px 8px rgb(0 0 0 / .12); }
.cstm-popup.is-shadow-md { box-shadow: 0 8px 32px rgb(0 0 0 / .18); }
.cstm-popup.is-shadow-lg { box-shadow: 0 16px 56px rgb(0 0 0 / .28); }
.cstm-popup-banner.is-br { right: 16px; bottom: 16px; }
.cstm-popup-banner.is-bl { left: 16px; bottom: 16px; }
.cstm-popup-banner.is-tr { right: 16px; top: 16px; }
.cstm-popup-banner.is-tl { left: 16px; top: 16px; }
/* 角に重ねるときは、はみ出す分だけ画面の端から離す */
.cstm-popup-banner.is-close-corner.is-br, .cstm-popup-banner.is-close-corner.is-tr { right: calc(16px + var(--cstm-popup-x) / 2); }
.cstm-popup-banner.is-close-corner.is-tr, .cstm-popup-banner.is-close-corner.is-tl { top: calc(16px + var(--cstm-popup-x) / 2); }

.cstm-popup-close {
	--cstm-popup-x-bg: rgb(255 255 255 / .9);
	--cstm-popup-x-line: #222;
	position: absolute; top: 8px; right: 8px; z-index: 1;
	width: var(--cstm-popup-x); height: var(--cstm-popup-x); padding: 0; margin: 0;
	border: 0; border-radius: 50%;
	background: var(--cstm-popup-x-bg); box-shadow: 0 1px 4px rgb(0 0 0 / .3);
	cursor: pointer;
}
.cstm-popup-close::before, .cstm-popup-close::after {
	content: ""; position: absolute; top: 50%; left: 50%;
	width: calc(var(--cstm-popup-x) * .45); height: 2px; background: var(--cstm-popup-x-line);
	translate: -50% -50%; rotate: 45deg;
}
.cstm-popup-close::after { rotate: -45deg; }
.cstm-popup-close:focus-visible { outline: 2px solid #1a73e8; outline-offset: 2px; }
.cstm-popup-banner .cstm-popup-close { top: 6px; right: 6px; }
.is-close-black .cstm-popup-close { --cstm-popup-x-bg: #000; --cstm-popup-x-line: #fff; }
.is-close-gray .cstm-popup-close { --cstm-popup-x-bg: #555; --cstm-popup-x-line: #fff; }
/* 角に重ねる: ボタンの中心を枠の右上の角（枠線の外側）に置く */
.cstm-popup.is-close-corner .cstm-popup-close {
	top: calc(var(--cstm-popup-x) / -2 - var(--cstm-popup-bdw, 0px));
	right: calc(var(--cstm-popup-x) / -2 - var(--cstm-popup-bdw, 0px));
}

.cstm-popup-img { display: block; }
.cstm-popup-img picture, .cstm-popup-img img { display: block; width: 100%; height: auto; max-width: none; margin: 0; border: 0; }

.cstm-popup-body { --cstm-popup-pad: 24px; padding: var(--cstm-popup-pad); }
.cstm-popup a.cstm-popup-link { display: block; color: inherit; text-decoration: none; }
.cstm-popup-banner .cstm-popup-body { --cstm-popup-pad: 16px; }
/* 閉じるボタンを内側に置くとき、画像が無ければ見出しの右を空けて重ならないようにする */
.cstm-popup.is-close-inside .cstm-popup-inner > .cstm-popup-body:first-child > .cstm-popup-title:first-child { padding-right: 32px; }
.cstm-popup .cstm-popup-title {
	margin: 0 0 8px; padding: 0; border: 0; background: none;
	color: inherit; font-size: 20px; font-weight: bold; line-height: 1.4; text-align: left;
}
.cstm-popup .cstm-popup-title::before, .cstm-popup .cstm-popup-title::after { content: none; }
.cstm-popup-banner .cstm-popup-title { font-size: 16px; }

/* 本文（ブロック）。ブロック間の余白はテーマの p・見出しの margin に頼らず揃える（ブロックで余白を指定すれば style 属性が勝つ） */
.cstm-popup .cstm-popup-content { margin: 16px 0 0; overflow-wrap: anywhere; }
.cstm-popup .cstm-popup-content:first-child { margin-top: 0; }
.cstm-popup-banner .cstm-popup-content { font-size: 14px; }
/* 配置機能（layout）に対応しないテーマではグループの中身が __inner-container で包まれるので、そちらも同じに扱う */
.cstm-popup .cstm-popup-content > *, .cstm-popup .cstm-popup-content :is(.wp-block-group, .wp-block-group__inner-container) > * { margin-block: 0; }
.cstm-popup .cstm-popup-content > * + *, .cstm-popup .cstm-popup-content :is(.wp-block-group, .wp-block-group__inner-container):not(.is-layout-flex, .is-layout-grid) > * + * { margin-block-start: 16px; }
/* text-align・font-size はブロックの指定（クラスの詳細度が低い）を消すので触らない */
.cstm-popup .cstm-popup-content :is(h1, h2, h3, h4, h5, h6) { padding: 0; border: 0; background: none; color: inherit; line-height: 1.4; }
.cstm-popup .cstm-popup-content :is(h1, h2, h3, h4, h5, h6)::before, .cstm-popup .cstm-popup-content :is(h1, h2, h3, h4, h5, h6)::after { content: none; }
.cstm-popup .cstm-popup-content img { max-width: 100%; height: auto; }
/* 「全幅」のブロックはポップアップの端まで広げ、本文の先頭・末尾なら上下の余白も詰める */
.cstm-popup .cstm-popup-content > .alignfull { width: auto; max-width: none; margin-inline: calc(var(--cstm-popup-pad) * -1); }
.cstm-popup-inner > .cstm-popup-body:first-child > .cstm-popup-content:first-child > .alignfull:first-child { margin-top: calc(var(--cstm-popup-pad) * -1); }
.cstm-popup-body > .cstm-popup-content:last-child > .alignfull:last-child { margin-bottom: calc(var(--cstm-popup-pad) * -1); }
/* グローバルスタイルを外したテーマ向けの配置の土台。:where で詳細度 0 にし、ブロックごとの配置指定（wp-container-*）に負ける */
:where(.cstm-popup-content .is-layout-flex) { display: flex; flex-wrap: wrap; align-items: center; }
:where(.cstm-popup-content .is-layout-flex, .cstm-popup-content .is-layout-grid) > * { margin: 0; }
:where(.cstm-popup-content .is-layout-grid) { display: grid; }

.cstm-popup .cstm-popup-act { margin: 16px 0 0; padding: 0; text-align: center; }
.cstm-popup .cstm-popup-act:first-child { margin-top: 0; }
/* .cstm-popup-act を挟むのは、テーマのリンク色（例 `.base a:not(.hd *)` は 0,2,1）に負けないため */
.cstm-popup .cstm-popup-act .cstm-popup-btn {
	display: inline-block; min-width: 160px; padding: 12px 24px;
	border-radius: 999px; background: var(--cstm-popup-btn-bg); color: var(--cstm-popup-btn-color);
	font-size: 16px; font-weight: bold; line-height: 1.4; text-decoration: none;
}
.cstm-popup .cstm-popup-act .cstm-popup-btn:hover { opacity: .85; }
.cstm-popup .cstm-popup-act .cstm-popup-btn:focus-visible { outline: 2px solid #1a73e8; outline-offset: 2px; }
