/*
 * トップのファーストビューの、期間限定のクリスマスの飾り（library/v2/xmas.php）。
 * .v2-hero に is-xmas-snow / is-xmas-tree が付いたものだけを出す。
 * 雪は白の結晶、ツリーは白・緑・赤の光の粒。動かすのは transform（scale・rotate・translate を含む）と opacity だけ。
 */
@layer components {
	.v2-xmas-snow,
	.v2-xmas-tree {
		display: none;
	}

	.is-xmas-snow .v2-xmas-snow,
	.is-xmas-tree .v2-xmas-tree {
		display: block;
	}

	/* 雪とツリーは面の大きさに合わせて動かすので、面の幅・高さを cq の単位で使う */
	.is-xmas-snow .v2-hero__plane--r,
	.is-xmas-tree .v2-hero__plane--r {
		container-type: size;
	}

	/* ===== A: 雪 ===== */
	/* 雪の結晶の形 3 種（樹枝状・中心が六角の板・細かい枝の多い形）。白で描いた SVG をマスクに使う */
	.v2-xmas-snow {
		--xtal-1: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='1.1' stroke-linecap='round' stroke-linejoin='round'%3E%3Cdefs%3E%3Cg id='a'%3E%3Cpath d='M12 12V1.5M12 8.4l-2.5-2.5M12 8.4l2.5-2.5M12 5l-1.7-1.7M12 5l1.7-1.7'/%3E%3C/g%3E%3C/defs%3E%3Cuse href='%23a'/%3E%3Cuse href='%23a' transform='rotate%2860 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28120 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28180 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28240 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28300 12 12%29'/%3E%3Cpath d='M12 9.8l1.9 1.1v2.2L12 14.2l-1.9-1.1v-2.2z'/%3E%3C/svg%3E");
		--xtal-2: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cdefs%3E%3Cg id='a'%3E%3Cpath d='M12 12V3.2M12 7l-1.6-1.6M12 7l1.6-1.6M12 1.4l1 1.3-1 1.3-1-1.3z'/%3E%3C/g%3E%3C/defs%3E%3Cuse href='%23a'/%3E%3Cuse href='%23a' transform='rotate%2860 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28120 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28180 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28240 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28300 12 12%29'/%3E%3Cpath d='M12 8.8l2.8 1.6v3.2L12 15.2l-2.8-1.6v-3.2z' fill='%23fff'/%3E%3C/svg%3E");
		--xtal-3: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='0.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cdefs%3E%3Cg id='a'%3E%3Cpath d='M12 12V1.2M12 9.6l-1.5-1.5M12 9.6l1.5-1.5M12 7.2l-1.9-1.9M12 7.2l1.9-1.9M12 4.6l-1.5-1.5M12 4.6l1.5-1.5M12 2.6l-.8-.8M12 2.6l.8-.8'/%3E%3C/g%3E%3C/defs%3E%3Cuse href='%23a'/%3E%3Cuse href='%23a' transform='rotate%2860 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28120 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28180 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28240 12 12%29'/%3E%3Cuse href='%23a' transform='rotate%28300 12 12%29'/%3E%3C/svg%3E");
		position: absolute;
		inset: 0;
	}

	/*
	 * 雪は白の結晶。外の span がゆっくり落ち、中の i が左右に揺れながら傾く。2 つの周期がずれるので、ふわふわと舞って見える。
	 * --s（0.45〜1）で大きさ（12〜28px）と濃さを変え、小さいものほど薄くして奥行きを出す。値は 1 粒ずつスクリプトが決める
	 */
	.v2-xmas-snow__flake {
		position: absolute;
		top: -24px;
		left: var(--x);
		will-change: transform;
		animation: v2-xmas-fall var(--t) linear var(--d) infinite;
	}

	.v2-xmas-snow__xtal {
		--xtal: var(--xtal-1);
		display: block;
		width: calc(28px * var(--s));
		height: calc(28px * var(--s));
		background: var(--c-on-brand);
		opacity: calc(var(--s) - 0.05);
		mask: var(--xtal) center / contain no-repeat;
		animation: v2-xmas-sway var(--p) ease-in-out var(--pd) infinite alternate;
	}

	.v2-xmas-snow__flake.is-k2 .v2-xmas-snow__xtal {
		--xtal: var(--xtal-2);
	}

	.v2-xmas-snow__flake.is-k3 .v2-xmas-snow__xtal {
		--xtal: var(--xtal-3);
	}

	@keyframes v2-xmas-fall {
		to {
			transform: translate3d(var(--w), calc(100cqh + 48px), 0);
		}
	}

	@keyframes v2-xmas-sway {
		from {
			transform: translateX(calc(var(--a) * -1)) rotate(-25deg);
		}

		to {
			transform: translateX(var(--a)) rotate(25deg);
		}
	}

	/* ===== C: ツリー ===== */
	/*
	 * 光の粒を円すい形に集めたツリー。粒は根元から順に灯り、そのあと 1 粒ずつ違う間隔でまたたく。
	 * 一部の粒は立ちのぼって消え、てっぺんの星は光の筋が脈打つ。
	 * 面の右端に立てる。--tw はツリーの幅で、高さは幅の 1.5 倍。
	 * 幅は、てっぺんの星が AI 相談の箱の右端より右に来る大きさまで（右の空きの約 2 倍）にし、80〜300px に収める。
	 * 円すいなので、広い根元は箱より下に来て、粒が箱に隠れない。1359px 以下では出さない（下の @media）
	 */
	.v2-xmas-tree {
		--tw: clamp(80px, calc(100vw - var(--w-content) - var(--gutter) * 2 - 48px), 300px);
		position: absolute;
		right: 24px;
		bottom: 2%;
		width: var(--tw);
		height: calc(var(--tw) * 1.5);
	}

	/* 根元に広がる光のたまりと、円すいの内側のほのかな明るさ */
	.v2-xmas-tree__glow {
		position: absolute;
		inset: 10% -45% -12%;
		background:
			radial-gradient(ellipse 50% 14% at 50% 88%, rgb(255 243 196 / 0.32), rgb(95 211 141 / 0.12) 55%, transparent),
			radial-gradient(ellipse 22% 55% at 50% 62%, rgb(255 255 255 / 0.14), transparent 70%);
		animation:
			v2-xmas-fade 1.2s 1.2s both,
			v2-xmas-breathe 4s 2.4s ease-in-out infinite alternate;
	}

	.v2-xmas-tree__lights {
		position: absolute;
		inset: 0;
	}

	/* 光の粒。灯る（scale）とまたたく（opacity）は別のプロパティで重ねる */
	.v2-xmas-tree__dot {
		position: absolute;
		top: var(--y);
		left: var(--x);
		width: var(--z);
		height: var(--z);
		margin: calc(var(--z) / -2);
		border-radius: 50%;
		background: var(--c);
		box-shadow: 0 0 calc(var(--z) * 2) calc(var(--z) * 0.5) var(--c);
		animation:
			v2-xmas-on 0.5s var(--on) var(--ease-out) both,
			v2-xmas-twinkle var(--tt) var(--td) ease-in-out infinite alternate;
	}

	/* 立ちのぼる粒 */
	.v2-xmas-tree__dot.is-rise {
		animation:
			v2-xmas-on 0.5s var(--on) var(--ease-out) both,
			v2-xmas-rise var(--rt) var(--rd) ease-out infinite;
	}

	/* 根元のぼけた光の帯。大きく薄く、ゆっくりまたたく */
	.v2-xmas-tree__dot.is-bokeh {
		opacity: 0.35;
		box-shadow: 0 0 var(--z) calc(var(--z) * 0.4) var(--c);
		animation:
			v2-xmas-on 0.8s 1.2s var(--ease-out) both,
			v2-xmas-bokeh calc(var(--tt) * 2) var(--td) ease-in-out infinite alternate;
	}

	@keyframes v2-xmas-bokeh {
		from {
			opacity: 0.12;
		}

		to {
			opacity: 0.45;
		}
	}

	/* 星: 白い芯から縦横に光の筋が伸びる */
	.v2-xmas-tree__star {
		position: absolute;
		top: 0;
		left: 50%;
		width: 16px;
		height: 16px;
		margin: -8px;
		border-radius: 50%;
		background: radial-gradient(circle, #fff 0 28%, rgb(255 243 196 / 0.7) 42%, transparent 70%);
		animation:
			v2-xmas-fade 0.6s 2.4s both,
			v2-xmas-pulse 2.2s 3s ease-in-out infinite alternate;
	}

	.v2-xmas-tree__star::before,
	.v2-xmas-tree__star::after {
		content: "";
		position: absolute;
		top: 50%;
		left: 50%;
		translate: -50% -50%;
	}

	.v2-xmas-tree__star::before {
		width: calc(var(--tw) * 0.75);
		height: 2px;
		background: linear-gradient(90deg, transparent, rgb(255 255 255 / 0.9), transparent);
	}

	.v2-xmas-tree__star::after {
		width: 2px;
		height: calc(var(--tw) * 0.45);
		background: linear-gradient(transparent, rgb(255 255 255 / 0.9), transparent);
	}

	@keyframes v2-xmas-on {
		from {
			scale: 0;
		}

		to {
			scale: 1;
		}
	}

	@keyframes v2-xmas-twinkle {
		from {
			opacity: 0.25;
		}

		to {
			opacity: 1;
		}
	}

	@keyframes v2-xmas-rise {
		0% {
			translate: 0 0;
			opacity: 0;
		}

		20% {
			opacity: 1;
		}

		100% {
			translate: 6px calc(var(--tw) * -0.5);
			opacity: 0;
		}
	}

	@keyframes v2-xmas-fade {
		from {
			opacity: 0;
		}
	}

	@keyframes v2-xmas-breathe {
		from {
			opacity: 0.7;
		}

		to {
			opacity: 1;
		}
	}

	@keyframes v2-xmas-pulse {
		from {
			scale: 0.8;
		}

		to {
			scale: 1.2;
		}
	}

	/* 1359px 以下は、AI 相談の箱の右にも下にもツリーを置ける空きが無い（箱の下は 60px ほど）ので出さない。
	   xmas.php のスクリプトも同じ値で粒を作るかを決めるので、変えるときは両方を直す */
	@media (max-width: 1359px) {
		.is-xmas-tree .v2-xmas-tree {
			display: none;
		}
	}

	/* 動きを減らす設定では、雪は散らした位置で止め、ツリーは灯った形で止める（立ちのぼる粒は出さない） */
	@media (prefers-reduced-motion: reduce) {
		.v2-xmas-snow__flake,
		.v2-xmas-snow__xtal,
		.v2-xmas-tree__glow,
		.v2-xmas-tree__dot,
		.v2-xmas-tree__dot.is-bokeh,
		.v2-xmas-tree__star {
			animation: none;
		}

		.v2-xmas-tree__dot.is-rise {
			display: none;
		}

		.v2-xmas-snow__flake {
			top: var(--y);
		}

		.v2-xmas-snow__xtal {
			transform: none;
		}
	}
}
