@property --toggle-orbit {
	syntax: "<angle>";
	inherits: true;
	initial-value: 0deg;
}

@property --toggle-light {
	syntax: "<color>";
	inherits: true;
	initial-value: #ffa82e;
}

@property --toggle-glow {
	syntax: "<color>";
	inherits: true;
	initial-value: transparent;
}

@property --toggle-hover-shadow {
	syntax: "<color>";
	inherits: true;
	initial-value: transparent;
}

@property --toggle-fill {
	syntax: "<color>";
	inherits: true;
	initial-value: transparent;
}

@property --toggle-hover-blur {
	syntax: "<length>";
	inherits: true;
	initial-value: 10px;
}

@property --sunray1 {
	syntax: "<percentage>";
	inherits: true;
	initial-value: 27%;
}

@property --sunlight {
	syntax: "<percentage>";
	inherits: true;
	initial-value: 91%;
}

.theme-toggle {
	--toggle-speed: var(--duration-theme-expand);
	--ray-step: calc(var(--stagger-step) / 2);
	--toggle-orbit: calc(var(--theme-turn, 0) * 180deg);
	--toggle-border: var(--accent-border);
	--toggle-light: light-dark(var(--toggle-sun), var(--toggle-moon));
	--toggle-glow: light-dark(
		color-mix(in oklch, var(--toggle-light) 70%, transparent),
		color-mix(in oklch, var(--toggle-light) 85%, transparent)
	);
	--toggle-fill: var(--button-bg);
	appearance: none;
	padding: 0;
	font-size: 1rem;
	border: 2px solid transparent;
	border-radius: var(--radius-5);
	background:
		linear-gradient(var(--toggle-fill), var(--toggle-fill)) padding-box,
		conic-gradient(
			from calc(var(--toggle-orbit) - 70deg),
			var(--toggle-border),
			var(--toggle-light) 70deg,
			var(--toggle-border) 140deg
		)
		border-box;
	--toggle-hover-blur: 10px;
	--toggle-hover-shadow: transparent;
	box-shadow:
		calc(sin(var(--toggle-orbit)) * 3px) calc(cos(var(--toggle-orbit)) * -3px)
		10px -3px var(--toggle-glow),
		0 0 var(--toggle-hover-blur) var(--toggle-hover-shadow);
	color: var(--text-color);
	cursor: pointer;
	margin-left: 5px;
	display: flex;
	align-items: center;
	justify-content: center;
	height: calc(1rem + 15px + 6px);
	width: calc(1rem + 15px + 6px);
	position: relative;
	overflow: hidden;
	transition:
		--toggle-orbit var(--toggle-speed) var(--ease-in-out) var(--stagger-step),
		--toggle-light var(--toggle-speed) var(--ease-out),
		--toggle-glow var(--toggle-speed) var(--ease-out),
		--toggle-fill var(--duration-3) var(--ease-out),
		--toggle-hover-shadow var(--duration-3) var(--ease-out),
		--toggle-hover-blur var(--duration-3) var(--ease-out),
		transform var(--duration-2) var(--ease-out);
}

[data-theme="light"] .theme-toggle {
	--toggle-speed: var(--duration-theme-collapse);
}

.theme-icon {
	position: relative;
	z-index: var(--z-local-3);
	width: calc(1rem + 5px);
	height: calc(1rem + 5px);
	overflow: visible;
	transition: transform var(--duration-3) var(--ease-out);
}

.theme-icon
	:is(
		.theme-icon-core,
		.theme-icon-cut,
		.theme-icon-rays,
		.theme-icon-rays line
	) {
	transform-box: view-box;
	transform-origin: 12px 12px;
}

.theme-icon-rays {
	transition: transform var(--duration-3) var(--ease-out);
}

.theme-icon-rays line {
	transition:
		transform var(--duration-4) var(--ease-spring)
		calc(var(--duration-3) + var(--i) * var(--ray-step)),
		opacity var(--duration-2) var(--ease-out)
		calc(var(--duration-3) + var(--i) * var(--ray-step));
}

.theme-icon-core {
	transition: transform var(--duration-4) var(--ease-spring-soft);
}

.theme-icon-cut {
	transform: translate(13px, -13px);
	transition: transform var(--duration-4) var(--ease-in-out);
}

.theme-icon-stars {
	transform-box: view-box;
	opacity: 0;
	transform: scale(0.4) rotate(-45deg);
	transform-origin: 19.5px 4.5px;
	transition:
		opacity var(--duration-1) var(--ease-out),
		transform var(--duration-1) var(--ease-out);
}

[data-theme="dark"] .theme-icon-rays line {
	opacity: 0;
	transform: scale(0.3);
	transition:
		transform var(--duration-3) var(--ease-in-out)
		calc(var(--i) * var(--ray-step)),
		opacity var(--duration-3) var(--ease-out)
		calc(var(--stagger-step) + var(--i) * var(--ray-step));
}

[data-theme="dark"] .theme-icon-core {
	transform: scale(1.7);
	transition: transform var(--duration-5) var(--ease-spring-soft)
		var(--duration-1);
}

[data-theme="dark"] .theme-icon-cut {
	transform: translate(2.5px, -2.5px);
	transition: transform var(--duration-5) var(--ease-spring-soft)
		var(--duration-1);
}

[data-theme="dark"] .theme-icon-stars {
	opacity: 1;
	transform: none;
	transition:
		opacity var(--duration-3) var(--ease-out) var(--duration-5),
		transform var(--duration-4) var(--ease-spring) var(--duration-5);
	animation: theme-star-twinkle calc(var(--duration-loop) * 2.8)
		var(--ease-in-out)
		calc(var(--duration-5) + var(--duration-4) + var(--duration-3))
		var(--loop-count);
}

@keyframes theme-star-twinkle {
	50% {
		opacity: 0.45;
	}
}

.theme-toggle::before {
	content: "";
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: var(--z-local-1);
	background:
		radial-gradient(
			circle at 50% calc(100% - 0.3em),
			rgba(255, 239, 203, 0.95) 0.075em,
			rgba(255, 204, 153, 0.8),
			rgba(255, 183, 102, 0.6),
			rgba(255, 162, 51, 0.4),
			rgba(255, 142, 0, 0.2),
			transparent 1.4em
		)
		50% 100%,
		radial-gradient(
			circle at 50% calc(100% - 0.2em),
			rgba(255, 255, 255, 0.9) 0.25em,
			rgba(255, 255, 255, 0.7) 0.6em,
			transparent 1.2em
		),
		repeating-conic-gradient(
			at 50% calc(100% - 0.3em),
			rgba(255, 255, 255, 0.05) 0 4%,
			transparent 9%
		)
		50% 50% / 100% 100%,
		repeating-conic-gradient(
			at 50% calc(100% - 0.3em),
			rgba(255, 255, 255, 0.03) 6%,
			transparent 14%
		)
		50% 50% / 100% 100%,
		repeating-conic-gradient(
			at 50% calc(100% - 0.3em),
			rgba(255, 255, 255, 0.03) 1deg,
			transparent 4deg
		)
		50% 50% / 100% 100%;
	mask: radial-gradient(
		farthest-side at 50% calc(100% - 0.3em),
		#000 85%,
		transparent
	);
	opacity: 0;
	transform: translate(0, 100%);
	transition:
		transform var(--duration-2) var(--ease-out),
		opacity var(--duration-2) var(--ease-out);
}

.theme-toggle::after {
	content: "";
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 120%;
	z-index: var(--z-local-2);
	border-radius: var(--radius-round);
	box-shadow: 0 -0.15em 0.3em -0.1em rgba(255, 255, 255, 0.8);
	background:
		radial-gradient(
			circle at 50% 0,
			rgba(255, 255, 255, 0.9),
			rgba(187, 177, 168, 0.8),
			rgba(228, 222, 215, 0.6),
			transparent 2.2em
		)
		50% 100%,
		radial-gradient(
			100% 50% at 50% 0,
			rgba(255, 255, 255, 0.5),
			transparent 20%
		),
		radial-gradient(
			farthest-side at 20% 50%,
			rgba(17, 8, 32, 0.5) 80%,
			transparent
		),
		radial-gradient(
			farthest-side at 70% 50%,
			rgba(8, 4, 16, 0.5) 80%,
			transparent
		),
		radial-gradient(60% 50%, rgba(18, 60, 96, 0.6) var(--sunlight), #ffff),
		repeating-conic-gradient(
			at 50% 0,
			transparent 27%,
			rgba(255, 255, 255, 0.15) var(--sunray1)
		),
		radial-gradient(
			farthest-side,
			rgba(1, 40, 96, 0.5) 60%,
			rgba(1, 35, 84, 0.4) 70%,
			rgba(238, 238, 238, 0.95) 99%
		);
	transform: translate(0, 65%);
	transition:
		transform var(--duration-2) var(--ease-out),
		box-shadow var(--duration-2) var(--ease-out),
		--sunray1 var(--duration-2) var(--ease-out),
		--sunlight var(--duration-2) var(--ease-out);
}

[data-theme="light"] .theme-toggle::before {
	opacity: 1;
	transform: translate(0, 0);
}

[data-theme="light"] .theme-toggle::after {
	--sunray1: 40%;
	--sunlight: 81%;
	transform: translate(0, 100%);
}

[data-theme="dark"] .theme-toggle::before {
	opacity: 0;
	transform: translate(0, 100%);
}

[data-theme="dark"] .theme-toggle::after {
	--sunray1: 27%;
	--sunlight: 91%;
	transform: translate(0, 65%);
}

@media (hover: hover) and (pointer: fine) {
	.theme-toggle:hover {
		--toggle-fill: var(--button-hover);
		--toggle-hover-shadow: var(--glow-color);
	}

	.theme-toggle:hover .theme-icon {
		transform: scale(1.05);
	}

	[data-theme="dark"] .theme-toggle:hover {
		--toggle-hover-blur: 12px;
	}

	[data-theme="light"] .theme-toggle:hover .theme-icon-rays {
		transform: rotate(45deg);
	}

	[data-theme="light"] .theme-toggle:hover::after {
		--sunlight: 85%;
	}

	[data-theme="dark"] .theme-toggle:hover::after {
		--sunlight: 88%;
	}
}
