# Comprehensive Sandbox Control - selected-state and selected-country overlays

scripted_gui = {
	csc_state_sandbox_menu_gui = {
		context_type = selected_state_context
		window_name = "csc_state_sandbox_menu_container"
		parent_window_token = selected_state_view
		dirty = global.csc_state_gui_refresh
		ai_enabled = { always = no }
		visible = { ROOT = { csc_disruptive_enabled = yes } }
		effects = {
			csc_state_sandbox_menu_button_click = {
				if = {
					limit = { ROOT = { has_country_flag = csc_state_sandbox_open } }
					ROOT = {
						clr_country_flag = csc_state_sandbox_open
						clr_country_flag = csc_state_resources_tab_active
					}
				}
				else = {
					ROOT = {
						set_country_flag = csc_state_sandbox_open
						clr_country_flag = csc_state_resources_tab_active
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
		}
	}

	csc_state_sandbox_actions_panel_gui = {
		context_type = selected_state_context
		window_name = "csc_state_sandbox_actions_panel_container"
		parent_window_token = selected_state_view
		dirty = global.csc_state_gui_refresh
		ai_enabled = { always = no }
		visible = {
			ROOT = {
				csc_disruptive_enabled = yes
				has_country_flag = csc_state_sandbox_open
				NOT = { has_country_flag = csc_state_resources_tab_active }
			}
		}
		effects = {
			csc_state_sandbox_close_button_click = {
				ROOT = {
					clr_country_flag = csc_state_sandbox_open
					clr_country_flag = csc_state_resources_tab_active
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_actions_tab_click = {
				ROOT = { clr_country_flag = csc_state_resources_tab_active }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_resources_tab_click = {
				ROOT = { set_country_flag = csc_state_resources_tab_active }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_transfer_owner_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_transfer_owner
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_transfer_controller_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_transfer_controller
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_add_core_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_add_core
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_remove_core_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_remove_core
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_add_claim_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_add_claim
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_remove_claim_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_remove_claim
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_move_capital_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_move_capital
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_build_slots_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_build_slots
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_repair_buildings_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_repair_buildings
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_give_resource_rights_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_give_resource_rights
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_remove_resource_rights_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_state
					ROOT = {
						set_country_flag = csc_confirmation_pending
						set_country_flag = csc_pending_action_remove_resource_rights
						country_event = { id = csc_confirmation.1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			# Bulk multi-state transfer: mark/unmark the selected state (instant
			# toggle), transfer all marked states to ROOT (confirmed), clear marks.
			csc_state_sandbox_mark_state_button_click = {
				if = {
					limit = { ROOT = { is_in_array = { array = csc_marked_states_array value = PREV.id } } }
					ROOT = {
						remove_from_array = { array = csc_marked_states_array value = PREV.id }
						subtract_from_variable = { csc_marked_count = 1 }
					}
				}
				else = {
					ROOT = {
						add_to_array = { array = csc_marked_states_array value = PREV.id }
						add_to_variable = { csc_marked_count = 1 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_transfer_marked_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					ROOT = {
						set_country_flag = csc_confirmation_pending
						country_event = { id = csc_confirmation.3 }
					}
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sandbox_clear_marks_button_click = {
				ROOT = {
					clear_array = csc_marked_states_array
					set_variable = { csc_marked_count = 0 }
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
		}
		triggers = {
			csc_state_sandbox_transfer_owner_button_click_enabled = {
				NOT = { is_owned_by = ROOT }
			}
			csc_state_sandbox_transfer_controller_button_click_enabled = {
				NOT = { is_controlled_by = ROOT }
			}
			csc_state_sandbox_add_core_button_click_enabled = {
				NOT = { is_core_of = ROOT }
			}
			csc_state_sandbox_remove_core_button_click_enabled = {
				is_core_of = ROOT
			}
			csc_state_sandbox_add_claim_button_click_enabled = {
				NOT = { is_claimed_by = ROOT }
			}
			csc_state_sandbox_remove_claim_button_click_enabled = {
				is_claimed_by = ROOT
			}
			csc_state_sandbox_move_capital_button_click_enabled = {
				is_owned_by = ROOT
				NOT = { is_capital = yes }
			}
			csc_state_sandbox_build_slots_button_click_enabled = {
				is_owned_by = ROOT
			}
			csc_state_sandbox_repair_buildings_button_click_enabled = {
				is_controlled_by = ROOT
			}
			csc_state_sandbox_give_resource_rights_button_click_enabled = {
				NOT = { is_owned_by = ROOT }
				NOT = { ROOT = { has_resources_rights = { state = PREV } } }
			}
			csc_state_sandbox_remove_resource_rights_button_click_enabled = {
				ROOT = { has_resources_rights = { state = PREV } }
			}
			# Mark only states ROOT does not own (you transfer them TO yourself).
			csc_state_sandbox_mark_state_button_click_enabled = {
				NOT = { is_owned_by = ROOT }
			}
			# Transfer / clear are available only when something is marked.
			csc_state_sandbox_transfer_marked_button_click_enabled = {
				ROOT = { check_variable = { csc_marked_count > 0 } }
			}
			csc_state_sandbox_clear_marks_button_click_enabled = {
				ROOT = { check_variable = { csc_marked_count > 0 } }
			}
		}
	}

	csc_state_sandbox_resources_panel_gui = {
		context_type = selected_state_context
		window_name = "csc_state_sandbox_resources_panel_container"
		parent_window_token = selected_state_view
		dirty = global.csc_state_gui_refresh
		ai_enabled = { always = no }
		visible = {
			ROOT = {
				csc_disruptive_enabled = yes
				has_country_flag = csc_state_sandbox_open
				has_country_flag = csc_state_resources_tab_active
			}
		}
		effects = {
			csc_state_sandbox_resources_close_button_click = {
				ROOT = {
					clr_country_flag = csc_state_sandbox_open
					clr_country_flag = csc_state_resources_tab_active
				}
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_actions_tab_click = {
				ROOT = { clr_country_flag = csc_state_resources_tab_active }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_resources_tab_click = {
				ROOT = { set_country_flag = csc_state_resources_tab_active }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			# Shared increment selector. The active step is stored globally and
			# applied by every resource + / - button.
			csc_step_1_click = {
				set_variable = { global.csc_resource_step = 1 }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_step_5_click = {
				set_variable = { global.csc_resource_step = 5 }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_step_10_click = {
				set_variable = { global.csc_resource_step = 10 }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			# Default scope is the selected state. + adds the selected increment;
			# - removes min(step, current) so the value clamps at zero with no
			# hidden negative production modifier. resource@<token> reads the live
			# state amount.
			csc_state_add_oil_click = {
				add_resource = { type = oil amount = global.csc_resource_step }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sub_oil_click = {
				set_temp_variable = { csc_resource_remove = resource@oil }
				if = {
					limit = { check_variable = { csc_resource_remove > global.csc_resource_step } }
					set_temp_variable = { csc_resource_remove = global.csc_resource_step }
				}
				multiply_temp_variable = { csc_resource_remove = -1 }
				add_resource = { type = oil amount = csc_resource_remove }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_add_aluminium_click = {
				add_resource = { type = aluminium amount = global.csc_resource_step }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sub_aluminium_click = {
				set_temp_variable = { csc_resource_remove = resource@aluminium }
				if = {
					limit = { check_variable = { csc_resource_remove > global.csc_resource_step } }
					set_temp_variable = { csc_resource_remove = global.csc_resource_step }
				}
				multiply_temp_variable = { csc_resource_remove = -1 }
				add_resource = { type = aluminium amount = csc_resource_remove }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_add_rubber_click = {
				add_resource = { type = rubber amount = global.csc_resource_step }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sub_rubber_click = {
				set_temp_variable = { csc_resource_remove = resource@rubber }
				if = {
					limit = { check_variable = { csc_resource_remove > global.csc_resource_step } }
					set_temp_variable = { csc_resource_remove = global.csc_resource_step }
				}
				multiply_temp_variable = { csc_resource_remove = -1 }
				add_resource = { type = rubber amount = csc_resource_remove }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_add_tungsten_click = {
				add_resource = { type = tungsten amount = global.csc_resource_step }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sub_tungsten_click = {
				set_temp_variable = { csc_resource_remove = resource@tungsten }
				if = {
					limit = { check_variable = { csc_resource_remove > global.csc_resource_step } }
					set_temp_variable = { csc_resource_remove = global.csc_resource_step }
				}
				multiply_temp_variable = { csc_resource_remove = -1 }
				add_resource = { type = tungsten amount = csc_resource_remove }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_add_steel_click = {
				add_resource = { type = steel amount = global.csc_resource_step }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sub_steel_click = {
				set_temp_variable = { csc_resource_remove = resource@steel }
				if = {
					limit = { check_variable = { csc_resource_remove > global.csc_resource_step } }
					set_temp_variable = { csc_resource_remove = global.csc_resource_step }
				}
				multiply_temp_variable = { csc_resource_remove = -1 }
				add_resource = { type = steel amount = csc_resource_remove }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_add_chromium_click = {
				add_resource = { type = chromium amount = global.csc_resource_step }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sub_chromium_click = {
				set_temp_variable = { csc_resource_remove = resource@chromium }
				if = {
					limit = { check_variable = { csc_resource_remove > global.csc_resource_step } }
					set_temp_variable = { csc_resource_remove = global.csc_resource_step }
				}
				multiply_temp_variable = { csc_resource_remove = -1 }
				add_resource = { type = chromium amount = csc_resource_remove }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_add_coal_click = {
				add_resource = { type = coal amount = global.csc_resource_step }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
			csc_state_sub_coal_click = {
				set_temp_variable = { csc_resource_remove = resource@coal }
				if = {
					limit = { check_variable = { csc_resource_remove > global.csc_resource_step } }
					set_temp_variable = { csc_resource_remove = global.csc_resource_step }
				}
				multiply_temp_variable = { csc_resource_remove = -1 }
				add_resource = { type = coal amount = csc_resource_remove }
				add_to_variable = { global.csc_state_gui_refresh = 1 }
			}
		}
		triggers = {
			# The active increment button greys out to show the selection.
			csc_step_1_click_enabled = {
				NOT = { check_variable = { global.csc_resource_step = 1 } }
			}
			csc_step_5_click_enabled = {
				NOT = { check_variable = { global.csc_resource_step = 5 } }
			}
			csc_step_10_click_enabled = {
				NOT = { check_variable = { global.csc_resource_step = 10 } }
			}
			# Each - button is disabled when the state has none of that resource.
			csc_state_sub_oil_click_enabled = {
				has_resources_amount = { resource = oil amount > 0 }
			}
			csc_state_sub_aluminium_click_enabled = {
				has_resources_amount = { resource = aluminium amount > 0 }
			}
			csc_state_sub_rubber_click_enabled = {
				has_resources_amount = { resource = rubber amount > 0 }
			}
			csc_state_sub_tungsten_click_enabled = {
				has_resources_amount = { resource = tungsten amount > 0 }
			}
			csc_state_sub_steel_click_enabled = {
				has_resources_amount = { resource = steel amount > 0 }
			}
			csc_state_sub_chromium_click_enabled = {
				has_resources_amount = { resource = chromium amount > 0 }
			}
			csc_state_sub_coal_click_enabled = {
				has_resources_amount = { resource = coal amount > 0 }
			}
		}
	}

	csc_country_sandbox_menu_gui = {
		context_type = selected_country_context
		window_name = "csc_country_sandbox_menu_container"
		parent_window_token = selected_country_view
		dirty = global.csc_country_gui_refresh
		ai_enabled = { always = no }
		visible = { ROOT = { csc_disruptive_enabled = yes } }
		effects = {
			csc_country_sandbox_menu_button_click = {
				if = {
					limit = { ROOT = { has_country_flag = csc_country_sandbox_open } }
					ROOT = { clr_country_flag = csc_country_sandbox_open }
				}
				else = { ROOT = { set_country_flag = csc_country_sandbox_open } }
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
		}
	}


	csc_country_sandbox_panel_gui = {
		context_type = selected_country_context
		window_name = "csc_country_sandbox_panel_container"
		dirty = global.csc_country_gui_refresh
		ai_enabled = { always = no }
		visible = {
			ROOT = {
				csc_disruptive_enabled = yes
				has_country_flag = csc_country_sandbox_open
			}
		}
		effects = {
			csc_country_sandbox_close_button_click = {
				ROOT = { clr_country_flag = csc_country_sandbox_open }
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_annex_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_annex country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_puppet_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_puppet country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_release_subject_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_release_subject country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_grant_independence_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_grant_independence country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_set_autonomy_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_set_autonomy country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_white_peace_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_white_peace country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_faction_invite_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_faction_invite country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_faction_remove_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_faction_remove country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_leave_faction_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_leave_faction country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_create_faction_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_create_faction country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_dismantle_faction_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_dismantle_faction country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
			csc_country_sandbox_set_faction_leader_button_click = {
				if = {
					limit = { ROOT = { NOT = { has_country_flag = csc_confirmation_pending } } }
					save_global_event_target_as = csc_pending_target_country
					ROOT = { set_country_flag = csc_confirmation_pending set_country_flag = csc_pending_action_set_faction_leader country_event = { id = csc_confirmation.2 } }
				}
				add_to_variable = { global.csc_country_gui_refresh = 1 }
			}
		}
		triggers = {
			csc_country_sandbox_annex_button_click_enabled = {
				exists = yes NOT = { tag = ROOT }
			}
			csc_country_sandbox_puppet_button_click_enabled = {
				exists = yes NOT = { tag = ROOT } NOT = { is_subject_of = ROOT }
			}
			csc_country_sandbox_release_subject_button_click_enabled = {
				exists = yes is_subject = yes is_subject_of = ROOT
			}
			csc_country_sandbox_grant_independence_button_click_enabled = {
				exists = yes is_subject_of = ROOT
			}
			csc_country_sandbox_set_autonomy_button_click_enabled = {
				exists = yes is_subject_of = ROOT
			}
			csc_country_sandbox_white_peace_button_click_enabled = {
				exists = yes has_war_with = ROOT
			}
			csc_country_sandbox_faction_invite_button_click_enabled = {
				exists = yes
				NOT = { tag = ROOT }
				ROOT = { is_in_faction = yes is_faction_leader = yes }
				NOT = { is_in_faction_with = ROOT }
			}
			csc_country_sandbox_faction_remove_button_click_enabled = {
				exists = yes
				NOT = { tag = ROOT }
				ROOT = { is_in_faction = yes is_faction_leader = yes }
				is_in_faction_with = ROOT
			}
			csc_country_sandbox_leave_faction_button_click_enabled = {
				ROOT = { is_in_faction = yes }
			}
			csc_country_sandbox_create_faction_button_click_enabled = {
				exists = yes
				NOT = { tag = ROOT }
				ROOT = { is_in_faction = no }
				NOT = { is_in_faction = yes }
			}
			csc_country_sandbox_dismantle_faction_button_click_enabled = {
				ROOT = { is_in_faction = yes is_faction_leader = yes }
			}
			csc_country_sandbox_set_faction_leader_button_click_enabled = {
				exists = yes is_in_faction_with = ROOT NOT = { is_faction_leader = yes }
			}
		}
	}

}
