on_actions = {

	on_daily = {
		effect = {
			# College construction countdown
			if = {
				limit = {
					check_variable = { wc_construction_active = 1 }
				}
				subtract_from_variable = { wc_construction_days_remaining = 1 }
				if = {
					limit = {
						check_variable = { wc_construction_days_remaining < 1 }
					}
					wc_complete_construction_effect = yes
				}
			}

			# Recompute the construction progress bar's x offset each day.
			# Math: bar_x = -days_remaining * 377 / 90
			#   days = 90 (just started) -> bar_x = -377 (fully clipped)
			#   days = 45 (halfway)      -> bar_x = -188 (half visible)
			#   days =  0 (done)         -> bar_x =    0 (fully visible)
			# The clipping container in the .gui hides the overhang so the
			# bar appears to fill from left to right.
			# Skipped if construction just completed (the if above cleared
			# wc_construction_active to 0, so this branch won't fire).
			if = {
				limit = {
					check_variable = { wc_construction_active = 1 }
				}
				set_variable = { wc_construction_bar_x = wc_construction_days_remaining }
				multiply_variable = { wc_construction_bar_x = -377 }
				divide_variable = { wc_construction_bar_x = 90 }
			}

			# Phase cooldown countdown - decrement only while a training is
			# active and the cooldown is still running. Floor at 0.
			# When the phase 3 cooldown hits 0 (the "final training period"
			# elapses), grant the 180-day mastery idea exactly once. The
			# wc_phase_cooldown_days < 1 check after the decrement catches
			# the transition step.
			if = {
				limit = {
					check_variable = { wc_training_active = 1 }
					check_variable = { wc_phase_cooldown_days > 0 }
				}
				subtract_from_variable = { wc_phase_cooldown_days = 1 }
				if = {
					limit = {
						check_variable = { wc_training_phase = 3 }
						check_variable = { wc_phase_cooldown_days < 1 }
					}
					wc_grant_mastery_for_active_training_effect = yes
				}
			}

			# Auto-advance: if the player toggled the checkbox on, push
			# the active training to the next phase as soon as cooldown
			# expires AND the equipment is on hand. Only covers phases
			# 0->1->2->3; the final 30-day mastery period and the
			# Conclude click stay manual (per design - we don't restart
			# trainings, just automate the three advance clicks).
			if = {
				limit = {
					check_variable = { wc_auto_advance_enabled = 1 }
					check_variable = { wc_training_active = 1 }
					check_variable = { wc_phase_cooldown_days < 1 }
					check_variable = { wc_training_phase < 3 }
					wc_can_pay_current_phase = yes
				}
				wc_advance_active_training_effect = yes
			}

			# Academy upgrade countdown. Same pattern as the construction
			# countdown above: decrement, and when it hits 0 fire the
			# completion handler exactly once. The civ-drain timed idea
			# self-removes at the same step.
			if = {
				limit = {
					check_variable = { wc_active_upgrade_id > 0 }
					check_variable = { wc_upgrade_days_remaining > 0 }
				}
				subtract_from_variable = { wc_upgrade_days_remaining = 1 }
				if = {
					limit = { check_variable = { wc_upgrade_days_remaining < 1 } }
					wc_complete_upgrade_effect = yes
				}
			}

			# Daily academy XP grant for assigned officers. Only ticks
			# while the college is built; the grant per officer is
			# inside wc_academy_daily_tick_effect.
			if = {
				limit = { check_variable = { wc_built = 1 } }
				wc_academy_daily_tick_effect = yes
			}
		}
	}
}
