function l_star = solve_lstar(alpha)
%==========================================================================
% solve_lstar.m
% -------------------------------------------------------------------------
% Computes the optimal labor supply l* for a given preference parameter α.
% The household maximizes U(c,l) = c^α * (1 - l)^(1 - α)
% subject to c = w*l + (1+r)*a0 - T, with bounds 0 ≤ l ≤ 1.
%
% INPUT:
%   alpha  - preference parameter on consumption (0 < α < 1)
%
% OUTPUT:
%   l_star - optimal labor supply
%
% Used inside calibration routines to match target labor supply.
%==========================================================================

% --- Model parameters (can be adjusted if needed) ---
w  = 1;          % wage rate
r  = 0.02;       % interest rate
a0 = 0.05;       % initial assets
T  = 0.1;        % taxes or lump-sum transfer
eps_c = 1e-10;   % to avoid log(0) or negative consumption

% --- Objective: negative utility (for minimization) ---
Uneg = @(l) -((max(w*l + (1+r)*a0 - T, eps_c)).^alpha .* (1 - l).^(1 - alpha));

% --- Bounds and initial guess ---
lb = 0; ub = 1; l0 = 0.5;

% --- Solve using fmincon ---
opts = optimoptions('fmincon','Display','off');
l_star = fmincon(Uneg, l0, [], [], [], [], lb, ub, [], opts);

% --- Optional: clip to bounds to avoid numerical issues ---
l_star = max(min(l_star, ub), lb);

end