/**
 * 匠パーツ：ページの背景（1.5.0）.
 *
 * 背景を選んだページでだけ読み込む（inc/page-bg.php）。エディターでは
 * 右サイドバーの見本（.tp-pbg-preview / .tp-pbg-tile）にも使う。
 *
 * 変数（<body> に入る。エディターの見本では見本の要素に入る）:
 *   --tp-pbg-c1 / --tp-pbg-c2  色1・色2（未指定なら種類ごとの標準色）
 *   --tp-pbg-k                 背景の濃さ（1 = 標準、0〜2）
 *   --tp-pbg-card              本文カードの白さ（0〜100。未指定なら種類ごとの標準）
 *   --tp-pbg-b                 ぼかしの倍率（見本を小さく描くときに下げる）
 */

/* =========================================================
   1. ページ全体と本文カード
   ========================================================= */
body.tp-pbg {
	--tp-pbg-card-d: 72;
	background: transparent;
}

body.tp-pbg--night {
	--tp-pbg-card-d: 90;
}

/* テーマの「サイトの背景（背景画像）」より、ページごとの背景を優先する */
body.tp-pbg .site-bg-layer {
	display: none;
}

/* 本文カード（テーマ「匠」の .site-main > .container）を半透明にして背景を透かす。
   色はテーマの「本文エリアの背景色」（--tp-pbg-card-rgb）。白さ（不透明度）は
   ページの設定 → テーマの「本文エリアの背景の透明度」（100以外のとき）→ 種類ごとの標準、の順 */
body.tp-pbg .site-main > .container {
	background: rgb(var(--tp-pbg-card-rgb, 255 255 255) / calc(var(--tp-pbg-card, var(--tp-pbg-card-d)) / 100));
	border-color: rgb(255 255 255 / .75);
	box-shadow: 0 12px 40px rgb(31 41 90 / .10), inset 0 1px 0 rgb(255 255 255 / .85);
}

body.tp-pbg--night .site-main > .container {
	border-color: rgb(255 255 255 / .28);
	box-shadow: 0 18px 60px rgb(0 0 0 / .35), inset 0 1px 0 rgb(255 255 255 / .5);
}

/* 夜空ではカードの外のパンくずを明るい色に（背景カードをオンにしているときはそのまま） */
body.tp-pbg--night:not(.has-breadcrumb-card) .single-breadcrumbs .breadcrumbs,
body.tp-pbg--night:not(.has-breadcrumb-card) .single-breadcrumbs .breadcrumbs a,
body.tp-pbg--night:not(.has-breadcrumb-card) .single-breadcrumbs .breadcrumbs [aria-current="page"] {
	color: #e2e8f0;
}

/* =========================================================
   2. 背景レイヤー（<body> の直後に1つ。画面に固定）
   ========================================================= */
.tp-pbg-layer {
	--tp-pbg-b: 1;
	position: fixed;
	z-index: -1;
	inset: 0;
	overflow: hidden;
	pointer-events: none;
	contain: layout paint;
}

.tp-pbg-layer > i {
	position: absolute;
	display: none;
	pointer-events: none;
}

/* --- 2a. パステルアメーバ --- */
.tp-pbg-layer--amoeba {
	background: linear-gradient(160deg, #fff7fb 0%, #f6f3ff 48%, #eef7ff 100%);
}

.tp-pbg-layer--amoeba.is-custom {
	background: linear-gradient(160deg,
		color-mix(in oklab, var(--tp-pbg-c1, #ff5fa8) 7%, #fff) 0%,
		#fff 50%,
		color-mix(in oklab, var(--tp-pbg-c2, #a78bfa) 8%, #fff) 100%);
}

.tp-pbg-layer--amoeba > i {
	display: block;
	aspect-ratio: 1;
	/* 動きを止めたときもアメーバの形のまま（アニメーションの最初の形と同じ） */
	border-radius: 58% 42% 37% 63% / 46% 55% 45% 54%;
	opacity: min(1, calc(.8 * var(--tp-pbg-k, 1)));
	will-change: transform, border-radius;
}

.tp-pbg-layer--amoeba > i:nth-child(1) {
	width: 34%; top: -7%; left: -8%;
	background: #ffc0dd;
	filter: blur(calc(14px * var(--tp-pbg-b)));
	animation: tp-pbg-morph1 23s ease-in-out infinite, tp-pbg-float1 41s ease-in-out infinite;
}

.tp-pbg-layer--amoeba > i:nth-child(2),
.tp-pbg-layer--amoeba > i:nth-child(5) {
	border-radius: 42% 58% 63% 37% / 58% 41% 59% 42%;
}

.tp-pbg-layer--amoeba > i:nth-child(3),
.tp-pbg-layer--amoeba > i:nth-child(6) {
	border-radius: 50% 50% 42% 58% / 62% 36% 64% 38%;
}

.tp-pbg-layer--amoeba > i:nth-child(2) {
	width: 30%; bottom: -8%; right: -6%;
	background: #d4c8ff;
	filter: blur(calc(14px * var(--tp-pbg-b)));
	animation: tp-pbg-morph2 29s ease-in-out infinite, tp-pbg-float2 37s ease-in-out infinite;
}

.tp-pbg-layer--amoeba > i:nth-child(3) {
	width: 22%; top: 22%; right: 3%;
	background: #fff09e;
	filter: blur(calc(11px * var(--tp-pbg-b)));
	animation: tp-pbg-morph3 19s ease-in-out infinite, tp-pbg-float3 31s ease-in-out infinite;
}

.tp-pbg-layer--amoeba > i:nth-child(4) {
	width: 20%; top: 58%; left: -2%;
	background: #b8ddff;
	filter: blur(calc(11px * var(--tp-pbg-b)));
	animation: tp-pbg-morph1 31s ease-in-out infinite reverse, tp-pbg-float2 43s ease-in-out infinite;
}

.tp-pbg-layer--amoeba > i:nth-child(5) {
	width: 12%; top: 8%; left: 44%;
	background: #ffb3d2;
	filter: blur(calc(9px * var(--tp-pbg-b)));
	animation: tp-pbg-morph2 17s ease-in-out infinite, tp-pbg-float1 27s ease-in-out infinite reverse;
}

.tp-pbg-layer--amoeba > i:nth-child(6) {
	width: 11%; bottom: 13%; left: 26%;
	background: #fff6b8;
	filter: blur(calc(9px * var(--tp-pbg-b)));
	animation: tp-pbg-morph3 21s ease-in-out infinite, tp-pbg-float3 33s ease-in-out infinite reverse;
}

/* 色を選んだときは、その2色からパステル色を作る */
.tp-pbg-layer--amoeba.is-custom > i:nth-child(1),
.tp-pbg-layer--amoeba.is-custom > i:nth-child(5) {
	background: color-mix(in oklab, var(--tp-pbg-c1, #ff5fa8) 40%, #fff);
}

.tp-pbg-layer--amoeba.is-custom > i:nth-child(2) {
	background: color-mix(in oklab, var(--tp-pbg-c2, #a78bfa) 40%, #fff);
}

.tp-pbg-layer--amoeba.is-custom > i:nth-child(3),
.tp-pbg-layer--amoeba.is-custom > i:nth-child(6) {
	background: color-mix(in oklab, color-mix(in oklab, var(--tp-pbg-c1, #ff5fa8) 50%, var(--tp-pbg-c2, #a78bfa)) 30%, #fff);
}

.tp-pbg-layer--amoeba.is-custom > i:nth-child(4) {
	background: color-mix(in oklab, var(--tp-pbg-c2, #a78bfa) 26%, #fff);
}

/* --- 2b. オーロラ（ぼかしフィルターを使わず、放射グラデーションの縁でやわらかく） --- */
.tp-pbg-layer--aurora {
	background: linear-gradient(180deg, #f4f8ff 0%, #f8f5ff 55%, #f1fbf7 100%);
}

.tp-pbg-layer--aurora > i:nth-child(-n+4) {
	display: block;
}

.tp-pbg-layer--aurora > i {
	border-radius: 50%;
	opacity: min(1, calc(.7 * var(--tp-pbg-k, 1)));
	will-change: transform;
}

.tp-pbg-layer--aurora > i:nth-child(1) {
	width: 85%; aspect-ratio: 1; top: -45%; left: -25%;
	background: radial-gradient(closest-side, color-mix(in oklab, var(--tp-pbg-c1, #38bdf8) 55%, transparent), transparent);
	animation: tp-pbg-aurora1 26s ease-in-out infinite alternate;
}

.tp-pbg-layer--aurora > i:nth-child(2) {
	width: 80%; aspect-ratio: 1; top: -30%; right: -30%;
	background: radial-gradient(closest-side, color-mix(in oklab, var(--tp-pbg-c2, #a78bfa) 55%, transparent), transparent);
	animation: tp-pbg-aurora2 31s ease-in-out infinite alternate;
}

.tp-pbg-layer--aurora > i:nth-child(3) {
	width: 90%; aspect-ratio: 1; bottom: -55%; left: 5%;
	background: radial-gradient(closest-side, color-mix(in oklab, color-mix(in oklab, var(--tp-pbg-c1, #34d399) 50%, #34d399) 50%, transparent), transparent);
	animation: tp-pbg-aurora3 37s ease-in-out infinite alternate;
}

/* 斜めに流れる光の帯 */
.tp-pbg-layer--aurora > i:nth-child(4) {
	width: 140%; height: 34%; top: 20%; left: -20%;
	background: radial-gradient(closest-side,
		color-mix(in oklab, color-mix(in oklab, var(--tp-pbg-c1, #38bdf8) 50%, var(--tp-pbg-c2, #a78bfa)) 38%, transparent),
		transparent);
	opacity: min(1, calc(.55 * var(--tp-pbg-k, 1)));
	transform: rotate(-14deg);
	animation: tp-pbg-ribbon 23s ease-in-out infinite alternate;
}

/* --- 2c. やわらかグラデーション（ほぼ静止。光がゆっくり移ろうだけ） --- */
.tp-pbg-layer--soft {
	background:
		radial-gradient(60% 55% at 12% 8%, color-mix(in oklab, var(--tp-pbg-c1, #7dd3fc) calc(34% * var(--tp-pbg-k, 1)), transparent), transparent 72%),
		radial-gradient(58% 55% at 92% 92%, color-mix(in oklab, var(--tp-pbg-c2, #f9a8d4) calc(34% * var(--tp-pbg-k, 1)), transparent), transparent 72%),
		linear-gradient(135deg,
			color-mix(in oklab, var(--tp-pbg-c1, #7dd3fc) calc(12% * var(--tp-pbg-k, 1)), #fff),
			#fff 50%,
			color-mix(in oklab, var(--tp-pbg-c2, #f9a8d4) calc(12% * var(--tp-pbg-k, 1)), #fff));
}

.tp-pbg-layer--soft > i:nth-child(1) {
	display: block;
	width: 70%; aspect-ratio: 1; top: 10%; left: 15%;
	border-radius: 50%;
	background: radial-gradient(closest-side, rgb(255 255 255 / .75), transparent);
	animation: tp-pbg-aurora2 40s ease-in-out infinite alternate;
}

/* --- 2d. 夜空（星がまたたき、ときどき流れ星） --- */
.tp-pbg-layer--night {
	background:
		radial-gradient(85% 60% at 50% 118%, color-mix(in oklab, var(--tp-pbg-c2, #818cf8) calc(42% * var(--tp-pbg-k, 1)), transparent), transparent 72%),
		radial-gradient(60% 45% at 8% -6%, color-mix(in oklab, var(--tp-pbg-c1, #38bdf8) calc(26% * var(--tp-pbg-k, 1)), transparent), transparent 70%),
		linear-gradient(180deg, #060a1c 0%, #0c1431 46%, #1a1840 100%);
}

.tp-pbg-layer--night > i:nth-child(-n+3) {
	display: block;
	inset: 0;
	background-repeat: repeat;
}

.tp-pbg-layer--night > i:nth-child(1) {
	background-image:
		radial-gradient(1px 1px at 18px 24px, #fff, transparent),
		radial-gradient(1px 1px at 92px 70px, #fff, transparent),
		radial-gradient(1px 1px at 160px 18px, #fff, transparent),
		radial-gradient(1px 1px at 210px 150px, #fff, transparent),
		radial-gradient(1px 1px at 40px 190px, #fff, transparent),
		radial-gradient(1px 1px at 130px 220px, #fff, transparent),
		radial-gradient(1px 1px at 230px 60px, #fff, transparent);
	background-size: 250px 250px;
	opacity: .75;
	animation: tp-pbg-twinkle 4.5s ease-in-out infinite alternate;
}

.tp-pbg-layer--night > i:nth-child(2) {
	background-image:
		radial-gradient(1.5px 1.5px at 60px 40px, #fff, transparent),
		radial-gradient(1.5px 1.5px at 300px 120px, #fff, transparent),
		radial-gradient(1.5px 1.5px at 180px 300px, #fff, transparent),
		radial-gradient(1.5px 1.5px at 340px 330px, #fff, transparent),
		radial-gradient(1.5px 1.5px at 20px 260px, #fff, transparent);
	background-size: 380px 380px;
	animation: tp-pbg-twinkle 6.5s ease-in-out infinite alternate-reverse;
}

.tp-pbg-layer--night > i:nth-child(3) {
	background-image:
		radial-gradient(2px 2px at 120px 90px, color-mix(in oklab, var(--tp-pbg-c1, #38bdf8) 45%, #fff), transparent),
		radial-gradient(2px 2px at 420px 260px, #fff, transparent),
		radial-gradient(2.5px 2.5px at 260px 470px, color-mix(in oklab, var(--tp-pbg-c2, #818cf8) 45%, #fff), transparent);
	background-size: 560px 560px;
	animation: tp-pbg-twinkle 9s ease-in-out infinite alternate;
}

/* 流れ星（2本・時間をずらして） */
.tp-pbg-layer--night > i:nth-child(4),
.tp-pbg-layer--night > i:nth-child(5) {
	display: block;
	width: 11%;
	min-width: 60px;
	height: 1.5px;
	border-radius: 2px;
	/* 進む向き（回転後の右端）が明るい頭、うしろが尾 */
	background: linear-gradient(90deg, rgb(255 255 255 / 0), #fff);
	opacity: 0;
	transform-origin: 0 50%;
	animation: tp-pbg-shoot 11s ease-in infinite;
}

.tp-pbg-layer--night > i:nth-child(4) {
	top: 14%; left: 72%;
	animation-delay: 2s;
}

.tp-pbg-layer--night > i:nth-child(5) {
	top: 34%; left: 92%;
	animation-delay: 7.5s;
}

/* =========================================================
   3. 動き
   ========================================================= */
@keyframes tp-pbg-morph1 {
	0%, 100% { border-radius: 58% 42% 37% 63% / 46% 55% 45% 54%; }
	25%      { border-radius: 38% 62% 56% 44% / 62% 38% 62% 38%; }
	50%      { border-radius: 64% 36% 44% 56% / 38% 64% 36% 62%; }
	75%      { border-radius: 45% 55% 62% 38% / 57% 42% 58% 43%; }
}

@keyframes tp-pbg-morph2 {
	0%, 100% { border-radius: 42% 58% 63% 37% / 58% 41% 59% 42%; }
	30%      { border-radius: 66% 34% 38% 62% / 41% 63% 37% 59%; }
	55%      { border-radius: 35% 65% 55% 45% / 63% 36% 64% 37%; }
	80%      { border-radius: 55% 45% 33% 67% / 44% 57% 43% 56%; }
}

@keyframes tp-pbg-morph3 {
	0%, 100% { border-radius: 50% 50% 42% 58% / 62% 36% 64% 38%; }
	28%      { border-radius: 62% 38% 60% 40% / 36% 60% 40% 64%; }
	62%      { border-radius: 34% 66% 48% 52% / 55% 44% 56% 45%; }
	85%      { border-radius: 58% 42% 36% 64% / 42% 62% 38% 58%; }
}

@keyframes tp-pbg-float1 {
	0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
	22%      { transform: translate3d(38%, 42%, 0) rotate(48deg) scale(1.12); }
	48%      { transform: translate3d(-22%, 88%, 0) rotate(-30deg) scale(.9); }
	74%      { transform: translate3d(48%, -46%, 0) rotate(72deg) scale(1.07); }
}

@keyframes tp-pbg-float2 {
	0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
	26%      { transform: translate3d(-44%, -48%, 0) rotate(-55deg) scale(1.1); }
	54%      { transform: translate3d(30%, -92%, 0) rotate(35deg) scale(.88); }
	78%      { transform: translate3d(-34%, 34%, 0) rotate(-80deg) scale(1.05); }
}

@keyframes tp-pbg-float3 {
	0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
	20%      { transform: translate3d(-36%, 60%, 0) rotate(60deg) scale(.92); }
	52%      { transform: translate3d(62%, 24%, 0) rotate(-45deg) scale(1.15); }
	80%      { transform: translate3d(14%, -70%, 0) rotate(90deg) scale(1.02); }
}

@keyframes tp-pbg-aurora1 {
	from { transform: translate3d(0, 0, 0) scale(1); }
	to   { transform: translate3d(22%, 16%, 0) scale(1.18); }
}

@keyframes tp-pbg-aurora2 {
	from { transform: translate3d(0, 0, 0) scale(1.05); }
	to   { transform: translate3d(-20%, 22%, 0) scale(.9); }
}

@keyframes tp-pbg-aurora3 {
	from { transform: translate3d(0, 0, 0) scale(.95); }
	to   { transform: translate3d(14%, -20%, 0) scale(1.15); }
}

@keyframes tp-pbg-ribbon {
	from { transform: translate3d(-8%, -6%, 0) rotate(-14deg); }
	to   { transform: translate3d(8%, 10%, 0) rotate(-6deg); }
}

@keyframes tp-pbg-twinkle {
	from { opacity: .35; }
	to   { opacity: 1; }
}

@keyframes tp-pbg-shoot {
	0%   { opacity: 0; transform: rotate(152deg) translateX(0); }
	2%   { opacity: 1; }
	9%   { opacity: 0; transform: rotate(152deg) translateX(520%); }
	100% { opacity: 0; transform: rotate(152deg) translateX(520%); }
}

/* 動きを止める（設定）／「視差効果を減らす」の端末 */
.tp-pbg-layer.is-still > i {
	animation: none !important;
}

.tp-pbg-layer--night.is-still > i:nth-child(4),
.tp-pbg-layer--night.is-still > i:nth-child(5) {
	display: none;
}

@media (prefers-reduced-motion: reduce) {
	.tp-pbg-layer > i {
		animation: none !important;
	}

	.tp-pbg-layer--night > i:nth-child(4),
	.tp-pbg-layer--night > i:nth-child(5) {
		display: none;
	}
}

/* スマホ：アメーバは3匹にして1匹ずつを大きく */
@media (max-width: 600px) {
	.tp-pbg-layer--amoeba > i:nth-child(n+4) {
		display: none;
	}

	.tp-pbg-layer--amoeba > i:nth-child(1) { width: 62%; }
	.tp-pbg-layer--amoeba > i:nth-child(2) { width: 58%; }
	.tp-pbg-layer--amoeba > i:nth-child(3) { width: 44%; top: 40%; }

	.tp-pbg-layer--aurora > i:nth-child(-n+3) { width: 150%; }
	.tp-pbg-layer--aurora > i:nth-child(4) { height: 24%; }
}

/* =========================================================
   4. エディターの見本（右サイドバー）
   ========================================================= */
.tp-pbg-preview,
.tp-pbg-tile-art {
	position: relative;
	display: block;
	overflow: hidden;
	isolation: isolate;
}

.tp-pbg-preview .tp-pbg-layer,
.tp-pbg-tile-art .tp-pbg-layer {
	position: absolute;
	z-index: 0;
}

.tp-pbg-preview .tp-pbg-layer {
	--tp-pbg-b: .35;
}

.tp-pbg-tile-art .tp-pbg-layer {
	--tp-pbg-b: .18;
}

.tp-pbg-preview-card {
	position: absolute;
	z-index: 1;
	inset: 22% 14% 14%;
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 10px 12px;
	border: 1px solid rgb(255 255 255 / .75);
	border-radius: 6px;
	background: rgb(var(--tp-pbg-card-rgb, 255 255 255) / calc(var(--tp-pbg-card, var(--tp-pbg-card-d, 72)) / 100));
	box-shadow: 0 6px 18px rgb(31 41 90 / .12);
}

.tp-pbg-preview-card > span {
	display: block;
	height: 6px;
	border-radius: 3px;
	background: #c7ccd6;
}

.tp-pbg-preview-card > span:first-child {
	width: 55%;
	height: 9px;
	background: #6b7280;
}

.tp-pbg-preview-card > span:nth-child(3) {
	width: 80%;
}
